Skip to content

Commit

Permalink
front: Fix train displaying as not honored despite respecting times a…
Browse files Browse the repository at this point in the history
…nd stops

The bug was caused by attempting to match the schedule constraint data with the train's arrival times at each point along its route.
The first table (`trainSchedule.schedule`) contains only points with time constraints, while the second table (`trainSummary.path_item_times_final`) includes the train's arrival times for all intermediate points, including those without time constraints.
So, matching the indices between the two tables doesn't work because the first table skips points that aren't constrained.
  • Loading branch information
kmer2016 committed Sep 2, 2024
1 parent fa9ff3a commit beeef07
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions front/src/applications/operationalStudies/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,17 @@ export const isScheduledPointsNotHonored = (
}

if (!trainSchedule.schedule) return false;
return trainSchedule.schedule.some((schedule, index) => {
return trainSchedule.schedule.some((schedule) => {
if (!schedule.arrival) return false;
// need to add +1 because origin will never be in schedules
const matchindIndex = trainSchedule.path.findIndex((pathItem) => pathItem.id === schedule.at);
if (matchindIndex === -1) {
throw new Error(
`No matching index found for schedule ${schedule} on trainSchedule ${trainSchedule}`
);
}
const arrivalTimeInMs = sToMs(ISO8601Duration2sec(schedule.arrival));
return (
Math.abs(arrivalTimeInMs - trainSummary.path_item_times_final[index + 1]) >=
Math.abs(arrivalTimeInMs - trainSummary.path_item_times_final[matchindIndex]) >=
ARRIVAL_TIME_ACCEPTABLE_ERROR_MS
);
});
Expand Down

0 comments on commit beeef07

Please sign in to comment.