From 197478e0ae7658739a7e886e3401510291760144 Mon Sep 17 00:00:00 2001 From: Luca Angemi Date: Mon, 1 Dec 2025 17:46:07 +0100 Subject: [PATCH 1/3] Add bus_coords attribute to Line class --- emt_madrid/domain/line.py | 1 + 1 file changed, 1 insertion(+) diff --git a/emt_madrid/domain/line.py b/emt_madrid/domain/line.py index 946adfb..c7342e1 100644 --- a/emt_madrid/domain/line.py +++ b/emt_madrid/domain/line.py @@ -18,6 +18,7 @@ class Line: day_type: Optional[DayType] = None arrival: Optional[int] = None next_arrival: Optional[int] = None + bus_coords: Optional[list[float]] = None def __str__(self) -> str: """Return a string representation of the line.""" From a55333e78316de1d25956936acf048bec48f4297 Mon Sep 17 00:00:00 2001 From: Luca Angemi Date: Mon, 1 Dec 2025 17:52:00 +0100 Subject: [PATCH 2/3] Add bus coordinates handling in arrival data processing --- emt_madrid/infrastructure/emt_api_repository.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/emt_madrid/infrastructure/emt_api_repository.py b/emt_madrid/infrastructure/emt_api_repository.py index d1428b9..437174f 100644 --- a/emt_madrid/infrastructure/emt_api_repository.py +++ b/emt_madrid/infrastructure/emt_api_repository.py @@ -217,6 +217,7 @@ async def get_arrivals(self, stop: Stop) -> Stop: for arrival in arrivals_data: try: line_number = str(arrival["line"]) + coords = arrival["geometry"]["coordinates"] if line_number not in line_arrivals: line_arrivals[line_number] = [] line_arrivals[line_number].append( @@ -233,12 +234,22 @@ async def get_arrivals(self, stop: Stop) -> Stop: if not sorted_arrivals: line.arrival = None line.next_arrival = None + line.bus_coords = None else: line.arrival = sorted_arrivals[0] line.next_arrival = ( sorted_arrivals[1] if len(sorted_arrivals) > 1 else None ) + bus_for_line = [ + a for a in arrivals_data if str(a["line"]) == line.line_number + ] + if bus_for_line: + first_bus = min(bus_for_line, key=lambda x: int(x["estimateArrive"])) + line.bus_coords = first_bus["geometry"]["coordinates"] + else: + line.bus_coords = None + return stop except Exception as e: From f529d0a6ca6238933de902449782cbf35c944a94 Mon Sep 17 00:00:00 2001 From: Luca Angemi Date: Mon, 1 Dec 2025 18:28:57 +0100 Subject: [PATCH 3/3] Remove unused 'coords' variable Remove unused variable 'coords' from arrivals processing. --- emt_madrid/infrastructure/emt_api_repository.py | 1 - 1 file changed, 1 deletion(-) diff --git a/emt_madrid/infrastructure/emt_api_repository.py b/emt_madrid/infrastructure/emt_api_repository.py index 437174f..8434f59 100644 --- a/emt_madrid/infrastructure/emt_api_repository.py +++ b/emt_madrid/infrastructure/emt_api_repository.py @@ -217,7 +217,6 @@ async def get_arrivals(self, stop: Stop) -> Stop: for arrival in arrivals_data: try: line_number = str(arrival["line"]) - coords = arrival["geometry"]["coordinates"] if line_number not in line_arrivals: line_arrivals[line_number] = [] line_arrivals[line_number].append(