"""Per-visit report of a drive on park-lab: verdict, how fast the car came, and how the plate was read (source of the votes, seconds to the decision). Runs ON park-lab, read-only: ssh park-lab python3 - [camera] < trial_report.py""" import json, sys, os from datetime import datetime, timezone OUT = os.path.expanduser("~/zone-anpr-gpu/out") since = sys.argv[1] if len(sys.argv) > 1 else "2026-11-22T00:00" only = sys.argv[2] if len(sys.argv) > 2 else None ts = lambda iso: datetime.fromisoformat(iso).timestamp() rows = lambda n: [json.loads(l) for l in open(f"{OUT}/{n}")] if os.path.exists(f"{OUT}/{n}") else [] visits, reads = rows("visits.jsonl"), rows("reads.jsonl") W = 1280 print(f"{'start UTC':9s} {'cam':5s} {'verdict':9s} {'speed':>6s} {'to line':>7s} {'seen/s':>6s} | {'plate':18s} {'after':>6s} {'stream t/r/v':>12s} {'still t/r/v':>11s} {'stills kept':>11s}") for v in visits: if v["at"] < since or not v["path"] or (only and v["camera"] != only): continue t0, t1 = ts(v["path"][0]["at"]), ts(v["at"]) clip = None for d in sorted(os.listdir(f"{OUT}/clips")) if os.path.isdir(f"{OUT}/clips") else []: if d.endswith("_" + v["camera"]): try: c0 = datetime.strptime(d.split("_")[0], "%Y%m%dT%H%M%SZ").replace(tzinfo=timezone.utc).timestamp() except ValueError: continue if abs(c0 - t0) < 2: clip = d speed = dets = kept = None if clip: fr = [json.loads(l) for l in open(f"{OUT}/clips/{clip}/frames.jsonl")] if len(fr) > 2: dets = (len(fr) - 1) / max(0.2, fr[-1]["t"] - fr[0]["t"]) a = [r for r in fr if r["t"] - fr[0]["t"] <= 1.5] if len(a) > 2: cx = lambda r: (r["box"][0] + r["box"][2]) / 2 / W speed = abs(cx(a[-1]) - cx(a[0])) / (a[-1]["t"] - a[0]["t"]) # frame widths a second, first 1.5 s kept = len([x for x in os.listdir(f"{OUT}/clips/{clip}") if x.startswith("still_") and x.endswith(".jpg")]) line = next((ts(p["at"]) - t0 for p in v["path"][1:] if p["side"] == "line"), None) r = [x for x in reads if x["camera"] == v["camera"] and t0 - 1.5 <= ts(x["at"]) <= t1 + 1.5] r = r[-1] if r else {} s = r.get("sources") or {} f = lambda k: "%d/%d/%d" % (s[k]["tries"], s[k]["reads"], s[k]["votes"]) if k in s else "-" plate = (r.get("status", "nothing") + " " + (r.get("plate") or "")).strip() print(f"{v['path'][0]['at'][11:19]:9s} {v['camera']:5s} {v['verdict']:9s} {('%.2f' % speed) if speed is not None else '-':>6s} " f"{('%.1fs' % line) if line is not None else '-':>7s} {('%.1f' % dets) if dets else '-':>6s} | {plate:18s} " f"{('%.1fs' % r['after_s']) if r.get('after_s') is not None else '-':>6s} {f('stream'):>12s} {f('still'):>11s} {kept if kept is not None else '-':>11}") print("\nspeed = how fast the car's box moved across the picture in its first 1.5 s (picture widths a second); to line = seconds from first sight to the line;") print("seen/s = looks a second in which the followed car was matched (the detector itself runs at 5); t/r/v = tries / reads that found a plate / reads that voted.")