forked from NoorMajdoub/Challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender_leaderboard.py
More file actions
30 lines (21 loc) · 802 Bytes
/
render_leaderboard.py
File metadata and controls
30 lines (21 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import pandas as pd
csv_path = "leaderboard/leaderboard.csv"
md_path = "leaderboard/leaderboard.md"
# Load CSV safely
df = pd.read_csv(csv_path)
# Normalize column names
df.columns = [c.strip().lower() for c in df.columns]
# Ensure required columns exist
if "team" not in df.columns or "score" not in df.columns:
raise ValueError(f"Invalid leaderboard.csv format. Found columns: {df.columns}")
# Convert score to float
df["score"] = df["score"].astype(float)
# Sort
df = df.sort_values(by="score", ascending=False)
# Build Markdown
md_table = ["| Team | Score |", "|------|-------|"]
for _, row in df.iterrows():
md_table.append(f"| {row['team']} | {row['score']:.4f} |")
with open(md_path, "w") as f:
f.write("\n".join(md_table))
print(f"Rendered {len(df)} entries to {md_path}")