Skip to main content
src/dashboard/app.py · chapter The dashboard and publishing, file 2 · 611 lines · open in the repository

What it does

Calendar Effects dashboard (decisions 0008 and 0013): one Streamlit app, on a laptop and hosted. On a laptop, next to the streaming job: streamlit run src/dashboard/app.py Hosted (free, Streamlit Community Cloud): common.settings.DASHBOARD_URL, also embedded in the Hugging Face Space. scripts/sync_dashboard_app.sh deploys it. Four views: Live stream the streaming job’s output as it is written: today’s alerts, tomorrow’s watchlist from the big-move model, event CARs as windows close, alerts per day, one retailer. Shows a published run (the online live feed a job writes with —publish-live, src/hosting/live.py: the cloud streamer or a laptop) or, on a computer that can run the job, that job’s output folder. The hosted app shows published runs only. Replay the same view over the recorded stream, any range of years (by default the big-move model’s test years, which it never saw in training), played day by day from hosting/snapshot/ (replay.json and replay_rows.parquet, src/hosting/snapshot.py). Event history each event type’s CAR path in every year, the average, a straight-line trend to the next year with its prediction interval, and the model’s flags on each event day. About what the project is, and links to the docs, the dataset and the model. Only micro-batch folders Spark has finished (they hold a _SUCCESS file) are read, so a half-written batch never shows up, and each finished folder is read once and cached.

What is inside

  • MIN_HISTORY · line 44
  • LINK_NAMES · line 48
  • REPLAY · line 50
  • VIEWS · line 51
  • read_batch(folder) · line 57: One finished micro-batch folder (cached: a finished batch never changes).
  • read_stream(dataset, stream_dir) · line 62: Every finished micro-batch of one streaming output, in batch order.
  • CAN_STREAM_HERE · line 80
  • local_runs() · line 84: This computer’s stream folders with finished batches (the demo’s, then the full run’s), newest first, each with the time its latest batch finished.
  • streaming_here() · line 95: Is a job writing on this computer right now (a batch finished in the last two minutes)?
  • shown(path) · line 102: A folder as people type it: relative to the repository when it is inside it.
  • live_feed() · line 111: The online live feed, copied to data/live/ (shared by every viewer, refreshed every 4 s). CALENDAR_EFFECTS_OFFLINE=1 turns it off (the tests use it).
  • retailers() · line 124
  • calendar() · line 129
  • snapshot(name) · line 138
  • read_json(path, modified) · line 144
  • replay_frames() · line 148: The recorded stream (hosting/snapshot/) as the tables the live view reads.
  • replay_tables(modified) · line 155
  • pct(x, digits) · line 173
  • render_stream(signals, cars, preds, lookback, kinds, focus, batches) · line 179: Today’s picture of the stream: everything up to the latest day in signals.
  • fixed_lines(data, colors, y_title, height) · line 284: One line per column of data (indexed by date), in a chart that does not zoom or pan. Streamlit’s own line charts zoom when the page is scrolled over them, and the zoom then stays through every refresh of the live view, so the dates no longer match the other charts.
  • stream_controls() · line 300
  • live_view() · line 309
  • replay_view() · line 372
  • legend_color(domain, colors) · line 428
  • event_view() · line 434
  • about_view() · line 557
  • main() · line 596

Connections

Uses: src/dashboard/__init__.py, src/common/contracts.py, src/common/settings.py, src/common/study.py, src/hosting/live.py Used by: tests/test_dashboard.py

Source

src/dashboard/app.py