Skip to content

Commit

Permalink
Fix path to reqs; add basic leaderboard func
Browse files Browse the repository at this point in the history
  • Loading branch information
klieret committed Jul 12, 2024
1 parent a1f2424 commit b429916
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/build-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
- run: uv pip install --python ${Python_ROOT_DIR} '../../requirements.txt'
- run: uv pip install --python ${Python_ROOT_DIR} -r 'requirements.txt'
- name: Build Documentation
if: github.ref != 'refs/heads/main'
run: mkdocs build
Expand Down
65 changes: 65 additions & 0 deletions leaderboard/create_leaderboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env python

import argparse
import dataclasses
from pathlib import Path
import pandas as pd
import json


@dataclasses.dataclass
class Submission:
"""Represents a single submission"""
date: str
author: str
model: str
scores: dict[str, float]

@classmethod
def from_file(cls, path: Path):
data = json.loads(path.read_text())
return cls(**data)

def to_single_score_dict(self, score="default") -> dict[str, float]:
data = dataclasses.asdict(self)
del data["scores"]
data["score"] = self.scores[score]
return data


class LeaderboardAggregator:
def __init__(self):
self.submissions = []

def load_file(self, path: Path):
submission = Submission.from_file(path)
self.submissions.append(submission)

def format_markdown(self, score="default") -> str:
df = pd.DataFrame.from_records([s.to_single_score_dict(score) for s in self.submissions])
print(df)
df = df.sort_values(by="score", ascending=False)
df = df.reset_index(drop=True)
return df.to_markdown(index=False)

def to_file(self, path: Path, score="default"):
path.write_text(self.format_markdown(score))


def main(input: str, output: str) -> None:
la = LeaderboardAggregator()
for inpt in Path(input).rglob("score.json"):
print("Loading", inpt)
la.load_file(inpt)
la.to_file(Path(output))


def cli():
parser = argparse.ArgumentParser(description="Aggregate leaderboard data and format table")
parser.add_argument("--input", help="Path to leaderboard data")
parser.add_argument("--output", help="Path to save leaderboard table")
return parser


if __name__ == "__main__":
main(**vars(cli().parse_args()))
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ mkdocs
mkdocs-material
mkdocs-glightbox
mkdocs-include-markdown-plugin
pandas
tabulate

0 comments on commit b429916

Please sign in to comment.