"""TutorSyntax v24 — original synthetic data experiment. Standard library only.
Run alongside synthetic_sensor_readings.csv in the same folder.
"""
import csv
from pathlib import Path

file_path = Path(__file__).with_name("synthetic_sensor_readings.csv")
with file_path.open(newline="", encoding="utf-8") as file:
    rows = list(csv.DictReader(file))

# A threshold is a modelling choice, not proof of accuracy or fairness.
threshold = 65
tp = tn = fp = fn = 0
for row in rows:
    truth = int(row["needs_attention"])
    prediction = int(int(row["sensor_score"]) >= threshold)
    if prediction == 1 and truth == 1: tp += 1
    elif prediction == 0 and truth == 0: tn += 1
    elif prediction == 1 and truth == 0: fp += 1
    else: fn += 1
print("threshold:", threshold, "correct:", tp + tn, "/", len(rows))
print("true positives:", tp, "true negatives:", tn)
print("false positives:", fp, "false negatives:", fn)
# Challenge: try thresholds 40, 55, 70, 85 and record the counts.
