Skip to content

quacksire/baywheeling

Repository files navigation

BayWheel(.ing)

Next.js MapLibre GL Deck.gl Cloudflare wakatime

Exploring Bay Area bike-share patterns with Bay Wheel open data

About

Baywheel.ing visualizes BayWheels trip patterns using anonymized historical system data published by Lyft.

How It Works

Click any station to view stats. Browse different months to spot seasonal patterns.

Architecture

Database & Caching

Rides Data:

  • Historical trip data is stored in D1 partitioned by month (rides_YYYYMM tables)
  • Each ride includes start/end stations, times, and (once computed) cached route polylines

Route Polylines:

  • OSRM API computes cycling routes between stations on-demand
  • Computed routes are cached in D1 (per-ride) and KV (per route pair) to avoid redundant API calls
  • Routes are grouped by origin→destination pair; if multiple rides share the same route, the line thickness increases by 1 + log(rideCount) * 0.1 for subtle visual emphasis

Station Stats:

  • Aggregated stats (top destinations, busiest hours, etc.) are streamed as JSON-lines and cached in KV to avoid expensive re-aggregation

Rate Limiting

OSRM enforces a 1 request/second limit per IP. To respect this:

  • Client initiates requests with a 2 concurrent limit
  • Requests are staggered by 500ms (queueIndex * 500) to maintain spacing
  • Combined with Cloudflare's caching, this prevents bandwidth blocks

Limitations

Route lines are computed using OSRM, the only free open-source routing engine I could find.

It only supports driving and walking modes. Cycling is used here.

If you have another free and simple option, feel free to open an issue.

Built With

Getting Started

Prerequisites

  • Node.js 18+ and pnpm
  • Cloudflare account with D1 and KV enabled

Setup

  1. Clone and install:

    git clone https://github.com/samwarnick/baywheeling
    cd baywheeling
    pnpm install
    pnpm run init
  2. Run the development server:

    pnpm dev

    Open http://localhost:3000 in your browser.

  3. Deploying to Cloudflare (optional):

    pnpm deploy

    This builds and deploys to Cloudflare Pages, Workers, D1, and KV using the bindings configured in wrangler.jsonc.

Data Ingestion

Note

The app relies on historical trip data from Lyft's Bay Wheels system. This data is not included in the repository due to size, but you can easily load it yourself using the steps below. Make you run the init script before loading data, as it sets up the D1 database. KV should just work without initialization, but D1 needs the schema to be created first.

To load Bay Wheels trip data into D1:

  1. Download system data: Download CSV files from Lyft's Bay Wheels system data and place them in utils/data/:

    utils/data/202512-baywheels-tripdata.csv
    utils/data/202601-baywheels-tripdata.csv
    # etc.
    
  2. Convert CSV to SQL:

    python utils/csv_to_d1_sql.py utils/data

    This generates SQL insert statements from the CSV files.

  3. Upload to D1:

    ./utils/load-seeds.sh

    This loads the generated SQL into your Cloudflare D1 database.

About

Exploring Bay Area bike-share patterns with Bay Wheel open data

Resources

Stars

Watchers

Forks

Contributors