#!/usr/bin/env python3
"""Prune the tail end of the shipin1 pen run: frames 2564-2567.
The pen exits the left edge after f2563 (eye-verified: f2563 box is on the
real white pen with red lettering; f2567 box is on a dark glove fingertip,
and f2564-2566 boxes are edge slivers at x0=0, widths 84/45/14).
Drops pen boxes on those 4 frames only; everything else untouched.
Input:  shipin1_tail_paintmarker_filtered.boxes.json (138 boxes / 138 frames)
Output: shipin1_tail_paintmarker_pruned.boxes.json (134 boxes / 134 frames)
"""
import json
import os

JOB_DIR = "/home/agent/.claude/workspace/project/data/out/c3de403cfd15"
SRC = os.path.join(JOB_DIR, "shipin1_tail_paintmarker_filtered.boxes.json")
DST = os.path.join(JOB_DIR, "shipin1_tail_paintmarker_pruned.boxes.json")
DROP = {2564, 2565, 2566, 2567}


def main():
    rows = json.load(open(SRC))
    dropped = 0
    for r in rows:
        if r["frame"] in DROP and r.get("boxes"):
            dropped += len(r["boxes"])
            r["boxes"] = []
            r["conf"] = []
            r["ids"] = []
    json.dump(rows, open(DST, "w"))
    kept = sum(len(r.get("boxes") or []) for r in rows)
    kept_frames = sum(1 for r in rows if r.get("boxes"))
    print(f"dropped={dropped} frames {sorted(DROP)} -> kept={kept} boxes on {kept_frames} frames -> {DST}")


if __name__ == "__main__":
    main()
