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

datex2 assignments #128

Open
wants to merge 1 commit 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
53 changes: 53 additions & 0 deletions webapp/public_rest_api/datex2/datex2_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
Use of this source code is governed by an MIT-style license that can be found in the LICENSE.txt.
"""

from validataclass.helpers import UnsetValue

from webapp.models import ParkingSite
from webapp.models.parking_site import OpeningStatus, ParkingSiteType
from webapp.public_rest_api.datex2.datex2_models import (
Datex2Assignment,
Datex2AssignmentType,
Datex2Coordinate,
Datex2FuelType,
Datex2LocationAndDimension,
Datex2ParkingPublicationLight,
Datex2ParkingSite,
Datex2ParkingSiteType,
Datex2Publication,
Datex2UserType,
)


Expand Down Expand Up @@ -44,6 +50,53 @@ def map_parking_site(self, parking_site: ParkingSite) -> Datex2ParkingSite:
else:
datex2_parking_site.numberOfSpaces = parking_site.capacity

# Add different assignments, starting with disabled
if parking_site.realtime_free_capacity_disabled is not None:
datex2_parking_site.assignedFor.append(
Datex2Assignment(
availableSpaces=parking_site.realtime_free_capacity_disabled,
typeOfAssignment=Datex2AssignmentType.onlyFor,
user=Datex2UserType.wheelchairUsers,
),
)

# Assignment women
if parking_site.realtime_free_capacity_woman is not None:
datex2_parking_site.assignedFor.append(
Datex2Assignment(
availableSpaces=parking_site.realtime_free_capacity_woman,
typeOfAssignment=Datex2AssignmentType.onlyFor,
user=Datex2UserType.women,
),
)

# Assignment family
if parking_site.realtime_free_capacity_family is not None:
datex2_parking_site.assignedFor.append(
Datex2Assignment(
availableSpaces=parking_site.realtime_free_capacity_family,
typeOfAssignment=Datex2AssignmentType.onlyFor,
user=Datex2UserType.families,
),
)

# Assignment charging
if parking_site.realtime_free_capacity_charging is not None:
datex2_parking_site.assignedFor.append(
Datex2Assignment(
availableSpaces=parking_site.realtime_free_capacity_charging,
typeOfAssignment=Datex2AssignmentType.onlyFor,
fuelType=Datex2FuelType.battery,
),
)

# TODO: carsharing seems to be impossible to map
# TODO: it seems that there is no way to make assignments to numberOfSpaces, just to availableSpaces, which is not helpful for most
# data sources, as usually there is no realtime data at parking spots for groups, just static data.

if len(datex2_parking_site.assignedFor) == 0:
datex2_parking_site.assignedFor = UnsetValue

if parking_site.realtime_opening_status == OpeningStatus.OPEN:
datex2_parking_site.isOpenNow = True
elif parking_site.realtime_opening_status == OpeningStatus.CLOSED:
Expand Down
3 changes: 2 additions & 1 deletion webapp/public_rest_api/datex2/datex2_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from datetime import datetime
from enum import Enum

from validataclass.dataclasses import Default
from validataclass.helpers import OptionalUnset, UnsetValue

from webapp.common.dataclass import DataclassMixin
Expand Down Expand Up @@ -217,7 +218,7 @@ class Datex2LocationAndDimension(DataclassMixin):
@dataclass(kw_only=True)
class Datex2ParkingSite(DataclassMixin):
uid: str
assignedFor: OptionalUnset[list[Datex2Assignment]] = UnsetValue
assignedFor: OptionalUnset[list[Datex2Assignment]] = Default([])
locationAndDimension: Datex2LocationAndDimension
availableSpaces: OptionalUnset[int] = UnsetValue # should be >= 0
description: OptionalUnset[str] = UnsetValue
Expand Down