BABUNI.DEV

Tidningsrundan / Architecture

Tidningsrundan: Architecture

How the route builder, the route data and the phone app fit together, as of version 7 (1 December 2026).

Overview

OpenStreetMap data ─┐
config.json ────────┼─> tools/build_route.py ─> app/route_data.json
recordings (JSON) ──┘                               │
        ^                                           v
        │                                    app/ (web app) ─> android-app/ ─> APK
        │                                           │
        └──── “Share / save file” export ───────────┘

The builder runs on a computer and takes several minutes. The app does no route computing: it follows the bundled route and records what happens.

Route builder (tools/build_route.py)

Python with NumPy and SciPy.

  1. Road graph. OpenStreetMap roads inside the bounding box (tracks excluded) are cut at junctions. Each piece becomes two lanes, one per direction; one-way roads keep only one. Blocked roads are cut at the blocked point.
  2. Zones. The island (Selaön) and the mainland are separated by graph connectivity from a seed point; the village area is a buffer around its streets. Rounds are made from zones.
  3. Stops. Recorded mailboxes are placed on the lane they were recorded from, so they sit on the driver's left. Records are deduplicated across exports by time; kinds are mailbox, none, note, confirm and move. Before 1 December, building outlines of house size (45–350 m²) were snapped to the nearest road as guessed houses.
  4. Required jobs. A mailbox requires its lane. Streets served on both sides need one pass in either direction. A dead-end chain (walking back from a dead end to the first junction) is one job: in, both sides, out. Dead ends are trimmed after the last mailbox.
  5. Lane graph with turn costs. Nodes are lanes; an arc means “drive this lane next” and costs its travel time plus a turn penalty (U-turn mid-road 45 s, at a dead end 8 s, left 4 s, right 2 s). Only the strongly connected core reachable from the start and back is used.
  6. Ordering. All-pairs shortest paths between jobs (Dijkstra), a greedy construction with random noise and restarts, or-opt improvement, orientation flips for both-sides jobs, then an iterated local search for a set time per round (ils_seconds). The joined round also tries the separate rounds end to end in every order.
  7. Delivery modes. Every round is built twice: left only, and both sides, where a right-side stop costs extra seconds and a road is served in one pass only when that beats driving it again.
  8. Output. For each round and mode: the line geometry with cumulative distance, turn-by-turn steps with road names, the stops with box counts and side, distance, driving time and an estimate from the stop-time constants. Measured times from recorded drives are added.

tools/plot_route.py draws one round over the road network for a quick visual check.

Route data (app/route_data.json)

One JSON file with the start point, blocked points and a list of tours (samhalle, landsbygd, selaon, alla, and each with @both). Each tour holds line, cum, steps, houses, length_m, drive_s, est_min, measured_min, mode and right_stops.

Phone app (app/)

Android packaging (android-app/)

Capacitor 7 copies app/ into www/ and builds a debug APK with Gradle and JDK 21. Plugins: filesystem, share, keep-awake and text-to-speech. App id se.stallarholmen.tidningsrundan.

Tests

Babuni's project documentation, imported from the private project folder. Code and route data are not published.