{# Reusable badge/chip macros #}
{% macro pass_rate_badge(rate) -%}
{%- set pct = rate * 100 -%}
{%- if pct >= 80 -%}{{ "%.1f"|format(pct) }}%
{%- elif pct >= 50 -%}{{ "%.1f"|format(pct) }}%
{%- elif pct >= 20 -%}{{ "%.1f"|format(pct) }}%
{%- elif pct > 0 -%}{{ "%.1f"|format(pct) }}%
{%- else -%}0%
{%- endif -%}
{%- endmacro %}
{% macro score_badge(score) -%}
{%- if score is none -%}—
{%- elif score != score or score == score * 2 + 1 -%}overflow
{%- elif score >= 1e6 or score <= -1e6 or (score != 0 and -1e-3 < score < 1e-3) -%}{{ "%.3e"|format(score) }}
{%- else -%}{{ "%.4g"|format(score) }}
{%- endif -%}
{%- endmacro %}
{% macro best_badge(run) -%}
{%- if run.has_score and run.best_score is not none -%}{{ score_badge(run.best_score) }}
{%- else -%}{{ pass_rate_badge(run.best_pass_rate) }}
{%- endif -%}
{%- endmacro %}
{# Rescaled 0-100 score chip (higher-is-better; graded like pass rate). #}
{% macro rescaled_badge(v) -%}
{%- if v is none -%}—
{%- elif v != v -%}nan
{%- elif v >= 80 -%}{{ "%.1f"|format(v) }}
{%- elif v >= 50 -%}{{ "%.1f"|format(v) }}
{%- elif v >= 20 -%}{{ "%.1f"|format(v) }}
{%- elif v > 0 -%}{{ "%.1f"|format(v) }}
{%- else -%}0.0
{%- endif -%}
{%- endmacro %}
{# Best badge that shows rescaled (0-100) by default with raw underneath; the
shared score-view toggle swaps which one is visible. Falls back to the plain
raw badge when the run has no rescaled score. #}
{% macro best_badge_dual(run) -%}
{%- if run.has_rescaled and run.best_score_0_100 is not none -%}
{{ rescaled_badge(run.best_score_0_100) }}{{ best_badge(run) }}
{%- else -%}{{ best_badge(run) }}
{%- endif -%}
{%- endmacro %}
{# Segmented Rescaled | Raw control. Wired by the shared script in base.html. #}
{% macro score_view_toggle() -%}
Score
{%- endmacro %}
{% macro submission_badge(sub, run=none) -%}
{%- if run is not none and run.has_score and sub.score is not none -%}{{ score_badge(sub.score) }}
{%- else -%}{{ pass_rate_badge(sub.pass_rate) }}
{%- endif -%}
{%- endmacro %}
{# Submission badge that shows rescaled (0-100) by default with raw underneath,
swapped by the shared score-view toggle. Falls back to the plain badge when
this submission has no rescaled score. #}
{% macro submission_badge_dual(sub, run=none) -%}
{%- if run is not none and run.has_rescaled and sub.score_0_100 is not none -%}
{{ rescaled_badge(sub.score_0_100) }}{{ submission_badge(sub, run) }}
{%- else -%}{{ submission_badge(sub, run) }}
{%- endif -%}
{%- endmacro %}
{% macro agent_chip(agent) -%}
{%- if agent -%}{{ agent }}
{%- else -%}—
{%- endif -%}
{%- endmacro %}
{% macro model_chip(model) -%}
{%- if model -%}{{ model }}
{%- else -%}—
{%- endif -%}
{%- endmacro %}
{% macro status_badge(status) -%}
{%- if status == "PASSED" -%}PASSED
{%- elif status == "FAILED" -%}FAILED
{%- elif status == "ERROR" -%}ERROR
{%- elif status == "SKIPPED" -%}SKIPPED
{%- else -%}{{ status }}
{%- endif -%}
{%- endmacro %}
{% macro run_status(run) -%}
{%- if run.infra_error -%}⚠ infra-error
{%- elif run.aborted -%}aborted
{%- elif not run.has_final -%}running
{%- elif run.timed_out -%}timed-out
{%- else -%}done
{%- endif -%}
{%- endmacro %}
{% macro download_icon(href, label, tooltip="") -%}
{{ label }}
{%- endmacro %}