GoTrain tracks trains
GoTrain is a server application for receiving, processing and distributing
real-time data about train services in the Netherlands.
GoTrain is designed to continuously receive data streams offered as open data
by the Dutch Railways (NS). The data is processed and
saved in-memory in order to offer a very fast REST API, which can be used by
numerous clients to show live information about train departures, arrivals etc.
GoTrain is currently able to process the following data streams:
And it offers the received data through a number of REST APIs, which allow you
to:
You can also use GoTrain to store all services to a Redis queue for further
processing (archive function).
It is easy to extend GoTrain’s functionality or to build your own applications
using the REST API. For example: create your live departures board, or analyze
which trains are currently delayed or cancelled on the Dutch rail network.
GoTrain includes a convenient REST API.
An example request: Request all departures from Utrecht Centraal:/v2/departures/station/UT
Response (shortened):
{
"departures": [
{
"cancelled": false,
"company": "NS",
"delay": 0,
"departure_time": "2019-07-14T00:49:00+02:00",
"destination_actual": "'t Harde",
"destination_actual_codes": [
"HDE"
],
"destination_planned": "'t Harde",
"name": null,
"platform_actual": "12",
"platform_changed": false,
"platform_planned": "12",
"remarks": [],
"service_date": "2019-07-13",
"service_id": "591",
"service_number": "591",
"station": "UT",
"status": 2,
"timestamp": "2019-07-13T22:49:00Z",
"tips": [
"Stopt ook in Harderwijk"
],
"type": "Intercity",
"type_code": "IC",
"via": "Amersfoort",
"wings": []
}
],
"status": "UP"
}
The following endpoints are available:
/
- API version/v2/status
- System status/v2/arrivals/stats
- Arrival statistics/v2/arrivals/station/{station}
- Arrivals for {station}
(e.g. UT
)/v2/arrivals/arrival/{id}/{station}/{date}
- Specific arrival details/v2/departures/stats
- Departures statistics/v2/departures/station/{station}
- Departures for {station}
(e.g. UT
)/v2/departures/departure/{id}/{station}/{date}
- Specific departure details/v2/services/stats
- Services statistics/v2/services/service/{service_number}/{date}
- Specific service detailsThe full API documentation, including parameters and response formats, is included
in the GoTrain OpenAPI specification. Or check out the nicely
formatted GoTrain API on Apiary.
The archive function allows you to store all data to an archive for further
processing or analysis at a later time. When running gotrain archiver
,
GoTrain simply pushes all received services to a Redis queue (in JSON format).
A Prometheus integration is included to expose metrics about recieved messages
and API requests. This integration can be enabled optionally on a separate port.
Binary packages will be provided in a future update. For now, the best way to install GoTrain is by
downloading the source code and manually compile
the application.
go get
go build
Now, configure the application:
config/
directoryexample.yaml
to config.yaml
Configuration is also possible with environment variables. Example:
API_ADDRESS=:8080
SOURCE_SERVER=tcp://pubsub.besteffort.ndovloket.nl:7664
SOURCE_ENVELOPES_ARRIVALS=/RIG/InfoPlusDASInterface4
SOURCE_ENVELOPES_DEPARTURES=/RIG/InfoPlusDVSInterface4
SOURCE_ENVELOPES_SERVICES=/RIG/InfoPlusRITInterface2
./gotrain server
.The CLI interface of GoTrain also allows you to:
./gotrain status -u http://localhost:8080/
./gotrain inspect departure parsers/testdata/departure.xml
./gotrain help
to show all commands.It is also possible to deploy GoTrain with Docker.
docker build -t gotrain
Running the container:
docker run gotrain
(To use environment variables with docker, add them with -e KEY=VALUE
)
You can also use the official GoTrain Docker image which is updated with the latest release.
You need access to a data feed from NS called InfoPlus. This data feed is distributed freely by the NDOVloket.
Tip: you can find a public best-effort data feed from the NDOV on this page: NDOVloket realtime.
You need the address listed for ‘NS InfoPlus’, likely in the format tcp://pubsub.besteffort.ndovloket.nl:...
Consider signing up for free if you are planning to use this application for production purposes.
The data feed is the same, but it’s covered by a SLA, and it helps NDOVloket to keep track of their users.
The main objectives for GoTrain have now been developed, but there is a roadmap
for further development. The main planned improvements are:
GoTrain is currently being used in production by
Rijden de Treinen as a source for realtime
departure times, arrivals and for trip details, both on the website and in the
mobile app. Please let it known when you use GoTrain for a cool project, a big
application or for some other purpose!
Copyright (c) 2019-2022 Geert Wirken, Rijden de Treinen
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses.