> ## Documentation Index
> Fetch the complete documentation index at: https://calendar-effects.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 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).

`scripts/demo_live.sh` · chapter [The dashboard and publishing](https://calendar-effects.mintlify.site/tour/09-dashboards-and-publishing.md), file 7 · 71 lines · [open in the repository](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/scripts/demo_live.sh)

## What it does

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](https://calendar-effects.streamlit.app)).

scripts/demo\_live.sh                 from 2023-06-01 to the end of the data (December 2025): each
stock's 120-day baseline is built by January 2024, so the
model's test years (2024-2025) are fully scored
scripts/demo\_live.sh 2016-01-04      from another date (2016-01-04 is the whole study period)
scripts/demo\_live.sh --resume        carry on the last run from where it was stopped
scripts/demo\_live.sh --every=10      seconds between micro-batches (default 5)
scripts/demo\_live.sh --private       without publishing (only this computer's dashboard shows it)

Stop with Ctrl-C: the run ends cleanly and the hosted dashboard marks it stopped (--resume carries it
on). When the replay runs out, the job stops by itself and the dashboard marks the run complete.
The cloud streamer (the "Live stream" workflow on github.com, decision 0015) runs this same script.
It writes to data/demo/ (and checkpoints/demo), so the full run in data/stream/, which the
recording and the results come from, is never touched. To watch it on this computer's dashboard:
streamlit run src/dashboard/app.py; its Live stream view picks "A job on this computer" while this runs.
It finds Java 17 or 21 by itself (Spark 4 does not start on newer Java, such as 26).
Needs: .venv (./run\_everything.sh makes it), a trained model in data/models/ (src/ml/train.py, or
hf download calendar-effects/big-move-model --local-dir data/models), and, to publish, a Hugging
Face login with write access to the calendar-effects organisation (hf auth login, or \$HF\_TOKEN).

## Source

```bash title="scripts/demo_live.sh" lines expandable theme={null}
#!/usr/bin/env bash
# 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).
#
#   scripts/demo_live.sh                 from 2023-06-01 to the end of the data (December 2025): each
#                                        stock's 120-day baseline is built by January 2024, so the
#                                        model's test years (2024-2025) are fully scored
#   scripts/demo_live.sh 2016-01-04      from another date (2016-01-04 is the whole study period)
#   scripts/demo_live.sh --resume        carry on the last run from where it was stopped
#   scripts/demo_live.sh --every=10      seconds between micro-batches (default 5)
#   scripts/demo_live.sh --private       without publishing (only this computer's dashboard shows it)
#
# Stop with Ctrl-C: the run ends cleanly and the hosted dashboard marks it stopped (--resume carries it
# on). When the replay runs out, the job stops by itself and the dashboard marks the run complete.
# The cloud streamer (the "Live stream" workflow on github.com, decision 0015) runs this same script.
# It writes to data/demo/ (and checkpoints/demo), so the full run in data/stream/, which the
# recording and the results come from, is never touched. To watch it on this computer's dashboard:
# streamlit run src/dashboard/app.py; its Live stream view picks "A job on this computer" while this runs.
# It finds Java 17 or 21 by itself (Spark 4 does not start on newer Java, such as 26).
# Needs: .venv (./run_everything.sh makes it), a trained model in data/models/ (src/ml/train.py, or
#   hf download calendar-effects/big-move-model --local-dir data/models), and, to publish, a Hugging
#   Face login with write access to the calendar-effects organisation (hf auth login, or $HF_TOKEN).
set -euo pipefail
cd "$(git rev-parse --show-toplevel)"

start=2023-06-01
every=5
resume=""
publish=(--publish-live)
for arg in "$@"; do
  case "$arg" in
    --private) publish=() ;;
    --resume) resume=1 ;;
    --every=*) every="${arg#*=}" ;;
    [12][0-9][0-9][0-9]-[01][0-9]-[0-3][0-9]) start="$arg" ;;
    -h|--help) awk 'NR == 1 {next} /^#/ {print; next} {exit}' "$0"; exit 0 ;;
    *) echo "unknown option: $arg (see scripts/demo_live.sh --help)"; exit 2 ;;
  esac
done
[[ "$every" =~ ^[0-9]+$ ]] || { echo "--every needs whole seconds, e.g. --every=5"; exit 2; }

java_major() {  # the major version of $1/bin/java, or nothing
  [[ -x "$1/bin/java" ]] || return 0
  "$1/bin/java" -version 2>&1 | awk -F'"' '/version/ {split($2, v, "."); print v[1]; exit}'
}
java_ok() { local v; v="$(java_major "$1")"; [[ "$v" == 17 || "$v" == 21 ]]; }
if ! { [[ -n "${JAVA_HOME:-}" ]] && java_ok "$JAVA_HOME"; }; then
  candidates=(/opt/homebrew/opt/openjdk@21 /opt/homebrew/opt/openjdk@17 /usr/local/opt/openjdk@21 /usr/local/opt/openjdk@17)
  for p in /usr/lib/jvm/*21* /usr/lib/jvm/*17*; do [[ -d "$p" ]] && candidates+=("$p"); done
  JAVA_HOME=""
  for p in "${candidates[@]}"; do java_ok "$p" && { JAVA_HOME="$p"; break; }; done
  [[ -n "$JAVA_HOME" ]] || { echo "No Java 17 or 21 found. macOS: brew install openjdk@21"; exit 1; }
fi
export JAVA_HOME PATH="$JAVA_HOME/bin:$PATH"

python=python3
[[ -x .venv/bin/python ]] && python=.venv/bin/python

job=(src/streaming/job.py --source files --input-dir data/demo/replay --out data/demo/stream
     --checkpoint checkpoints/demo --trigger "$every seconds" --stop-when-idle 180)
if [[ -n "$resume" ]]; then
  [[ -d checkpoints/demo && -d data/demo/replay ]] || { echo "Nothing to resume: no earlier run in data/demo/."; exit 1; }
  echo "Java $(java_major "$JAVA_HOME"); carrying on the last run, a micro-batch every ${every} s; ${publish[*]:-private run}"
else
  echo "Java $(java_major "$JAVA_HOME"); replaying from $start, a micro-batch every ${every} s; ${publish[*]:-private run}"
  rm -rf data/demo/replay
  "$python" src/producers/replay_to_files.py --start "$start" --out data/demo/replay
  job+=(--fresh)
fi
exec "$python" "${job[@]}" ${publish[@]+"${publish[@]}"}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.