Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plausibility check for realtime_free_capacity values #222

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions webapp/services/import_service/generic/generic_import_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,34 @@ def _save_realtime_parking_site_input(self, source: Source, realtime_parking_sit
original_uid=realtime_parking_site_input.uid,
)

parking_site_capacities = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typing :)

Also: the essential information is just one value: ' capacity' or 'capacity_woman' or ... . So it could be just a list of string, and then:

fields: list[str] = ['capacity', 'capacity_woman']

for field in fields:
    realtime_free_capacity = getattr(realtime_parking_site_input, f'realtime_free_{field}')

('realtime_capacity', 'realtime_free_capacity', parking_site.capacity),
('realtime_capacity_woman', 'realtime_free_capacity_woman', parking_site.capacity_woman),
('realtime_capacity_disabled', 'realtime_free_capacity_disabled', parking_site.capacity_disabled),
('realtime_capacity_charging', 'realtime_free_capacity_charging', parking_site.capacity_charging),
('realtime_capacity_carsharing', 'realtime_free_capacity_carsharing', parking_site.capacity_carsharing),
('realtime_capacity_bus', 'realtime_free_capacity_bus', parking_site.capacity_bus),
('realtime_capacity_family', 'realtime_free_capacity_family', parking_site.capacity_family),
('realtime_capacity_truck', 'realtime_free_capacity_truck', parking_site.capacity_truck),
]

for realtime_capacity_type, realtime_free_capacity_type, parking_site_capacity in parking_site_capacities:
realtime_free_capacity = getattr(realtime_parking_site_input, realtime_free_capacity_type)
realtime_capacity = getattr(realtime_parking_site_input, realtime_capacity_type)

if realtime_capacity == UnsetValue and realtime_free_capacity > parking_site.capacity:
setattr(realtime_parking_site_input, realtime_free_capacity, parking_site_capacity)
self.logger.warn(
LogMessageType.FAILED_PARKING_SITE_HANDLING,
f'At {parking_site.original_uid} from {source.id}, {realtime_free_capacity_type} {realtime_free_capacity} was higher than {realtime_capacity_type} {parking_site_capacity}',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is to long. Please make sure that you use ruff before committing. This can be done automatically using the pre commit hook which is part of the project. For more information about pre commit hooks, please visit https://pre-commit.com (not sure if that works at Windows, though).

)
elif realtime_capacity != UnsetValue and realtime_free_capacity > realtime_capacity:
setattr(realtime_parking_site_input, realtime_free_capacity, realtime_capacity)
self.logger.warn(
LogMessageType.FAILED_PARKING_SITE_HANDLING,
f'At {parking_site.original_uid} from {source.id}, {realtime_free_capacity_type} {realtime_free_capacity} was higher than {realtime_capacity_type} {realtime_capacity}',
)

history_enabled: bool = self.config_helper.get('HISTORY_ENABLED', False)
history_changed = False
for key, value in realtime_parking_site_input.to_dict().items():
Expand Down