Datasets:
Download code/evaluation-code/v0.2-0c2690ae/apps/console/server/batch_summary.py from VEHwang/cocogni4d: direct link, hf CLI and curl.
- Browser
- Download file 4.53 kB
-
https://huggingface.co/datasets/VEHwang/cocogni4d/resolve/main/code/evaluation-code/v0.2-0c2690ae/apps/console/server/batch_summary.py
- Command line
-
hf download hf://datasets/VEHwang/cocogni4d/code/evaluation-code/v0.2-0c2690ae/apps/console/server/batch_summary.py
-
curl -L -o batch_summary.py https://huggingface.co/datasets/VEHwang/cocogni4d/resolve/main/code/evaluation-code/v0.2-0c2690ae/apps/console/server/batch_summary.py
4.53 kB
| """新生成器段和原生出题结果汇总;CLI: python -m apps.console.server.batch_summary OUT VOUT SUMMARY。""" | |
| import collections | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| import re | |
| import sys | |
| def length_tier(script, name, duration_s): | |
| generator = script.get('generator', {}) | |
| for tier in (generator.get('tier'), generator.get('config', {}).get('tier')): | |
| if tier in ('short', 'long'): | |
| return tier | |
| match = re.search(r'-(short|long)-', name) | |
| if match: | |
| return match.group(1) | |
| # Segments from the retired gen.run --case carried a tier: short=90 s, long=360 s. | |
| return 'long' if duration_s >= 360 else 'short' | |
| def summarize(out_dir, vout_dir): | |
| per_case = [] | |
| decisions, generic = collections.Counter(), collections.Counter() | |
| versions = collections.defaultdict(lambda: dict(candidates=0, PASS=0, prover_candidates=0)) | |
| prover_reasons = collections.Counter() # 证明器判前拒因(vout 摘要逐版 reject_reasons):prefiltered:* 按件计,其余按候选首个不过的检查计 | |
| prover = 0 # 证明器判前的候选(vout 摘要 totals.candidates);questions.jsonl 只有它交出的题,candidates 恒等于 PASS 看不出淘汰率 | |
| for receipt in sorted(Path(vout_dir).glob('*/summary.json')): | |
| sp = Path(out_dir) / receipt.parent.name / 'script.json' | |
| script = json.loads(sp.read_text()) | |
| sid = script['script_id'] | |
| folder = receipt.parent # the segment folder, which need not be named after script_id | |
| summary = json.loads((folder / 'summary.json').read_text()) | |
| rows = [json.loads(line) for line in (folder / 'questions.jsonl').read_text().splitlines() if line.strip()] | |
| # Prover receipts identify the segment directory; script.json retains the source id. | |
| if summary['script_id'] != folder.name or len(rows) != summary['candidates']: | |
| raise ValueError('出题摘要身份或候选分母不符: ' + sid) | |
| prover += summary.get('totals', {}).get('candidates') or 0 | |
| case_prover = collections.Counter() | |
| for version, row in summary.get('versions', {}).items(): | |
| versions[version]['prover_candidates'] += row.get('candidates') or 0 | |
| case_prover.update({k: n for k, n in (row.get('reject_reasons') or {}).items() if n}) | |
| prover_reasons.update(case_prover) | |
| case_dec, reasons = collections.Counter(), collections.Counter() | |
| for row in rows: | |
| raw = row['decision']['result'] | |
| if raw not in ('PASS', 'FAIL', 'UNKNOWN', 'ERROR'): | |
| raise ValueError('未知检查状态: ' + raw) | |
| # ERROR remains an explicit execution reason, never a numeric FAIL. | |
| res = 'UNKNOWN' if raw == 'ERROR' else raw | |
| why = row['decision'].get('reason') or ('accepted_interval' if raw == 'PASS' else | |
| 'numeric_interval_outside_acceptance' if raw == 'FAIL' else 'unspecified_undecided') | |
| decisions[res] += 1; case_dec[res] += 1 | |
| generic[why] += 1; reasons[why] += 1 | |
| version = (row.get('public') or row.get('binding'))['version_id'] | |
| versions[version]['candidates'] += 1 | |
| versions[version]['PASS'] += raw == 'PASS' | |
| name = sp.parent.name | |
| house = script.get('generator', {}).get('house') | |
| world = Path(house).name if house else name.split('-')[1] | |
| duration_s = script['span_s'][1] - script['span_s'][0] | |
| per_case.append(dict(name=name, script_id=sid, world=world, | |
| length=length_tier(script, name, duration_s), | |
| duration_s=duration_s, constructed=len(rows), | |
| decisions=dict(case_dec), reasons=dict(reasons), prover_reasons=dict(case_prover), | |
| sources={'case.json': dict(sha256=hashlib.sha256(sp.read_bytes()).hexdigest(), | |
| note='script.json sha256(新生成器无 case.json)')})) | |
| n = len(per_case) | |
| return dict(expected_cases=n, completed_cases=n, errors=0, candidates=sum(decisions.values()), prover_candidates=prover, prover_reasons=dict(prover_reasons), | |
| decisions={k: decisions[k] for k in ('PASS', 'FAIL', 'UNKNOWN')}, | |
| generic_reasons=dict(generic), dimensions=dict(version=dict(versions)), per_case=per_case) | |
| if __name__ == '__main__': | |
| result = summarize(*sys.argv[1:3]) | |
| Path(sys.argv[3]).write_text(json.dumps(result, ensure_ascii=False, indent=1)) | |
| print(result['completed_cases'], result['decisions']) | |