Giter Club home page Giter Club logo

transpo-rt's Introduction

transpo-rt

Simple API for public transport realtime data.

This API reads a public transport base schedule (a GTFS) and some realtime data (for the moment in GTFS_RT) to provide realtime feeds in siri lite.

Using

A hosted version of this API, with some french datasets can be freely used.

The API provides several routes:

  • GET /: list the available datasets - example call
  • GET /spec: OpenApi v3 description of this API - example call
  • GET /{id}/gtfs-rt: get the gtfs-rt as binary - example call
  • GET /{id}/gtfs-rt.json: get the gtfs-rt as json - example call
  • GET /{id}/siri/2.0/stop-monitoring.json: get a siri-lite stop monitoring response - example call
  • GET /{id}/siri/2.0/stoppoints-discovery.json: get a siri-lite stoppoint discovery response - example call
  • GET /{id}/siri/2.0/general-message.json: get a siri-lite general message response - example call
  • GET /{id}/: simple status on the dataset - example call

API details

/siri/2.0/stop-monitoring.json

The API follow the Siri-lite specification (documentation in french).

A formal description of the supported parameters and of the response can be seen in the OpenAPI endpoint.

/siri/2.0/stoppoints-discovery.json

The API follow the Siri-lite specification (documentation in french).

A formal description of the supported parameters and of the response can be seen in the OpenAPI endpoint.

Developping

Building

To build the api, you need an up to date Rust version:

If you don't already have it, install Rust:

curl https://sh.rustup.rs -sSf | sh

Or update it:

rustup update

Then you can build it:

cargo build

Running

You can check the needed cli parameters with the -h option:

cargo run --release -- -h

Note: an example configuration file can be seen here.

Testing

You can run all the tests (unit test, integration, clippy and fmt) with:

make check

It will save you some time for the code review and continous integration ;)

Architecture

The API has been made with actix-web. This makes it possible to have a multithreaded API with data reloading and realtime updates without dataraces (thanks to rust), nor mutexes (thanks to the actix actor model).

To achieve this there is an Actor in charge of the data (DatasetActor). The api workers query this actor to get the latest data. The DatasetActor does not return directly the data, but a Arc to them (a rust shared pointer).

In the background, 2 actors are in charge of periodic data reloading:

  • BaseScheduleReloader reloads once in a while the baseschedule dataset
  • RealTimeReloader reloads frequently the realtime dataset

Once the data (baseschedule or realtime) has been reloaded, it is send to the DatasetActor via a message. When the DatasetActor processes this message, it replaces it's Arc to this data, dropping the references. The API workers that have aquired an Arc to those data can continue their work on those data. The old data will be deleted when all workers have finished their work on them (thus noboby owns an Arc to those data anymore).

transpo-rt's People

Contributors

antoine-de avatar tristramg avatar l-vincent-l avatar

Watchers

James Cloos avatar  avatar

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.