Skip to content

Commit 88237f3

Browse files
committed
Write elo results to website leaderboard
1 parent 588486a commit 88237f3

1 file changed

Lines changed: 43 additions & 1 deletion

File tree

codeclash/analysis/metrics/elo2.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from scipy.stats import kendalltau, spearmanr
1313
from tqdm import tqdm
1414

15-
from codeclash.analysis.metrics.elo import get_scores
15+
from codeclash.analysis.metrics.elo_broken import get_scores
1616
from codeclash.analysis.significance import calculate_p_value
1717
from codeclash.analysis.viz.utils import FONT_BOLD, MODEL_TO_DISPLAY_NAME
1818
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:
13341334
logger.info(f"Saved LaTeX table: {output_file}")
13351335

13361336

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+
13371378
if __name__ == "__main__":
13381379
parser = argparse.ArgumentParser(description="Build win matrix and fit Bradley-Terry model")
13391380
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:
14061447
plotter.create_validation_plots(args.output_dir, regularization=args.regularization)
14071448
plotter.create_elo_plots(args.output_dir)
14081449
write_latex_table(results, args.output_dir)
1450+
write_website_results(results, args.output_dir)
14091451

14101452
if uncertainties_supported:
14111453
for bootstrap_type in ["nonparametric", "parametric"]:

0 commit comments

Comments
 (0)