openpi / scripts /parse_report_task_line.py
zhicao's picture
Add files using upload-large-folder tool
9398fb9 verified
Raw History Blame Contribute Delete
1.01 kB
#!/usr/bin/env python3
"""Parse ``Task N:`` lines from pi05_final suite summary txt files."""
from __future__ import annotations
import re
from pathlib import Path
_TASK_LINE = re.compile(r"^Task\s+(\d+):\s+\d+/\d+\s*=\s*[\d.]+%\s*\|\s*(.+)$", re.MULTILINE)
def parse_suite_summary(path: Path, suite_name: str) -> dict[int, str]:
text = path.read_text(encoding="utf-8")
marker = f"PER-TASK SUCCESS RATE SUMMARY ({suite_name})"
if marker not in text:
raise ValueError(f"{path}: missing section {suite_name!r}")
start = text.index(marker) + len(marker)
rest = text[start:]
end = rest.find("PER-TASK SUCCESS RATE SUMMARY (")
section = rest if end < 0 else rest[:end]
out: dict[int, str] = {}
for m in _TASK_LINE.finditer(section):
out[int(m.group(1))] = m.group(2).strip()
return out
def report_task_to_slot(report_task: int) -> int:
"""Map report line ``Task N`` → benchmark ``get_task(N - 1)`` index."""
return int(report_task) - 1