Browse Source

back: Document realtime data

main
Mattéo Delabre 4 years ago
parent
commit
dd32739736
Signed by: matteo GPG Key ID: AE3FBD02DC583ABB
  1. 25
      back/data/realtime.js

25
back/data/realtime.js

@ -1,19 +1,26 @@
const tam = require('./sources/tam');
const util = require('../util');
let nextUpdate = null;
let currentCourses = null;
/**
* Fetch real-time information about courses in the TaM network.
* Fetch real-time information about active courses in the TaM network.
*
* New data will only be fetched from the TaM server once every minute,
* otherwise pulling from the in-memory cache.
*
* New data will only be fetched from the TaM server if necessary, otherwise
* pulling from the in-memory cache.
* The following information is provided for each active course:
*
* @return Mapping from active course IDs to current information about the
* course, including its line number, next stop and next stop estimated
* time of arrival (ETA).
* - `id`: Unique identifier for the course.
* - `line`: Line number.
* - `nextStop`: Identifier of the next stop of the course.
* - `arrivalTime`: Timestamp at which the vehicle is predicted to arrive
* to the next stop.
* - `finalStop`: The final stop to which the course is headed.
*
* @return Mapping from active course IDs to information about each course.
*/
let nextUpdate = null;
let currentCourses = null;
const getCourses = () => new Promise((res, rej) =>
{
if (nextUpdate !== null && Date.now() < nextUpdate)

Loading…
Cancel
Save