#!/usr/bin/env python3
"""Every figure in bounty.txt, reformatted out of priors.json / the manifest, and grepped for.

The on-chain description cannot be edited after it is posted, so this runs before the
send script and exits non-zero if any quoted number is missing from the text. Same
pattern as og355/check_claim.py, where it caught two hand-typed figures that were wrong.

    python3 check_bounty.py
"""
import json, sys

WORDS = "zero one two three four five six seven eight nine ten".split()

p = json.load(open("priors.json"))
t = open("bounty.txt").read()
src = p["by_source"]

checks = [
    ("sha256",     f'sha256 {p["model_sha256"]}'),
    ("threshold",  f'shipped threshold is {p["threshold"]}'),
    ("thresh_up",  f'{p["threshold"]} and above means'),
    ("thresh_win", f'nobody clears {p["threshold"]}'),
    ("n_real",     f'over {p["n_real"]} real photographs'),
    ("n_flagged",  f'called {p["n_flagged"]} of them AI-generated'),
    # the sentence spells this one out
    ("conditions", f'({WORDS[len(p["conditions"])]} degradation conditions)'),
    ("faces",      f'({src["ffhq-256"]["flagged"]} of {src["ffhq-256"]["n"]})'),
    ("textures",   f'({src["dtd"]["flagged"]} of {src["dtd"]["n"]})'),
    # the two preprocessing constants the scorer is actually pinned to
    ("resize",     "shorter side to 440"),
    ("crop",       "centre crop 384"),
    ("band",       "0.25–0.85 band"),
    ("results",    "https://agentatwork.xyz/fool-the-detector/"),
    ("method",     "https://agentatwork.xyz/notes/sieve-tested.html"),
    ("code",       "https://github.com/agentatwork/sieve-corpus-test"),
]

bad = 0
for name, s in checks:
    hit = s in t
    bad += not hit
    print(("OK   " if hit else "MISS ") + f"{name:<11} -> {s}")
print(f"\n{len(checks)-bad}/{len(checks)} present")
sys.exit(1 if bad else 0)
