File size: 6,872 Bytes
9fe20a2 2d64baa 9fe20a2 2d64baa 9fe20a2 2d64baa 9fe20a2 2d64baa 9fe20a2 | 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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | "use strict";
import {MODEL_TYPES, modelType} from "./plot-data.mjs";
import {setupPlotter} from "./plotter.mjs";
const state = {board: null, metric: "rms", domain: "all", search: "", sort: "macro.f1", descending: true};
const $ = id => document.getElementById(id);
const pretty = value => value.replaceAll("_", " ");
function selectedStats(result) { return state.domain === "all" ? result : result.by_domain?.[state.domain]; }
function safeURL(value) { try { const url = new URL(value); return url.protocol === "https:" ? url.href : ""; } catch { return ""; } }
function render() {
if (!state.board) return;
const rows = state.board.results.filter(r => selectedStats(r) &&
r.submission.method_name.toLowerCase().includes(state.search.toLowerCase()));
const [aggregation, field] = state.sort.split(".");
rows.sort((a, b) => {
const delta = selectedStats(b)[aggregation][state.metric][field] - selectedStats(a)[aggregation][state.metric][field];
return (state.descending ? delta : -delta) || a.submission.submission_id.localeCompare(b.submission.submission_id);
});
const body = $("results"); body.replaceChildren();
if (!rows.length) {
const cell = body.insertRow().insertCell(); cell.colSpan = 11;
const empty = document.createElement("div"); empty.className = "empty-state";
const icon = document.createElement("span"); icon.className = "empty-icon"; icon.textContent = "▥"; icon.setAttribute("aria-hidden", "true");
const heading = document.createElement("h3"); heading.textContent = state.board.results.length ? "No matching submissions." : "Ready for the first result.";
const text = document.createElement("p"); text.textContent = state.board.results.length ? "Try another model name or domain." : "No reviewed model submissions yet. Run your model on the test images and help set the benchmark.";
const link = document.createElement("a"); link.href = "#submit"; link.textContent = "See the submission guide →";
empty.append(icon, heading, text, link); cell.append(empty);
}
rows.forEach((result, rank) => {
const stats = selectedStats(result), row = body.insertRow();
row.insertCell().textContent = rank + 1;
const name = row.insertCell(), link = document.createElement("a");
const url = safeURL(result.evidence_url); if (url) {link.href = url; link.target = "_blank"; link.rel = "noopener";}
link.textContent = result.submission.method_name;
const detail = document.createElement("small"); detail.textContent = result.submission.model_revision;
name.append(link, detail);
const type = modelType(result.submission), typeCell = row.insertCell();
const badge = document.createElement("span"); badge.className = "model-type-badge";
const dot = document.createElement("i"); dot.style.setProperty("--color", MODEL_TYPES[type].color);
badge.append(dot, document.createTextNode(MODEL_TYPES[type].label)); typeCell.append(badge);
for (const average of ["macro", "micro"])
for (const measure of ["precision", "recall", "f1"])
row.insertCell().textContent = stats[average][state.metric][measure].toFixed(2);
row.insertCell().textContent = result.evaluation_mode + " · image-only";
row.insertCell().textContent = (stats.coverage.scored || 0) + " / " + stats.population.fragments;
});
$("board-count").textContent = rows.length + " reviewed submission" + (rows.length === 1 ? "" : "s");
document.querySelectorAll("[data-sort]").forEach(button => {
const active = button.dataset.sort === state.sort; button.classList.toggle("selected", active);
const field = button.dataset.sort.split(".")[1];
button.textContent = (field === "f1" ? "F1" : field[0].toUpperCase() + field.slice(1)) + (active ? (state.descending ? " ↓" : " ↑") : "");
button.setAttribute("aria-label", "Sort by " + button.dataset.sort + (active ? (state.descending ? " descending" : " ascending") : ""));
});
}
function showExample(examples, index) {
const example = examples[index];
$("example-id").textContent = example.paper_id + " / " + example.table_id;
$("example-image").src = example.image; $("example-image").alt = "Original table crop " + example.paper_id + ", " + example.table_id;
const table = document.createElement("table"); table.setAttribute("aria-label", "Gold table reconstruction");
example.gold_rows.forEach((values, i) => {
const row = table.insertRow();
values.forEach(value => { const cell = document.createElement(i === 0 ? "th" : "td"); cell.textContent = value; if (i === 0) cell.scope = "col"; row.append(cell); });
});
$("example-gold").replaceChildren(table);
}
async function init() {
try {
const responses = await Promise.all([fetch("data/leaderboard.json"), fetch("data/examples.json")]);
if (responses.some(response => !response.ok)) throw new Error("Unable to load benchmark data");
const [board, examples] = await Promise.all(responses.map(response => response.json()));
state.board = board; $("version").textContent = board.version;
for (const domain of Object.keys(board.domain_tables)) {
const option = document.createElement("option"); option.value = domain; option.textContent = pretty(domain); $("domain").append(option);
}
const select = $("example-select"); select.replaceChildren();
examples.forEach((example, index) => {const option = document.createElement("option"); option.value = index; option.textContent = pretty(example.domain); select.append(option);});
select.addEventListener("change", () => showExample(examples, Number(select.value)));
showExample(examples, 0); render(); setupPlotter(board);
} catch (error) { $("load-error").hidden = false; $("load-error").textContent = "Benchmark data could not be loaded. Please refresh or visit the dataset directly."; console.error(error); }
}
document.querySelectorAll("[data-metric]").forEach(button => button.addEventListener("click", () => {
state.metric = button.dataset.metric;
document.querySelectorAll("[data-metric]").forEach(tab => {tab.classList.toggle("active", tab === button); tab.setAttribute("aria-pressed", tab === button ? "true" : "false");});
$("metric-note").textContent = state.metric === "rms" ? "Relative Mapping Similarity · approximate matching with text and numeric tolerances." : "Exact Mapping Match · identical normalized mapping keys and values; no fuzzy tolerance.";
render();
}));
document.querySelectorAll("[data-sort]").forEach(button => button.addEventListener("click", () => {if (state.sort === button.dataset.sort) state.descending = !state.descending; else {state.sort = button.dataset.sort; state.descending = true;} render();}));
$("domain").addEventListener("change", event => {state.domain = event.target.value; render();});
$("search").addEventListener("input", event => {state.search = event.target.value; render();});
init();
|