# Code and ownership guide

## Where things live

- `data/raw/`: unchanged Game 1 source CSVs.
- `data/raw_game2/`: Game 2 CSVs and commit-pinned download manifest.
- `events-definitions.pdf`: provider definitions used for outcome design.
- `src/`: executable scripts developed during the learning exercise.
- `output/`: generated features, figures, specifications and predictions.
- `docs/case-study.md`: methods, findings, limits and contributions.
- `docs/starter-notes.md`: original README, preserved as history. Statements about pending work and contributions there describe the early stage, not the current project.

## Reproduce from supplied raw data

With the project environment active, from the project folder:

```sh
python src/run_analysis.py --check
python src/run_analysis.py --run
```

The preflight checks input files, installed package metadata and syntax. It does not execute the analysis or verify a fresh environment. The runner executes the stages below sequentially with the active Python. Plots are saved without opening windows; each stage has a log and environment record in a unique `output/runs/` folder. It stops on the first failure. Non-interactive plot warnings in logs are expected.

Raw CSVs are unchanged. Matching generated files, including experiment specifications, are overwritten. A rerun of the same fixed model is a reproducibility check, not another independent test. Preserve v1 outputs before changing methods. Game 2 has already been evaluated; choices informed by its performance cannot be presented as a fresh held-out experiment.

The runner does not download data. Use `src/download_game2.py` for Game 2; Game 1 currently requires the supplied starter CSVs. A fresh Game 1 download workflow is not yet automated. `requirements-analysis.txt` records observed analysis package versions; legacy `requirements.txt` records the earlier starter environment. A clean-environment installation remains unverified.

## Ordered stages

1. `audit_data.py`: Game 1 coverage and alignment.
2. `audit_ball_gaps.py`: missing-ball runs and candidate availability.
3. `build_pass_features.py`: candidate definitions and release geometry.
4. `check_pass_alignment.py`: event/player location diagnostics.
5. `add_closing_features.py`: fixed-pair pre-pass movement.
6. `plot_closing_window.py`: movement diagnostic plots.
7. `explore_pressure_outcomes.py`: distance comparison.
8. `explore_closing_outcomes.py`: movement within distance bands.
9. `compare_teams.py`: team-specific check.
10. `check_opponent_selection.py`: nearest-at-start sensitivity.
11. `check_restart_sensitivity.py`: approximate restart removal.
12. `prepare_game2.py`: Game 2 checks and equivalent features.
13. `evaluate_models.py`: fixed training and evaluation.
14. `bootstrap_model_comparison.py`: conditional evaluation uncertainty.

The owner-editable `explore_events.py` stays outside this fixed sequence: changing its EVENT_INDEX or colours should not change the analysis sample. Other `inspect_*` scripts and the original `first_look.py` and `verify_first_look.py` remain diagnostic/history tools. The original ball-path figure includes later travel as visual context; it is not a prediction feature.

## Be able to explain

- A DataFrame is a table; period/frame keys are analogous to SQL join keys.
- Convert x and y separately to metres before measuring distance.
- Candidate rules define the denominator; this is not an all-pass sample.
- Coordinate availability and timestamp agreement do not prove physical or annotation accuracy.
- Relative closing tracks a fixed identity and includes both players' movement.
- Interactions allow associations to differ by another variable; they do not establish causality.
- Scalers learn on training data only; outcomes, provider subtypes and realised endpoints are not prediction inputs.
- AUC measures ranking; log loss and Brier measure probability scores.
- Paired time blocks retain some dependence, but one evaluation match cannot establish between-match generalisation.

## Next independent exercise

Run the pipeline and inspect its logs and saved metrics. Explain a transformation without this guide. Then choose a different diagnostic event and independently change its plotted lookback window in a separate exploratory script. Record your prediction, actual observation and the code supplied by AI. Do not retune the v1 model against Game 2 and describe it as an untouched test.

## Verified end-to-end execution — 8 November 2026

The owner ran `python src/run_analysis.py --run` in the existing Python 3.9.6 environment. All 14 stages exited successfully. Run record: `output/runs/20261107T220756.689590Z/run.json` (folder timestamp is UTC). The regenerated model metric and bootstrap summary values match the earlier saved numerical values at the reported precision. This verifies execution from the supplied raw CSVs in the existing environment; it does not verify fresh installation, independent code authorship, or an additional held-out experiment.

## Dashboard presentation

The dashboard is a separate export step after analysis: `python src/build_dashboard.py`. Its Python exporter and `src/dashboard_template.html` are new AI-assisted presentation code. The owner has not yet independently modified or defended that code. See `docs/dashboard-guide.md` for opening, controls and source customisation. The analysis runner intentionally does not include this step.
