mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-16 23:40:32 +00:00
For data from last week and previous day, look back instead of looking forward
This commit is contained in:
@@ -110,23 +110,24 @@ export class InMemorySelfUpdatingETARepository extends BaseInMemoryETARepository
|
||||
|
||||
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 twoHoursAgo = new Date(referenceCurrentTime.getTime() - (60 * 60 * 1000));
|
||||
|
||||
const twoHoursInMs = 120 * 60 * 1000;
|
||||
const travelTimeSeconds = await this.getAverageTravelTimeSecondsWithFallbacks({
|
||||
routeId: shuttle.routeId,
|
||||
fromStopId: currentStop.stopId,
|
||||
toStopId: nextStop.stopId,
|
||||
}, [
|
||||
{
|
||||
from: oneWeekAgo,
|
||||
to: new Date(oneWeekAgo.getTime() + (60 * 60 * 1000))
|
||||
from: new Date(oneWeekAgo.getTime() - (twoHoursInMs)),
|
||||
to: oneWeekAgo,
|
||||
},
|
||||
{
|
||||
from: oneDayAgo,
|
||||
to: new Date(oneDayAgo.getTime() + (60 * 60 * 1000))
|
||||
from: new Date(oneDayAgo.getTime() - (twoHoursInMs)),
|
||||
to: oneDayAgo,
|
||||
},
|
||||
{
|
||||
from: oneHourAgo,
|
||||
from: twoHoursAgo,
|
||||
to: new Date(),
|
||||
}
|
||||
]);
|
||||
|
||||
@@ -133,19 +133,19 @@ export class RedisSelfUpdatingETARepository extends BaseRedisETARepository imple
|
||||
const oneDayAgo = new Date(referenceCurrentTime.getTime() - (60 * 60 * 24 * 1000));
|
||||
const twoHoursAgo = new Date(referenceCurrentTime.getTime() - (120 * 60 * 1000));
|
||||
|
||||
const twoHoursMs = 120 * 60 * 1000;
|
||||
const twoHoursInMs = 120 * 60 * 1000;
|
||||
const travelTimeSeconds = await this.getAverageTravelTimeSecondsWithFallbacks({
|
||||
routeId: shuttle.routeId,
|
||||
fromStopId: currentStop.stopId,
|
||||
toStopId: nextStop.stopId,
|
||||
}, [
|
||||
{
|
||||
from: oneWeekAgo,
|
||||
to: new Date(oneWeekAgo.getTime() + (twoHoursMs))
|
||||
from: new Date(oneWeekAgo.getTime() - (twoHoursInMs)),
|
||||
to: oneWeekAgo,
|
||||
},
|
||||
{
|
||||
from: oneDayAgo,
|
||||
to: new Date(oneDayAgo.getTime() + (twoHoursMs))
|
||||
from: new Date(oneDayAgo.getTime() - (twoHoursInMs)),
|
||||
to: oneDayAgo,
|
||||
},
|
||||
{
|
||||
from: twoHoursAgo,
|
||||
|
||||
@@ -121,9 +121,9 @@ describe.each(repositoryImplementations)('$name', (holder) => {
|
||||
const { route, systemId, stop1, stop2, stop3 } = await setupRouteAndOrderedStops();
|
||||
|
||||
// Populating travel time data
|
||||
const firstStopArrivalTime = new Date(2025, 0, 1, 12, 0, 0);
|
||||
const secondStopArrivalTime = new Date(2025, 0, 1, 12, 15, 0);
|
||||
const thirdStopArrivalTime = new Date(2025, 0, 1, 12, 20, 0);
|
||||
const firstStopArrivalTime = new Date(2025, 0, 1, 11, 0, 0);
|
||||
const secondStopArrivalTime = new Date(2025, 0, 1, 11, 15, 0);
|
||||
const thirdStopArrivalTime = new Date(2025, 0, 1, 11, 20, 0);
|
||||
|
||||
repository.setReferenceTime(currentTime);
|
||||
repository.startListeningForUpdates();
|
||||
@@ -185,8 +185,8 @@ describe.each(repositoryImplementations)('$name', (holder) => {
|
||||
);
|
||||
}, 60000);
|
||||
|
||||
test("uses previous hour fallback calculation when no data available from one day ago", async () => {
|
||||
const shuttleSecondArrivalTimeAtFirstStop = new Date(2025, 0, 1, 13, 5, 0);
|
||||
test("uses previous two-hour fallback calculation when no data available from one day ago", async () => {
|
||||
const shuttleSecondArrivalTimeAtFirstStop = new Date(2025, 0, 1, 12, 5, 0);
|
||||
const currentTime = new Date(shuttleSecondArrivalTimeAtFirstStop.getTime() + 7 * 60 * 1000);
|
||||
await assertEtaIsValidGivenCurrentTimeAndSecondArrivalTime(
|
||||
currentTime, shuttleSecondArrivalTimeAtFirstStop
|
||||
|
||||
Reference in New Issue
Block a user