Skip to main content
There is one dashboard, 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, or scripts/demo_live.sh for 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-stream repository on github.com has a Live stream workflow (hosting/workflows/live-stream.yml, decision 0015) that runs scripts/demo_live.sh on 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 on main, the post-commit hook pushes a copy of what the demo needs to the repository’s project branch (scripts/sync_live_stream.sh), just as it pushes the docs site and the dashboard.
  • The recording: snapshot.py builds hosting/snapshot/ (committed) from the stream’s output, the batch study and the model. It checks the forecast’s slope against stats.py’s trend and stops if they differ.
  • Deploying: scripts/sync_dashboard_app.sh copies the app and only the code it imports to the team’s dashboard repository on github.com after each commit; Streamlit Community Cloud redeploys it.
  • Publishing: publish_hf.py stages 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.
Live: the dashboard · Hugging Face organisation calendar-effects: dataset, model, Space.

Words you will meet

Where one new year’s value should fall, not just where the trend line is. It is wider than the line’s confidence band, because single years scatter around the line.
The micro-batches a running job publishes online, so a hosted dashboard can show a run that happens somewhere else: on a laptop or on GitHub’s servers.
A script GitHub runs on its own servers, started by a button (Run workflow), a schedule or a push. Each run gets a fresh machine, which is why it downloads the project and installs Python and Java every time.
The README of a Hugging Face repository: what is in it, how it was made, its limits and licence.

Read these files in this order

1

src/dashboard/init.py

Live alerts dashboard (decision 0008): streamlit run src/dashboard/app.py Read it
2

src/dashboard/app.py

Calendar Effects dashboard (decisions 0008 and 0013): one Streamlit app, on a laptop and hosted. Read it
3

src/dashboard/reloader.py

Keep the dashboard’s own modules current between reruns (decision 0013). Read it
4

src/hosting/init.py

Publishing: the public dashboard page and the Hugging Face uploads (decision 0010). Read it
5

src/hosting/snapshot.py

Build the recorded stream and event history the dashboard shows (decisions 0010 and 0013). Read it
6

src/hosting/live.py

The live feed (decision 0013): the streaming job publishes each micro-batch online, so the hosted dashboard shows a real run within seconds. Read it
7

scripts/demo_live.sh

The live demo in one command (decisions 0013 and 0015): replay the stored data from a start date and stream it through the Spark job, one micro-batch (5 trading days) every 5 seconds, publishing each one to the hosted dashboard (https://calendar-effects.streamlit.app). Read it
8

hosting/workflows/live-stream.yml

The cloud streamer (decision 0015): the live demo on GitHub’s servers instead of a team member’s computer. It runs scripts/demo_live.sh, which replays the stored data through the Spark job and publishes every micro-batch to the hosted dashboard. The project comes from this repository’s 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 it
9

hosting/live-stream/README.md

Calendar Effects: the cloud streamer Read it
10

hosting/streamlit/requirements.txt

What the hosted dashboard installs on Streamlit Community Cloud (decision 0013). scripts/sync_dashboard_app.sh puts this file at the root of the dashboard’s repository. Read it
11

hosting/streamlit/config.toml

Streamlit settings for the hosted dashboard (copied to .streamlit/config.toml). Colours go in separate light and dark themes: a plain [theme] section would replace Streamlit’s Light and Dark themes and hide the viewer’s System / Light / Dark choice in the app menu. Read it
12

hosting/streamlit/README.md

Calendar Effects dashboard (hosted copy) Read it
13

hosting/space/index.html

Retail stocks and Wikipedia attention around shopping events: the Calendar Effects dashboard (Kafka, Spark Structured Streaming, an event study and a Spark MLlib model). Read it
14

src/hosting/publish_hf.py

Publish the project on Hugging Face (decision 0010): a dataset, a model and the dashboard. Read it
15

hosting/cards/dataset.md

A Hugging Face card template: its {placeholders} are filled in by src/hosting/publish_hf.py. Read it
16

hosting/cards/model.md

A Hugging Face card template: its {placeholders} are filled in by src/hosting/publish_hf.py. Read it
17

hosting/cards/space.md

A Hugging Face card template: its {placeholders} are filled in by src/hosting/publish_hf.py. Read it

Questions you should be able to answer

The model was trained and tuned on 2016–2023. Replaying those years shows it scoring days it has already seen, which flatters it, so the view warns when you pick them. The test years, 2024–2025, show it as it really performs. You can still pick any years to watch the stream itself.
No: it predicts tomorrow from today’s data, so it needs that year’s prices. The yearly forecast is a separate, simple trend model, labelled as a trend with its interval.
It holds Yahoo’s prices: the project copy includes the replay’s input, 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.
With --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.
Spark writes _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.