🎨 Reorganize back-end code
This commit is contained in:
14
backend/api/schemas/__init__.py
Normal file
14
backend/api/schemas/__init__.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from .line import Line, TransportMode
|
||||
from .next_passage import NextPassage, NextPassages
|
||||
from .stop import Stop, StopArea, StopShape
|
||||
|
||||
|
||||
__all__ = [
|
||||
"Line",
|
||||
"NextPassage",
|
||||
"NextPassages",
|
||||
"Stop",
|
||||
"StopArea",
|
||||
"StopShape",
|
||||
"TransportMode",
|
||||
]
|
60
backend/api/schemas/line.py
Normal file
60
backend/api/schemas/line.py
Normal 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]
|
22
backend/api/schemas/next_passage.py
Normal file
22
backend/api/schemas/next_passage.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
from idfm_interface.idfm_types import TrainStatus
|
||||
|
||||
|
||||
class NextPassage(BaseModel):
|
||||
line: int
|
||||
operator: str
|
||||
destinations: list[str]
|
||||
atStop: bool
|
||||
aimedArrivalTs: int | None
|
||||
expectedArrivalTs: int | None
|
||||
arrivalPlatformName: str | None
|
||||
aimedDepartTs: int | None
|
||||
expectedDepartTs: int | None
|
||||
arrivalStatus: TrainStatus
|
||||
departStatus: TrainStatus
|
||||
|
||||
|
||||
class NextPassages(BaseModel):
|
||||
ts: int
|
||||
passages: dict[int, dict[str, list[NextPassage]]]
|
31
backend/api/schemas/stop.py
Normal file
31
backend/api/schemas/stop.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
from idfm_interface import StopAreaType
|
||||
|
||||
|
||||
class Stop(BaseModel):
|
||||
id: int
|
||||
name: str
|
||||
town: str
|
||||
epsg3857_x: float
|
||||
epsg3857_y: float
|
||||
lines: list[int]
|
||||
|
||||
|
||||
class StopArea(BaseModel):
|
||||
id: int
|
||||
name: str
|
||||
town: str
|
||||
type: StopAreaType
|
||||
lines: list[int] # SNCF lines are linked to stop areas and not stops.
|
||||
stops: list[Stop]
|
||||
|
||||
|
||||
Point = tuple[float, float]
|
||||
|
||||
|
||||
class StopShape(BaseModel):
|
||||
id: int
|
||||
type: int
|
||||
epsg3857_bbox: list[Point]
|
||||
epsg3857_points: list[Point]
|
Reference in New Issue
Block a user