From 2901dddf0309942583ffc812168a149b65b3bdc6 Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Sat, 22 Nov 2025 17:59:54 +0100 Subject: feat: Enhance bus position calculation to support previous trip shapes and improve trip ID parsing for multiple formats --- src/Costasdev.Busurbano.Backend/Controllers/VigoController.cs | 4 ++-- src/gtfs_vigo_stops/stop_report.py | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Costasdev.Busurbano.Backend/Controllers/VigoController.cs b/src/Costasdev.Busurbano.Backend/Controllers/VigoController.cs index 570b56d..8e3f54e 100644 --- a/src/Costasdev.Busurbano.Backend/Controllers/VigoController.cs +++ b/src/Costasdev.Busurbano.Backend/Controllers/VigoController.cs @@ -315,8 +315,8 @@ public class VigoController : ControllerBase // If the bus is further away than the distance from the start of the trip to the stop, // it implies the bus is on the previous trip (or earlier). double distOnPrevTrip = estimate.Meters - closestCirculation.ShapeDistTraveled; - usePreviousShape = !isRunning && - !string.IsNullOrEmpty(closestCirculation.PreviousTripShapeId) && + usePreviousShape = !isRunning && + !string.IsNullOrEmpty(closestCirculation.PreviousTripShapeId) && distOnPrevTrip > 0; if (usePreviousShape) diff --git a/src/gtfs_vigo_stops/stop_report.py b/src/gtfs_vigo_stops/stop_report.py index adc08b1..cb10801 100644 --- a/src/gtfs_vigo_stops/stop_report.py +++ b/src/gtfs_vigo_stops/stop_report.py @@ -166,7 +166,6 @@ def parse_trip_id_components(trip_id: str) -> Optional[Tuple[str, str, int]]: if len(parts) >= 2: shift_part = parts[-2] trip_num_str = parts[-1] - if len(shift_part) == 6 and shift_part.isdigit() and trip_num_str.isdigit(): line = shift_part[:3] shift_id = shift_part[3:6] @@ -186,7 +185,6 @@ def parse_trip_id_components(trip_id: str) -> Optional[Tuple[str, str, int]]: shift_id = shift_part[3:6] # Next 3 digits trip_number = int(trip_num_str) return (line, shift_id, trip_number) - return None except (ValueError, IndexError): return None -- cgit v1.3