Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent Delay Times #343

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/utils/RouteUtilsV3.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this consider the delay for the first walking portion before you get onto the bus? I think you will also need to check if the first bus in the directions is delayed and if so, add that time to the first walking portion of the directions (when you walk to the bus stop).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,42 @@ async function getSectionedRoutes(
isArriveBy,
);

// Iterates over each route in finalBusRoutes, calculates total delay from bus segments,
// and applies this delay to the 'walk' segment if it follows a delayed bus segment.
finalBusRoutes.forEach((route) => {
let totalDelay = 0;
let firstDelay = null;
let foundFirstDelay = false;
let firstDelayIndex = 0;

const { directions } = route;

for (let i = 0; i < directions.length; i++) {
const segment = directions[i];
const { delay } = segment;
if (!foundFirstDelay && delay !== null) {
firstDelay = delay;
foundFirstDelay = true;
firstDelayIndex = i;
}

if (segment.type === 'walk' && totalDelay > 0) {
segment.delay = totalDelay;
} else if (delay !== null) {
totalDelay += delay;
}
}

// assign delay to walking route before first bus delay
let i = 0;
if (foundFirstDelay) {
while (directions[i].type === 'walk' && firstDelay != null && i < firstDelayIndex) {
directions[i].delay = firstDelay;
i += 1;
}
}
});

finalBusRoutes.forEach((route) => {
if (originBusStopName !== null
&& route.directions
Expand Down