🎉 First commit !!!
This commit is contained in:
60
backend/idfm_matrix_backend/schemas/line.py
Normal file
60
backend/idfm_matrix_backend/schemas/line.py
Normal file
@@ -0,0 +1,60 @@
|
||||
from enum import StrEnum
|
||||
from typing import Self
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from ..idfm_interface import (
|
||||
IdfmLineState,
|
||||
IdfmState,
|
||||
TransportMode as IdfmTransportMode,
|
||||
TransportSubMode as IdfmTransportSubMode,
|
||||
)
|
||||
|
||||
|
||||
class TransportMode(StrEnum):
|
||||
"""Computed transport mode from
|
||||
idfm_interface.TransportMode and idfm_interface.TransportSubMode.
|
||||
"""
|
||||
|
||||
bus = "bus"
|
||||
tram = "tram"
|
||||
metro = "metro"
|
||||
funicular = "funicular"
|
||||
# idfm_types.TransportMode.rail + idfm_types.TransportSubMode.regionalRail
|
||||
rail_ter = "ter"
|
||||
# idfm_types.TransportMode.rail + idfm_types.TransportSubMode.local
|
||||
rail_rer = "rer"
|
||||
# idfm_types.TransportMode.rail + idfm_types.TransportSubMode.suburbanRailway
|
||||
rail_transilien = "transilien"
|
||||
# idfm_types.TransportMode.rail + idfm_types.TransportSubMode.railShuttle
|
||||
val = "val"
|
||||
|
||||
@classmethod
|
||||
def from_idfm_transport_mode(
|
||||
cls, mode: IdfmTransportMode, sub_mode: IdfmTransportSubMode
|
||||
) -> Self:
|
||||
if mode == IdfmTransportMode.rail:
|
||||
if sub_mode == IdfmTransportSubMode.regionalRail:
|
||||
return cls.rail_ter
|
||||
if sub_mode == IdfmTransportSubMode.local:
|
||||
return cls.rail_rer
|
||||
if sub_mode == IdfmTransportSubMode.suburbanRailway:
|
||||
return cls.rail_transilien
|
||||
if sub_mode == IdfmTransportSubMode.railShuttle:
|
||||
return cls.val
|
||||
return TransportMode(mode)
|
||||
|
||||
|
||||
class Line(BaseModel):
|
||||
id: str
|
||||
shortName: str
|
||||
name: str
|
||||
status: IdfmLineState
|
||||
transportMode: TransportMode
|
||||
backColorHexa: str
|
||||
foreColorHexa: str
|
||||
operatorId: str
|
||||
accessibility: IdfmState
|
||||
visualSignsAvailable: IdfmState
|
||||
audibleSignsAvailable: IdfmState
|
||||
stopIds: list[str]
|
Reference in New Issue
Block a user