File size: 3,802 Bytes
4eefabb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# MicroClimate-X β€” common dev tasks. Run `make help` for a full list.
#
# Conventions:
#   * `make <target>` is the single source of truth for a workflow step.
#   * Targets are idempotent; running twice should not break anything.
#   * Heavy tasks (train, eval) write into git-ignored directories.

PYTHON  ?= ./.venv/bin/python
PIP     ?= ./.venv/bin/pip
UVICORN ?= ./.venv/bin/uvicorn
PYTEST  ?= ./.venv/bin/pytest
RUFF    ?= ./.venv/bin/ruff

.DEFAULT_GOAL := help

.PHONY: help venv install install-dev test test-fast lint format coverage \
        synth preprocess train evaluate run clean docker docker-run

help:                          ## Show this help.
	@awk 'BEGIN{FS=":.*##";print "MicroClimate-X β€” available targets:"} /^[a-zA-Z_-]+:.*?##/{printf "  \033[36m%-15s\033[0m %s\n",$$1,$$2}' $(MAKEFILE_LIST)

venv:                          ## Create a Python 3.10+ venv at ./.venv
	python3 -m venv .venv
	$(PIP) install --upgrade pip

install: venv                  ## Install runtime dependencies.
	$(PIP) install -r requirements.txt

install-dev: install           ## Install runtime + dev dependencies.
	$(PIP) install -r requirements-dev.txt

# ── Quality ────────────────────────────────────────────────────────────
lint:                          ## Run ruff lint check.
	$(RUFF) check backend/ scripts/ tests/

format:                        ## Format code with ruff.
	$(RUFF) format backend/ scripts/ tests/
	$(RUFF) check --fix backend/ scripts/ tests/

test:                          ## Run the full test suite with coverage.
	$(PYTEST) tests/ --cov=backend --cov-report=term-missing

test-fast:                     ## Run tests quietly, no coverage.
	$(PYTEST) tests/ -q

coverage:                      ## Generate an HTML coverage report.
	$(PYTEST) tests/ --cov=backend --cov-report=html
	@echo "Open htmlcov/index.html in your browser."

# ── ML pipeline ────────────────────────────────────────────────────────
synth:                         ## Generate synthetic dataset (no network).
	$(PYTHON) scripts/1b_synth_dataset.py

preprocess:                    ## Build features + target (data/processed.csv).
	$(PYTHON) scripts/2_preprocess.py

train:                         ## Train the Random Forest model.
	$(PYTHON) scripts/3_train_model.py

evaluate:                      ## Generate publication figures + threshold sweep.
	$(PYTHON) scripts/4_evaluate_model.py

# ── Local run ──────────────────────────────────────────────────────────
run:                           ## Start the FastAPI dev server with auto-reload.
	$(UVICORN) backend.main:app --reload --host 127.0.0.1 --port 8000

# ── Docker ─────────────────────────────────────────────────────────────
docker:                        ## Build the Docker image.
	docker build -t microclimate-x:latest .

docker-run: docker             ## Build then run the container on port 8000.
	docker compose up --build

# ── Housekeeping ───────────────────────────────────────────────────────
clean:                         ## Remove caches, coverage, and SQLite WAL files.
	rm -rf .pytest_cache htmlcov .coverage coverage.xml
	rm -f  cache.sqlite3 cache.sqlite3-*
	find . -name __pycache__ -type d -prune -exec rm -rf {} +