#!/bin/bash
EV=~/EtherGold/dev/data/events.jsonl
echo "=== all E001 event types ==="
grep '"tid": "E001"' "$EV" 2>/dev/null | grep -oE '"ev": "[^"]+"' | sort | uniq -c
echo "=== E001 msgs by ev ==="
grep '"tid": "E001"' "$EV" 2>/dev/null | python3 -c '
import sys,json
from collections import Counter
c=Counter()
for line in sys.stdin:
  try: o=json.loads(line)
  except: continue
  c[(o.get("ev"), o.get("msg"), o.get("sent_msg"))] += 1
for k,v in sorted(c.items(), key=lambda x:-x[1])[:40]:
  print(v, k)
'
echo "=== any msg to E001 that is not 20 ==="
grep '"tid": "E001"' "$EV" 2>/dev/null | python3 -c '
import sys,json
for line in sys.stdin:
  try: o=json.loads(line)
  except: continue
  if o.get("msg") and o.get("msg")!="20":
    print(o.get("ev"), o.get("msg"), o.get("sent_tid"), o.get("len"))
' | sort | uniq -c | head -30
echo "=== packets.raw present? ==="
ls -la ~/EtherGold/dev/data/packets.raw 2>/dev/null || echo none
