🎨 Reorganize back-end code

This commit is contained in:
2023-09-20 22:08:32 +02:00
parent bdbc72ab39
commit 3434802b31
28 changed files with 29 additions and 36 deletions

View File

@@ -0,0 +1,60 @@
from enum import StrEnum
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"
# Self return type replaced by "TransportMode" to fix following mypy error:
# Incompatible return value type (got "TransportMode", expected "Self")
# TODO: Is it the good fix ?
@classmethod
def from_idfm_transport_mode(cls, mode: str, sub_mode: str) -> "TransportMode":
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 cls(mode)
class Line(BaseModel):
id: int
shortName: str
name: str
status: IdfmLineState
transportMode: TransportMode
backColorHexa: str
foreColorHexa: str
operatorId: int
accessibility: IdfmState
visualSignsAvailable: IdfmState
audibleSignsAvailable: IdfmState
stopIds: list[int]