♻️ Update stop destinations returned value
This commit is contained in:
@@ -2,6 +2,7 @@ from .idfm_interface import IdfmInterface
|
|||||||
|
|
||||||
from .idfm_types import (
|
from .idfm_types import (
|
||||||
Coordinate,
|
Coordinate,
|
||||||
|
Destinations,
|
||||||
FramedVehicleJourney,
|
FramedVehicleJourney,
|
||||||
IdfmLineState,
|
IdfmLineState,
|
||||||
IdfmOperator,
|
IdfmOperator,
|
||||||
@@ -35,6 +36,7 @@ from .idfm_types import (
|
|||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"Coordinate",
|
"Coordinate",
|
||||||
|
"Destinations",
|
||||||
"FramedVehicleJourney",
|
"FramedVehicleJourney",
|
||||||
"IdfmInterface",
|
"IdfmInterface",
|
||||||
"IdfmLineState",
|
"IdfmLineState",
|
||||||
|
@@ -22,6 +22,7 @@ from ..db import Database
|
|||||||
from ..models import ConnectionArea, Line, LinePicto, Stop, StopArea, StopShape
|
from ..models import ConnectionArea, Line, LinePicto, Stop, StopArea, StopShape
|
||||||
from .idfm_types import (
|
from .idfm_types import (
|
||||||
ConnectionArea as IdfmConnectionArea,
|
ConnectionArea as IdfmConnectionArea,
|
||||||
|
Destinations as IdfmDestinations,
|
||||||
IdfmLineState,
|
IdfmLineState,
|
||||||
IdfmResponse,
|
IdfmResponse,
|
||||||
Line as IdfmLine,
|
Line as IdfmLine,
|
||||||
@@ -521,20 +522,40 @@ class IdfmInterface:
|
|||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
async def get_destinations(self, stop_point_id: str) -> Iterable[str]:
|
async def get_destinations(self, stop_id: int) -> IdfmDestinations | None:
|
||||||
# TODO: Store in database the destination for the given stop and line id.
|
|
||||||
begin_ts = time()
|
begin_ts = time()
|
||||||
destinations: dict[str, str] = {}
|
|
||||||
if (res := await self.get_next_passages(stop_point_id)) is not None:
|
destinations: IdfmDestinations = defaultdict(set)
|
||||||
|
|
||||||
|
if (stop := await Stop.get_by_id(stop_id)) is not None:
|
||||||
|
expected_stop_ids = {stop.id}
|
||||||
|
|
||||||
|
elif (stop_area := await StopArea.get_by_id(stop_id)) is not None:
|
||||||
|
expected_stop_ids = {stop.id for stop in stop_area.stops}
|
||||||
|
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if (res := await self.get_next_passages(stop_id)) is not None:
|
||||||
|
|
||||||
for delivery in res.Siri.ServiceDelivery.StopMonitoringDelivery:
|
for delivery in res.Siri.ServiceDelivery.StopMonitoringDelivery:
|
||||||
if delivery.Status == IdfmState.true:
|
if delivery.Status == IdfmState.true:
|
||||||
for stop_visit in delivery.MonitoredStopVisit:
|
for stop_visit in delivery.MonitoredStopVisit:
|
||||||
|
|
||||||
|
monitoring_ref = stop_visit.MonitoringRef.value
|
||||||
|
try:
|
||||||
|
monitored_stop_id = int(monitoring_ref.split(":")[-2])
|
||||||
|
except (IndexError, ValueError):
|
||||||
|
print(f"Unable to get stop id from {monitoring_ref}")
|
||||||
|
continue
|
||||||
|
|
||||||
journey = stop_visit.MonitoredVehicleJourney
|
journey = stop_visit.MonitoredVehicleJourney
|
||||||
if (destination_name := journey.DestinationName) and (
|
if (
|
||||||
line_ref := journey.LineRef
|
dst_names := journey.DestinationName
|
||||||
):
|
) and monitored_stop_id in expected_stop_ids:
|
||||||
line_id = line_ref.value.replace("STIF:Line::", "")[:-1]
|
|
||||||
print(f"{line_id = }")
|
line_id = journey.LineRef.value.split(":")[-2]
|
||||||
destinations[line_id] = destination_name[0].value
|
destinations[line_id].add(dst_names[0].value)
|
||||||
|
|
||||||
print(f"get_next_passages: {time() - begin_ts}")
|
print(f"get_next_passages: {time() - begin_ts}")
|
||||||
return destinations
|
return destinations
|
||||||
|
@@ -197,6 +197,8 @@ class Line(Struct):
|
|||||||
|
|
||||||
Lines = dict[str, Line]
|
Lines = dict[str, Line]
|
||||||
|
|
||||||
|
Destinations = dict[str, set[str]]
|
||||||
|
|
||||||
|
|
||||||
# TODO: Set structs frozen
|
# TODO: Set structs frozen
|
||||||
class StopLineAssoFields(Struct):
|
class StopLineAssoFields(Struct):
|
||||||
|
Reference in New Issue
Block a user