pearlygates / production /scripts /parse_uploaded_log.py
theapemachine's picture
Add initial project structure with core files and configurations
5d6894b
Raw
History Blame Contribute Delete
1.07 kB
#!/usr/bin/env python3
from __future__ import annotations
import csv
import sys
from pathlib import Path
from pearlygates.log_parser import parse_all_benchmark_tables, split_modes
def main() -> int:
if len(sys.argv) != 3:
print("usage: parse_uploaded_log.py CODE_TXT OUT_DIR", file=sys.stderr)
return 2
src = Path(sys.argv[1])
out_dir = Path(sys.argv[2])
out_dir.mkdir(parents=True, exist_ok=True)
text = src.read_text(encoding="utf-8")
for mode, chunk in split_modes(text).items():
(out_dir / f"{mode}.txt").write_text(chunk.strip() + "\n", encoding="utf-8")
rows = [r.to_dict() for r in parse_all_benchmark_tables(text)]
with (out_dir / "benchmark_tables.csv").open("w", newline="", encoding="utf-8") as handle:
if rows:
writer = csv.DictWriter(handle, fieldnames=list(rows[0].keys()))
writer.writeheader()
writer.writerows(rows)
print(f"wrote {len(rows)} benchmark rows to {out_dir}")
return 0
if __name__ == "__main__":
raise SystemExit(main())