bencher.scorecard.model

Pure data-shaping for the scorecard: summary dicts -> table cells.

No filesystem and no templating here — every function takes already-parsed summary records (the result_to_dict() contract, with per-metric series) and returns plain dicts the renderer turns into HTML. This keeps the column/verdict/formatting logic unit-testable in isolation.

Functions

unify_metric_names(→ tuple[dict[str, dict], dict[str, ...)

Apply aliases to one benchmark's metrics + regressions.

metric_columns(→ list[str])

Union of metric names, ordered by (shared-by-most, first-seen).

cell_verdict(→ str)

4-way display verdict for a cell.

fmt_value(→ str)

Compact human label for a scalar value ( when missing).

fmt_change(→ str)

Signed percent label for a Δ (empty when not computable).

build_cell(→ dict | None)

Build one table cell for (benchmark, metric), or None when absent.

Module Contents

bencher.scorecard.model.unify_metric_names(metrics: dict[str, dict], regressions: dict[str, dict], aliases: dict[str, str]) tuple[dict[str, dict], dict[str, dict]]

Apply aliases to one benchmark’s metrics + regressions.

Returns new dicts keyed by canonical column names, preserving metric order. A renamed metric records its original name under source_variable so a cell tooltip can surface it. Collisions (the canonical name already exists on this benchmark, or two of its metrics map to the same alias) keep the raw name to never drop or shadow data.

bencher.scorecard.model.metric_columns(records: list[dict]) list[str]

Union of metric names, ordered by (shared-by-most, first-seen).

bencher.scorecard.model.cell_verdict(reg: dict | None) str

4-way display verdict for a cell.

None — no regression gate on this metric (or too little history) — maps to the uncolored "trend" fallback. Otherwise defer to bencher’s 3-state core verdict and render its "unchanged" as "passed" (the gate ran and did not flag). A gate with no threshold can only have “passed”.

bencher.scorecard.model.fmt_value(value: float | None, units: str | None, *, as_percent: bool = False) str

Compact human label for a scalar value ( when missing).

bencher.scorecard.model.fmt_change(change_percent: float | None) str

Signed percent label for a Δ (empty when not computable).

bencher.scorecard.model.build_cell(rec: dict, var: str, config: bencher.scorecard.config.ScorecardConfig) dict | None

Build one table cell for (benchmark, metric), or None when absent.