"""Summarize index mutations from the existing bounded atproto-bench capture.""" import collections import hashlib import json import struct import sys from pathlib import Path from atproto_core.cbor import decode_dag_multi path = Path(sys.argv[1]) data = path.read_bytes() count, = struct.unpack_from(">I", data) position = 4 seen = set() frames = collections.Counter() ops = collections.Counter() pairs_per_frame = collections.Counter() novel_per_frame = collections.Counter() times = [] for _ in range(count): length, = struct.unpack_from(">I", data, position) position += 4 raw = data[position:position + length] assert len(raw) == length position += length header, payload = decode_dag_multi(raw) frames[header.get("t", "other")] += 1 if header.get("t") != "#commit": continue if payload.get("time"): times.append(payload["time"]) pairs, new = set(), set() for op in payload.get("ops", []): action = op.get("action") ops[action] += 1 if action not in ("create", "update"): continue collection, slash, _ = op.get("path", "").partition("/") if not slash or not collection: continue pair = (payload["repo"], collection) pairs.add(pair) if pair not in seen: new.add(pair) seen.add(pair) pairs_per_frame[len(pairs)] += 1 novel_per_frame[len(new)] += 1 assert position == len(data) print(json.dumps({ "file": path.name, "bytes": len(data), "sha256": hashlib.sha256(data).hexdigest(), "frames": dict(frames), "ops": dict(ops), "unique_pairs": len(seen), "distinct_pairs_per_commit": dict(sorted(pairs_per_frame.items())), "new_pairs_per_commit_cold": dict(sorted(novel_per_frame.items())), "first_time": min(times), "last_time": max(times), }, indent=2))