Datasets:
Download code/evaluation-code/v0.2-0c2690ae/apps/console/tools/fill_check.py from VEHwang/cocogni4d: direct link, hf CLI and curl.
- Browser
- Download file 6.48 kB
-
https://huggingface.co/datasets/VEHwang/cocogni4d/resolve/main/code/evaluation-code/v0.2-0c2690ae/apps/console/tools/fill_check.py
- Command line
-
hf download hf://datasets/VEHwang/cocogni4d/code/evaluation-code/v0.2-0c2690ae/apps/console/tools/fill_check.py
-
curl -L -o fill_check.py https://huggingface.co/datasets/VEHwang/cocogni4d/resolve/main/code/evaluation-code/v0.2-0c2690ae/apps/console/tools/fill_check.py
6.48 kB
| """交付检查:按真批次统计三个台每一栏的数据填满了多少,空的报红。 | |
| 核对表曾经只看控件在不在页面上(consoles-v3-check-live 30/36 判“有”),这里改看数据: | |
| 每栏只在“这道题/这一段用得上”的分母里算填充率,分母大于 0 而一个都没填就是红(退出码 1)。 | |
| 它读的数据和页面读的一样:剧本验收台读 /api/v1/segments,渲染验收台读 /evidence/ev/ 下的 questions.json、q/<id>.json、<段>.answers.json。 | |
| 用法: python -m apps.console.tools.fill_check http://127.0.0.1:19042 [--run 批次前缀] [--sample N] | |
| """ | |
| import argparse | |
| import json | |
| import sys | |
| import urllib.parse | |
| import urllib.request | |
| from apps.console.server.review_pack import BEARING, STAMPING, TIME_KEYS | |
| def nodes(n): | |
| """Every slot node in a slot tree (fill values may be slots, strings or lists of slots).""" | |
| if isinstance(n, dict): | |
| if 'method' in n: | |
| yield n | |
| for v in (n.get('fill') or {}).values() if 'method' in n else n.values(): | |
| yield from nodes(v) | |
| elif isinstance(n, list): | |
| for v in n: | |
| yield from nodes(v) | |
| def has(q, prefix): | |
| return any(str(n.get('method', '')).startswith(prefix) for n in nodes(q.get('slots') or {})) | |
| # 事件只在 STAMPING 那几种外壳里有时刻(review_pack 从外壳给事件盖时刻)。别的事件(at_event、temporal_order、after_event 等), | |
| # 时刻就是所问或推得出答案,盲看时不画,这一栏对它用不上;没有时刻的题(map_choice.static)题槽时刻也用不上 | |
| TIMED = ('instant.', 'period.') | |
| def hidden(q): | |
| return {b.split('.')[0] for b in BEARING.get(q.get('version_id'), [])} | |
| def open_slots(q): | |
| """The slots the blind page may show times for: answer-bearing ones are left out (answer_bearing_slots).""" | |
| return {n: v for n, v in (q.get('slots') or {}).items() if n not in hidden(q)} | |
| def leaks(q): | |
| """Answer-bearing slots whose times still reach the blind page (slot values, steps, event stamps).""" | |
| h = hidden(q) | |
| timed = [n for n in h if any(k in v for v in nodes_values((q.get('slots') or {}).get(n)) for k in TIME_KEYS)] | |
| return timed + [s['slot'] for s in q.get('steps') or [] if s.get('slot') in h] + [e['event_id'] for e in q.get('event_readings') or [] if str(e['event_id']).split('.')[0] in h] | |
| def nodes_values(n): | |
| if isinstance(n, dict): | |
| if isinstance(n.get('value'), dict): | |
| yield n['value'] | |
| for k, v in n.items(): | |
| if k != 'value': | |
| yield from nodes_values(v) | |
| elif isinstance(n, list): | |
| for v in n: | |
| yield from nodes_values(v) | |
| def timed_event(q): | |
| return any(n.get('method') in STAMPING and has({'slots': n.get('fill') or {}}, 'event.') for n in nodes(open_slots(q))) | |
| # 渲染验收台每一栏:(名字, 这道题用得上吗, 填了没有);q 是 ev/q/<id>.json,a 是这题在 answers.json 里的答案 | |
| QUESTION_FIELDS = ( | |
| ('主体绑定(画面上框人)', lambda q, a: has(q, 'actor.'), lambda q, a: bool(q.get('roles'))), | |
| ('题槽时刻(揭晓跳帧)', lambda q, a: any(has({'slots': open_slots(q)}, p) for p in TIMED), lambda q, a: any(s.get('slot') for s in q.get('steps') or [])), | |
| ('答案槽盲看不露时刻', lambda q, a: bool(hidden(q)), lambda q, a: not leaks(q) and bool(((a or {}).get('reveal') or {}).get('steps'))), | |
| ('事件时刻(时间轴事件刻)', lambda q, a: timed_event(q), lambda q, a: bool(q.get('event_readings'))), | |
| ('房间绑定(俯视图高亮)', lambda q, a: has(q, 'area.room'), lambda q, a: bool((q.get('bindings') or {}).get('rooms'))), | |
| ('录像是现行渲染代码', lambda q, a: True, lambda q, a: q.get('render_stale') == []), # 没有这个字段是旧代码打的包,不算齐(18:11 假齐) | |
| ('答案判分(容差)', lambda q, a: True, lambda q, a: ((a or {}).get('scoring') or {}).get('status') not in (None, 'unknown')), | |
| ('两路锚定(多机身)', lambda q, a: len([r for r in q.get('routes') or [] if r.get('public')]) > 1, lambda q, a: bool(q.get('anchor'))), | |
| ) | |
| # 剧本验收台段列表每一栏(行来自 /api/v1/segments) | |
| SEGMENT_FIELDS = ( | |
| ('自检结论', lambda s: True, lambda s: str(s.get('selfcheck_conclusion')).lower() not in ('none', 'not_checked')), | |
| ('剩余原地占比', lambda s: True, lambda s: s.get('idle_remainder_fraction') is not None), | |
| ) | |
| def rates(rows, fields): | |
| """{名字: (填了, 用得上)};rows 是参数元组的列表。""" | |
| out = {} | |
| for name, applies, filled in fields: | |
| use = [r for r in rows if applies(*r)] | |
| out[name] = (sum(bool(filled(*r)) for r in use), len(use)) | |
| return out | |
| def get(base, path): | |
| with urllib.request.urlopen(base.rstrip('/') + '/' + path, timeout=20) as r: | |
| return json.load(r) | |
| def main(argv=None): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument('base') | |
| ap.add_argument('--run', help='批次前缀;默认取题目索引里最新的一批') | |
| ap.add_argument('--sample', type=int, default=100, help='渲染验收台每批抽多少道(均匀抽)') | |
| a = ap.parse_args(argv) | |
| index = get(a.base, 'evidence/ev/questions.json')['questions'] | |
| run = a.run or max(q['segment'].split('__')[0] for q in index) | |
| picked = [q for q in index if q['segment'].startswith(run)] | |
| picked = picked[::max(1, len(picked) // a.sample)][:a.sample] | |
| answers, rows = {}, [] | |
| for q in picked: | |
| if q['segment'] not in answers: | |
| answers[q['segment']] = get(a.base, f"evidence/ev/{urllib.parse.quote(q['segment'], safe='')}.answers.json") | |
| rows.append((get(a.base, f"evidence/ev/q/{urllib.parse.quote(q['instance_id'], safe='')}.json"), answers[q['segment']].get(q['instance_id']))) | |
| segs = [(s,) for s in get(a.base, 'api/v1/segments')['segments'] if s['id'].startswith(run)] | |
| red = 0 | |
| print(f'批次 {run}:渲染验收台抽 {len(rows)} 道,剧本验收台 {len(segs)} 段') | |
| for screen, table in (('渲染验收台', rates(rows, QUESTION_FIELDS)), ('剧本验收台', rates(segs, SEGMENT_FIELDS))): | |
| for name, (got, use) in table.items(): | |
| mark = '红' if use and not got else '缺' if got < use else '齐' if use else '—' | |
| red += mark == '红' | |
| print(f' {mark} {screen} · {name}: {got}/{use}') | |
| return 1 if red else 0 | |
| if __name__ == '__main__': | |
| sys.exit(main()) | |