add stops info

This commit is contained in:
2025-12-15 14:51:30 +01:00
parent a43bdda953
commit 10d1d133ef
3 changed files with 41 additions and 4 deletions

View File

@@ -6,8 +6,8 @@ export default class BratislavaOpendata {
this.apiKey = apiKey;
}
async fetchOneStop(stationId) {
return this.request('/stationstop/' + stationId);
async fetchOneStop(stationStopId) {
return this.request('/stationstop/' + stationStopId);
}
async fetchAllStops() {

View File

@@ -14,6 +14,7 @@ export default class MhdMapApp {
this.stops = null;
this.oldVehicles = null;
this.vehicles = null;
this.stopCache = {};
this.lastUpdatedStatic = null;
this.lastUpdatedDynamic = null;
this.lastDelta = null;
@@ -92,6 +93,22 @@ export default class MhdMapApp {
}
}
async getStopInfo(stationStopId) {
let cached = this.stopCache[stationStopId] || null;
if (cached && cached.t.getTime() > (Date.now() - 15 * 1000)) { // cache for 15 seconds
return cached;
}
const data = await this.opendata.fetchOneStop(stationStopId);
if (!data)
return cached; // null or stale
return (this.stopCache[stationStopId] = {
t: new Date(),
data: data,
});
}
calculateVehiclesDelta(beforeObj, afterObj) {
let delta = {};
@@ -216,6 +233,8 @@ export default class MhdMapApp {
return await this.recorder.getVehicleTrace(data.vehicle, data.count || 20);
} else if (action === 'requestLineTrace') {
return await this.recorder.getSimpleLineTrace(data.line, data.count || 20);
} else if (action === 'requestStopInfo') {
return await this.getStopInfo(data.stationStopId);
}
return null;
}