Rail open data gateway - deploys a connection to most NROD, Darwin and NRE subscription services and places messages on a RabbitMQ Broker for consumption by other services:
- NROD TRUST, VSTP, TD, RTPPM, TSR
- Darwin Push Port, Darwin Real Time Incidents Feed
- NRE Live Departure Board
- NR Lift & Escalator feed
As a containerised application, the application stack can be ran in numerous environments but this readme assumes running on a GNU/Linux system of some description.
We currently run the application stack on a Ubuntu 20.04 LTS small business server on our local network but it can easily be run on a VPS, AWS EC2 instance, hired bare metal server etc... or indeed on your local machine.
- docker
- docker-compose
- credentials for Network Rail open data feeds (NROD)
- access token for Live Departure Boards feed (NRE - Darwin Web Service (Staff))
- access credentials for Darwin feeds Push Port/Knowledge Base
- access key for NR Lifts & Escalator feed
The services that connect to NROD assume the following NROD subscriptions; users can set match these subscriptions by logging on to datafeeds.networkrail.co.uk
and navigating to My Feeds
and setting your subscription to:
- Train Movements: All TOCs
- TD: All Signalling Areas
- VSTP: All TOCs
- TSR: All Routes
- RTPPM: All TOCs
- SCHEDULE: All Full Daily, All Update Daily
Ensure a subscription to the following feeds at opendata.nationalrail.co.uk
:
- Darwin (PushPort)
- Knowledgebase (KB) Real Time Incidents
A Subscription is required for the Live Departure Board service - See details at https://wiki.openraildata.com/index.php?title=About_the_National_Rail_Feeds
for instructions.
Register and subscribe to the graphQL feed here: https://portal.nr-lift-and-escalator.net/
To function correctly, the following environment variables need to be set and available:
export RMQ_ADMIN_USER=<RMQ admin account user name>
export RMQ_ADMIN_PASS=<RMQ admin account password>
export RMQ_PROD_USER=<RMQ producer account user name>
export RMQ_PROD_PASS=<RMQ producer account password>
export RMQ_SUB_USER=<RMQ subscriber account user name>
export RMQ_SUB_PASS=<RMQ subscriber account password>
export RMQ_V_HOST=<FQDN for RMQ virtual host>
export GRAFANA_V_HOST=<FQDN for grafana virtual host>
export NROD_USER=<NROD credentials - user name>
export NROD_PASS=<NROD credentials - password>
export RMQ_PORT=5672
export RMQ_HOST=rabbitmq
export GFA_USER=<Grafana admin account user name>
export GFA_PASSWORD=<Grafana admin account password>
export ADMIN_PT_HOST=<FQDN for portainer virtual host>
export DARWIN_USER=<Darwin user name>
export DARWIN_PASS=<Darwin password>
export NTFY_V_HOST=<FQDN for ntfy virtual host>
export RTI_USER=<RTI account user name>
export RTI_PASS=<RTI account password>
export SLDB_TOKEN=<Access token for live departure boards>
export CRS=CRE,PAD - CSV list of CRS
export LNE_P_KEY=<Primary key for Lifts and Escalators>
export LNE_S_KEY=<Secondary key for Lifts and Escalators>
git clone git@github.com:JonathanMoss/OpenRailDataGateway.git
cd OpenRailDataGateway
docker-compose build
docker-compose up -d
We provide a set of unit tests with moderate code coverage which use pytest
as the testing framework.
It is recommended that you create a virtual environment for testing; we provide a requirements.txt for this purpose, e.g.
python3 -m venv ~/nrod_gateway_venv
. ~/nrod_gateway_venv/bin/activate
pip3 install -r requirements.txt
If you are running the tests on a local machine, where the environment variables described above have not been set, then export the following variables:
export LOG_LEVEL="DEBUG"
export LOG_DIR="test/logs/"
export RMQ_HOST="rabbitmq"
export RMQ_PORT="5672"
Now navigate to the root folder, and type to run all tests:
pytest test/unit_test/
TODO: Not yet implemented.
Within the application stack, we validate and later serialise NROD data prior to placing on the broker for consumption; the modelling we have employed is to fit our particular use case however, we provide detailed schema for each message type placed on the broker. These are available in schema
We employ the use of pydantic
, which is used to validate data and to build representative models of the NROD data.
In connection with the schema described above, users may wish to peruse the models and validation defined in the following files, to gain a deeper understanding of the type and data validation we have employed:
gateway/nrod/c_class.py
gateway/nrod/s_class.py
gateway/nrod/train_movement.py
gateway/nrod/vstp.py
This is a work in progress; we are currently working on the following:
- Pydantic modelling for RTPPM
- Pydantic modelling for TSR