Skip to content

Commit

Permalink
Add plausibility check for realtime_free_capacity values
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdullahiFatola committed Nov 20, 2024
1 parent 3a8fb1d commit e123ff3
Showing 1 changed file with 178 additions and 0 deletions.
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 (
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

0 comments on commit e123ff3

Please sign in to comment.