2 Commits

Author SHA1 Message Date
4056b3a739 🐛 Error raised by frontend Map component if no stop found 2023-09-09 23:18:03 +02:00
f7f0fdb980 ️ Use of integer to store Line and Stop id
Update Line and Stop schemas.
2023-09-09 23:05:18 +02:00
5 changed files with 19 additions and 13 deletions

View File

@@ -31,6 +31,10 @@ class IdfmInterface:
async def startup(self) -> None: async def startup(self) -> None:
... ...
@staticmethod
def _format_line_id(line_id: str) -> int:
return int(line_id[1:] if line_id[0] == "C" else line_id)
async def render_line_picto(self, line: Line) -> tuple[None | str, None | str]: async def render_line_picto(self, line: Line) -> tuple[None | str, None | str]:
line_picto_path = line_picto_format = None line_picto_path = line_picto_format = None
target = f"/tmp/{line.id}_repr" target = f"/tmp/{line.id}_repr"
@@ -81,7 +85,6 @@ class IdfmInterface:
if (stop := await Stop.get_by_id(stop_id)) is not None: if (stop := await Stop.get_by_id(stop_id)) is not None:
expected_stop_ids = {stop.id} expected_stop_ids = {stop.id}
elif (stop_area := await StopArea.get_by_id(stop_id)) is not None: elif (stop_area := await StopArea.get_by_id(stop_id)) is not None:
expected_stop_ids = {stop.id for stop in stop_area.stops} expected_stop_ids = {stop.id for stop in stop_area.stops}
else: else:
@@ -105,7 +108,8 @@ class IdfmInterface:
if ( if (
dst_names := journey.DestinationName dst_names := journey.DestinationName
) and monitored_stop_id in expected_stop_ids: ) and monitored_stop_id in expected_stop_ids:
line_id = journey.LineRef.value.split(":")[-2] raw_line_id = journey.LineRef.value.split(":")[-2]
line_id = IdfmInterface._format_line_id(raw_line_id)
destinations[line_id].add(dst_names[0].value) destinations[line_id].add(dst_names[0].value)
return destinations return destinations

View File

@@ -53,8 +53,8 @@ class Line(BaseModel):
transportMode: TransportMode transportMode: TransportMode
backColorHexa: str backColorHexa: str
foreColorHexa: str foreColorHexa: str
operatorId: str operatorId: int
accessibility: IdfmState accessibility: IdfmState
visualSignsAvailable: IdfmState visualSignsAvailable: IdfmState
audibleSignsAvailable: IdfmState audibleSignsAvailable: IdfmState
stopIds: list[str] stopIds: list[int]

View File

@@ -9,7 +9,7 @@ class Stop(BaseModel):
town: str town: str
epsg3857_x: float epsg3857_x: float
epsg3857_y: float epsg3857_y: float
lines: list[str] lines: list[int]
class StopArea(BaseModel): class StopArea(BaseModel):
@@ -17,7 +17,7 @@ class StopArea(BaseModel):
name: str name: str
town: str town: str
type: StopAreaType type: StopAreaType
lines: list[str] # SNCF lines are linked to stop areas and not stops. lines: list[int] # SNCF lines are linked to stop areas and not stops.
stops: list[Stop] stops: list[Stop]

View File

@@ -116,7 +116,9 @@ export const Map: ParentComponent<{}> = () => {
const foundStopIds = new Set(); const foundStopIds = new Set();
for (const foundStop of stops) { for (const foundStop of stops) {
foundStopIds.add(foundStop.id); foundStopIds.add(foundStop.id);
foundStop.stops.forEach(s => foundStopIds.add(s.id)); if (foundStop.stops !== undefined) {
foundStop.stops.forEach(s => foundStopIds.add(s.id));
}
} }
for (const [stopIdStr, feature] of Object.entries(displayedFeatures)) { for (const [stopIdStr, feature] of Object.entries(displayedFeatures)) {

View File

@@ -8,7 +8,7 @@ export enum TrafficStatus {
export class Passage { export class Passage {
line: number; line: number;
operator: string; operator: number;
destinations: string[]; destinations: string[];
atStop: boolean; atStop: boolean;
aimedArrivalTs: number; aimedArrivalTs: number;
@@ -19,7 +19,7 @@ export class Passage {
arrivalStatus: string; arrivalStatus: string;
departStatus: string; departStatus: string;
constructor(line: number, operator: string, destinations: string[], atStop: boolean, aimedArrivalTs: number, constructor(line: number, operator: number, destinations: string[], atStop: boolean, aimedArrivalTs: number,
expectedArrivalTs: number, arrivalPlatformName: string, aimedDepartTs: number, expectedDepartTs: number, expectedArrivalTs: number, arrivalPlatformName: string, aimedDepartTs: number, expectedDepartTs: number,
arrivalStatus: string, departStatus: string) { arrivalStatus: string, departStatus: string) {
this.line = line; this.line = line;
@@ -45,9 +45,9 @@ export class Stop {
epsg3857_x: number; epsg3857_x: number;
epsg3857_y: number; epsg3857_y: number;
stops: Stop[]; stops: Stop[];
lines: string[]; lines: number[];
constructor(id: number, name: string, town: string, epsg3857_x: number, epsg3857_y: number, stops: Stop[], lines: string[]) { constructor(id: number, name: string, town: string, epsg3857_x: number, epsg3857_y: number, stops: Stop[], lines: number[]) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.town = town; this.town = town;
@@ -82,7 +82,7 @@ export class StopShape {
export type StopShapes = Record<number, StopShape>; export type StopShapes = Record<number, StopShape>;
export class Line { export class Line {
id: string; id: number;
shortName: string; shortName: string;
name: string; name: string;
status: string; // TODO: Use an enum status: string; // TODO: Use an enum
@@ -95,7 +95,7 @@ export class Line {
audibleSignsAvailable: string; // TODO: Use an enum audibleSignsAvailable: string; // TODO: Use an enum
stopIds: number[]; stopIds: number[];
constructor(id: string, shortName: string, name: string, status: string, transportMode: string, backColorHexa: string, constructor(id: number, shortName: string, name: string, status: string, transportMode: string, backColorHexa: string,
foreColorHexa: string, operatorId: number, accessibility: boolean, visualSignsAvailable: string, foreColorHexa: string, operatorId: number, accessibility: boolean, visualSignsAvailable: string,
audibleSignsAvailable: string, stopIds: number[]) { audibleSignsAvailable: string, stopIds: number[]) {
this.id = id; this.id = id;