Skip to content

This dashboard displays the near real-time position of any bus, tram, or train (ATAC and Roma TPL operators) within the Metropolitan City of Rome Capital.

License

Notifications You must be signed in to change notification settings

ivandorte/Rome-in-transit

Repository files navigation

🚎 Rome in Transit (GTFS-RT)

img

License: CC BY-SA 4.0

Description

This dashboard displays the near real-time position of any bus, tram, or train (ATAC and Roma TPL operators) within the Metropolitan City of Rome Capital. The stream layers automatically updates every 10 seconds through a periodic callback with new data retrieved from the GTFS-RealTime (Overview) feed provided and mantained by Roma Mobilità (website)

Hugging Face: https://huggingface.co/spaces/ivn888/Rome-in-transit

GitHub Pages: https://ivandorte.github.io/Rome-in-transit/gtfs-rt/app.html

Components

Two stream layers (maps):

  1. The "Vehicle status" map shows, as the name implies, the current status of the vehicle:

    • $\textcolor{#0077BB}{\rm \textbf{In\ transit}}$
    • $\textcolor{#EE7733}{\rm \textbf{Stopped}}$
  2. The "Delays map" displays whether a vehicle is on time (ahead + on time) or behind schedule (late)

  3. :

    • $\textcolor{#009988}{\rm \textbf{On\ time}}$
    • $\textcolor{#CC3311}{\rm \textbf{Late}}$

N.B.: The value of the delay field (in minutes) will be zero if the vehicle is on time (A), negative if ahead of schedule (B) or positive if late (C).

img

Five number indicators showing:

  • The number of currently active vehicles (fleet) divided between in transit or stopped;

  • The number of vehicles on time or behind schedule;

Data

ToDo

  • Add alerts feed;
  • Add routes, stops, etc...;

Known problems:

  • If you view a blank page in HF restart the Space;

  • The periodic callback may suddenly stop working (I don't know why) and the data will not be updated, simply refresh the application page;

Deployment on GitHub pages

  1. Loaded my custom Python modules from GitHub:

const custom_modules = ['https://raw.githubusercontent.com/ivandorte/Rome-in-transit/main/modules_pyodide/colors.py', 'https://raw.githubusercontent.com/ivandorte/Rome-in-transit/main/modules_pyodide/constants.py', 'https://raw.githubusercontent.com/ivandorte/Rome-in-transit/main/modules_pyodide/indicators.py', 'https://raw.githubusercontent.com/ivandorte/Rome-in-transit/main/modules_pyodide/rome_gtfs_rt.py', 'https://raw.githubusercontent.com/ivandorte/Rome-in-transit/main/modules_pyodide/time_utils.py']
for (const module of custom_modules) {
let module_name;
module_name = module.split('/').slice(-1)[0]
await pyodide.runPythonAsync(`
from pyodide.http import pyfetch
module_pyodide = await pyfetch('${module}')
with open('${module_name}', 'wb') as f:
f.write(await module_pyodide.bytes())
`);
}

  1. Loaded protobuf and gtfs-realtime-bindings wheels from a CDN URL:

  2. How I partially solved the CORS problem?

    • Used corsproxy.io to bypass CORS errors on HTTP requests;

    • Used XMLHttpRequest (js) to make HTTP requests of binary data;

def read_feed_xhr(url):
"""
HTTP request used to retrieve binary data from
Roma mobilità GTFS-RT feed (XHR).
Adapted from: https://bartbroere.eu/2022/04/25/pyodide-requests-binary-works-update/
"""
xhr = XMLHttpRequest.new()
xhr.open("GET", url, False)
xhr.overrideMimeType("text/plain; charset=x-user-defined")
xhr.responseIsBinary = True
xhr.send(None)
response = xhr.response
return bytes(ord(byte) & 0xFF for byte in response)

Deployment on HF

Just read this Medium article written by Sophia Yang, Ph.D.

References

Authors

  • Ivan D'Ortenzio

Twitter

LinkedIn

Releases

No releases published

Packages

No packages published