Commit Graph
11 Commits
Author SHA1 Message Date
jschoubben b55f9cd615 Keep map tiles on disk and fetch them in parallel; send posters with an ETag
A race poster took 8.8 s, 78% of it fetching 40 map tiles one by one,
and every poster, thumb and locator of the same circuit fetched the same
tiles again. Tiles are now kept on disk in the cache volume for 30 days
(stored only once the stitch is no placeholder) and fetched in parallel,
at most 6 at once per Esri service and 2 for OpenStreetMap, as its tile
usage policy asks, across every render. Measured: a poster of a new
circuit 2.4 s, of a known one 0.8 s; a weekend's first thumb 1.4 s, each
further thumb 0.8 s (was about 12 s each). PNGs are saved without
optimize (1.6 s less per render, 2% larger).

A stored poster is sent with an ETag and a day's cache instead of a
year's, and an If-None-Match that matches gets a 304, so a poster whose
look changes reaches clients within a day.

Claude-Session: https://claude.ai/code/session_01NcbgfJAa38xFpzy69BWrqh
2026-11-27 10:31:39 +01:00
jschoubben d9c6fdc46c Back off a failed Jolpica ask; render posters off the event loop
Review round 1 (two findings):
- While Jolpica failed, every schedule read asked it again, up to four
  times per poster request, and the poster, thumb and grand-prix routes
  were async, so the pacing, a 429's pause and a timeout stalled every
  request. A failed ask is now remembered for ten minutes (the kept
  schedule, or none, is answered meanwhile), a schedule in memory is
  answered without waiting for an ask under way, and those routes are
  plain defs in the threadpool. A rendered picture is stored whole
  (written aside, then renamed), as two may now render it side by side.
- Bytecode was tracked: tests/__pycache__ (added with the tests) and
  models/__pycache__ that the cleanup missed. Untracked; .gitignore
  already names __pycache__/.

From the review's notes: a poster whose map or photo failed is sent with
a five-minute cache instead of a year's; uvicorn trusts the proxy's
forwarded headers, so /examples redirects to https, not http; stale
comments naming CARTO and the zoom lookup's key are corrected.

Claude-Session: https://claude.ai/code/session_01NcbgfJAa38xFpzy69BWrqh
2026-11-27 10:24:04 +01:00
jschoubben 6490dc5933 List the routes the API serves at its root
The root's list named a /grand-prix/{name}/year/{year} route and a
/tracks/.../layout/... route that do not exist, and left out the
per-layout file route, the session thumbs and the Kometa metadata, so a
reader of / was sent to addresses that answer 404.

Claude-Session: https://claude.ai/code/session_01NcbgfJAa38xFpzy69BWrqh
2026-11-27 09:48:21 +01:00
jschoubben b6e6e9d565 Add an example site that calls every route, served at /examples/
A reader learns the API fastest from working calls: one page per area
(circuit browser, track images, GPS traces on a map, grand prix lookup,
posters, Kometa) shows the exact request URL next to its answer. Pages
call their own origin when the app serves them, and the public service
when opened from disk or given ?api=. Posters render only on a button
press, since each one fetches map tiles on the server. A body that does
not match the asked format is said in red, never shown as success.

The image copies examples/ so the deployed app serves the same pages.

Claude-Session: https://claude.ai/code/session_01NcbgfJAa38xFpzy69BWrqh
2026-11-27 09:48:04 +01:00
jschoubben 1e2c1b898f Keep Jolpica schedules, pace the requests, never keep a failure
A Kometa YAML request asks Jolpica for every season at once; Jolpica
(4 requests a second, 500 an hour) answered 429 for 24 seasons on
2026-11-27 09:28, and lru_cache kept each failure as an empty schedule,
so every poster and thumb of those seasons answered 404 until a restart.
The service also ran two Jolpica clients, so the race lookup and the
posters held different schedules.

Now one client serves the whole service; a season that is over is kept
on disk in the cache volume for good, one not yet over is asked again
after six hours; requests are paced under the limit, a 429 is asked
again after its Retry-After; a failure is never kept. The Kometa
endpoint runs in the threadpool, as its first fill takes minutes.

Claude-Session: https://claude.ai/code/session_01NcbgfJAa38xFpzy69BWrqh
2026-11-27 09:46:56 +01:00
jschoubben 6352eea892 Serve each track format's own file
/png and /geojson answered the SVG file under a PNG or GeoJSON media
type, so the GPS-traced GeoJSON of a layout was never served at all.
Each format now serves its own file; a layout without one answers 404.

Claude-Session: https://claude.ai/code/session_01NcbgfJAa38xFpzy69BWrqh
2026-11-27 09:40:28 +01:00
jschoubben 6474e109f1 Add 1920x1080 session thumbs with track overlay + episode YAML entries
posters_service:
- Standard / sprint episode-index → (label, slug) maps mirroring Kometa's
  F1 builder numbering
- _fetch_map_landscape: aerial tile stitcher in 1920x1080
- render_session_thumb: GP aerial bg + projected track outline + GP name
  + session label with red accent bar
- _draw_track_projected now takes canvas_w / geo_center_y so it can be
  reused for both 2:3 posters and 16:9 thumbs
- render_kometa_metadata now emits an episodes: block per Plex season
  pointing every Kometa-numbered episode at the matching session thumb;
  sprint vs standard format is detected from the Jolpica race entry

cdn-api:
- GET /posters/session/{name}/{year}/{slug}.png returns the thumb
2026-06-15 02:28:03 +02:00
jschoubben 9430d499cc Map backgrounds (aerial/osm/dark/light), bbox zoom, world locator, kometa YAML endpoint
posters_service:
- BackgroundStyle enum + tile stitcher for race posters
  (Esri aerial / OSM Carto / CartoDB dark / CartoDB light / none)
- _resolve_circuit_geo: GeoJSON bbox centre + auto-zoom (no hand tuning),
  falls back to Jolpica lat/lon + f1-locations.json zoom
- _draw_track_projected: project the layout's GeoJSON points into the
  same window as the tile background, so the white outline aligns with
  the actual track (the hand-drawn SVGs had arbitrary orientations)
- _render_world_locator: 140x140 CartoDB Dark inset at zoom 5 with a
  red marker pinning the circuit on the continent
- _race_dark_overlay: dimming so the heading + footer stay legible
  against any underlying tiles
- render_kometa_metadata: emits a Kometa-compatible YAML covering
  every season 1950..current+1 with per-show + per-round url_poster

cdn-api:
- GET /posters/race/{name}/{year}.png supports ?bg= query param
- GET /kometa/formula-1-metadata.yml serves the generated config so
  Kometa pulls it via metadata_files.url (auto-updates with schedule)
2026-06-14 17:42:02 +02:00
jschoubben 847ae2bae1 Add Plex-ready race + season poster endpoints
GET /posters/race/{grand_prix_name}/{season}.png
GET /posters/season/{season}.png

1000x1500 PNGs composed with Pillow + cairosvg:
checkered-flag strips top/bottom, F1 wordmark, round/year ribbon,
GP name, rasterised track outline (white), race date. Season poster
is wordmark + giant year + 'WORLD CHAMPIONSHIP'. Cached under
cache/posters/ so cold renders happen once.
2026-06-13 20:57:28 +02:00
jschoubben 83311a6079 Fix circular reference recursion in JSON serialization
Dataclass models have parent back-references (TrackLayout→Circuit→
Locality→Country) causing infinite recursion in dataclasses.asdict().
Add to_dict() methods that exclude parent refs, use them in API endpoints.
2026-05-08 03:01:42 +02:00
jschoubben c94ebcfb22 Add all local circuit work — year-by-year SVGs and tooling 2026-03-25 22:17:47 +01:00