Chris Leo commited on
scorevision: push artifact
Browse files
detect_crime_ops/scripts/summarize_challenges.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import argparse
|
| 5 |
+
import csv
|
| 6 |
+
from collections import Counter
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def _f(x: str) -> float:
|
| 11 |
+
try:
|
| 12 |
+
return float(x)
|
| 13 |
+
except Exception:
|
| 14 |
+
return 0.0
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def main() -> int:
|
| 18 |
+
ap = argparse.ArgumentParser()
|
| 19 |
+
ap.add_argument("--csv", required=True)
|
| 20 |
+
args = ap.parse_args()
|
| 21 |
+
|
| 22 |
+
p = Path(args.csv)
|
| 23 |
+
if not p.exists():
|
| 24 |
+
print(f"[error] missing {p}")
|
| 25 |
+
return 1
|
| 26 |
+
|
| 27 |
+
rows = list(csv.DictReader(p.open()))
|
| 28 |
+
if not rows:
|
| 29 |
+
print("[info] no rows yet")
|
| 30 |
+
return 0
|
| 31 |
+
|
| 32 |
+
n = len(rows)
|
| 33 |
+
my = [_f(r.get("my_score", "0")) for r in rows]
|
| 34 |
+
king = [_f(r.get("king_score", "0")) for r in rows]
|
| 35 |
+
delta = [m - k for m, k in zip(my, king)]
|
| 36 |
+
p95 = [_f(r.get("my_latency_p95_ms", "0")) for r in rows]
|
| 37 |
+
preds = [_f(r.get("my_pred_count", "0")) for r in rows]
|
| 38 |
+
|
| 39 |
+
tags = Counter()
|
| 40 |
+
for r in rows:
|
| 41 |
+
raw = r.get("tag_list", "")
|
| 42 |
+
for t in [x.strip() for x in raw.split(",") if x.strip()]:
|
| 43 |
+
tags[t] += 1
|
| 44 |
+
|
| 45 |
+
print("=== Detect-crime challenge summary ===")
|
| 46 |
+
print(f"rows={n}")
|
| 47 |
+
print(f"my_score: avg={sum(my)/n:.4f} min={min(my):.4f} max={max(my):.4f}")
|
| 48 |
+
print(f"king_score: avg={sum(king)/n:.4f} min={min(king):.4f} max={max(king):.4f}")
|
| 49 |
+
print(f"delta: avg={sum(delta)/n:+.4f} wins={sum(1 for d in delta if d > 0)}/{n}")
|
| 50 |
+
print(f"latency p95 avg={sum(p95)/n:.1f}ms")
|
| 51 |
+
print(f"pred_count avg={sum(preds)/n:.2f}")
|
| 52 |
+
if tags:
|
| 53 |
+
print("top failure tags:")
|
| 54 |
+
for k, v in tags.most_common(8):
|
| 55 |
+
print(f" - {k}: {v}")
|
| 56 |
+
return 0
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
raise SystemExit(main())
|