"""Derive reviewed numerical summaries from measured visits, excluding discovery.""" import json from collections import Counter from pathlib import Path root = Path(__file__).parent / 'evidence/2026-10-13/fresh-sessions' rows = [] for f in sorted(root.glob('*.json')): doc = json.loads(f.read_text()) if not isinstance(doc, dict) or 'result' not in doc: continue r = doc['result'] if r['condition'] == 'discovery': continue phases = {} for phase in ('initial', 'choice', 'comparison', 'reload'): requests = [e for e in doc['events'] if e['kind'] == 'request' and e['phase'] == phase] responses = [e for e in doc['events'] if e['kind'] == 'response' and e['phase'] == phase] phases[phase] = { 'requestCount': len(requests), 'requestHosts': dict(sorted(Counter(e.get('host', '') for e in requests).items())), 'responseStatuses': dict(Counter(str(e.get('status')) for e in responses)), 'failures': sum(e['kind'] == 'failure' and e['phase'] == phase for e in doc['events']), } cookies = {} for checkpoint in ('before', 'afterAction', 'after', 'afterReload'): if checkpoint in r: entries = r[checkpoint]['cookies'] cookies[checkpoint] = {'count': len(entries), 'names': sorted(c['name'] for c in entries)} rows.append({ 'file': f.name, 'geo': r['geo'], 'provider': r['provider'], 'condition': r['condition'], 'status': r['status'], 'startedAt': r['startedAt'], 'elapsedMs': r['elapsedMs'], 'attempt': r.get('attempt', 'primary'), 'extraRenderWait': r.get('extraRenderWait', False), 'browserVersion': r['browserVersion'], 'headless': r['headless'], 'cookiesAtStartCount': len(r.get('cookiesAtStart', [])), 'action': r.get('action'), 'cookies': cookies, 'network': phases, 'observationWindows': r.get('phases', []), }) out = {'runCount': len(rows), 'statusCounts': dict(Counter(r['status'] for r in rows)), 'visits': rows} (root / 'measured-summary.json').write_text(json.dumps(out, indent=2)) for r in rows: before = r['cookies'].get('before', {}).get('count') after = r['cookies'].get('after', {}).get('count') print(r['geo'], r['provider'], r['condition'], r['status'], f'cookies={before}->{after}', 'comparison_hosts=' + ','.join(r['network']['comparison']['requestHosts']))