Skip to content

mzwoelfer/nextbike-city-analysis

 
 

Repository files navigation

Nextbike City Analysis

Analyze NextBike trips in your city: collect, process, and visualize bike trips.

🔴 Live Preview

Overview

- collection/       # Setup data collection
- data/             # Stored trips data
- docs/             # Documentation
- processing/       # Calculate trips
- visualization/    # Web visualization

Prerequisites

🚀 Install

  1. Clone the repository:

    git clone https://github.com/zwoefler/nextbike-city-analysis.git
    cd nextbike-city-analysis
  2. Create your .env file:

    cp .env.example .env

    Edit .env and set your values:

    Variable Description
    DB_USER Postgres username
    DB_PASSWORD Postgres password
    DB_NAME Postgres database name
    DB_HOST Postgres host (nextbike_postgres when using compose)
    DB_PORT Postgres port (default: 5432)
    DB_BIKES_TABLE Table name for raw bike data
    DB_STATIONS_TABLE Table name for station data
    DB_CITIES_TABLE Table name for city data
    CITY_IDS Comma-separated Nextbike city IDs to collect, e.g. 467,210
    STATIONS_SYNC_INTERVAL_HOURS How often to sync stations
    CITIES_SYNC_INTERVAL_HOURS How often to sync city metadata
    EXPORT_DIR Output folder for processed trip files (default: /data)
    VISUALIZATION_PORT Port for the web UI (default: 8080)

    Find your city ID in city_ids_2025_02_15.md.

  3. Start everything:

    docker compose up -d

    This starts four services:

    • postgres - database for raw bike, station, route, and trip data
    • collector - polls the Nextbike API every 60 seconds and writes to postgres
    • processor - runs at midnight; calculates trips for each city in CITY_IDS, caches OSM routes in the database, and writes .geojson.gz files to the trip_data volume
    • visualization - FastAPI app at http://localhost:${VISUALIZATION_PORT} that serves trip and station data live from the database
  4. Open http://localhost:8080 (or your configured VISUALIZATION_PORT) in your browser.

    ⚠ To trigger processing manually, see docs/manual-processing.md.

Stop / destroy

# Stop containers
docker compose down

# Stop and delete all data (including the database volume)
docker compose down -v --remove-orphans

Credits

Inspired by 36c3 - Verkehrswende selber hacken by ubahnverleih & robbie5.

Visualization inspired by Technologiestiftung Berlin:

About

NextBike data analysis for your city. Includes Data gathering, aggregation, cleanup and display.

Topics

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages

  • Python 60.8%
  • JavaScript 23.9%
  • CSS 9.2%
  • HTML 5.0%
  • Shell 1.1%