Skip to content

Commit b429916

Browse files
committed
Fix path to reqs; add basic leaderboard func
1 parent a1f2424 commit b429916

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

.github/workflows/build-docs.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Install uv
3535
run: |
3636
curl -LsSf https://astral.sh/uv/install.sh | sh
37-
- run: uv pip install --python ${Python_ROOT_DIR} '../../requirements.txt'
37+
- run: uv pip install --python ${Python_ROOT_DIR} -r 'requirements.txt'
3838
- name: Build Documentation
3939
if: github.ref != 'refs/heads/main'
4040
run: mkdocs build

leaderboard/create_leaderboard.py

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env python
2+
3+
import argparse
4+
import dataclasses
5+
from pathlib import Path
6+
import pandas as pd
7+
import json
8+
9+
10+
@dataclasses.dataclass
11+
class Submission:
12+
"""Represents a single submission"""
13+
date: str
14+
author: str
15+
model: str
16+
scores: dict[str, float]
17+
18+
@classmethod
19+
def from_file(cls, path: Path):
20+
data = json.loads(path.read_text())
21+
return cls(**data)
22+
23+
def to_single_score_dict(self, score="default") -> dict[str, float]:
24+
data = dataclasses.asdict(self)
25+
del data["scores"]
26+
data["score"] = self.scores[score]
27+
return data
28+
29+
30+
class LeaderboardAggregator:
31+
def __init__(self):
32+
self.submissions = []
33+
34+
def load_file(self, path: Path):
35+
submission = Submission.from_file(path)
36+
self.submissions.append(submission)
37+
38+
def format_markdown(self, score="default") -> str:
39+
df = pd.DataFrame.from_records([s.to_single_score_dict(score) for s in self.submissions])
40+
print(df)
41+
df = df.sort_values(by="score", ascending=False)
42+
df = df.reset_index(drop=True)
43+
return df.to_markdown(index=False)
44+
45+
def to_file(self, path: Path, score="default"):
46+
path.write_text(self.format_markdown(score))
47+
48+
49+
def main(input: str, output: str) -> None:
50+
la = LeaderboardAggregator()
51+
for inpt in Path(input).rglob("score.json"):
52+
print("Loading", inpt)
53+
la.load_file(inpt)
54+
la.to_file(Path(output))
55+
56+
57+
def cli():
58+
parser = argparse.ArgumentParser(description="Aggregate leaderboard data and format table")
59+
parser.add_argument("--input", help="Path to leaderboard data")
60+
parser.add_argument("--output", help="Path to save leaderboard table")
61+
return parser
62+
63+
64+
if __name__ == "__main__":
65+
main(**vars(cli().parse_args()))

requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ mkdocs
22
mkdocs-material
33
mkdocs-glightbox
44
mkdocs-include-markdown-plugin
5+
pandas
6+
tabulate

0 commit comments

Comments
 (0)