"""Reproduce printed LNE score means, not optical-media lifetime estimates.""" import argparse from fractions import Fraction import hashlib import json from pathlib import Path HERE = Path(__file__).resolve().parent def load_input(path): def pairs(items): result = {} for key, value in items: if key in result: raise ValueError("duplicate JSON key: " + key) result[key] = value return result return json.loads(path.read_text(), object_pairs_hook=pairs, parse_constant=lambda value: (_ for _ in ()).throw(ValueError(value))) def validate(data): table = data["score_table"] if table["unit"] != "score_out_of_10" or table["includes_baseline"] is not True: raise ValueError("score semantics changed") if table["times_hours"] != list(range(0, 2001, 250)): raise ValueError("nine printed time points, including T0, are required") rows = table["rows"] if len(rows) != 6 or {r["reference"] for r in rows} != set(range(1, 7)): raise ValueError("six unique historical references required") for row in rows: if len(row["scores"]) != 9: raise ValueError("do not discard zero scores or T0") for value in row["scores"] + [row["reported_global"]]: if not isinstance(value, str) or not 0 <= Fraction(value) <= 10: raise ValueError("invalid printed score") protocol = data["lne_protocol"] if protocol["models"] * protocol["discs_per_model"] != protocol["heat_total_discs"]: raise ValueError("heat denominator mismatch") if protocol["models"] * protocol["light_discs_per_model"] != protocol["light_total_discs"]: raise ValueError("light denominator mismatch") if protocol["acceleration_factor"] is not None: raise ValueError("no calibrated acceleration factor supplied") source_ids = {s["id"] for s in data["sources"]} if len(source_ids) != len(data["sources"]): raise ValueError("duplicate source") for claim in data["claims"]: if not claim["source_ids"] or not set(claim["source_ids"]) <= source_ids: raise ValueError("unknown source") iraci = next(s for s in data["sources"] if s["id"] == "iraci2018") if iraci["full_text_verified"] is not False or data["iraci_abstract"]["sample_count"] is not None: raise ValueError("unverified full-text information") if data["physical_experiment"] is not False: raise ValueError("this is a source audit, not a new physical experiment") def rounded_tenth(value): # All ratings are nonnegative; integer arithmetic avoids binary float ties. tenths = (value * 10 + Fraction(1, 2)).numerator // (value * 10 + Fraction(1, 2)).denominator return str(tenths // 10) + "." + str(tenths % 10) def audit(data): validate(data) rows = [] for row in data["score_table"]["rows"]: mean = sum(map(Fraction, row["scores"]), Fraction()) / 9 rounded = rounded_tenth(mean) if rounded != row["reported_global"]: raise ValueError("printed mean does not reproduce: " + row["label"]) rows.append({"reference": row["reference"], "label": row["label"], "exact_mean_of_printed_scores": str(mean), "rounded_mean": rounded, "reported_global": row["reported_global"]}) return {"schema_version": 1, "kind": "arithmetic_check_of_published_rounded_scores", "rows": rows, "reproduced_rows": len(rows), "unit": "score_out_of_10", "lifetime_years": None, "physical_experiment": False, "scope": "Checks printed arithmetic only; not raw data, failure probability or shelf life."} def main(): parser = argparse.ArgumentParser() parser.add_argument("--check", action="store_true") parser.add_argument("--output", type=Path, default=HERE / "results.json") parser.add_argument("--input", type=Path, default=HERE / "inputs.json") args = parser.parse_args() data = load_input(args.input) result = audit(data) result["input_sha256"] = hashlib.sha256(args.input.read_bytes()).hexdigest() encoded = json.dumps(result, indent=2, sort_keys=True) + "\n" if args.check: if args.output.read_text() != encoded: raise SystemExit("generated results differ") else: args.output.write_text(encoded) print("6/6 historical rounded means verified; no lifetime estimate generated.") if __name__ == "__main__": main()