add work in progress code to get data for etas

This commit is contained in:
2024-12-23 14:50:38 -08:00
parent 7a50bec048
commit bacad935a5
3 changed files with 35 additions and 5 deletions

View File

@@ -41,10 +41,11 @@ export interface IEta {
}
export interface IOrderedStop {
nextStop?: IOrderedStop,
previousStop?: IOrderedStop,
nextStop?: IOrderedStop;
previousStop?: IOrderedStop;
routeId: string;
stopId: string;
position: number;
}
/**

View File

@@ -37,13 +37,13 @@ export class RepositoryDataLoader {
await this.fetchAndUpdateRouteDataForExistingSystems();
await this.fetchAndUpdateStopAndPolylineDataForRoutesInExistingSystems();
await this.fetchAndUpdateShuttleDataForExistingSystems();
await this.fetchAndUpdateEtaData();
await this.fetchAndUpdateEtaDataForExistingOrderedStops();
} catch (e) {
console.error(e);
} finally {
// TODO test if memoization of shouldBeRunning works as intended,
// I have no idea how JavaScript works
setTimeout(this.startFetchDataAndUpdate, timeout);
// setTimeout(this.startFetchDataAndUpdate, timeout);
}
}
@@ -181,8 +181,30 @@ export class RepositoryDataLoader {
}));
}
private async fetchAndUpdateEtaData() {
private async fetchAndUpdateEtaDataForExistingOrderedStops() {
// TODO implement once I figure out how to associate ETA data with shuttles
// const systems = await this.repository.getSystems();
// await Promise.all(systems.map(async (system: ISystem) => {
// const stops = await this.repository.getStopsBySystemId(system.id);
//
// await Promise.all(stops.map(async (stop: IStop) => {
// const orderedStops = await this.repository.getOrderedStopsByStopId(stop.id);
//
// await Promise.all(orderedStops.map(async (orderedStop) => {
// const params = {
// eta: "3",
// stopIds: stop.id,
// routeId: orderedStop.routeId,
// position: orderedStop.position,
// };
//
// // How to get shuttle ID?????????
// // API doesn't provide it
// // I might be cooked
// }));
// }));
// }));
}
private async updateStopDataForSystemAndApiResponse(system: ISystem, json: any) {
@@ -225,6 +247,7 @@ export class RepositoryDataLoader {
constructedOrderedStop = {
routeId,
stopId,
position: index + 1,
};
}
@@ -232,12 +255,14 @@ export class RepositoryDataLoader {
constructedOrderedStop.previousStop = {
routeId,
stopId: jsonOrderedStopData[index - 1][1],
position: index,
};
}
if (index < jsonOrderedStopData.length - 1) {
constructedOrderedStop.nextStop = {
routeId,
stopId: jsonOrderedStopData[index + 1][1],
position: index + 2,
};
}

View File

@@ -50,10 +50,12 @@ const orderedStopsForRedRoute: IOrderedStop[] = [
{
routeId: routes[0].id,
stopId: stops[0].id,
position: 1,
},
{
routeId: routes[0].id,
stopId: stops[1].id,
position: 2,
},
];
@@ -61,10 +63,12 @@ const orderedStopsForTealRoute: IOrderedStop[] = [
{
routeId: routes[1].id,
stopId: stops[1].id,
position: 1,
},
{
routeId: routes[1].id,
stopId: stops[0].id,
position: 2,
},
]