diff --git a/src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts b/src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts index e2e6a0d..4d50dcf 100644 --- a/src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts +++ b/src/loaders/shuttle/ApiBasedShuttleRepositoryLoader.ts @@ -1,5 +1,5 @@ import { ShuttleGetterSetterRepository } from "../../repositories/shuttle/ShuttleGetterSetterRepository"; -import { IEta, IRoute, IShuttle, IStop } from "../../entities/ShuttleRepositoryEntities"; +import { IRoute, IShuttle, IStop } from "../../entities/ShuttleRepositoryEntities"; import { ShuttleRepositoryLoader } from "./ShuttleRepositoryLoader"; import { ICoordinates, IEntityWithId } from "../../entities/SharedEntities"; import { ApiResponseError } from "../ApiResponseError"; @@ -34,11 +34,6 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader await this.updateRouteDataForSystem(); await this.updateStopAndPolylineDataForRoutesInSystem(); await this.updateShuttleDataForSystemBasedOnProximityToRoutes(); - - // Because ETA method doesn't support pruning yet, - // add a call to the clear method here - await this.repository.clearEtaData(); - await this.updateEtaDataForExistingStopsForSystem(); } public async updateRouteDataForSystem() { @@ -238,65 +233,6 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader return null; } - public async updateEtaDataForExistingStopsForSystem() { - const stops = await this.repository.getStops(); - await Promise.all(stops.map(async (stop) => { - let stopId = stop.id; - await this.updateEtaDataForStopId(stopId); - })); - } - - public async updateEtaDataForStopId(stopId: string) { - try { - const json = await this.fetchEtaDataJson(stopId); - const etas = this.constructEtasFromJson(json, stopId); - if (etas !== null) { - await this.updateEtaDataInRepository(etas); - } else { - console.warn(`ETA update failed for stop ${stopId} with the following JSON: ${JSON.stringify(json)}`); - } - } catch(e: any) { - throw new ApiResponseError(e.message); - } - } - - private async updateEtaDataInRepository(etas: IEta[]) { - // ETAs are now calculated internally by the repository based on shuttle movements - // External ETAs from the API are no longer used - } - - private async fetchEtaDataJson(stopId: string) { - const params = { - eta: "3", - stopIds: stopId, - }; - - const query = new URLSearchParams(params).toString(); - - const response = await fetch(`${this.baseUrl}?${query}`, { - method: "GET", - }); - return await response.json(); - } - - private constructEtasFromJson(json: any, stopId: string): IEta[] | null { - if (json.ETAs && json.ETAs[stopId]) { - return json.ETAs[stopId].map((jsonEta: any) => { - const shuttleId: string = jsonEta.busId; - const eta: IEta = { - secondsRemaining: jsonEta.secondsSpent, - shuttleId: `${shuttleId}`, - stopId: stopId, - updatedTime: new Date(), - systemId: this.systemIdForConstructedData, - }; - return eta; - }); - } - - return null; - } - protected async updateStopDataForSystemAndApiResponse( json: any, setOfIdsToPrune: Set = new Set(), diff --git a/src/loaders/shuttle/ShuttleRepositoryLoader.ts b/src/loaders/shuttle/ShuttleRepositoryLoader.ts index d556455..ea67d22 100644 --- a/src/loaders/shuttle/ShuttleRepositoryLoader.ts +++ b/src/loaders/shuttle/ShuttleRepositoryLoader.ts @@ -4,6 +4,4 @@ export interface ShuttleRepositoryLoader extends RepositoryLoader { updateRouteDataForSystem(): Promise; updateStopAndPolylineDataForRoutesInSystem(): Promise; updateShuttleDataForSystemBasedOnProximityToRoutes(): Promise; - updateEtaDataForExistingStopsForSystem(): Promise; - updateEtaDataForStopId(stopId: string): Promise; }