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

# AGENTS.md

> Calendar Effects (CMPT 732, Fall 2026)

`AGENTS.md` · chapter [Tests and team tooling](https://calendar-effects.mintlify.site/tour/10-tests-and-tooling.md), file 18 · 132 lines · [open in the repository](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/AGENTS.md)

## What it does

The full text is below.

## Source

````markdown title="AGENTS.md" lines expandable theme={null}
# Calendar Effects (CMPT 732, Fall 2026)

**How holidays and shopping events move retail stocks, in real time.** The repo is `aba395/Calendar-Effects` on github.sfu.ca; it was formerly `BD-Project`, and the project was formerly called "Streaming Event-Study Engine".

This is the shared brief for any AI coding assistant. Claude Code reads it through `CLAUDE.md`, and Cursor, Codex and similar tools read it directly. Keep it short. Detail belongs in `docs/`.

## What we are building

We replay retail stock prices and Wikipedia page views ("attention") through Kafka. A Spark Structured Streaming job flags abnormal returns and attention spikes around calendar events, and we check the streaming results against a batch market-model event study (abnormal returns and CAR).

**Everything that defines the study is data, not code.** `config/` holds one CSV per list you can add to: events (`event_types.csv`, with a rule for computing each event's dates), retailers (`retailers.csv`), their Wikipedia articles (`wiki_articles.csv`) and the retail sales series (`retail_series.csv`). Adding an event or a retailer means adding a row and re-running the ETL, not writing code (decisions 0003 and 0005).

- **Every command, in order: `docs/running.md`**
- Current task split: the team table below; how the clean data was first built, and the ETL timeline: `docs/etl-guide.md`
- Original plan and phases: `docs/WORKPLAN.md`
- Detailed proposal: `docs/proposal.pdf` (add it if it is missing)
- Dataset schemas: `docs/data-contracts.md`
- Current status: `docs/STATUS.md`, plus the newest notes in `docs/handoffs/`
- Decisions already made: `docs/decisions/`

## Team

The split below by name is the current one (the ETL phase's details are in `docs/etl-guide.md`). Older docs still use the role letters A–D.

| Name | ETL (due Nov 3–4) | Nov 14–22: Kafka and streaming | Nov 23–Dec 1: report and video | GitHub (github.sfu.ca) |
|---|---|---|---|---|
| Mahad | Stock prices and volume | Price producer and the Spark streaming job (lead) | Demo video | mma447 |
| Sanchi | Wikipedia pageviews, final join | Kafka topics, attention producer | Report: results | ska510 |
| Anushiya | Ticker list and event calendar | Spike rule (settled 2026-11-17, see decision 0004), streaming job with Mahad, run-everything script, README | Report: data and methods | aba395 (repo owner) |
| Areej | Retail sales | Batch event study and the answer key | Report: intro, assembling and editing; project management | sas66 |

## Ground rules for every task

1. **Data contracts are law.** Schemas live in `docs/data-contracts.md` and `src/common/contracts.py`, and `tests/test_contracts.py` checks that they match. Change a schema only by editing both in the same commit, then add a decision record.
2. **All times are UTC.** Timestamp columns end in `_utc`. No local times in data.
3. **No look-ahead.** Baselines and estimation windows use only data from before the event window.
4. **Never commit** raw downloads, run outputs, credentials or student numbers. `raw/`, `data/` and `checkpoints/` are gitignored. The exceptions are small and deliberate: the clean tables in `clean/` (ETL guide), the dashboard's recording in `hosting/snapshot/` (decision 0013) and the results pack in `docs/results/` (decision 0014), the last two derived statistics only.
5. **Each person commits their own work** (a course rule). Use small commits with messages like `streaming: add 10-minute watermark`.
6. **Pushing to `main` is allowed** (agreed 2026-11-25). Each member is responsible for their own pushes, and everyone else is responsible for keeping up with them:
    - **Before you push:** the tests pass (the commit hook checks), and `docs-site/` is rebuilt (rule 12).
    - **When you push:** tell the team what changed and why, in the group chat, a handoff note (`/handoff`) and `docs/STATUS.md`. Point them to the docs site (https://calendar-effects.mintlify.app), which updates with every push.
    - **After a teammate pushes:** run `/sync`, read their note and the changed pages of the docs site, and ask them about anything unclear.
    - **Branches are optional,** for bigger or riskier work: name them `<name>/<topic>` (for example `mahad/streaming-job`).
    - **If a push breaks `main`:** anyone may roll it back with `git revert <commit>`, which adds a new commit that undoes it, and push that, then tell its author. Never rewrite `main`'s history: no force push (it is blocked in `.claude/settings.json`) and no `git reset` on pushed commits.
7. **Log AI help** in `docs/ai-usage/<name>.md`: date, tool, what the AI did, and what you checked, changed or decided. The course's AI Usage Report is written from it. `/handoff` adds the entry, and `tests/test_ai_usage.py` fails if a handoff note has no entry for its date in its author's log.
8. **Never type in a value that is defined once elsewhere** (decision 0005). `tests/test_no_hardcoding.py` fails on any of these in `etl/`, `src/` or `scripts/`:
   - tickers, events, Wikipedia titles, retail series: read `config/` with `common.contracts` (`price_tickers`, `load_retailers`, `expand_events`, `load_event_types`, `load_wiki_articles`, `load_retail_series`)
   - years, the market index, windows, thresholds: `common.study`
   - file paths, Kafka servers: `common.settings` (`clean_path`, `RAW_DIR`, `REPLAY_DIR`, `STREAM_DIR`, `RESULTS_DIR`, `CHECKPOINT_DIR`, `KAFKA_BOOTSTRAP`); the topic: `KAFKA_TOPICS`

   A new list someone might add to (more indices, more series) becomes a new `config/` CSV with a contract, a loader and a test, never a Python list. A value that only looks like config (pandas' month code `'M'`, a bootstrap count of 2000) may stay if its line ends with `# not-config: <reason>`.
9. **Validate before writing.** Every script that writes a dataset calls `require_contract("<dataset>", pandas_columns(df))` first. `tests/test_clean_files.py` checks the committed clean files against their contracts and `config/`.
10. **Scripts run from any folder.** `pip install -r requirements.txt` installs `src/` as a package, so `import common` just works: no `sys.path` tricks, no paths relative to the current folder.
11. **Tests pass before every commit:** `python3 -m pytest -q`. If a test fails, fix the code, the config or the contract. Never weaken or skip a test to get a commit through; if a test is wrong, say so and fix it in its own commit.
12. **The docs site stays in step with the code** (decision 0011). `docs-site/` is a guided tour of the codebase, built by `scripts/build_docs.py`, and `tests/test_docs_site.py` fails when it is out of date or a file has no place in the tour. With every change:
    - run `python3 scripts/build_docs.py` and commit `docs-site/` with the change;
    - a new file: add it to the right chapter in `docs-site/reading_order.json`, where a reader meets it;
    - a change to what a stage does or why: update that chapter's text in `docs-site/tour/` (everything outside the GENERATED markers), including its questions and ideas;
    - never edit generated pages (`docs-site/reference/`, `decisions/`, `diagrams/`, `log/`, `contracts.mdx`, `docs.json`); change the code's docstrings or `docs/` instead.

## How to add or change things

| To add or change | Edit | Then |
|---|---|---|
| An event | a row in `config/event_types.csv` (dates in `config/event_dates.csv` if its rule is `listed`) | `pytest`; re-run `etl/join_master.py`. Two in-scope events on one day stop the join |
| A retailer | a row in `config/retailers.csv`, and its titles in `config/wiki_articles.csv` | `pytest` lists the ETL scripts to re-run |
| A renamed Wikipedia article | add the new title to `config/wiki_articles.csv`, keep the old one | re-run the pageview scripts and the join |
| A retail sales series | a row in `config/retail_series.csv`; download `raw/census/<series_id>.csv` | re-run `etl/retail_clean.py` |
| Years, market index, windows, thresholds | `src/common/study.py` | re-run all of `etl/`; write a decision record |
| A dataset or a column | `docs/data-contracts.md` and `src/common/contracts.py`, same commit | write a decision record |
| A file, or what a stage does | the file's docstring; `docs-site/reading_order.json` for a new file; the chapter in `docs-site/tour/` | `python3 scripts/build_docs.py`, commit `docs-site/` with it |

Changing what is in scope (`in_scope = yes`) changes the analysis, so agree it with the team or in a decision record.

## Repository layout

```
config/          what is studied: events, retailers, Wikipedia articles, retail series (one CSV each)
etl/             download and clean scripts, raw/ -> clean/ (each owned by one person; docs/etl-guide.md)
src/common/      shared code: contracts.py (schemas, config loaders, validation),
                 study.py (years, market index, windows), settings.py (paths, Kafka)
src/producers/   replay clean/master.parquet into Kafka (or into files, for local runs)
src/streaming/   Structured Streaming job (Mahad)
src/eventstudy/  batch market-model event study (Areej)
src/ml/          the big-move model: Spark MLlib on the stream's output (Mahad, decision 0007)
src/dashboard/   live alerts dashboard, Streamlit (Mahad, decision 0008)
src/hosting/     dashboard recording, live feed, Hugging Face upload (Mahad, decisions 0010, 0013)
hosting/         snapshot/ (the recording, committed), streamlit/ (hosted app), space/ (HF Space), cards/,
                 workflows/ and live-stream/ (the cloud streamer, decision 0015)
scripts/         Kafka helpers, checks, the live demo, docs build, git hooks and the github.com copies
notebooks/       for exploration (empty so far)
tests/           pytest tests (run: python3 -m pytest -q)
docs/            plan, contracts, status, handoffs, decisions, AI-usage logs
docs-site/       the docs site (Mintlify): a tour of the codebase, built by scripts/build_docs.py
raw/             downloads (gitignored)
clean/           clean tables, small and committed
data/            run outputs: replay files, stream output, results (gitignored)
checkpoints/     Spark streaming checkpoints (gitignored)
```

## Commands

Every command, in order, for people: `docs/running.md` (the docs site's *Run it* page). Keep it in step when a command changes.

- Setup, once: `python3 -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt -r requirements-dev.txt`. Spark needs Java 17 or 21 (`JAVA_HOME`).
- Tests: `python3 -m pytest -q`
- Docs site: `python3 scripts/build_docs.py` (rebuild), `cd docs-site && npx mint dev` (preview, Node 20.17+)
- Dashboard: `streamlit run src/dashboard/app.py`; hosted at https://calendar-effects.streamlit.app. Live demo there: the cloud streamer (github.com `Calendar-Effects/live-stream` > Actions > Live stream > Run workflow; Cancel run stops it, mode resume carries it on; decision 0015), or `scripts/demo_live.sh` on a laptop (sets Java 21, replays from mid-2023, streams with `--publish-live`; Ctrl-C stops it, `--resume` carries it on). `scripts/install_workflows.sh` updates the github.com workflows after `hosting/workflows/` changes
- After a full run: `src/hosting/snapshot.py`, `scripts/export_results.py`, then `src/hosting/publish_hf.py --upload`
- ETL, in order: `etl/prices_download.py`, `etl/prices_clean.py`, `etl/pageviews_download.py`, `etl/pageviews_clean.py`, `etl/retail_clean.py`, `etl/join_master.py`
- Streaming on a laptop: `src/producers/replay_to_files.py`, then `src/streaming/job.py --source files --once --fresh`, then `scripts/check_streaming.py`
- Cluster (`ssh cluster.cs.sfu.ca`, on the SFU VPN; run long jobs in `tmux`). The cluster's `python3` has no pyspark, so the job goes through `spark-submit` with the Kafka connector on its command line:
  ```
  cd Calendar-Effects && export PYTHONPATH=src
  python3 scripts/create_topics.py --topic <topic>
  python3 src/producers/replay_master.py --topic <topic> --seconds-per-day 0 [--late-fraction 0.02]
  spark-submit --packages org.apache.spark:spark-sql-kafka-0-10_2.13:3.5.8 src/streaming/job.py \
      --source kafka --topic <topic> --max-per-trigger 390 --once \
      --out calendar-effects/stream --checkpoint calendar-effects/checkpoint
  hdfs dfs -get calendar-effects/stream ~/stream-out
  ```
  `--out` and `--checkpoint` are HDFS paths: clear them with `hdfs dfs -rm -r` before a rerun. The team topic is `calendar-effects-master`; use your own test topic for experiments.

## Key dates

| Phase | Dates | Done when |
|---|---|---|
| 0 · Shared setup | Oct 26–28 | Repo exists, schemas agreed, everyone can run `spark-submit` on the cluster |
| 1 · Data and infrastructure | Oct 28–Nov 3 | One ticker and one event travel end to end |
| 2 · Pipeline and core analysis | Nov 4–10 | Streaming output and batch CAR exist for all tickers |
| 3 · Validation and write-up | Nov 11–17 | Comparison done, report sections drafted |
| 4 · Polish and submit | Nov 18–Dec 11 | Tag `final`, report and video submitted. Treat **Dec 8** as the real deadline. |
````


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