diff --git a/webapp/public_rest_api/park_api_v1/park_api_v1_handler.py b/webapp/public_rest_api/park_api_v1/park_api_v1_handler.py index acae1e8..a0e3112 100644 --- a/webapp/public_rest_api/park_api_v1/park_api_v1_handler.py +++ b/webapp/public_rest_api/park_api_v1/park_api_v1_handler.py @@ -66,8 +66,8 @@ def get_parking_site_list_as_dict(self, search_query: ParkingSiteSearchInput) -> continue lot[key] = getattr(parking_site, key) - if parking_site.has_realtime_data and parking_site.realtime_free_spots is not None: - lot['free'] = parking_site.realtime_free_spots + if parking_site.has_realtime_data and parking_site.realtime_free_capacity is not None: + lot['free'] = parking_site.realtime_free_capacity if parking_site.has_realtime_data and parking_site.realtime_opening_status is not None: lot['state'] = parking_site.realtime_opening_status.name.lower() elif parking_site.opening_hours: diff --git a/webapp/public_rest_api/park_api_v2/park_api_v2_handler.py b/webapp/public_rest_api/park_api_v2/park_api_v2_handler.py index 36a53f7..31f7429 100644 --- a/webapp/public_rest_api/park_api_v2/park_api_v2_handler.py +++ b/webapp/public_rest_api/park_api_v2/park_api_v2_handler.py @@ -65,20 +65,21 @@ def get_parking_site_list_as_dict(self, search_query: ParkingSiteSearchInput) -> continue lot[key] = getattr(parking_site, key) - if parking_site.opening_hours or parking_site.realtime_capacity: + if parking_site.opening_hours or (parking_site.has_realtime_data and parking_site.realtime_free_capacity is not None): lot['latest_data'] = {} if parking_site.opening_hours: oh = OpeningHours(parking_site.opening_hours) lot['latest_data']['status'] = oh.state() - if parking_site.has_realtime_data: + if parking_site.has_realtime_data and parking_site.realtime_free_capacity is not None: capacity = parking_site.capacity if parking_site.realtime_capacity is None else parking_site.realtime_capacity - lot['latest_data']['timestamp'] = parking_site.realtime_data_updated_at - lot['latest_data']['capacity'] = capacity - lot['latest_data']['num_free'] = parking_site.realtime_free_spots - lot['latest_data']['num_occupied'] = capacity - parking_site.realtime_capacity - lot['latest_data']['percent_free'] = round(parking_site.realtime_capacity / capacity * 100, 2) + if capacity: + lot['latest_data']['timestamp'] = parking_site.realtime_data_updated_at + lot['latest_data']['capacity'] = capacity + lot['latest_data']['num_free'] = parking_site.realtime_free_capacity + lot['latest_data']['num_occupied'] = capacity - parking_site.realtime_free_capacity + lot['latest_data']['percent_free'] = round(parking_site.realtime_free_capacity / capacity * 100, 2) lots.append(lot) diff --git a/webapp/services/import_service/generic/parking_site_generic_import_mapper.py b/webapp/services/import_service/generic/parking_site_generic_import_mapper.py index ce73b8e..f2bc798 100644 --- a/webapp/services/import_service/generic/parking_site_generic_import_mapper.py +++ b/webapp/services/import_service/generic/parking_site_generic_import_mapper.py @@ -41,10 +41,10 @@ def map_lot_info_to_parking_site(self, lot_info_input: LotInfoInput, parking_sit def map_lot_data_to_parking_site(self, lot_data_input: LotDataInput, parking_site: ParkingSite): if lot_data_input.num_free is not None: - parking_site.realtime_free_spots = lot_data_input.num_free + parking_site.realtime_free_capacity = lot_data_input.num_free elif lot_data_input.num_occupied is not None and lot_data_input.capacity is not None: - parking_site.realtime_free_spots = lot_data_input.capacity - lot_data_input.num_occupied + parking_site.realtime_free_capacity = lot_data_input.capacity - lot_data_input.num_occupied else: - parking_site.realtime_free_spots = None + parking_site.realtime_free_capacity = None parking_site.realtime_capacity = lot_data_input.capacity parking_site.realtime_opening_status = self.opening_mapping.get(lot_data_input.status, OpeningStatus.UNKNOWN)