mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
Add proof-of-concept which also queries same time period yesterday, as well as last hour
This commit is contained in:
@@ -90,8 +90,10 @@ export class RedisSelfUpdatingETARepository extends BaseRedisETARepository imple
|
|||||||
referenceCurrentTime = this.referenceTime;
|
referenceCurrentTime = this.referenceTime;
|
||||||
}
|
}
|
||||||
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 oneHourAgo = new Date(referenceCurrentTime.getTime() - (60 * 60 * 1000));
|
||||||
|
|
||||||
const travelTimeSeconds = await this.getAverageTravelTimeSeconds({
|
let travelTimeSeconds = await this.getAverageTravelTimeSeconds({
|
||||||
routeId: shuttle.routeId,
|
routeId: shuttle.routeId,
|
||||||
fromStopId: lastStop.stopId,
|
fromStopId: lastStop.stopId,
|
||||||
toStopId: nextStop.stopId,
|
toStopId: nextStop.stopId,
|
||||||
@@ -99,6 +101,30 @@ export class RedisSelfUpdatingETARepository extends BaseRedisETARepository imple
|
|||||||
from: oneWeekAgo,
|
from: oneWeekAgo,
|
||||||
to: new Date(oneWeekAgo.getTime() + (60 * 60 * 1000))
|
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;
|
if (travelTimeSeconds == undefined) return;
|
||||||
|
|
||||||
const elapsedTimeMs = referenceCurrentTime.getTime() - lastStop.timestamp.getTime();
|
const elapsedTimeMs = referenceCurrentTime.getTime() - lastStop.timestamp.getTime();
|
||||||
|
|||||||
Reference in New Issue
Block a user