.PHONY: FORCE

DATA_DIR ?= ../data
MODEL ?= models/sbs2g-20250614_1551-pos97.22-neg94.72.pt
INF ?= 99999999
METHOD ?= qrcmpnet
TRAIN_RATE ?= 0.8
SCAN_IDS ?= 80653
benchmark:
	./ai/benchmark.py -m $(MODEL) -d data/samples.json -s $(SCAN_IDS)

upload:
	ls -l $(MODEL)
	./ai/upload.py $(MODEL)

upload-qrs:
	./scripts/upload-qrs.py --dir data/qrs/tree

server_url=http://localhost:6500
# server_url=https://themblem.com

qr_verify:
	echo 'pos'
	for scan_id in 101378 124999; do \
		curl $(server_url)/api/v5/qr_verify \
			-F frame=@data/scans/$$scan_id/frame.jpg; \
	done
	echo 'neg'
	for scan_id in 102095 105387; do \
		curl $(server_url)/api/v5/qr_verify \
			-F frame=@data/scans/$$scan_id/frame.jpg; \
	done

fullqr:
	./ai/fullqr.py

fetch:
	./ai/fetch-scans.py --data-dir $(DATA_DIR)
	./ai/make-sbs.py --data-dir $(DATA_DIR)

sbs:
	./ai/make-sbs.py --data-dir $(DATA_DIR)

clarity: METHOD=clarity
clarity: train


VERIFY_RANGE ?= 160000-$(INF)
NCELLS ?= 1
verify:
	./ai/verify.py -d $(DATA_DIR) -m $(MODEL) -r $(VERIFY_RANGE) --name $(notdir $(MODEL))-$(VERIFY_RANGE) --with-margins --ncells $(NCELLS)

verify-ue:
	./ai/verify.py -d $(DATA_DIR) -m $(MODEL) -r 0-$(INF) --name $(notdir $(MODEL))-ue --labels ue


predict:
	./ai/predict.py -m $(MODEL) data/gridcrop2/117803/sbs.jpg

aiweb:
	cd ai/aiweb && npm run serve

server:
	./ai/server.py --debug

hypertrain:
	./ai/hypertrain.py --max-epochs 20 --min-epochs 10 --ntrials 20

train:
	./ai/train.py --sample-rate 1 --num-epochs 100 --data-dir $(DATA_DIR) --val-codes ai/validate-codes.txt

quick:
	./ai/train.py --sample-rate 0.1 --num-epochs 1 --data-dir $(DATA_DIR) --val-codes ai/validate-codes.txt