Code Monkey home page Code Monkey logo

ivandorte / rome-in-transit Goto Github PK

View Code? Open in Web Editor NEW
14.0 1.0 1.0 4.45 MB

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.

Home Page: https://huggingface.co/spaces/ivn888/Rome-in-transit

License: Creative Commons Attribution 4.0 International

Python 98.33% Dockerfile 1.67%
dataapps gis gtfs gtfs-realtime holoviz panel pyodide pyproj python rome stream transportation geospatial geospatial-visualization google pandas protobuf

rome-in-transit's Introduction

🚎 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

rome-in-transit's People

Contributors

ivandorte avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

felipeescallon

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.