-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleaderboard.py
More file actions
48 lines (42 loc) · 1.44 KB
/
leaderboard.py
File metadata and controls
48 lines (42 loc) · 1.44 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
leaderboard.py — In-Memory Best-Score Tracker
Tracks every execution attempt across all tasks so the /leaderboard
endpoint can display real-time standings.
"""
from collections import defaultdict
from datetime import datetime, timezone
from typing import Any, Dict, List
_board: Dict[str, List[Dict[str, Any]]] = defaultdict(list)
def record(
task_id: str,
speedup: float,
score: float,
results_match: bool,
steps: int,
) -> None:
_board[task_id].append(
{
"speedup": round(speedup, 3),
"score": round(score, 4),
"results_match": results_match,
"steps": steps,
"ts": datetime.now(timezone.utc).isoformat(),
}
)
def get_board() -> Dict[str, Any]:
out: Dict[str, Any] = {}
for task_id, entries in _board.items():
if not entries:
continue
best = max(entries, key=lambda e: e["score"])
valid = [e for e in entries if e["results_match"]]
fastest = max(valid, key=lambda e: e["speedup"]) if valid else None
out[task_id] = {
"best_score": best["score"],
"best_speedup": fastest["speedup"] if fastest else 0.0,
"total_attempts": len(entries),
"correct_attempts": len(valid),
"success_rate": round(len(valid) / len(entries), 3),
"best_attempt_at": best["ts"],
}
return out