Skip to content

A web application to retrieve all planned trips that arrive or depart from a station using DB timetable API.

License

Notifications You must be signed in to change notification settings

justaprog/traffic-data-analysis

Repository files navigation

traffic-data-analysis

Introduction

This project analyzes live train traffic using Deutsche Bahn's Timetables API. It retrieves all planned and real-time trips that arrive or depart from selected stations and visualizes delays and patterns.

Demo

Check it out on: http://youroctopus.com/
Here’s what the traffic information page looks like:

Traffic Page Screenshot

Delayed Traffic Visualisation

Setup

There need to be a file named .env in rootfolder to set up enviroment variables.

Database Connection

To connect to the postgreSQL database, .env need to contain:
"
DATABASE_URL = "postgresql+psycopg2://DB_USER:DB_PASSWORD@DB_HOST/DB_NAME"
DB_HOST=YOURHOST
DB_NAME=YOURNAME
DB_USER=YOURUSER
DB_PASSWORD=YOURPASSWORD "

Deutsche Bahn API

To access the API, .env need to contain
" CLIENT_ID = "Your API ID"
CLIENT_SECRET = "Your API Secret" "

Install Docker Engine (Optional)

https://docs.docker.com/engine/install/ubuntu/

How to start

With python

Flask App

Create virtual environment for Linux and WSL(pip & virtualenv):
run: pip install -U pip
run: sudo apt install python3 python3-pip
run: pip install virtualenv
run: virtualenv venv # erstellt im aktuellen Ordner einen Ordner 'venv' mit der virtuellen Umgebung
run: source venv/bin/activate # danach erscheint ein (venv) vor dem Command Prompt
run: pip install -r requirements.txt
run: flask --app src/app run --debug from root to start web application. go to: http://localhost:5000/

Data Analysis

run: python -m src.app.data_analysis.punctuality from root.

With Docker

run: docker compose up -d --build
go to: http://localhost:5000/

Tools

Database: PostgreSQL, SQLAlchemy.
Frontend: HTML/CSS, Javascript.
Backend: Python, Flask. ETL & Analysis: Pandas, Matplotlib

Data

Deutsche Bahn's Timetables-API, Interne Bahnhofsnummer(IBNR).

About

A web application to retrieve all planned trips that arrive or depart from a station using DB timetable API.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published