Merge pull request #88 from brendan-ch:hotfix/use-two-hour-windows-for-all-fallbacks

hotfix/use-two-hour-windows-for-all-fallbacks
This commit is contained in:
2025-11-14 10:54:14 -08:00
committed by GitHub
3 changed files with 27 additions and 25 deletions

View File

@@ -110,25 +110,26 @@ export class InMemorySelfUpdatingETARepository extends BaseInMemoryETARepository
const oneWeekAgo = new Date(referenceCurrentTime.getTime() - (60 * 60 * 24 * 7 * 1000)); const oneWeekAgo = new Date(referenceCurrentTime.getTime() - (60 * 60 * 24 * 7 * 1000));
const oneDayAgo = new Date(referenceCurrentTime.getTime() - (60 * 60 * 24 * 1000)); const oneDayAgo = new Date(referenceCurrentTime.getTime() - (60 * 60 * 24 * 1000));
const oneHourAgo = new Date(referenceCurrentTime.getTime() - (60 * 60 * 1000)); const twoHoursAgo = new Date(referenceCurrentTime.getTime() - (60 * 60 * 1000));
const twoHoursInMs = 120 * 60 * 1000;
const travelTimeSeconds = await this.getAverageTravelTimeSecondsWithFallbacks({ const travelTimeSeconds = await this.getAverageTravelTimeSecondsWithFallbacks({
routeId: shuttle.routeId, routeId: shuttle.routeId,
fromStopId: currentStop.stopId, fromStopId: currentStop.stopId,
toStopId: nextStop.stopId, toStopId: nextStop.stopId,
}, [ }, [
{ {
from: oneWeekAgo, from: twoHoursAgo,
to: new Date(oneWeekAgo.getTime() + (60 * 60 * 1000))
},
{
from: oneDayAgo,
to: new Date(oneDayAgo.getTime() + (60 * 60 * 1000))
},
{
from: oneHourAgo,
to: new Date(), to: new Date(),
} },
{
from: new Date(oneDayAgo.getTime() - (twoHoursInMs)),
to: oneDayAgo,
},
{
from: new Date(oneWeekAgo.getTime() - (twoHoursInMs)),
to: oneWeekAgo,
},
]); ]);
if (travelTimeSeconds == undefined) return; if (travelTimeSeconds == undefined) return;

View File

@@ -133,23 +133,24 @@ export class RedisSelfUpdatingETARepository extends BaseRedisETARepository imple
const oneDayAgo = new Date(referenceCurrentTime.getTime() - (60 * 60 * 24 * 1000)); const oneDayAgo = new Date(referenceCurrentTime.getTime() - (60 * 60 * 24 * 1000));
const twoHoursAgo = new Date(referenceCurrentTime.getTime() - (120 * 60 * 1000)); const twoHoursAgo = new Date(referenceCurrentTime.getTime() - (120 * 60 * 1000));
const twoHoursInMs = 120 * 60 * 1000;
const travelTimeSeconds = await this.getAverageTravelTimeSecondsWithFallbacks({ const travelTimeSeconds = await this.getAverageTravelTimeSecondsWithFallbacks({
routeId: shuttle.routeId, routeId: shuttle.routeId,
fromStopId: currentStop.stopId, fromStopId: currentStop.stopId,
toStopId: nextStop.stopId, toStopId: nextStop.stopId,
}, [ }, [
{
from: oneWeekAgo,
to: new Date(oneWeekAgo.getTime() + (60 * 60 * 1000))
},
{
from: oneDayAgo,
to: new Date(oneDayAgo.getTime() + (60 * 60 * 1000))
},
{ {
from: twoHoursAgo, from: twoHoursAgo,
to: new Date(), to: new Date(),
} },
{
from: new Date(oneDayAgo.getTime() - (twoHoursInMs)),
to: oneDayAgo,
},
{
from: new Date(oneWeekAgo.getTime() - (twoHoursInMs)),
to: oneWeekAgo,
},
]); ]);
if (travelTimeSeconds == undefined) return; if (travelTimeSeconds == undefined) return;

View File

@@ -121,9 +121,9 @@ describe.each(repositoryImplementations)('$name', (holder) => {
const { route, systemId, stop1, stop2, stop3 } = await setupRouteAndOrderedStops(); const { route, systemId, stop1, stop2, stop3 } = await setupRouteAndOrderedStops();
// Populating travel time data // Populating travel time data
const firstStopArrivalTime = new Date(2025, 0, 1, 12, 0, 0); const firstStopArrivalTime = new Date(2025, 0, 1, 11, 0, 0);
const secondStopArrivalTime = new Date(2025, 0, 1, 12, 15, 0); const secondStopArrivalTime = new Date(2025, 0, 1, 11, 15, 0);
const thirdStopArrivalTime = new Date(2025, 0, 1, 12, 20, 0); const thirdStopArrivalTime = new Date(2025, 0, 1, 11, 20, 0);
repository.setReferenceTime(currentTime); repository.setReferenceTime(currentTime);
repository.startListeningForUpdates(); repository.startListeningForUpdates();
@@ -185,8 +185,8 @@ describe.each(repositoryImplementations)('$name', (holder) => {
); );
}, 60000); }, 60000);
test("uses previous hour fallback calculation when no data available from one day ago", async () => { test("uses previous two-hour fallback calculation when no data available from one day ago", async () => {
const shuttleSecondArrivalTimeAtFirstStop = new Date(2025, 0, 1, 13, 5, 0); const shuttleSecondArrivalTimeAtFirstStop = new Date(2025, 0, 1, 12, 5, 0);
const currentTime = new Date(shuttleSecondArrivalTimeAtFirstStop.getTime() + 7 * 60 * 1000); const currentTime = new Date(shuttleSecondArrivalTimeAtFirstStop.getTime() + 7 * 60 * 1000);
await assertEtaIsValidGivenCurrentTimeAndSecondArrivalTime( await assertEtaIsValidGivenCurrentTimeAndSecondArrivalTime(
currentTime, shuttleSecondArrivalTimeAtFirstStop currentTime, shuttleSecondArrivalTimeAtFirstStop