#!/usr/bin/env python3 """Do the headline figures in a doc match its committed reference data? Numbers drift between a run and the prose written about it, and nothing was checking. This compares the two NUMERICALLY, which matters: a naive string grep reports every figure as a mismatch, because the data files write `14709` and the docs write `14 709` (thin space) and round `33.66` to `33.7`. That false-positive run is why this is a script and not a grep. doc_figure_check.py # runs the built-in case list """ import re, sys CASES = [ ("eff-bit-census.txt", "structures/ui-paint-order-key.md", [14709, 2338, 2657, 1399, 8315, 0.468, 0.144]), ("plateau-census.txt", "structures/ui-resting-pose.md", [15493, 3807, 24.57, 50.2]), ("rotation-toplevel-census.txt", "structures/ui-keyframe-rotation.md", [2152, 13.89]), ("eff-bit-alpha-test.txt", "structures/ui-paint-order-key.md", [55.52, 33.66, 52.52, 30.17, 76.5, 64.1]), ] NUM = re.compile(r"\d[\d   ,]*\.?\d*") def nums(text): out = set() for m in NUM.finditer(text): try: out.add(float(re.sub(r"[   ,]", "", m.group()))) except ValueError: pass return out def main(): bad = 0 for dfile, mfile, figs in CASES: D = nums(open(f"docs/re/data/{dfile}", encoding="utf-8").read()) M = nums(open(f"docs/re/{mfile}", encoding="utf-8").read()) for f in figs: in_d = any(abs(f - x) < 0.011 for x in D) in_m = any(abs(f - x) < 0.051 for x in M) # the doc may round if not (in_d and in_m): bad += 1 print(f" CHECK {dfile} / {mfile}: {f} data:{in_d} doc:{in_m}") print(f"{sum(len(c[2]) for c in CASES)} figures checked, {bad} to look at") return 1 if bad else 0 if __name__ == "__main__": sys.exit(main())