|
12 | 12 | from scipy.stats import kendalltau, spearmanr |
13 | 13 | from tqdm import tqdm |
14 | 14 |
|
15 | | -from codeclash.analysis.metrics.elo import get_scores |
| 15 | +from codeclash.analysis.metrics.elo_broken import get_scores |
16 | 16 | from codeclash.analysis.significance import calculate_p_value |
17 | 17 | from codeclash.analysis.viz.utils import FONT_BOLD, MODEL_TO_DISPLAY_NAME |
18 | 18 | from codeclash.constants import LOCAL_LOG_DIR, RESULT_TIE |
@@ -1334,6 +1334,47 @@ def write_latex_table(results: dict[str, dict], output_dir: Path) -> None: |
1334 | 1334 | logger.info(f"Saved LaTeX table: {output_file}") |
1335 | 1335 |
|
1336 | 1336 |
|
| 1337 | +def write_website_results(results: dict[str, dict], output_dir: Path) -> None: |
| 1338 | + """Write results in JSON format for website consumption. |
| 1339 | +
|
| 1340 | + Creates a leaderboard JSON with rankings per arena and overall. |
| 1341 | + Format: |
| 1342 | + { |
| 1343 | + "ArenaName": [ |
| 1344 | + {"rank": 1, "model": "model_name", "elo": 1500}, |
| 1345 | + ... |
| 1346 | + ], |
| 1347 | + "Overall": [...] |
| 1348 | + } |
| 1349 | + """ |
| 1350 | + output_dir.mkdir(parents=True, exist_ok=True) |
| 1351 | + output_file = output_dir / "leaderboard.json" |
| 1352 | + |
| 1353 | + leaderboard = {} |
| 1354 | + |
| 1355 | + for game_name, game_result in results.items(): |
| 1356 | + players = game_result["players"] |
| 1357 | + strengths = game_result["strengths"] |
| 1358 | + |
| 1359 | + # Convert Bradley-Terry strengths to Elo ratings |
| 1360 | + elos = {p: BradleyTerryFitter.bt_to_elo(s) for p, s in zip(players, strengths)} |
| 1361 | + |
| 1362 | + # Sort by Elo (descending) |
| 1363 | + sorted_players = sorted(elos.items(), key=lambda x: x[1], reverse=True) |
| 1364 | + |
| 1365 | + # Create leaderboard entries |
| 1366 | + leaderboard[game_name] = [ |
| 1367 | + {"rank": rank + 1, "model": MODEL_TO_DISPLAY_NAME.get(player, player), "elo": round(elo, 1)} |
| 1368 | + for rank, (player, elo) in enumerate(sorted_players) |
| 1369 | + ] |
| 1370 | + |
| 1371 | + # Write to file |
| 1372 | + with open(output_file, "w") as f: |
| 1373 | + json.dump(leaderboard, f, indent=2) |
| 1374 | + |
| 1375 | + logger.info(f"Saved leaderboard JSON: {output_file}") |
| 1376 | + |
| 1377 | + |
1337 | 1378 | if __name__ == "__main__": |
1338 | 1379 | parser = argparse.ArgumentParser(description="Build win matrix and fit Bradley-Terry model") |
1339 | 1380 | parser.add_argument("-d", "--log_dir", type=Path, default=LOCAL_LOG_DIR) |
@@ -1406,6 +1447,7 @@ def write_latex_table(results: dict[str, dict], output_dir: Path) -> None: |
1406 | 1447 | plotter.create_validation_plots(args.output_dir, regularization=args.regularization) |
1407 | 1448 | plotter.create_elo_plots(args.output_dir) |
1408 | 1449 | write_latex_table(results, args.output_dir) |
| 1450 | + write_website_results(results, args.output_dir) |
1409 | 1451 |
|
1410 | 1452 | if uncertainties_supported: |
1411 | 1453 | for bootstrap_type in ["nonparametric", "parametric"]: |
|
0 commit comments