diff --git a/src/sharedMemory.ts b/src/sharedMemory.ts deleted file mode 100644 index fe371aa..0000000 --- a/src/sharedMemory.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { System } from "./generated/graphql"; - -export interface SharedMemory { - systems: System[], -}; - -export const sharedMemory: SharedMemory = { - systems: [], -}; diff --git a/src/sharedMemoryUpdater.ts b/src/sharedMemoryUpdater.ts deleted file mode 100644 index f24040b..0000000 --- a/src/sharedMemoryUpdater.ts +++ /dev/null @@ -1,96 +0,0 @@ -import { sharedMemory } from "./sharedMemory"; -import { Stop, System } from "./generated/graphql"; - -const baseUrl = "https://passiogo.com/mapGetData.php"; - -async function updateStopAndOrderedStopDataForSystem(systemToConstruct: System) { - const params = { - getStops: "2", - }; - - const formDataJsonObject = { - "s0": systemToConstruct.id, - "sA": "1", - } - const formData = new FormData(); - formData.set("json", JSON.stringify(formDataJsonObject)); - - const query = new URLSearchParams(params).toString(); - const response = await fetch(`${baseUrl}?${query}`, { - method: "POST", - body: formData, - }); - const json = await response.json(); - - if (typeof json.stops === "object") { - const jsonStops = Object.values(json.stops); - - systemToConstruct.stops = jsonStops.map((jsonStop: any) => { - return { - id: jsonStop.id, - name: jsonStop.name, - coordinates: { - latitude: jsonStop.latitude, - longitude: jsonStop.longitude, - }, - system: systemToConstruct, - etas: [], - orderedStops: [], - } - }); - } -} - -async function updateSystemData() { - // Construct the graph from the bottom up, so that - // system data is populated with all necessary fields - - const params = { - getSystems: "2", - }; - const query = new URLSearchParams(params).toString(); - const response = await fetch(`${baseUrl}?${query}`); - const json = await response.json() - - if (typeof json.all === "object") { - sharedMemory.systems = await Promise.all(json.all.map(async (jsonSystem: any) => { - const constructedSystem: System = { - id: jsonSystem.id, - name: jsonSystem.fullname, - routes: [], - stops: [], - shuttles: [], - }; - - try { - await updateStopAndOrderedStopDataForSystem(constructedSystem); - } catch (e) { - console.error(e); - } - - return constructedSystem; - })); - } -} - -async function fetchDataAndUpdateStore() { - try { - await updateSystemData(); - } catch (e) { - console.error(e); - } -} - -async function runDataUpdateScheduler() { - // while (true) { - const timeoutInMilliseconds = 10000; - await fetchDataAndUpdateStore(); - await new Promise((resolve) => setTimeout(resolve, timeoutInMilliseconds)); - // } -} - -function startDataUpdater() { - runDataUpdateScheduler(); -} - -export { startDataUpdater };