diff options
| author | Ariel Costas Guerrero <ariel@costas.dev> | 2025-11-21 21:02:50 +0100 |
|---|---|---|
| committer | Ariel Costas Guerrero <ariel@costas.dev> | 2025-11-21 21:02:50 +0100 |
| commit | a08d0262115dfebdd11141df8a9b4204d0456dfa (patch) | |
| tree | ac422afaef133b7dce4d7ac6a272e25775c26d88 | |
| parent | 3af7ff6ecdf816849d45e094d20f1fa57a4c07cc (diff) | |
Fix data consolidation
3 files changed, 27 insertions, 53 deletions
diff --git a/src/Costasdev.Busurbano.Backend/Controllers/VigoController.cs b/src/Costasdev.Busurbano.Backend/Controllers/VigoController.cs index f3f3d69..151baa3 100644 --- a/src/Costasdev.Busurbano.Backend/Controllers/VigoController.cs +++ b/src/Costasdev.Busurbano.Backend/Controllers/VigoController.cs @@ -53,8 +53,8 @@ public class VigoController : ControllerBase ) { // Include a significant number of previous points to ensure continuity and context - // Backtrack 50 points to cover any potential gaps or dense point sequences - var adjustedStartIndex = Math.Max(0, startPointIndex - 50); + // Backtrack 15 points to cover any potential gaps or dense point sequences + var adjustedStartIndex = Math.Max(0, startPointIndex - 15); var path = await _shapeService.GetShapePathAsync(shapeId, adjustedStartIndex); if (path == null) { @@ -208,53 +208,27 @@ public class VigoController : ControllerBase ScheduledArrival? closestCirculation = null; // Matching strategy: - // 1) Prefer a started trip whose scheduled calling time is close to the estimated arrival. - // 2) If no good started match, pick the next not-started trip (soonest in the future). - // 3) Reject matches where the bus would arrive >3 minutes BEFORE schedule (too early). - // 4) Fallbacks: if no future trips, use the best started one even if far. - const int startedMatchToleranceMinutes = 15; // how close a started trip must be to consider it a match - const int maxEarlyArrivalMinutes = 3; // reject if bus arrives more than 3 minutes before schedule + // 1) Filter trips that are not "too early" (TimeDiff <= 3). + // TimeDiff = Schedule - Realtime. + // If TimeDiff > 3, bus is > 3 mins early. Reject. + // 2) From the valid trips, pick the one with smallest Abs(TimeDiff). + // This handles "as late as it gets" (large negative TimeDiff) by preferring smaller delays if available, + // but accepting large delays if that's the only option (and better than an invalid early trip). + const int maxEarlyArrivalMinutes = 3; - var startedCandidates = possibleCirculations - .Where(c => c.StartingDateTime()!.Value <= now) - .Select(c => new - { - Circulation = c, - AbsDiff = Math.Abs((estimatedArrivalTime - c.CallingDateTime()!.Value).TotalMinutes), - TimeDiff = (c.CallingDateTime()!.Value - estimatedArrivalTime).TotalMinutes // positive if scheduled is later - }) - .OrderBy(x => x.AbsDiff) - .ToList(); - - var bestStarted = startedCandidates.FirstOrDefault(); - - var futureCandidates = possibleCirculations - .Where(c => c.StartingDateTime()!.Value > now) + var bestMatch = possibleCirculations .Select(c => new { Circulation = c, TimeDiff = (c.CallingDateTime()!.Value - estimatedArrivalTime).TotalMinutes }) - .ToList(); + .Where(x => x.TimeDiff <= maxEarlyArrivalMinutes) + .OrderBy(x => Math.Abs(x.TimeDiff)) + .FirstOrDefault(); - // Check best started candidate - if (bestStarted != null && - bestStarted.AbsDiff <= startedMatchToleranceMinutes && - bestStarted.TimeDiff >= -maxEarlyArrivalMinutes) // reject if bus arrives too early - { - closestCirculation = bestStarted.Circulation; - } - else if (futureCandidates.Count > 0) - { - // Pick the soonest upcoming trip - var soonest = futureCandidates.First(); - closestCirculation = soonest.Circulation; - } - else if (bestStarted != null && - bestStarted.TimeDiff >= -maxEarlyArrivalMinutes) + if (bestMatch != null) { - // nothing upcoming today; fallback to the closest started one (if timing is reasonable) - closestCirculation = bestStarted.Circulation; + closestCirculation = bestMatch.Circulation; } if (closestCirculation == null) diff --git a/src/frontend/app/components/SchedulesTable.tsx b/src/frontend/app/components/SchedulesTable.tsx index 5df01e5..faf7b01 100644 --- a/src/frontend/app/components/SchedulesTable.tsx +++ b/src/frontend/app/components/SchedulesTable.tsx @@ -1,7 +1,7 @@ import { useTranslation } from "react-i18next"; +import { useApp } from "~/AppContext"; import LineIcon from "./LineIcon"; import "./SchedulesTable.css"; -import { useApp } from "~/AppContext"; export type ScheduledTable = { trip_id: string; diff --git a/src/frontend/app/components/Stops/ConsolidatedCirculationList.css b/src/frontend/app/components/Stops/ConsolidatedCirculationList.css index 680a511..1788ba8 100644 --- a/src/frontend/app/components/Stops/ConsolidatedCirculationList.css +++ b/src/frontend/app/components/Stops/ConsolidatedCirculationList.css @@ -150,27 +150,27 @@ } .meta-chip.delay-ok { - background: rgba(34, 197, 94, 0.15); - border-color: rgba(34, 197, 94, 0.3); + background: hsla(142, 71%, 45%, 0.15); + border-color: hsla(142, 71%, 45%, 0.5); color: #1a9e56; } .meta-chip.delay-warn { - background: rgba(251, 191, 36, 0.25); - border-color: rgba(251, 191, 36, 0.5); - color: #fbbf24; + background: hsla(43, 96%, 56%, 0.25); + border-color: hsla(43, 96%, 56%, 0.6); + color: hsl(43, 96%, 40%); } .meta-chip.delay-critical { - background: rgba(239, 68, 68, 0.2); - border-color: rgba(239, 68, 68, 0.35); - color: #b91c1c; + background: hsla(0, 84%, 60%, 0.2); + border-color: hsla(0, 84%, 60%, 0.35); + color: hsl(0, 74%, 42%); } .meta-chip.delay-early { - background: rgba(59, 130, 246, 0.17); - border-color: rgba(59, 130, 246, 0.3); - color: #1d4ed8; + background: hsla(217, 91%, 60%, 0.17); + border-color: hsla(217, 91%, 60%, 0.3); + color: hsl(224, 90%, 50%); } /* GPS Indicator */ |
