Skip to content

Commit

Permalink
new variable adaptions
Browse files Browse the repository at this point in the history
  • Loading branch information
the-infinity committed Oct 27, 2023
1 parent ca77ea0 commit 5344c96
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions webapp/public_rest_api/park_api_v1/park_api_v1_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 8 additions & 7 deletions webapp/public_rest_api/park_api_v2/park_api_v2_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 5344c96

Please sign in to comment.