.PHONY: test test-fast lint typecheck reproduce figures data clean build

# ── development ────────────────────────────────────────────────────────────────

test:
	uv run pytest

test-fast:
	uv run pytest -m "not slow"

lint:
	uv run ruff check . && uv run ruff format --check .

typecheck:
	uv run mypy src/driftdep

build:
	uv build

# ── paper reproduction ─────────────────────────────────────────────────────────
# Regenerates every figure and table from seeds; outputs land in research/results/.
# Figures are deterministic (no timestamps) so diffs are clean.

reproduce:
	@echo "=== Logging library versions ==="
	uv run python -c "\
import sys, importlib, csv, pathlib; \
libs = ['numpy','scipy','statsmodels','arch','dcor','pandas','matplotlib','joblib']; \
rows = []; \
[rows.append({'package': l, 'version': getattr(importlib.import_module(l), '__version__', '?')}) for l in libs]; \
path = pathlib.Path('research/results/environment.txt'); \
path.write_text('\n'.join(f\"{r['package']}=={r['version']}\" for r in rows) + '\n'); \
print('Versions logged to', path)"
	@echo "=== Experiments ==="
	uv run python -m research.experiments.size screen
	uv run python -m research.experiments.size full
	uv run python -m research.experiments.power screen
	uv run python -m research.experiments.power multi
	uv run python -m research.experiments.streaming screen
	uv run python -m research.experiments.compute_cost
	uv run python -m research.experiments.realdata
	@echo "=== Figures and tables ==="
	$(MAKE) figures

figures:
	uv run python -m research.analysis.fig1_false_alarm
	uv run python -m research.analysis.fig2_ks_null
	uv run python -m research.analysis.fig3_ess_indicator
	uv run python -m research.analysis.fig4_size_after_correction
	uv run python -m research.analysis.fig5_power
	uv run python -m research.analysis.fig6_arl
	uv run python -m research.analysis.table1_size
	uv run python -m research.analysis.table2_realdata

# ── data download (separate from reproduce; requires internet) ─────────────────

data:
	uv run python -m research.data.download_fred
	uv run python -m research.data.download_uci
	uv run python -m research.data.download_m4

# ── housekeeping ───────────────────────────────────────────────────────────────

clean:
	find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
	find . -type f -name "*.pyc" -delete 2>/dev/null || true
	rm -rf dist/ build/ src/*.egg-info/
