Files
bus-department-schedule/docs/superpowers/specs/2026-10-06-bus-board-design.md
T
2026-10-07 00:55:17 +02:00

7.6 KiB
Raw Blame History

Bus departure board — design

Date: 2026-10-06 · Status: draft for review

Goal

Show the next bus/trolleybus departures from the two stops near home on the 3.5" Turing Smart Screen (320x480 panel used in 480x320 landscape), driven by a Docker container on the Coolify home server. The screen is plugged into the server over USB; this is already proven by the clock container.

Success: glancing at the screen answers "when is my next bus, from which stop, which line?" with a minutes countdown, without touching anything.

What the user said / decisions

  • Stops: Štípa,u potoka and Štípa,družstvo (Zlín, operator DSZO).

  • Lines and source pages (one page per line per stop, direction implied by the page):

    Line Stop Source page (DSZO)
    4 (trolleybus) Štípa,u potoka /bank1/trolejbusy/04b_22.html
    5 (trolleybus) Štípa,u potoka /bank1/trolejbusy/05a_03.html
    35 (bus) Štípa,družstvo /bank1/autobusy/35b_06.html
    36 (bus) Štípa,družstvo /bank1/autobusy/36b_06.html

    Pages are fetched as https://www.dszo.cz/jr/workhtml.php?htmlfile=<base64 of path>&grafikon=<opaque>; the exact URLs the user supplied go into lines.yaml verbatim.

  • Scheduled times only. No live delays needed.

  • Display per departure: line number, stop name, departure time, minutes countdown. The next departure additionally gets a large countdown.

Assumptions (not confirmed by the user)

  • Each supplied page is the direction the user wants; other directions are out of scope.
  • Time zone Europe/Prague.
  • The analog clock stays in the repo as a fallback view, not on the default screen.

Screen layout

┌────────────────────────────────────────────┐
│ [4]  Štípa,u potoka                 23:52  │  header: next bus + small clock
│      ► 4 min      odj. 23:56               │  big countdown
├────────────────────────────────────────────┤
│ [36] Štípa,družstvo       00:12    za 20 m │
│ [5]  Štípa,u potoka       00:31    za 39 m │
│ [4]  Štípa,u potoka       04:16    zítra   │
│ [35] Štípa,družstvo       04:40    zítra   │
└────────────────────────────────────────────┘
  • Departures of both stops are merged into one list sorted by time.
  • Top block: the very next departure; under one minute the countdown reads teď.
  • Below: the following four departures. Departures on the next calendar day are marked zítra, so the board is never empty after the last bus.
  • Redraw once per minute on the minute boundary (no per-second motion needed).
  • Visual style follows the clock: near-black background, one orange accent, Roboto, Czech text.

Components

One job per file; schedule.py and timetable.py have no screen or network side effects in their pure functions so they are unit-testable.

File Responsibility Depends on
lines.yaml List of {line, stop, url} entries —
timetable.py Download a page, parse into a Timetable (columns + departures); disk cache read/write requests/urllib, stdlib html parsing
schedule.py Pick the applicable column for a date; next_departures(timetables, now, n) holidays
render.py Draw the analog clock face (exists; fallback view) Pillow
board.py Draw the departure board image Pillow, schedule.Upcoming
store.py Read lines.yaml, download + cache pages, staleness timetable.py
app.py Testable glue: local time, refresh timing, board-or-nothing schedule.py, board.py
main.py (replaces clock.py) Own the display and the update loop all of the above

Data model

  • Departure: line, stop, time (HH:MM), mark (footnote letter or None).
  • Timetable: per source page, a list of columns, each with label, valid_from (date), optional explicit dates (special days) and day_kind (workday / rest_day / special), plus its departures.

Parsing (timetable.py)

  • The page is UTF-8 HTML. Departures are in table.stop-timetable: one row per hour (td.hour-cell), one td.minutes-cell per column, minutes space-separated.
  • Column headers give the kind and validity, e.g. Pracovní dny / platnost od 1.10.2026, Dny pracovního klidu / platnost od 3.10.2026, Prac.dny–školní prázdniny / platnost 29.–30.10.2026, 23.12.2026. Date ranges and lists in the header are parsed into explicit dates.
  • Footnote marks (<span class="idx">v</span>) are stored in mark. They describe per-trip route variations (e.g. v = continues to depot), not cancellations, so every departure is kept and marks are not displayed in v1.
  • Parse result with zero departures is treated as a failure.

Choosing the column (schedule.py)

For a given date:

  1. If the date is not a rest day and is in a special column's explicit dates → that column (the special column is workdays during school holidays, so it never applies on a Saturday, Sunday or state holiday).
  2. Else if it is a Saturday, Sunday or Czech state holiday → the rest_day column.
  3. Else → the workday column.

Among columns of the same kind, use the one with the latest valid_from <= date; if none yet applies, use the earliest. Steps 1–3 are the proposed default order (a special date on a workday beats the workday column; rest days always use the rest-day column); the user writes and may change this function, see "User-written code" below.

next_departures looks at today's selected column from now, and rolls into the next day(s) until it has n entries, flagging those not on today's date.

Data handling and errors

  • Fetch on container start and daily at ~03:00 local time; cache raw HTML plus the fetch timestamp in the /data Docker volume.
  • Download fails or parse yields zero departures → keep the existing cache, log the error, continue to show the board from cache.
  • Cache older than 3 days, or no cache at all and no download → show a small jízdní řád zastaralý marker on the board; with no data at all, fall back to the clock face.
  • A column whose valid_from lies in the future is used only from that date; this covers timetable changes announced on the page.
  • Pages are fetched politely: four requests a day, one User-Agent string identifying the project.

Testing

  • Save the four real pages as fixtures in tests/fixtures/.
  • Unit tests: parser (counts, column labels, special dates, marks), column selection (workday, Saturday, state holiday, special school-holiday date, validity switch), next_departures (rollover past midnight, zítra flag, fewer than n today).
  • Render tests generate PNG previews (committed preview of the board for review).
  • On-device check on the server: container logs plus a photo of the screen.

Out of scope (v1)

Live delays or vehicle positions, other directions or stops, showing footnote marks, touch input, anything beyond the four listed pages.

User-written code

schedule.py: select_column(columns, date) — the precedence rule above (special date vs. holiday vs. weekend) is a small piece of real judgment; the user writes it (about 8 lines) when we reach that step.

Delivery

Deployed as a Docker Compose resource in Coolify from the Gitea repo, with the /data volume and the screen device by its /dev/serial/by-id/ path. The manual copy in ~/bus-board-test on the server is removed afterwards.