Write LaTeX table with ELO results to file. Args: results: Dictionary mapping game name to fit results output_dir: Directory to save the LaTeX file
(results: dict[str, dict], output_dir: Path)
| 1296 | indices = np.argsort(result["strengths"])[::-1] |
| 1297 | for idx in indices: |
| 1298 | player = result["players"][idx] |
| 1299 | strength = result["strengths"][idx] |
| 1300 | elo = BradleyTerryFitter.bt_to_elo(strength) |
| 1301 | sigma = result.get("elo_std") |
| 1302 | if sigma is not None: |
| 1303 | s = sigma[idx] |
| 1304 | logger.info(f" {player:<30s} {strength:12.3f} {elo:8.0f} {s:8.0f}") |
| 1305 | else: |
| 1306 | logger.info(f" {player:<30s} {strength:12.3f} {elo:8.0f}") |
| 1307 | |
| 1308 | |
| 1309 | def write_latex_table(results: dict[str, dict], output_dir: Path) -> None: |
| 1310 | """Write LaTeX table with ELO results to file. |
| 1311 | |
| 1312 | Args: |
| 1313 | results: Dictionary mapping game name to fit results |
| 1314 | output_dir: Directory to save the LaTeX file |
| 1315 | """ |
| 1316 | output_dir.mkdir(parents=True, exist_ok=True) |
| 1317 | output_file = output_dir / "main_results.tex" |
| 1318 | |
| 1319 | single_arena_games = ["BattleSnake", "CoreWar", "Halite", "HuskyBench", "RoboCode", "RobotRumble"] |
| 1320 | games_in_table = [g for g in single_arena_games if g in results] |
| 1321 | |
| 1322 | if "ALL" not in results: |
| 1323 | logger.warning("No 'ALL' game found in results, skipping LaTeX table generation") |
| 1324 | return |
| 1325 | |
| 1326 | all_result = results["ALL"] |
| 1327 | all_players = all_result["players"] |
| 1328 | all_strengths = all_result["strengths"] |
| 1329 | all_elos = {p: BradleyTerryFitter.bt_to_elo(s) for p, s in zip(all_players, all_strengths)} |
| 1330 | sorted_players = sorted(all_elos.items(), key=lambda x: x[1], reverse=True) |
| 1331 | |
| 1332 | lines = [] |
| 1333 | lines.append("% LaTeX commands for formatting ELO results") |
| 1334 | lines.append(r"\newcommand{\eloSingleArenaResult}[1]{% #1=formatted number") |
| 1335 | lines.append(r" \begin{tikzpicture}[baseline=(text.base)]") |
| 1336 | lines.append(r" \pgfmathsetmacro{\barwidth}{#1 * 0.0007}") |
| 1337 | lines.append(r" \fill[black!15] (0, -0.15) rectangle (\barwidth, 0.25);") |
| 1338 | lines.append(r" \node[anchor=west,text=black,font=\footnotesize] (text) at (-0.05, 0.05) {#1};") |
| 1339 | lines.append(r" \end{tikzpicture}%") |
| 1340 | lines.append(r"}") |
| 1341 | lines.append(r"\newcommand{\eloMainResult}[1]{% #1=raw number") |
| 1342 | lines.append(r" \begin{tikzpicture}[baseline=(text.base)]") |
| 1343 | lines.append(r" \pgfmathsetmacro{\barwidth}{#1 * 0.001}") |
| 1344 | lines.append(r" \fill[chart!35] (0, -0.15) rectangle (\barwidth, 0.25);") |
| 1345 | lines.append(r" \node[anchor=west,font=\bfseries] (text) at (0, 0.05) {#1};") |
| 1346 | lines.append(r" \end{tikzpicture}%") |
| 1347 | lines.append(r"}") |
| 1348 | lines.append("") |
| 1349 | lines.append(r"\begin{table}[t]") |
| 1350 | lines.append(r"\centering") |
| 1351 | lines.append(r"\setlength{\tabcolsep}{3pt}") |
| 1352 | lines.append(r"\renewcommand{\arraystretch}{0.9}") |
| 1353 | lines.append(r"\begin{tabular}{l|" + "l" * len(games_in_table) + "|l}") |
| 1354 | lines.append(r"\toprule") |
| 1355 |