Skip to content

Commit

Permalink
better bahn and pbw mapping (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
the-infinity authored Feb 12, 2024
1 parent b558b8d commit a49df63
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
3 changes: 3 additions & 0 deletions v3/bahn_v2/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ def map_static_parking_site(bahn_input: BahnParkingSiteInput) -> StaticParkingSi
type=bahn_input.type.name.to_parking_site_type_input(),
has_realtime_data=False, # TODO: change this as soon as Bahn offers proper rate limits
static_data_updated_at=datetime.now(tz=timezone.utc),
public_url=bahn_input.url,
)
if bahn_input.access.openingHours.is24h:
static_parking_site_input.opening_hours = '24/7'

for capacity_data in bahn_input.capacity:
if capacity_data.type == BahnParkingSiteCapacityType.PARKING:
Expand Down
22 changes: 15 additions & 7 deletions v3/pbw/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,26 @@

class PbwMapper:
def map_static_parking_site(self, parking_site_detail_input: PbwParkingSiteDetailInput) -> StaticParkingSiteInput:
max_height = None
if parking_site_detail_input.ausstattung.einfahrtshoehe:
max_height = int(parking_site_detail_input.ausstattung.einfahrtshoehe * 100)

parking_site_type = None
if parking_site_detail_input.objekt.art_lang:
parking_site_type = parking_site_detail_input.objekt.art_lang.to_parking_site_type_input()

# We use StaticParkingSiteInput without validation because we validated the data before
return StaticParkingSiteInput(
uid=str(parking_site_detail_input.id),
name=parking_site_detail_input.objekt.name,
operator_name='Parkraumgesellschaft Baden-Württemberg mbH',
static_data_updated_at=datetime.now(tz=timezone.utc),
address=f'{parking_site_detail_input.objekt.strasse}, {parking_site_detail_input.objekt.plz} {parking_site_detail_input.objekt.ort}',
type=parking_site_detail_input.objekt.art_lang.to_parking_site_type_input()
if parking_site_detail_input.objekt.art_lang
else None,
max_height=int(parking_site_detail_input.ausstattung.einfahrtshoehe * 100)
if parking_site_detail_input.ausstattung.einfahrtshoehe
else None,
address=(
f'{parking_site_detail_input.objekt.strasse}, '
f'{parking_site_detail_input.objekt.plz} {parking_site_detail_input.objekt.ort}'
),
type=parking_site_type,
max_height=max_height,
# TODO: any way to create a fee_description or has_fee?
# TODO: which field is maps to is_supervised?
has_realtime_data=True,
Expand Down

0 comments on commit a49df63

Please sign in to comment.