"""Constructed byte accounting, not a Flashield or SSD simulator.""" from fractions import Fraction import json from pathlib import Path import sys def ratio(numerator, denominator): return str(Fraction(numerator, denominator)) if denominator else None def account(offered, admitted, host, nand): values = (offered, admitted, host, nand) if any(type(value) is not int or value < 0 for value in values): raise ValueError("Byte counts must be nonnegative integers") if admitted > offered or host < admitted: raise ValueError("This ledger assumes single admission and uncompressed host writes") return { "offered_bytes": offered, "admitted_bytes": admitted, "host_bytes": host, "nand_bytes": nand, "admitted_per_offered": ratio(admitted, offered), "host_per_admitted": ratio(host, admitted), "nand_per_host": ratio(nand, host), "nand_per_offered": ratio(nand, offered), } def packet(): rows = [ ("Filtered", (1000, 200, 250, 500)), ("Unfiltered", (1000, 1000, 1250, 2500)), ("No admission, maintenance writes", (1000, 0, 20, 40)), ] return { "schema_version": 1, "kind": "constructed-arithmetic", "unit": "byte", "generated": "2026-11-10", "method": "Exact rational ratios; null means zero denominator, not zero writes.", "assumptions": [ "Same accounting interval and byte scope; no carry-in payload.", "Each offered payload byte is admitted at most once; host writes include rewrites and metadata.", "No compression before the host boundary is modeled.", "No measured workload, hardware execution or Flashield simulation.", ], "rows": [{"label": label, **account(*values)} for label, values in rows], } if __name__ == "__main__": output = json.dumps(packet(), indent=2) + "\n" if len(sys.argv) == 2: Path(sys.argv[1]).write_text(output) else: print(output, end="")