Skip to content

A Deutsche Bahn statistics website (in German) with plots and tables about train delays, connections, and other railway metrics.

License

Notifications You must be signed in to change notification settings

piebro/deutsche-bahn-statistics

Repository files navigation

Deutsche Bahn Statistics

Deutsche Bahn Statistics is a (German) website with plots and tables about the Deutsche Bahn together with Python code to create them. The statistics are automatically updated monthly and use publicly available data. The data is available in a separate repo here: https://github.com/piebro/deutsche-bahn-data.

Develop

Setup

  1. Clone the repository:

    git clone https://github.com/piebro/deutsche-bahn-statistics
    cd deutsche-bahn-data
  2. Install the required dependencies in a virtual environment using uv:

    uv sync
  3. Download the data files:

    bash download_data.sh
  4. Host the website locally:

    uv run -m http.server

Update Statistics Manually

uv run run_all_calculations.py

Add a new Question

Do it manually and copy the folder structure of the previous question. An overview of the dataset with its columns can be found in the data repository.

Update all the generated parts of index.html using the following script, after adding a new question.

START_DATE=$(date -d "$(date +%Y-%m-01) -3 month" +%Y.%m.%d)
END_DATE=$(date +%Y.%m.01)
uv run generate_html_links.py $START_DATE $END_DATE "allgemein,zeitraum,direkter_zug,zugverbindung,verspaetungsverlauf_zugfahrt,verspaetung_pro_bahnhof,zuggattungen_pro_bahnhof,bahnhof,zuggattung"

Use ruff check and ruff format to lint and format the Python code before committing new code.

Related Deutsche Bahn and Open Data Websites

There are a few other projects that look at similar data.

  • Video: BahnMining - Pünktlichkeit ist eine Zier (David Kriesel) [2019]
  • www.deutschebahn.com: official statistics from Deutsche Bahn
  • bahn.expert: look at the departure monitor of train stations in real time
  • next.bahnvorhersage.de: a tool to calculate the probability that a train connection works using historical data
  • www.zugfinder.net: multiple maps of current train positions and statistics for long-distance trains in Germany, Austria, BeNeLux, Denmark, Italy and Slovenia
  • strecken-info.de: a map of the German railroads with current construction sites and disruptions on the routes
  • openrailwaymap.org: a worldwide map with railway infrastructure using OpenStreetMap Data

Contributing

Contributions are welcome. Open an Issue if you want to report a bug, have an idea, or want to propose a change.

Website Statistics

There is lightweight tracking with Plausible for the website to get info about how many people are visiting. Everyone who is interested can look at these stats here: https://plausible.io/piebro.github.io%2Fdeutsche-bahn-statistics?period=30d. Only users without an AdBlocker are counted, so these statistics are underestimating the actual count of visitors. I would guess that quite a few people (including me) visiting the site have an AdBlocker.

License

All code in this project is licensed under the MIT License. The data is licensed under Attribution 4.0 International (CC BY 4.0) by Deutsche Bahn.