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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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. - 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.
- 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/)
- Plain HTML, CSS and JavaScript, with Leaflet 1.9.4 for the map (OpenStreetMap tiles, optional satellite imagery). No framework and no build step.
- Position:
navigator.geolocation.watchPosition; the position is matched to the distance along the route, with a check for jumps to another part of the round. - Voice: the Capacitor text-to-speech plugin in the Android app, the browser's speech synthesis otherwise; English or Swedish.
- Storage: everything in
localStorageundertr.*keys: progress per round, work days, recordings, notes, mailbox changes and settings. Nothing is sent to a server. - Export: the Capacitor share and filesystem plugins save the recordings and work log as JSON.
?sim=<km/h>drives the route with simulated GPS for previewing.
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
tools/test_full_drive.pydrives a whole round in headless Chromium (Playwright) with simulated GPS and reports every place where the app's position along the route is more than 60 m off.tools/tests/test_v7_modes.pychecks the delivery-mode choice, “no mailbox” at a known mailbox, a new mailbox and the measured time and mailbox changes after finishing a round.