Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/leakgauge/leaderboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,26 @@ def y(rank: int) -> int:
f'<line x1="{left_x}" y1="{y1}" x2="{right_x}" y2="{y2}" '
f'stroke="{stroke}" stroke-width="{w}" opacity="{0.95 if moved else 0.55}"/>'
)
parts.append(f'<circle cx="{left_x}" cy="{y1}" r="6" fill="{stroke}"/>')
parts.append(f'<circle cx="{right_x}" cy="{y2}" r="6" fill="{stroke}"/>')
parts.append(f'<circle cx="{left_x}" cy="{y1}" r="9" fill="{stroke}"/>')
parts.append(f'<circle cx="{right_x}" cy="{y2}" r="9" fill="{stroke}"/>')
# Explicit rank position at each endpoint, so the reader doesn't have to
# infer it from vertical order.
parts.append(
f'<text x="{left_x}" y="{y1 + 4}" text-anchor="middle" font-size="11" '
f'font-weight="700" fill="#ffffff">{h_rank}</text>'
)
parts.append(
f'<text x="{right_x}" y="{y2 + 4}" text-anchor="middle" font-size="11" '
f'font-weight="700" fill="#ffffff">{l_rank}</text>'
)
# A mover gets its rank delta with an up/down glyph; a null (tau = 1)
# shows none. Rank 1 is best, so a smaller leakage rank is a move up.
if moved:
arrow = "&#9650;" if l_rank < h_rank else "&#9660;"
parts.append(
f'<text x="{right_x}" y="{y2 - 14}" text-anchor="middle" font-size="12" '
f'fill="{stroke}">{arrow}{abs(l_rank - h_rank)}</text>'
)
name = html.escape(m)
parts.append(
f'<text x="{left_x - 18}" y="{y1 + 5}" text-anchor="end" class="svg-lab">'
Expand Down
26 changes: 26 additions & 0 deletions tests/test_leaderboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,29 @@ def test_write_site_emits_index_html(tmp_path: Path) -> None:
path = write_site(summaries, rank_reorder(summaries), tmp_path)
assert path == tmp_path / "index.html"
assert path.read_text(encoding="utf-8").startswith("<!doctype html>")


def test_rank_numerals_and_delta_render_for_a_reorder() -> None:
# a hijacks more (hijack rank 1) but b leaks more (leakage rank 1): both move.
summaries = [_summary("prov:a", 0.9, 0.3), _summary("prov:b", 0.6, 0.7)]
reorder = rank_reorder(summaries)
assert reorder is not None

out = render_html(summaries, reorder)
# Explicit rank integers at the endpoints (white numerals on the nodes).
assert 'fill="#ffffff">1</text>' in out
assert 'fill="#ffffff">2</text>' in out
# Both models change rank, so an up and a down glyph with the delta appear.
assert "&#9650;1" in out # ▲1 (moved up)
assert "&#9660;1" in out # ▼1 (moved down)


def test_no_rank_delta_glyph_when_ranks_agree() -> None:
# a hijacks AND leaks more -> ranks agree (tau = 1), nobody moves.
summaries = [_summary("prov:a", 0.9, 0.8), _summary("prov:b", 0.4, 0.3)]
reorder = rank_reorder(summaries)
assert reorder is not None

out = render_html(summaries, reorder)
assert 'fill="#ffffff">1</text>' in out # ranks still numbered
assert "&#9650;" not in out and "&#9660;" not in out # but no movement glyph
Loading