Spaces:
Configuration error
Configuration error
File size: 1,568 Bytes
1acd444 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | # stratego/benchmarking/csv_logger.py
import csv
import os
from datetime import datetime
BENCHMARK_DIR = "stratego/benchmarking/output/benchmarks"
SUMMARY_DIR = "stratego/benchmarking/output/summaries"
def create_benchmark_csv(batch_size: int):
"""
Creates ONE CSV file for ONE benchmark run (multiple games).
"""
os.makedirs(BENCHMARK_DIR, exist_ok=True)
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
filename = f"benchmark_{timestamp}_games{batch_size}.csv"
path = os.path.join(BENCHMARK_DIR, filename)
f = open(path, "w", newline="", encoding="utf-8")
writer = csv.writer(f)
writer.writerow([
"game_id",
"model_p0",
"model_p1",
"board_size",
"winner",
"turns",
"invalid_moves_p0",
"invalid_moves_p1",
"repetitions",
"flag_captured",
"game_end_reason"
])
return f, writer, path
def write_summary_csv(summary: dict, source_csv: str):
"""
Writes ONE summary CSV corresponding to ONE benchmark CSV.
"""
os.makedirs(SUMMARY_DIR, exist_ok=True)
base = os.path.basename(source_csv).replace(".csv", "")
path = os.path.join(SUMMARY_DIR, f"{base}_SUMMARY.csv")
with open(path, "w", newline="", encoding="utf-8") as f:
writer = csv.writer(f)
writer.writerow(["metric", "value"])
writer.writerow(["source_benchmark_csv", source_csv])
for k, v in summary.items():
writer.writerow([k, v])
|