Add proof-of-concept which also queries same time period yesterday, as well as last hour

This commit is contained in:
2025-11-11 21:41:32 -08:00
parent 1866224b5b
commit 7463cb27f1

View File

@@ -90,8 +90,10 @@ export class RedisSelfUpdatingETARepository extends BaseRedisETARepository imple
referenceCurrentTime = this.referenceTime;
}
const oneWeekAgo = new Date(referenceCurrentTime.getTime() - (60 * 60 * 24 * 7 * 1000));
const oneDayAgo = new Date(referenceCurrentTime.getTime() - (60 * 60 * 24 * 1000));
const oneHourAgo = new Date(referenceCurrentTime.getTime() - (60 * 60 * 1000));
const travelTimeSeconds = await this.getAverageTravelTimeSeconds({
let travelTimeSeconds = await this.getAverageTravelTimeSeconds({
routeId: shuttle.routeId,
fromStopId: lastStop.stopId,
toStopId: nextStop.stopId,
@@ -99,6 +101,30 @@ export class RedisSelfUpdatingETARepository extends BaseRedisETARepository imple
from: oneWeekAgo,
to: new Date(oneWeekAgo.getTime() + (60 * 60 * 1000))
});
// Fallback to yesterday at the same time if no data
if (travelTimeSeconds == undefined) {
travelTimeSeconds = await this.getAverageTravelTimeSeconds({
routeId: shuttle.routeId,
fromStopId: lastStop.stopId,
toStopId: nextStop.stopId,
}, {
from: oneDayAgo,
to: new Date(oneDayAgo.getTime() + (60 * 60 * 1000))
});
}
// Fallback to last hour if still no data
if (travelTimeSeconds == undefined) {
travelTimeSeconds = await this.getAverageTravelTimeSeconds({
routeId: shuttle.routeId,
fromStopId: lastStop.stopId,
toStopId: nextStop.stopId,
}, {
from: oneHourAgo,
to: new Date(),
});
}
if (travelTimeSeconds == undefined) return;
const elapsedTimeMs = referenceCurrentTime.getTime() - lastStop.timestamp.getTime();