Skip to content

Commit

Permalink
datex2 assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
the-infinity committed Apr 27, 2024
1 parent deadd5e commit 102c602
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
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

0 comments on commit 102c602

Please sign in to comment.