"""2kwas: print the verbatim summary of hardin_results.json (review of iis:2611.00306)."""
import json, sys, collections
R = json.load(open(sys.argv[1]))
print("tables:", len(R), " readings without a match in hardin_specs.py:", [r["id"] for r in R if "error" in r])
print("families:", dict(collections.Counter(r["family"] for r in R)))
print("1. readings vs OEIS (grid + antidiagonal data, min(n,k) <= 5): %d entries, %d mismatches"
      % (sum(r["reading"]["entries_checked"] for r in R), sum(r["reading"]["n_mismatch"] for r in R)))
nogrid = [e["id"] for e in json.load(open(sys.argv[2])) if not e["grid"]] if len(sys.argv) > 2 else "?"
print("   tables without a 'Table starts' grid (only the data lines used):", nogrid)
print("2. engine vs literal enumeration (n*k <= 16; <= 14 for A267xxx): %d table-size pairs, %d mismatches"
      % (sum(r["enumeration"]["sizes_checked"] for r in R), sum(len(r["enumeration"]["mismatches"]) for r in R)))
main = [(r["id"], c) for r in R for c in r["claims"] if not c["extra"]]
extra = [(r["id"], c) for r in R for c in r["claims"] if c["extra"]]
print("3. claims in the paper's set: %d (column %d, row %d); hold: %d; fail: %d"
      % (len(main), sum(c["mode"] == "col" for _, c in main), sum(c["mode"] == "row" for _, c in main),
         sum(c["holds"] for _, c in main), sum(not c["holds"] for _, c in main)))
wn = [c for _, c in main if c["N"] is not None]
print("   with a stated range 'for n>N': %d; recurrence fails at n=N (range sharp): %d" % (len(wn), sum(1 for c in wn if c["sharp"])))
nn = [c for _, c in main if c["N"] is None]
print("   without a stated range: %d; hold from n = order+1: %d" % (len(nn), sum(1 for c in nn if c["holds_from"] == c["order"] + 1)))
print("   largest order: %d; largest number of live states (unlumped): %d" % (max(c["order"] for _, c in main), max(c["live_states"] for _, c in main)))
z = [(i, c) for i, c in main if c["live_states"] == 0]
print("   identically zero targets (no live state): %d" % len(z))
print("4. extra explicit claims not in the paper's set (a(k)= form): %d; hold: %d" % (len(extra), sum(c["holds"] for _, c in extra)))
print()
print("per claim: id mode idx | order N | live states L | defect checked zero on n=n0..n0+L-1 | holds | holds from | fails at n=N")
for i, c in main + extra:
    rng = ("n=%d..%d" % (c["n0"], c["checked_to"])) if c["live_states"] else "a = 0 (no live state)"
    print("%s %s%d | r=%d N=%s | L=%d | %s | %s | from %s | %s%s" % (
        i, c["mode"], c["idx"], c["order"], c["N"], c["live_states"], rng,
        "holds" if c["holds"] else "FAILS", c["holds_from"], {True: "sharp", False: "not sharp", None: "-"}[c["sharp"]],
        "  [extra]" if c["extra"] else ""))
