feat: Rangliste und Matrix für Batches
ranking.rs: Gesamtscore je Modell (gewichtet nach weight aus task.toml), Median-Dauer und Completion-Tokens als Tie-Breaker, Matrix Modell × Aufgabe mit Erfolgen und mittlerem Score. Befehl batch_ranking, Anzeige nach dem Batch. 5 Unit-Tests grün, 47 insgesamt. Wilson-Intervalle folgen mit F-12. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -26,7 +26,7 @@ Zeichen: ✓ fertig · ◐ teilweise · ✗ offen · ? nicht geprüft.
|
||||
| #1006 | F-06 SQLite inkl. Schritt-Log | SPEC 8, 12 | ◐ | `store.rs`: Tabellen `batch`, `run`, `step` nach SPEC 8, Lauf und Schritte in einer Transaktion. Datei `coding-bench.sqlite` im Datenordner, wird beim Start angelegt. Lesen über `batch_results`. Getestet in-memory und im Batch (→ #1023) |
|
||||
| #1007 | F-07 Tests a-01 bis a-03 und b-04 bis b-06 | SPEC 11, 12 | ◐ | Aufgaben liegen unter `tasks/`, gültig geladen (Test `repo_aufgaben_sind_gueltig`). Musterlösungen bestehen alle Checks, leere Lösung scheitert. Mit `qwen3:0.6b` 0 von 6 bestanden. Mit `qwen3.8-flash-next-q2_0` über strata (OpenAI-Format, LAN) 6 von 6 bestanden, Score 1.00 (Testbericht `testberichte/2026-11-06-strata-lauf.md`) (→ #1024) |
|
||||
| #1008 | F-08 GUI: Setup, Batch starten, Live-Fortschritt | SPEC 10, 12 | ◐ | Setup zeigt Pfade und Aufgaben, Batch-Start mit Modellen, Wiederholungen, Abbrechen, Fortschritt und Ergebnistabelle gebaut. `svelte-check` 0 Fehler. Nicht im Fenster geprüft; Klicktests `batch2fortsetzen.1–.2` offen (→ #1025) |
|
||||
| #1009 | F-09 Rangliste und Matrix | SPEC 9, 10, 12 | ✗ | noch nicht begonnen (→ #1026) |
|
||||
| #1009 | F-09 Rangliste und Matrix | SPEC 9, 10, 12 | ◐ | `ranking.rs`: Gesamtscore (gewichtet), Median-Dauer, Tie-Breaker, Matrix Modell × Aufgabe. 5 Unit-Tests grün. Oberfläche zeigt beides nach dem Batch. Ohne Intervall und Kategorie-Ranking (F-12). Klicktest `ergebnis2detail.1` manuell offen (→ #1026) |
|
||||
| #1010 | F-10 Tests c-07 bis c-09 | SPEC 11, 12 | ✗ | Phase 2 (→ #1027) |
|
||||
| #1011 | F-11 Adapter Aider-Polyglot-Teilmenge | SPEC 12 | ✗ | Phase 2 (→ #1028) |
|
||||
| #1012 | F-12 Kategorie-Ranking, Wilson-Intervalle, Markierung | SPEC 9, 12 | ✗ | Phase 2 (→ #1029) |
|
||||
@ -52,7 +52,7 @@ Zeichen: ✓ fertig · ◐ teilweise · ✗ offen · ? nicht geprüft.
|
||||
- [#1023] **SQLite-Speicher.** Umgesetzt in `src-tauri/src/store.rs`, Schema nach SPEC 8. Datei-Datenbank im Datenordner angebunden. Offen: Klicktest `lauf2ergebnis.2` mit Schritt-Ansicht (noch keine Oberfläche dafür). Tests `lauf2ergebnis.2`. → #1006
|
||||
- [#1024] **Aufgaben a-01 bis a-03, b-04 bis b-06 schreiben.** Geschrieben unter `tasks/`. b-06 mit Mutationstest; ein Fehler im Check (veralteter Bytecode bei Mutanten) ist behoben. Ergebnis: mit `qwen3.8-flash-next-q2_0` über strata 6 von 6 bestanden. Bericht in `testberichte/`. Offen: Zeitlimit von b-04 bei langsamen Modellen prüfen. → #1007
|
||||
- [#1025] **GUI Setup und Batch.** Gebaut: Pfade, Aufgabenauswahl, Modelle, Wiederholungen, Start, Abbrechen, Live-Log, Ergebnistabelle. Offen: Podman-Status im Setup, Schritt-Log in der Oberfläche, Klicktest `batch2fortsetzen.1` manuell. → #1008
|
||||
- [#1026] **Rangliste und Matrix.** Gesamtscore mit Intervall, Matrix Modell × Test nach Erfolgsquote, Lauf-Detail. Tests `ergebnis2detail.1`. → #1009
|
||||
- [#1026] **Rangliste und Matrix.** Gebaut: Gesamtscore (gewichtet nach `weight`), Median-Dauer als Tie-Breaker, Matrix Modell × Aufgabe mit Erfolgen und Farbe nach Score. Offen: Wilson-Intervall und „nicht unterscheidbar“ (F-12, Phase 2), Lauf-Detail mit Schrittliste, Klicktest `ergebnis2detail.1` manuell. Tests `ergebnis2detail.1`. → #1009
|
||||
|
||||
**P2 – danach (Release 0.2.0, Referenz und Tiefe)**
|
||||
- [#1027] **Tests c-07 bis c-09.** Neuer CLI-Parameter, Refactoring, Stacktrace-Fehler. → #1010
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
mod agent;
|
||||
mod config;
|
||||
mod ranking;
|
||||
mod runner;
|
||||
mod sandbox;
|
||||
mod store;
|
||||
@ -120,6 +121,19 @@ fn batch_results(paths: State<'_, AppPaths>, batch_id: i64) -> Result<Vec<RunRec
|
||||
store.runs_for_batch(batch_id)
|
||||
}
|
||||
|
||||
/// Rangliste und Matrix eines Batches. Gewichte kommen aus den Aufgaben.
|
||||
#[tauri::command]
|
||||
fn batch_ranking(paths: State<'_, AppPaths>, batch_id: i64) -> Result<ranking::Ranking, String> {
|
||||
let store = Store::open(&paths.0.data_dir.join(DB_FILE))?;
|
||||
let runs = store.runs_for_batch(batch_id)?;
|
||||
let weights: std::collections::BTreeMap<String, f64> = tasks::load_all(&paths.0.tasks_dir)
|
||||
.tasks
|
||||
.into_iter()
|
||||
.map(|t| (t.meta.id, t.meta.weight))
|
||||
.collect();
|
||||
Ok(ranking::compute(batch_id, &runs, &weights))
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
@ -149,7 +163,8 @@ pub fn run() {
|
||||
load_tasks,
|
||||
start_batch,
|
||||
cancel_batch,
|
||||
batch_results
|
||||
batch_results,
|
||||
batch_ranking
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
||||
225
src-tauri/src/ranking.rs
Normal file
225
src-tauri/src/ranking.rs
Normal file
@ -0,0 +1,225 @@
|
||||
//! Rangliste und Matrix aus den Läufen eines Batches (F-09, SPEC Abschnitt 9).
|
||||
//!
|
||||
//! Gesamtscore je Modell: gewichteter Mittelwert der Aufgaben-Scores (`weight` aus
|
||||
//! `task.toml`). Erfolgsquote je (Modell, Aufgabe): Anteil der Läufe mit Klasse `ok`.
|
||||
//! Tie-Breaker: Median der Dauer, dann mittlere Completion-Tokens. Wilson-Intervalle
|
||||
//! und Kategorie-Ranking folgen mit F-12 (Phase 2).
|
||||
|
||||
use crate::agent::ErrorClass;
|
||||
use crate::store::RunRecord;
|
||||
use serde::Serialize;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize)]
|
||||
pub struct ModelRank {
|
||||
pub rank: usize,
|
||||
pub model: String,
|
||||
/// Gewichteter Mittelwert der Aufgaben-Scores, 0.0 bis 1.0.
|
||||
pub total_score: f64,
|
||||
pub runs: usize,
|
||||
pub successes: usize,
|
||||
pub median_duration_ms: u128,
|
||||
pub mean_completion_tokens: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize)]
|
||||
pub struct MatrixCell {
|
||||
pub model: String,
|
||||
pub task_id: String,
|
||||
pub runs: usize,
|
||||
pub successes: usize,
|
||||
/// Mittlerer Score über die Wiederholungen.
|
||||
pub mean_score: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize)]
|
||||
pub struct Ranking {
|
||||
pub batch_id: i64,
|
||||
pub models: Vec<ModelRank>,
|
||||
pub cells: Vec<MatrixCell>,
|
||||
pub tasks: Vec<String>,
|
||||
}
|
||||
|
||||
/// Berechnet Rangliste und Matrix. `weights` ordnet jeder Aufgaben-ID ihr Gewicht zu;
|
||||
/// fehlt eine ID, zählt das Gewicht 1.0.
|
||||
pub fn compute(batch_id: i64, runs: &[RunRecord], weights: &BTreeMap<String, f64>) -> Ranking {
|
||||
let weight_of = |task: &str| weights.get(task).copied().unwrap_or(1.0);
|
||||
|
||||
// Pro Modell: Liste der Läufe.
|
||||
let mut by_model: BTreeMap<&str, Vec<&RunRecord>> = BTreeMap::new();
|
||||
for r in runs {
|
||||
by_model.entry(r.model.as_str()).or_default().push(r);
|
||||
}
|
||||
|
||||
let mut models: Vec<ModelRank> = by_model
|
||||
.iter()
|
||||
.map(|(model, rs)| {
|
||||
// Mittelwert je Aufgabe, dann gewichtet über die Aufgaben.
|
||||
let mut per_task: BTreeMap<&str, (f64, usize)> = BTreeMap::new();
|
||||
for r in rs {
|
||||
let e = per_task.entry(r.task_id.as_str()).or_insert((0.0, 0));
|
||||
e.0 += r.score;
|
||||
e.1 += 1;
|
||||
}
|
||||
let (mut wsum, mut wtotal) = (0.0, 0.0);
|
||||
for (task, (sum, n)) in &per_task {
|
||||
let w = weight_of(task);
|
||||
wsum += w * (sum / *n as f64);
|
||||
wtotal += w;
|
||||
}
|
||||
let total_score = if wtotal > 0.0 { wsum / wtotal } else { 0.0 };
|
||||
|
||||
let mut durations: Vec<u128> = rs.iter().map(|r| r.duration_ms).collect();
|
||||
durations.sort_unstable();
|
||||
let median = median_u128(&durations);
|
||||
|
||||
let mean_tokens = rs.iter().map(|r| r.completion_tokens as f64).sum::<f64>() / rs.len() as f64;
|
||||
let successes = rs.iter().filter(|r| r.error_class == ErrorClass::Ok).count();
|
||||
|
||||
ModelRank {
|
||||
rank: 0,
|
||||
model: model.to_string(),
|
||||
total_score,
|
||||
runs: rs.len(),
|
||||
successes,
|
||||
median_duration_ms: median,
|
||||
mean_completion_tokens: mean_tokens,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
// Absteigend nach Score, dann Median-Dauer, dann mittlere Completion-Tokens.
|
||||
models.sort_by(|a, b| {
|
||||
b.total_score
|
||||
.partial_cmp(&a.total_score)
|
||||
.unwrap_or(std::cmp::Ordering::Equal)
|
||||
.then(a.median_duration_ms.cmp(&b.median_duration_ms))
|
||||
.then(
|
||||
a.mean_completion_tokens
|
||||
.partial_cmp(&b.mean_completion_tokens)
|
||||
.unwrap_or(std::cmp::Ordering::Equal),
|
||||
)
|
||||
});
|
||||
for (i, m) in models.iter_mut().enumerate() {
|
||||
m.rank = i + 1;
|
||||
}
|
||||
|
||||
// Matrix Modell × Aufgabe.
|
||||
let mut cell_map: BTreeMap<(&str, &str), Vec<&RunRecord>> = BTreeMap::new();
|
||||
let mut task_set: BTreeMap<&str, ()> = BTreeMap::new();
|
||||
for r in runs {
|
||||
cell_map
|
||||
.entry((r.model.as_str(), r.task_id.as_str()))
|
||||
.or_default()
|
||||
.push(r);
|
||||
task_set.insert(r.task_id.as_str(), ());
|
||||
}
|
||||
let cells = cell_map
|
||||
.iter()
|
||||
.map(|((model, task), rs)| MatrixCell {
|
||||
model: model.to_string(),
|
||||
task_id: task.to_string(),
|
||||
runs: rs.len(),
|
||||
successes: rs.iter().filter(|r| r.error_class == ErrorClass::Ok).count(),
|
||||
mean_score: rs.iter().map(|r| r.score).sum::<f64>() / rs.len() as f64,
|
||||
})
|
||||
.collect();
|
||||
|
||||
Ranking {
|
||||
batch_id,
|
||||
models,
|
||||
cells,
|
||||
tasks: task_set.keys().map(|t| t.to_string()).collect(),
|
||||
}
|
||||
}
|
||||
|
||||
fn median_u128(sorted: &[u128]) -> u128 {
|
||||
match sorted.len() {
|
||||
0 => 0,
|
||||
n if n % 2 == 1 => sorted[n / 2],
|
||||
n => (sorted[n / 2 - 1] + sorted[n / 2]) / 2,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn run(model: &str, task: &str, score: f64, class: ErrorClass, dur: u128, tokens: u32) -> RunRecord {
|
||||
RunRecord {
|
||||
batch_id: 1,
|
||||
model: model.into(),
|
||||
task_id: task.into(),
|
||||
repeat_idx: 1,
|
||||
error_class: class,
|
||||
score,
|
||||
steps: 3,
|
||||
prompt_tokens: 0,
|
||||
completion_tokens: tokens,
|
||||
duration_ms: dur,
|
||||
tps: None,
|
||||
ttft_tool_ms: None,
|
||||
artifact_path: None,
|
||||
summary: None,
|
||||
check_output: String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gewichteter_score_und_rang() {
|
||||
let runs = vec![
|
||||
run("A", "t1", 1.0, ErrorClass::Ok, 1000, 10),
|
||||
run("A", "t2", 0.0, ErrorClass::CheckFailed, 1000, 10),
|
||||
run("B", "t1", 1.0, ErrorClass::Ok, 1000, 10),
|
||||
run("B", "t2", 1.0, ErrorClass::Ok, 1000, 10),
|
||||
];
|
||||
let mut w = BTreeMap::new();
|
||||
w.insert("t1".to_string(), 1.0);
|
||||
w.insert("t2".to_string(), 3.0);
|
||||
let r = compute(1, &runs, &w);
|
||||
assert_eq!(r.models[0].model, "B");
|
||||
assert_eq!(r.models[0].rank, 1);
|
||||
assert!((r.models[0].total_score - 1.0).abs() < 1e-9);
|
||||
// A: (1*1 + 3*0) / 4 = 0.25
|
||||
assert!((r.models[1].total_score - 0.25).abs() < 1e-9);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gleichstand_nach_median_dauer() {
|
||||
let runs = vec![
|
||||
run("slow", "t1", 1.0, ErrorClass::Ok, 9000, 10),
|
||||
run("fast", "t1", 1.0, ErrorClass::Ok, 2000, 10),
|
||||
];
|
||||
let r = compute(1, &runs, &BTreeMap::new());
|
||||
assert_eq!(r.models[0].model, "fast");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn matrix_zaehlt_erfolge_und_mittelwert() {
|
||||
let runs = vec![
|
||||
run("A", "t1", 1.0, ErrorClass::Ok, 1, 1),
|
||||
run("A", "t1", 0.5, ErrorClass::CheckFailed, 1, 1),
|
||||
run("A", "t1", 0.0, ErrorClass::MaxSteps, 1, 1),
|
||||
];
|
||||
let r = compute(1, &runs, &BTreeMap::new());
|
||||
assert_eq!(r.cells.len(), 1);
|
||||
assert_eq!(r.cells[0].runs, 3);
|
||||
assert_eq!(r.cells[0].successes, 1);
|
||||
assert!((r.cells[0].mean_score - 0.5).abs() < 1e-9);
|
||||
assert_eq!(r.tasks, vec!["t1".to_string()]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn median_gerade_und_ungerade() {
|
||||
assert_eq!(median_u128(&[1, 2, 3]), 2);
|
||||
assert_eq!(median_u128(&[1, 2, 3, 4]), 2);
|
||||
assert_eq!(median_u128(&[]), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leerer_batch_ergibt_leere_rangliste() {
|
||||
let r = compute(7, &[], &BTreeMap::new());
|
||||
assert!(r.models.is_empty() && r.cells.is_empty() && r.tasks.is_empty());
|
||||
assert_eq!(r.batch_id, 7);
|
||||
}
|
||||
}
|
||||
@ -44,6 +44,18 @@
|
||||
let progress = $state<{ done: number; total: number } | null>(null);
|
||||
let batchId = $state<number | null>(null);
|
||||
let rows = $state<RunRow[]>([]);
|
||||
type ModelRank = {
|
||||
rank: number;
|
||||
model: string;
|
||||
total_score: number;
|
||||
runs: number;
|
||||
successes: number;
|
||||
median_duration_ms: number;
|
||||
mean_completion_tokens: number;
|
||||
};
|
||||
type MatrixCell = { model: string; task_id: string; runs: number; successes: number; mean_score: number };
|
||||
type Ranking = { batch_id: number; models: ModelRank[]; cells: MatrixCell[]; tasks: string[] };
|
||||
let ranking = $state<Ranking | null>(null);
|
||||
let batchError = $state("");
|
||||
|
||||
let unlisten: UnlistenFn | null = null;
|
||||
@ -98,6 +110,7 @@
|
||||
async function start() {
|
||||
batchError = "";
|
||||
rows = [];
|
||||
ranking = null;
|
||||
log = [];
|
||||
progress = null;
|
||||
batchId = null;
|
||||
@ -111,6 +124,7 @@
|
||||
});
|
||||
batchId = summary.batch_id;
|
||||
rows = await invoke<RunRow[]>("batch_results", { batchId: summary.batch_id });
|
||||
ranking = await invoke<Ranking>("batch_ranking", { batchId: summary.batch_id });
|
||||
if (summary.cancelled) log = [...log, "Batch abgebrochen."];
|
||||
} catch (e) {
|
||||
batchError = String(e);
|
||||
@ -211,6 +225,65 @@
|
||||
{/if}
|
||||
</section>
|
||||
|
||||
{#if ranking && ranking.models.length > 0}
|
||||
<section>
|
||||
<h2>Rangliste, Batch {ranking.batch_id}</h2>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Rang</th>
|
||||
<th>Modell</th>
|
||||
<th>Score</th>
|
||||
<th>Erfolge</th>
|
||||
<th>Median-Dauer</th>
|
||||
<th>Ø Completion-Tokens</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each ranking.models as m (m.model)}
|
||||
<tr>
|
||||
<td>{m.rank}</td>
|
||||
<td>{m.model}</td>
|
||||
<td>{m.total_score.toFixed(2)}</td>
|
||||
<td>{m.successes} / {m.runs}</td>
|
||||
<td>{(m.median_duration_ms / 1000).toFixed(1)} s</td>
|
||||
<td>{m.mean_completion_tokens.toFixed(0)}</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3>Matrix: Erfolge je Aufgabe</h3>
|
||||
<table class="matrix">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Modell</th>
|
||||
{#each ranking.tasks as t (t)}
|
||||
<th>{t}</th>
|
||||
{/each}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each ranking.models as m (m.model)}
|
||||
<tr>
|
||||
<td>{m.model}</td>
|
||||
{#each ranking.tasks as t (t)}
|
||||
{@const cell = ranking.cells.find((c) => c.model === m.model && c.task_id === t)}
|
||||
<td
|
||||
class="zelle"
|
||||
style={cell ? `background: color-mix(in srgb, #2e7d32 ${Math.round(cell.mean_score * 100)}%, transparent)` : ""}
|
||||
title={cell ? `Score ${cell.mean_score.toFixed(2)}` : "keine Läufe"}
|
||||
>
|
||||
{cell ? `${cell.successes}/${cell.runs}` : "–"}
|
||||
</td>
|
||||
{/each}
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
{/if}
|
||||
|
||||
{#if batchId !== null && rows.length > 0}
|
||||
<section>
|
||||
<h2>Ergebnisse, Batch {batchId}</h2>
|
||||
@ -326,4 +399,9 @@
|
||||
.fehler {
|
||||
color: #c62828;
|
||||
}
|
||||
|
||||
.matrix .zelle {
|
||||
text-align: center;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user