mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-19 08:50:29 +00:00
Add code to mark shuttle at a stop (Redis set)
This commit is contained in:
@@ -84,6 +84,11 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt
|
|||||||
return `shuttle:eta:historical:${routeId}:${fromStopId}:${toStopId}`;
|
return `shuttle:eta:historical:${routeId}:${fromStopId}:${toStopId}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a set storing the shuttles that are currently at a stop.
|
||||||
|
*/
|
||||||
|
private readonly shuttleIsAtStopKey = "shuttle:atstop";
|
||||||
|
|
||||||
// Helper methods for converting entities to Redis hashes
|
// Helper methods for converting entities to Redis hashes
|
||||||
private createRedisHashFromStop = (stop: IStop): Record<string, string> => ({
|
private createRedisHashFromStop = (stop: IStop): Record<string, string> => ({
|
||||||
id: stop.id,
|
id: stop.id,
|
||||||
@@ -409,10 +414,19 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt
|
|||||||
lastStopArrival: lastStop,
|
lastStopArrival: lastStop,
|
||||||
willArriveAt: shuttleArrival,
|
willArriveAt: shuttleArrival,
|
||||||
});
|
});
|
||||||
|
await this.markShuttleAsAtStop(shuttleArrival.shuttleId);
|
||||||
await this.updateShuttleLastStopArrival(shuttleArrival);
|
await this.updateShuttleLastStopArrival(shuttleArrival);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async markShuttleAsAtStop(shuttleId: string) {
|
||||||
|
await this.redisClient.sAdd(this.shuttleIsAtStopKey, shuttleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async checkIfShuttleIsAtStop(shuttleId: string) {
|
||||||
|
return await this.redisClient.sIsMember(this.shuttleIsAtStopKey, shuttleId);
|
||||||
|
}
|
||||||
|
|
||||||
public async getAverageTravelTimeSeconds(
|
public async getAverageTravelTimeSeconds(
|
||||||
{ routeId, fromStopId, toStopId }: ShuttleTravelTimeDataIdentifier,
|
{ routeId, fromStopId, toStopId }: ShuttleTravelTimeDataIdentifier,
|
||||||
{ from, to }: ShuttleTravelTimeDateFilterArguments,
|
{ from, to }: ShuttleTravelTimeDateFilterArguments,
|
||||||
|
|||||||
Reference in New Issue
Block a user