Datasets:
feat: add Cost column to leaderboard (aggregate per-run cost)
Browse files
scripts/generate_leaderboard.py
CHANGED
|
@@ -167,6 +167,11 @@ def compute_stats(records: list[dict]) -> dict:
|
|
| 167 |
failures = sum(1 for r in records if r.get("evaluation_status") in (
|
| 168 |
"failure_api_or_parse", "failure_unexpected_type", "error_bad_ground_truth"))
|
| 169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
return {
|
| 171 |
"score": total_score,
|
| 172 |
"correct": correct,
|
|
@@ -174,6 +179,7 @@ def compute_stats(records: list[dict]) -> dict:
|
|
| 174 |
"incorrect": incorrect,
|
| 175 |
"skipped": skipped,
|
| 176 |
"failures": failures,
|
|
|
|
| 177 |
"num_questions": len(records),
|
| 178 |
}
|
| 179 |
|
|
@@ -190,6 +196,7 @@ def load_summary_json(filepath: str) -> dict | None:
|
|
| 190 |
"incorrect": data.get("overall_incorrect", data.get("overall_incorrect_choice", 0)),
|
| 191 |
"skipped": data.get("overall_skipped", 0),
|
| 192 |
"failures": data.get("overall_api_parse_failures", 0),
|
|
|
|
| 193 |
"num_questions": data.get("total_questions_processed", 0),
|
| 194 |
}
|
| 195 |
except (OSError, json.JSONDecodeError, KeyError):
|
|
|
|
| 167 |
failures = sum(1 for r in records if r.get("evaluation_status") in (
|
| 168 |
"failure_api_or_parse", "failure_unexpected_type", "error_bad_ground_truth"))
|
| 169 |
|
| 170 |
+
# Cost is None (not 0) when no record logged it, so the leaderboard can
|
| 171 |
+
# distinguish "free" from "predates cost logging" and render "?".
|
| 172 |
+
cost_vals = [r.get("cost") for r in records if r.get("cost") is not None]
|
| 173 |
+
cost = round(sum(cost_vals), 4) if cost_vals else None
|
| 174 |
+
|
| 175 |
return {
|
| 176 |
"score": total_score,
|
| 177 |
"correct": correct,
|
|
|
|
| 179 |
"incorrect": incorrect,
|
| 180 |
"skipped": skipped,
|
| 181 |
"failures": failures,
|
| 182 |
+
"cost": cost,
|
| 183 |
"num_questions": len(records),
|
| 184 |
}
|
| 185 |
|
|
|
|
| 196 |
"incorrect": data.get("overall_incorrect", data.get("overall_incorrect_choice", 0)),
|
| 197 |
"skipped": data.get("overall_skipped", 0),
|
| 198 |
"failures": data.get("overall_api_parse_failures", 0),
|
| 199 |
+
"cost": data.get("total_cost_usd"),
|
| 200 |
"num_questions": data.get("total_questions_processed", 0),
|
| 201 |
}
|
| 202 |
except (OSError, json.JSONDecodeError, KeyError):
|
scripts/leaderboard_template.html
CHANGED
|
@@ -49,6 +49,7 @@ a{color:var(--accent);}
|
|
| 49 |
<th data-k="model">Model</th>
|
| 50 |
<th data-k="score" class="num">Score</th>
|
| 51 |
<th data-k="pct" class="num">%</th>
|
|
|
|
| 52 |
<th data-k="correct" class="num">Correct</th>
|
| 53 |
<th data-k="partial" class="num">Partial</th>
|
| 54 |
<th data-k="incorrect" class="num">Incorrect</th>
|
|
@@ -90,11 +91,12 @@ function fillYears(){
|
|
| 90 |
|
| 91 |
function render(){
|
| 92 |
let rows = entries.filter(e => e.exam === state.exam && String(e.year) === String(state.year));
|
|
|
|
|
|
|
|
|
|
| 93 |
rows.sort((a,b) => {
|
| 94 |
if(state.sort === 'model') return state.dir * a.model.localeCompare(b.model);
|
| 95 |
-
|
| 96 |
-
let vb = state.sort === 'pct' ? (pct(b) ?? -1) : (b[state.sort] ?? 0);
|
| 97 |
-
return state.dir * (va - vb);
|
| 98 |
});
|
| 99 |
|
| 100 |
const fn = []; const fnIndex = {};
|
|
@@ -124,6 +126,7 @@ function render(){
|
|
| 124 |
'<td title="' + title.replace(/"/g,'"') + '">' + e.model + badge + lab + sup + '</td>' +
|
| 125 |
'<td class="num">' + e.score + (e.max_score ? (' / ' + e.max_score) : '') + '</td>' +
|
| 126 |
'<td class="num">' + (p !== null ? p.toFixed(1) : '?') + '</td>' +
|
|
|
|
| 127 |
'<td class="num">' + e.correct + '</td>' +
|
| 128 |
'<td class="num">' + e.partial + '</td>' +
|
| 129 |
'<td class="num">' + e.incorrect + '</td>' +
|
|
|
|
| 49 |
<th data-k="model">Model</th>
|
| 50 |
<th data-k="score" class="num">Score</th>
|
| 51 |
<th data-k="pct" class="num">%</th>
|
| 52 |
+
<th data-k="cost" class="num">Cost</th>
|
| 53 |
<th data-k="correct" class="num">Correct</th>
|
| 54 |
<th data-k="partial" class="num">Partial</th>
|
| 55 |
<th data-k="incorrect" class="num">Incorrect</th>
|
|
|
|
| 91 |
|
| 92 |
function render(){
|
| 93 |
let rows = entries.filter(e => e.exam === state.exam && String(e.year) === String(state.year));
|
| 94 |
+
const sortVal = (e) => state.sort === 'pct' ? (pct(e) ?? -1)
|
| 95 |
+
: state.sort === 'cost' ? (e.cost ?? -1)
|
| 96 |
+
: (e[state.sort] ?? 0);
|
| 97 |
rows.sort((a,b) => {
|
| 98 |
if(state.sort === 'model') return state.dir * a.model.localeCompare(b.model);
|
| 99 |
+
return state.dir * (sortVal(a) - sortVal(b));
|
|
|
|
|
|
|
| 100 |
});
|
| 101 |
|
| 102 |
const fn = []; const fnIndex = {};
|
|
|
|
| 126 |
'<td title="' + title.replace(/"/g,'"') + '">' + e.model + badge + lab + sup + '</td>' +
|
| 127 |
'<td class="num">' + e.score + (e.max_score ? (' / ' + e.max_score) : '') + '</td>' +
|
| 128 |
'<td class="num">' + (p !== null ? p.toFixed(1) : '?') + '</td>' +
|
| 129 |
+
'<td class="num">' + (e.cost != null ? '$' + e.cost.toFixed(2) : '?') + '</td>' +
|
| 130 |
'<td class="num">' + e.correct + '</td>' +
|
| 131 |
'<td class="num">' + e.partial + '</td>' +
|
| 132 |
'<td class="num">' + e.incorrect + '</td>' +
|
tests/test_leaderboard_html.py
CHANGED
|
@@ -48,6 +48,19 @@ def test_render_html_missing_placeholder_raises(tmp_path):
|
|
| 48 |
gl.render_html([], str(template), "2026-06-20")
|
| 49 |
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
def test_render_html_serializes_yaml_date_objects(tmp_path):
|
| 52 |
# PyYAML parses unquoted ISO dates into datetime.date, which json can't
|
| 53 |
# serialize natively. render_html must handle it.
|
|
|
|
| 48 |
gl.render_html([], str(template), "2026-06-20")
|
| 49 |
|
| 50 |
|
| 51 |
+
def test_compute_stats_sums_cost():
|
| 52 |
+
records = [
|
| 53 |
+
{"cost": 0.01, "marks_awarded": 4, "evaluation_status": "correct"},
|
| 54 |
+
{"cost": 0.02, "marks_awarded": 0, "evaluation_status": "incorrect"},
|
| 55 |
+
]
|
| 56 |
+
assert gl.compute_stats(records)["cost"] == 0.03
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def test_compute_stats_cost_none_when_absent():
|
| 60 |
+
records = [{"marks_awarded": 4, "evaluation_status": "correct"}]
|
| 61 |
+
assert gl.compute_stats(records)["cost"] is None
|
| 62 |
+
|
| 63 |
+
|
| 64 |
def test_render_html_serializes_yaml_date_objects(tmp_path):
|
| 65 |
# PyYAML parses unquoted ISO dates into datetime.date, which json can't
|
| 66 |
# serialize natively. render_html must handle it.
|