remove shared memory and shared memory updater files

This commit is contained in:
2024-12-23 14:59:09 -08:00
parent bacad935a5
commit 74d45057db
2 changed files with 0 additions and 105 deletions

View File

@@ -1,9 +0,0 @@
import { System } from "./generated/graphql";
export interface SharedMemory {
systems: System[],
};
export const sharedMemory: SharedMemory = {
systems: [],
};

View File

@@ -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 };