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 bahnv2 bike parking locked and open #172

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
90 changes: 45 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,51 @@ Publication Light at any extension of the model.

We support following data sources:

| name | purpose | type | uid | realtime |
|----------------------------------------------------------------|---------|-------------|--------------------------|----------|
| APCOA Services | car | pull | `apcoa` | no |
| Deutsche Bahn | car | pull | `bahn_v2` | no |
| Stadt Bietigheim-Bissingen | car | pull | `bietigheim_bissingen` | yes |
| Barrierefreie Reisekette Baden-Württemberg: PKW-Parkplätze | car | pull | `bfrk_bw_car` | no |
| Barrierefreie Reisekette Baden-Württemberg: Fahrrad-Parkplätze | bike | pull | `bfrk_bw_bike` | no |
| Stadt Ellwangen | car | push (xlsx) | `ellwangen` | no |
| Stadt Buchen | car | push (json) | `buchen` | yes |
| Stadt Freiburg | car | pull | `freiburg` | yes |
| GOLDBECK Parking Services | car | push (xlsx) | `goldbeck` | no |
| Stadt Heidelberg | car | pull | `heidelberg` | yes |
| Stadt Herrenberg | car | pull | `herrenberg` | no |
| Stadt Herrenberg - Munigrid | bike | pull | `herrenberg_bike` | no |
| PARK SERVICE HÜFNER GmbH + Co. KG | car | push (xlsx) | `huefner` | no |
| Stadt Karlsruhe: PKW-Parkplätze | car | pull | `karlsruhe` | yes |
| Stadt Karlsruhe: Fahhrrad-Abstellangen | bike | pull | `karlsruhe_bike` | no |
| Kienzler: Bike and Ride | bike | pull | `kienzler_bike_and_ride` | yes |
| Kienzler: Karlsruhe | bike | pull | `kienzler_karlruhe` | yes |
| Kienzler: Neckarsulm | bike | pull | `kienzler_neckarsulm` | yes |
| Kienzler: Offenburg | bike | pull | `kienzler_offenburg` | yes |
| Kienzler: RadSafe | bike | pull | `kienzler_rad_safe` | yes |
| Kienzler: Stuttgart | bike | pull | `kienzler_stuttgart` | yes |
| Kienzler: VRN | bike | pull | `kienzler_vrn` | yes |
| Konstanz | car | pull | `konstanz` | yes |
| Stadt Konstanz: Fahrrad-Abstellanlagen | bike | push | `konstanz_bike` | no |
| Stadt Mannheim | car | push (json) | `mannheim` | yes |
| Stadt Neckarsulm: PKW-Parkplätze | car | pull | `neckarsulm` | no |
| Stadt Neckarsulm: Fahrrad-Abstellanlagen | bike | pull | `neckarsulm_bike` | no |
| Open-Data-Plattform öV Schweiz | car | pull (json) | `opendata_swiss` | no |
| P + M Baden-Württemberg | car | pull | `p_m_bw` | yes |
| Baden-Württemberg: Parken und Mitfahren | car | push (xlsx) | `pum_bw` | no |
| RadVIS Baden-Württemberg (experimental) | bike | pull | `radvis_bw` | no |
| Parkraumgesellschaft Baden-Württemberg | car | pull | `pbw` | yes |
| Stadt Pforzheim | car | push (csv) | `pforzheim` | no |
| Stadt Reutlingen: PKW-Parkplätze | car | push (csv) | `reutlingen` | no |
| Stadt Reutlingen: Fahrrad-Abstellanlagen | bike | push (csv) | `reutlingen_bike` | no |
| Stadt Stuttgart | car | push (json) | `stuttgart` | yes |
| Stadt Ulm | car | pull | `ulm` | yes |
| Velobrix | bike | pull | `velobrix` | yes |
| Verband Region Stuttgart: Bondorf | car | pull | `vrs_bondorf` | yes |
| Verband Region Stuttgart: Kirchheim | car | pull | `vrs_kirchheim` | yes |
| Verband Region Stuttgart: Neustadt | car | pull | `vrs_neustadt` | yes |
| Verband Region Stuttgart: Park and Ride | car | push (xlsx) | `vrs_p_r` | no |
| Verband Region Stuttgart: Vaihingen | car | pull | `vrs_vaihingen` | yes |
| name | purpose | type | uid | realtime |
|----------------------------------------------------------------|------------|-------------|--------------------------|----------|
| APCOA Services | car | pull | `apcoa` | no |
| Deutsche Bahn | car & bike | pull | `bahn_v2` | no |
| Stadt Bietigheim-Bissingen | car | pull | `bietigheim_bissingen` | yes |
| Barrierefreie Reisekette Baden-Württemberg: PKW-Parkplätze | car | pull | `bfrk_bw_car` | no |
| Barrierefreie Reisekette Baden-Württemberg: Fahrrad-Parkplätze | bike | pull | `bfrk_bw_bike` | no |
| Stadt Ellwangen | car | push (xlsx) | `ellwangen` | no |
| Stadt Buchen | car | push (json) | `buchen` | yes |
| Stadt Freiburg | car | pull | `freiburg` | yes |
| GOLDBECK Parking Services | car | push (xlsx) | `goldbeck` | no |
| Stadt Heidelberg | car | pull | `heidelberg` | yes |
| Stadt Herrenberg | car | pull | `herrenberg` | no |
| Stadt Herrenberg - Munigrid | bike | pull | `herrenberg_bike` | no |
| PARK SERVICE HÜFNER GmbH + Co. KG | car | push (xlsx) | `huefner` | no |
| Stadt Karlsruhe: PKW-Parkplätze | car | pull | `karlsruhe` | yes |
| Stadt Karlsruhe: Fahhrrad-Abstellangen | bike | pull | `karlsruhe_bike` | no |
| Kienzler: Bike and Ride | bike | pull | `kienzler_bike_and_ride` | yes |
| Kienzler: Karlsruhe | bike | pull | `kienzler_karlruhe` | yes |
| Kienzler: Neckarsulm | bike | pull | `kienzler_neckarsulm` | yes |
| Kienzler: Offenburg | bike | pull | `kienzler_offenburg` | yes |
| Kienzler: RadSafe | bike | pull | `kienzler_rad_safe` | yes |
| Kienzler: Stuttgart | bike | pull | `kienzler_stuttgart` | yes |
| Kienzler: VRN | bike | pull | `kienzler_vrn` | yes |
| Konstanz | car | pull | `konstanz` | yes |
| Stadt Konstanz: Fahrrad-Abstellanlagen | bike | push | `konstanz_bike` | no |
| Stadt Mannheim | car | push (json) | `mannheim` | yes |
| Stadt Neckarsulm: PKW-Parkplätze | car | pull | `neckarsulm` | no |
| Stadt Neckarsulm: Fahrrad-Abstellanlagen | bike | pull | `neckarsulm_bike` | no |
| Open-Data-Plattform öV Schweiz | car | pull (json) | `opendata_swiss` | no |
| P + M Baden-Württemberg | car | pull | `p_m_bw` | yes |
| Baden-Württemberg: Parken und Mitfahren | car | push (xlsx) | `pum_bw` | no |
| RadVIS Baden-Württemberg (experimental) | bike | pull | `radvis_bw` | no |
| Parkraumgesellschaft Baden-Württemberg | car | pull | `pbw` | yes |
| Stadt Pforzheim | car | push (csv) | `pforzheim` | no |
| Stadt Reutlingen: PKW-Parkplätze | car | push (csv) | `reutlingen` | no |
| Stadt Reutlingen: Fahrrad-Abstellanlagen | bike | push (csv) | `reutlingen_bike` | no |
| Stadt Stuttgart | car | push (json) | `stuttgart` | yes |
| Stadt Ulm | car | pull | `ulm` | yes |
| Velobrix | bike | pull | `velobrix` | yes |
| Verband Region Stuttgart: Bondorf | car | pull | `vrs_bondorf` | yes |
| Verband Region Stuttgart: Kirchheim | car | pull | `vrs_kirchheim` | yes |
| Verband Region Stuttgart: Neustadt | car | pull | `vrs_neustadt` | yes |
| Verband Region Stuttgart: Park and Ride | car | push (xlsx) | `vrs_p_r` | no |
| Verband Region Stuttgart: Vaihingen | car | pull | `vrs_vaihingen` | yes |

New converters for new sources are always welcome, please have a look at "Contribute" below.

Expand Down
14 changes: 12 additions & 2 deletions src/parkapi_sources/converters/bahn_v2/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from parkapi_sources.models import RealtimeParkingSiteInput, SourceInfo, StaticParkingSiteInput

from .mapper import BahnMapper
from .validators import BahnParkingSiteInput
from .validators import BahnParkingSiteCapacityType, BahnParkingSiteInput


class BahnV2PullConverter(PullConverter):
Expand Down Expand Up @@ -48,9 +48,19 @@ def get_static_parking_sites(self) -> tuple[list[StaticParkingSiteInput], list[I
)
continue

for item in parking_site_input.capacity:
if item.type == BahnParkingSiteCapacityType.BIKE_PARKING_LOCKED:
static_parking_site_inputs.append(
self.mapper.map_static_parking_site_bike_locked(parking_site_input),
)
elif item.type == BahnParkingSiteCapacityType.BIKE_PARKING_OPEN:
static_parking_site_inputs.append(
self.mapper.map_static_parking_site_bike_open(parking_site_input),
)
static_parking_site_inputs.append(
self.mapper.map_static_parking_site(parking_site_input),
self.mapper.map_static_parking_site_car(parking_site_input),
)

return static_parking_site_inputs, static_parking_site_errors

def get_realtime_parking_sites(self) -> tuple[list[RealtimeParkingSiteInput], list[ImportParkingSiteException]]:
Expand Down
56 changes: 42 additions & 14 deletions src/parkapi_sources/converters/bahn_v2/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,69 @@
from datetime import datetime, timezone

from parkapi_sources.models import StaticParkingSiteInput
from parkapi_sources.models.enums import PurposeType

from .validators import BahnParkingSiteCapacityType, BahnParkingSiteInput, NameContext
from .validators import (
BahnParkingSiteCapacityType,
BahnParkingSiteInput,
NameContext,
)


class BahnMapper:
@staticmethod
def map_static_parking_site(bahn_input: BahnParkingSiteInput) -> StaticParkingSiteInput:
def map_static_parking_site_car(bahn_input: BahnParkingSiteInput) -> StaticParkingSiteInput:
return BahnMapper._map_static_parking_site(
bahn_input, '-parking', PurposeType.CAR, BahnParkingSiteCapacityType.PARKING
)

@staticmethod
def map_static_parking_site_bike_locked(bahn_input: BahnParkingSiteInput) -> StaticParkingSiteInput:
return BahnMapper._map_static_parking_site(
bahn_input, '-bike-locked', PurposeType.BIKE, BahnParkingSiteCapacityType.BIKE_PARKING_LOCKED
)

@staticmethod
def map_static_parking_site_bike_open(bahn_input: BahnParkingSiteInput) -> StaticParkingSiteInput:
return BahnMapper._map_static_parking_site(
bahn_input, '-bike-open', PurposeType.BIKE, BahnParkingSiteCapacityType.BIKE_PARKING_OPEN
)

@staticmethod
def _map_static_parking_site(
bahn_input, uid_suffix: str, purpose: PurposeType, capacity_type: BahnParkingSiteCapacityType
) -> StaticParkingSiteInput:
static_parking_site_input = StaticParkingSiteInput(
uid=str(bahn_input.id),
uid=f'{bahn_input.id}{uid_suffix}',
group_uid=str(bahn_input.id),
name=next(
iter(name_input.name for name_input in bahn_input.name if name_input.context == NameContext.NAME)
),
lat=bahn_input.address.location.latitude,
lon=bahn_input.address.location.longitude,
operator_name=bahn_input.operator.name,
address=f'{bahn_input.address.streetAndNumber}, {bahn_input.address.zip} {bahn_input.address.city}',
type=bahn_input.type.name.to_parking_site_type_input(),
type=next(
iter(
item.to_bike_parking_site_type_input() for item in bahn_input.capacity if item.type == capacity_type
)
)
if capacity_type != BahnParkingSiteCapacityType.PARKING
else 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,
purpose=purpose,
# Because it was checked in validation, we can be sure that capacity will be set
capacity=next(
iter(
int(round(item.total))
for item in bahn_input.capacity
if item.type == BahnParkingSiteCapacityType.PARKING
)
),
capacity=next(iter(int(round(item.total)) for item in bahn_input.capacity if item.type == capacity_type)),
)
if bahn_input.access.openingHours.is24h:
static_parking_site_input.opening_hours = '24/7'

# Map all additional capacities
for capacity_data in bahn_input.capacity:
if capacity_data.type == BahnParkingSiteCapacityType.HANDICAPPED_PARKING:
static_parking_site_input.capacity_disabled = int(round(capacity_data.total))
if capacity_type == BahnParkingSiteCapacityType.PARKING:
for capacity_data in bahn_input.capacity:
if capacity_data.type == BahnParkingSiteCapacityType.HANDICAPPED_PARKING:
static_parking_site_input.capacity_disabled = int(round(capacity_data.total))

return static_parking_site_input
Loading
Loading