"""Count thresholds on grouped teaching scores; no model training."""
import json
from pathlib import Path
groups = [(0.9, 500, 100), (0.6, 300, 800), (0.4, 150, 1000), (0.1, 50, 7100)]
rows = []
for threshold in [0.5, 0.8]:
    tp = sum(pos for score, pos, neg in groups if score >= threshold)
    fp = sum(neg for score, pos, neg in groups if score >= threshold)
    fn, tn = 1000 - tp, 9000 - fp
    rows.append(dict(threshold=threshold, TP=tp, FP=fp, FN=fn, TN=tn,
                     precision=tp/(tp+fp), recall=tp/(tp+fn), FPR=fp/(fp+tn)))
result = dict(scope="Grouped handcrafted scores for the 10,000 teaching orders; no trained probabilities or external performance.", groups=groups, rows=rows)
Path(__file__).with_name("threshold-counts.json").write_text(json.dumps(result, indent=2)+"\n")
print(json.dumps(result, indent=2))
