|
3 | 3 | Use of this source code is governed by an MIT-style license that can be found in the LICENSE.txt. |
4 | 4 | """ |
5 | 5 |
|
| 6 | +from validataclass.helpers import UnsetValue |
| 7 | + |
6 | 8 | from webapp.models import ParkingSite |
7 | 9 | from webapp.models.parking_site import OpeningStatus, ParkingSiteType |
8 | 10 | from webapp.public_rest_api.datex2.datex2_models import ( |
| 11 | + Datex2Assignment, |
| 12 | + Datex2AssignmentType, |
9 | 13 | Datex2Coordinate, |
| 14 | + Datex2FuelType, |
10 | 15 | Datex2LocationAndDimension, |
11 | 16 | Datex2ParkingPublicationLight, |
12 | 17 | Datex2ParkingSite, |
13 | 18 | Datex2ParkingSiteType, |
14 | 19 | Datex2Publication, |
| 20 | + Datex2UserType, |
15 | 21 | ) |
16 | 22 |
|
17 | 23 |
|
@@ -44,6 +50,53 @@ def map_parking_site(self, parking_site: ParkingSite) -> Datex2ParkingSite: |
44 | 50 | else: |
45 | 51 | datex2_parking_site.numberOfSpaces = parking_site.capacity |
46 | 52 |
|
| 53 | + # Add different assignments, starting with disabled |
| 54 | + if parking_site.realtime_free_capacity_disabled is not None: |
| 55 | + datex2_parking_site.assignedFor.append( |
| 56 | + Datex2Assignment( |
| 57 | + availableSpaces=parking_site.realtime_free_capacity_disabled, |
| 58 | + typeOfAssignment=Datex2AssignmentType.onlyFor, |
| 59 | + user=Datex2UserType.wheelchairUsers, |
| 60 | + ), |
| 61 | + ) |
| 62 | + |
| 63 | + # Assignment women |
| 64 | + if parking_site.realtime_free_capacity_woman is not None: |
| 65 | + datex2_parking_site.assignedFor.append( |
| 66 | + Datex2Assignment( |
| 67 | + availableSpaces=parking_site.realtime_free_capacity_woman, |
| 68 | + typeOfAssignment=Datex2AssignmentType.onlyFor, |
| 69 | + user=Datex2UserType.women, |
| 70 | + ), |
| 71 | + ) |
| 72 | + |
| 73 | + # Assignment family |
| 74 | + if parking_site.realtime_free_capacity_family is not None: |
| 75 | + datex2_parking_site.assignedFor.append( |
| 76 | + Datex2Assignment( |
| 77 | + availableSpaces=parking_site.realtime_free_capacity_family, |
| 78 | + typeOfAssignment=Datex2AssignmentType.onlyFor, |
| 79 | + user=Datex2UserType.families, |
| 80 | + ), |
| 81 | + ) |
| 82 | + |
| 83 | + # Assignment charging |
| 84 | + if parking_site.realtime_free_capacity_charging is not None: |
| 85 | + datex2_parking_site.assignedFor.append( |
| 86 | + Datex2Assignment( |
| 87 | + availableSpaces=parking_site.realtime_free_capacity_charging, |
| 88 | + typeOfAssignment=Datex2AssignmentType.onlyFor, |
| 89 | + fuelType=Datex2FuelType.battery, |
| 90 | + ), |
| 91 | + ) |
| 92 | + |
| 93 | + # TODO: carsharing seems to be impossible to map |
| 94 | + # TODO: it seems that there is no way to make assignments to numberOfSpaces, just to availableSpaces, which is not helpful for most |
| 95 | + # data sources, as usually there is no realtime data at parking spots for groups, just static data. |
| 96 | + |
| 97 | + if len(datex2_parking_site.assignedFor) == 0: |
| 98 | + datex2_parking_site.assignedFor = UnsetValue |
| 99 | + |
47 | 100 | if parking_site.realtime_opening_status == OpeningStatus.OPEN: |
48 | 101 | datex2_parking_site.isOpenNow = True |
49 | 102 | elif parking_site.realtime_opening_status == OpeningStatus.CLOSED: |
|
0 commit comments