aboutsummaryrefslogtreecommitdiff
path: root/src/Costasdev.Busurbano.Backend/Controllers/VigoController.cs
diff options
context:
space:
mode:
authorCopilot <198982749+Copilot@users.noreply.github.com>2025-11-21 15:24:11 +0100
committerGitHub <noreply@github.com>2025-11-21 15:24:11 +0100
commit19c1bb796fc3dcc3d191d884e53107ee3598e972 (patch)
treef0cb899a723aa792fd7ad52c28ce267d0c572213 /src/Costasdev.Busurbano.Backend/Controllers/VigoController.cs
parent7061660e7d475fe3ed016858a49a0c9b7ba10c18 (diff)
Reject running services arriving >3min early in consolidation algorithm (#108)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: arielcostas <94913521+arielcostas@users.noreply.github.com>
Diffstat (limited to 'src/Costasdev.Busurbano.Backend/Controllers/VigoController.cs')
-rw-r--r--src/Costasdev.Busurbano.Backend/Controllers/VigoController.cs11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/Costasdev.Busurbano.Backend/Controllers/VigoController.cs b/src/Costasdev.Busurbano.Backend/Controllers/VigoController.cs
index f1f5f4a..12489ca 100644
--- a/src/Costasdev.Busurbano.Backend/Controllers/VigoController.cs
+++ b/src/Costasdev.Busurbano.Backend/Controllers/VigoController.cs
@@ -211,9 +211,11 @@ public class VigoController : ControllerBase
// 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 scheduled time is >10 minutes AFTER realtime (data inconsistency).
- // 4) Fallbacks: if no future trips, use the best started one even if far.
+ // 4) Reject matches where the bus would arrive >3 minutes BEFORE schedule (too early).
+ // 5) 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 maxScheduleDelayMinutes = 10; // reject if scheduled is this much later than realtime
+ const int maxEarlyArrivalMinutes = 3; // reject if bus arrives more than 3 minutes before schedule
var startedCandidates = possibleCirculations
.Where(c => c.StartingDateTime()!.Value <= now)
@@ -240,7 +242,8 @@ public class VigoController : ControllerBase
// Check best started candidate
if (bestStarted != null &&
bestStarted.AbsDiff <= startedMatchToleranceMinutes &&
- bestStarted.TimeDiff <= maxScheduleDelayMinutes) // reject if scheduled too far after realtime
+ bestStarted.TimeDiff <= maxScheduleDelayMinutes && // reject if scheduled too far after realtime
+ bestStarted.TimeDiff >= -maxEarlyArrivalMinutes) // reject if bus arrives too early
{
closestCirculation = bestStarted.Circulation;
}
@@ -254,7 +257,9 @@ public class VigoController : ControllerBase
}
// Otherwise, leave it null (no valid match)
}
- else if (bestStarted != null && bestStarted.TimeDiff <= maxScheduleDelayMinutes)
+ else if (bestStarted != null &&
+ bestStarted.TimeDiff <= maxScheduleDelayMinutes &&
+ bestStarted.TimeDiff >= -maxEarlyArrivalMinutes)
{
// nothing upcoming today; fallback to the closest started one (if timing is reasonable)
closestCirculation = bestStarted.Circulation;