#!/usr/bin/env python3 """Aggregate ADI Lab JSONL results into check-level and full-profile rates.""" from __future__ import annotations import argparse import csv import json from collections import defaultdict from pathlib import Path def main() -> None: parser = argparse.ArgumentParser() parser.add_argument("input") parser.add_argument("--out", required=True) args = parser.parse_args() profiles = [json.loads(line) for line in Path(args.input).read_text(encoding="utf-8").splitlines() if line.strip()] by_browser = defaultdict(list) for profile in profiles: if "error" in profile: continue by_browser[profile["browser"]].append(profile) rows = [] for browser, group in sorted(by_browser.items()): total_checks = 0 passed_checks = 0 full = 0 for profile in group: checks = profile.get("checks", {}) values = [v for v in checks.values() if v is not None] total_checks += len(values) passed_checks += sum(1 for v in values if v is True) if values and all(v is True for v in values): full += 1 rows.append({ "browser": browser, "profiles": len(group), "check_level_pass_pct": round(100 * passed_checks / total_checks, 1) if total_checks else 0, "full_profile_pass_pct": round(100 * full / len(group), 1) if group else 0, "avg_checks_passed": round(passed_checks / len(group), 1) if group else 0, }) with Path(args.out).open("w", encoding="utf-8", newline="") as handle: writer = csv.DictWriter(handle, fieldnames=list(rows[0].keys()) if rows else ["browser"]) writer.writeheader() writer.writerows(rows) print(f"Wrote {args.out} ({len(rows)} browsers)") if __name__ == "__main__": main()