| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- """Deterministic fixture verification, not an LLM or scientific-quality evaluation."""
- import argparse
- import csv
- import hashlib
- import json
- import statistics
- from pathlib import Path
- root = Path(__file__).resolve().parent
- parser = argparse.ArgumentParser()
- parser.add_argument("--output", type=Path, required=True)
- args = parser.parse_args()
- for name, digest in json.loads((root / "inputs.sha256.json").read_text()).items():
- assert hashlib.sha256((root / name).read_bytes()).hexdigest() == digest, f"Fixture changed: {name}"
- rows = list(csv.DictReader((root / "csv/input.csv").open()))
- seen, cleaned = set(), []
- duplicates = missing = 0
- for row in rows:
- if row["id"] in seen:
- duplicates += 1
- continue
- seen.add(row["id"])
- if not row["value"].strip():
- missing += 1
- continue
- cleaned.append({**row, "value": float(row["value"])})
- stats = {}
- for group in ("control", "treatment"):
- values = [r["value"] for r in cleaned if r["group"] == group]
- stats[group] = {"n": len(values), "mean": statistics.mean(values), "sample_variance": statistics.variance(values)}
- difference = stats["treatment"]["mean"] - stats["control"]["mean"]
- result = {"raw_rows": len(rows), "duplicate_rows": duplicates, "missing_rows": missing,
- "clean_rows": len(cleaned), "groups": stats, "difference": difference,
- "relative_change": difference / stats["control"]["mean"]}
- assert result["clean_rows"] == 6 and result["difference"] == 3 and result["relative_change"] == .25
- args.output.mkdir(parents=True, exist_ok=True)
- (args.output / "expected.json").write_text(json.dumps(result, indent=2) + "\n")
- with (args.output / "clean.csv").open("w", newline="") as stream:
- writer = csv.DictWriter(stream, fieldnames=["id", "group", "value"])
- writer.writeheader()
- writer.writerows(cleaned)
- svg = ['<svg xmlns="http://www.w3.org/2000/svg" width="420" height="300" viewBox="0 0 420 300">',
- '<rect width="420" height="300" fill="white"/>',
- '<text x="20" y="25" font-size="16">Synthetic data: mean by group</text>',
- '<path d="M40 50 V240 H390" fill="none" stroke="#333"/>']
- for i, (group, values) in enumerate(stats.items()):
- x, height = 90 + i * 150, values["mean"] * 10
- svg += [f'<rect x="{x}" y="{240-height}" width="80" height="{height}" fill="#4286b5"/>',
- f'<text x="{x}" y="{230-height}">{values["mean"]}</text>',
- f'<text x="{x}" y="265">{group}</text>']
- svg.append('</svg>')
- (args.output / "means.svg").write_text("\n".join(svg))
- print(json.dumps({"fixture_integrity": "passed", "deterministic_baseline": result,
- "real_model": "not_run", "output": str(args.output)}, ensure_ascii=False))
|