src/dashboard/app.py (Streamlit). The same file runs on a laptop next to the streaming job and hosted for free on Streamlit Community Cloud, so what you demo is what teammates run. The dataset, the model and a Space that embeds the dashboard are on Hugging Face, in the team’s organisation.
The big idea
- Four views: Live stream (a run as it happens), Replay (the recorded stream played day by day, for the years you pick; the model’s test years by default), Event history & forecast (each event’s CAR path every year, the average, and a straight-line trend to the next year with a 95% prediction interval, plus what the model expected on each event day), and About.
- Reading safely: the app only reads micro-batch folders Spark has finished (they hold
_SUCCESS), so a half-written batch never appears. - Where a live run comes from: Published runs (online), the live feed below, which is all the hosted app offers; or, on a computer that can run the job, A job on this computer, its output folder with no delay, picked by itself while a job is writing there.
- Live, even when hosted: a hosted app cannot read your laptop’s
data/stream/. So the job uploads the finished batches every 15 seconds to a public Hugging Face dataset (src/hosting/live.py), without any price columns, and the hosted app copies that run and reads it like a local folder. It is opt-in (--publish-live, orscripts/demo_live.shfor the whole demo), with safeguards: only from a computer signed in to Hugging Face with write access, only from a local folder, and a new run only appears once no other run is streaming, so one person’s run cannot take over another’s demo. - The cloud streamer: nobody’s laptop has to run the demo. The private
Calendar-Effects/live-streamrepository on github.com has a Live stream workflow (hosting/workflows/live-stream.yml, decision 0015) that runsscripts/demo_live.shon GitHub’s servers, always publishing. Run workflow starts it, Cancel run stops it, and mode resume carries the same run on, because the run’s checkpoint is saved in the Actions cache. It also stops by itself when the replay runs out. It needs no access to github.sfu.ca: after each commit onmain, the post-commit hook pushes a copy of what the demo needs to the repository’sprojectbranch (scripts/sync_live_stream.sh), just as it pushes the docs site and the dashboard. - The recording:
snapshot.pybuildshosting/snapshot/(committed) from the stream’s output, the batch study and the model. It checks the forecast’s slope againststats.py’s trend and stops if they differ. - Deploying:
scripts/sync_dashboard_app.shcopies the app and only the code it imports to the team’sdashboardrepository on github.com after each commit; Streamlit Community Cloud redeploys it. - Publishing:
publish_hf.pystages the dataset (split by year like the model), the model and the Space with cards filled in from the run, and uploads only with--upload. It never publishes prices, volumes or raw returns: Yahoo’s terms do not allow it.
Words you will meet
Prediction interval
Prediction interval
Live feed
Live feed
GitHub Actions workflow
GitHub Actions workflow
Dataset and model cards
Dataset and model cards
Read these files in this order
src/dashboard/init.py
src/dashboard/app.py
src/dashboard/reloader.py
src/hosting/init.py
src/hosting/snapshot.py
src/hosting/live.py
scripts/demo_live.sh
hosting/workflows/live-stream.yml
project branch: a copy of what the demo needs, pushed after each commit on the team repository’s main (scripts/sync_live_stream.sh), so nothing here needs access to github.sfu.ca. Read ithosting/live-stream/README.md
hosting/streamlit/requirements.txt
hosting/streamlit/config.toml
hosting/streamlit/README.md
hosting/space/index.html
src/hosting/publish_hf.py
hosting/cards/dataset.md
hosting/cards/model.md
hosting/cards/space.md
Questions you should be able to answer
Why does the replay start at 2024 by default?
Why does the replay start at 2024 by default?
Can the big-move model forecast next year's Black Friday?
Can the big-move model forecast next year's Black Friday?
Why is the cloud streamer's repository private?
Why is the cloud streamer's repository private?
clean/master.parquet, and to resume, the workflow saves the job’s checkpoint, with returns computed from those prices, in GitHub’s cache. In a public repository anyone could read the copy, and a pull request’s workflow could read the cache. Private repositories get 2,000 free minutes a month, and a demo run uses about 20.How does a hosted dashboard show a run on a laptop?
How does a hosted dashboard show a run on a laptop?
--publish-live, the job publishes each finished micro-batch to a public Hugging Face dataset every 15 seconds. The hosted app checks for new batches every few seconds and copies them, data first and _SUCCESS last.What stops the dashboard reading half a batch?
What stops the dashboard reading half a batch?
_SUCCESS into a batch folder only after the whole batch is written; the reader skips folders without it.Ideas to improve it
- Push alerts to a chat channel when a flagged retailer moves.
- Add a “what if” view: pick a past event and replay only its window.