#!/usr/bin/env bash
# Full-corpus EDA driver. Every step is resumable (per-trial / per-subject caches under cache/).
# Run from reports/eda_full:  bash scripts/run_all.sh
set -euo pipefail
cd "$(dirname "$0")/.."
PY=../../.venv/bin/python
export OMP_NUM_THREADS=2 OPENBLAS_NUM_THREADS=2 MKL_NUM_THREADS=2

$PY scripts/a0_field_tree.py > /dev/null                 # CND field trees -> logs/cnd_field_tree.txt
$PY scripts/b1_cnd_extract.py                            # per-sample labels, azimuth, EOG, story names
$PY scripts/a1_qc.py                                     # Phase A per-trial/channel QC
$PY scripts/a2_qc_report.py                              # Phase A tables + figures
$PY scripts/b2_envelope_audit.py                         # Phase B label / envelope / design / reuse audits
$PY scripts/b3_drift_classifier.py                       # Phase B drift-only shortcut
$PY scripts/c0_cache_pp.py                               # filtered caches: c19, z19, cwide
MAIN=c19-common57-car
$PY scripts/c2_decoders.py $MAIN stats                   # sufficient statistics + within-subject LOTO
$PY scripts/c2_decoders.py $MAIN loso
$PY scripts/c2_decoders.py $MAIN lodo
$PY scripts/c2_decoders.py $MAIN crosshalf               # H6
$PY scripts/c3_windows.py $MAIN
for CFGX in z19-common57-car sup-common57-car cwide-common57-car c19-common57-nocar c19-b64ustc58-car c19-b64uhd62-car; do
  $PY scripts/c2_decoders.py $CFGX stats
  $PY scripts/c2_decoders.py $CFGX lodo
  $PY scripts/c3_windows.py $CFGX lodo_pool
done
$PY scripts/c4_decoder_report.py                         # accuracy vs window, SNR law, H9, pipelines
$PY scripts/c1_xcorr.py                                  # tracking curves, null, TRFs
$PY scripts/d0_spatial_cache.py full 2                   # Phase D feature cache
$PY scripts/d1_fingerprint.py                            # H10 covariance / amplitude fingerprints
$PY scripts/d3_spatial.py                                # H11 spatial decoding + trial fingerprint
$PY scripts/d4_physiology.py                             # H12 ALI / EOG
$PY scripts/e0_scorer_tests.py                           # scorer port equivalence (must pass)
$PY scripts/e1_switch.py $MAIN lodo_pool 0-500ms         # Phase E on LODO evidence
$PY scripts/e1_switch.py $MAIN lodo_pool 0-250ms
$PY scripts/e2_spatial_switch.py                         # genuine KUL-AV-GC switches with spatial evidence
$PY scripts/e3_lookahead_test.py                         # perturb-after-t+1s unit test
$PY scripts/b4_envelope_identity.py                    # stimulus identity from envelopes vs names
$PY scripts/f1_verdicts.py                               # H1-H12 verdict table + per-subject metrics
$PY scripts/f2_report.py                                 # README.md + EEG-sAAD_full_corpus_EDA_report.pdf
