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 1 commit
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
178 changes: 178 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,184 @@ def _save_realtime_parking_site_input(self, source: Source, realtime_parking_sit
original_uid=realtime_parking_site_input.uid,
)

if (
Copy link
Collaborator

Choose a reason for hiding this comment

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

That's a lot of copy-pasted code. Please make an approach which loops over the properties you want to handle instead of copy pasting code.

Copy link
Author

Choose a reason for hiding this comment

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

It's now resolved, thanks for the tip!

realtime_parking_site_input.realtime_capacity == UnsetValue
and realtime_parking_site_input.realtime_free_capacity > parking_site.capacity
):
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 {realtime_parking_site_input.realtime_free_capacity} was higher than capacity {parking_site.capacity}',
)
elif (
realtime_parking_site_input.realtime_capacity != UnsetValue
and realtime_parking_site_input.realtime_free_capacity > realtime_parking_site_input.realtime_capacity
):
realtime_parking_site_input.realtime_free_capacity = realtime_parking_site_input.realtime_capacity
self.logger.warn(
LogMessageType.FAILED_PARKING_SITE_HANDLING,
f'At {parking_site.original_uid} from {source.id}, realtime_free_capacity {realtime_parking_site_input.realtime_free_capacity} was higher than realtime_capacity {realtime_parking_site_input.realtime_capacity}',
)

if (
realtime_parking_site_input.realtime_capacity_woman == UnsetValue
and realtime_parking_site_input.realtime_free_capacity_woman > parking_site.capacity_woman
):
realtime_parking_site_input.realtime_free_capacity_woman = parking_site.capacity_woman
self.logger.warn(
LogMessageType.FAILED_PARKING_SITE_HANDLING,
f'At {parking_site.original_uid} from {source.id}, realtime_free_capacity_woman {realtime_parking_site_input.realtime_free_capacity_woman} was higher than capacity_woman {parking_site.capacity_woman}',
)

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

if (
realtime_parking_site_input.realtime_capacity_disabled == UnsetValue
and realtime_parking_site_input.realtime_free_capacity_disabled > parking_site.capacity_disabled
):
realtime_parking_site_input.realtime_free_capacity_disabled = parking_site.capacity_disabled
self.logger.warn(
LogMessageType.FAILED_PARKING_SITE_HANDLING,
f'At {parking_site.original_uid} from {source.id}, realtime_free_capacity_disabled {realtime_parking_site_input.realtime_free_capacity_disabled} was higher than capacity_disabled {parking_site.capacity_disabled}',
)

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

if (
realtime_parking_site_input.realtime_capacity_charging == UnsetValue
and realtime_parking_site_input.realtime_free_capacity_charging > parking_site.capacity_charging
):
realtime_parking_site_input.realtime_free_capacity_charging = parking_site.capacity_charging
self.logger.warn(
LogMessageType.FAILED_PARKING_SITE_HANDLING,
f'At {parking_site.original_uid} from {source.id}, realtime_free_capacity_charging {realtime_parking_site_input.realtime_free_capacity_charging} was higher than capacity_charging {parking_site.capacity_charging}',
)

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

if (
realtime_parking_site_input.realtime_capacity_carsharing == UnsetValue
and realtime_parking_site_input.realtime_free_capacity_carsharing > parking_site.capacity_carsharing
):
realtime_parking_site_input.realtime_free_capacity_carsharing = parking_site.capacity_carsharing
self.logger.warn(
LogMessageType.FAILED_PARKING_SITE_HANDLING,
f'At {parking_site.original_uid} from {source.id}, realtime_free_capacity_carsharing {realtime_parking_site_input.realtime_free_capacity_carsharing} was higher than capacity_carsharing {parking_site.capacity_carsharing}',
)

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

if (
realtime_parking_site_input.realtime_capacity_bus == UnsetValue
and realtime_parking_site_input.realtime_free_capacity_bus > parking_site.capacity_bus
):
realtime_parking_site_input.realtime_free_capacity_bus = parking_site.capacity_bus
self.logger.warn(
LogMessageType.FAILED_PARKING_SITE_HANDLING,
f'At {parking_site.original_uid} from {source.id}, realtime_free_capacity_bus {realtime_parking_site_input.realtime_free_capacity_bus} was higher than capacity_bus {parking_site.capacity_bus}',
)

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

if (
realtime_parking_site_input.realtime_capacity_family == UnsetValue
and realtime_parking_site_input.realtime_free_capacity_family > parking_site.capacity_family
):
realtime_parking_site_input.realtime_free_capacity_family = parking_site.capacity_family
self.logger.warn(
LogMessageType.FAILED_PARKING_SITE_HANDLING,
f'At {parking_site.original_uid} from {source.id}, realtime_free_capacity_family {realtime_parking_site_input.realtime_free_capacity_family} was higher than capacity_family {parking_site.capacity_family}',
)

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

if (
realtime_parking_site_input.realtime_capacity_truck == UnsetValue
and realtime_parking_site_input.realtime_free_capacity_truck > parking_site.capacity_truck
):
realtime_parking_site_input.realtime_free_capacity_truck = parking_site.capacity_truck
self.logger.warn(
LogMessageType.FAILED_PARKING_SITE_HANDLING,
f'At {parking_site.original_uid} from {source.id}, realtime_free_capacity_truck {realtime_parking_site_input.realtime_free_capacity_truck} was higher than capacity_truck {parking_site.capacity_truck}',
)

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

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