Switch benchmark usage chart from monthly to weekly buckets
Browse files
app.py
CHANGED
|
@@ -594,13 +594,13 @@ def _rounded_top_rect(x, y, w, h, r) -> str:
|
|
| 594 |
)
|
| 595 |
|
| 596 |
|
| 597 |
-
def
|
| 598 |
-
"""Bars of how many model releases reported this benchmark each
|
| 599 |
-
the whole dataset time range (empty
|
| 600 |
-
t0 = MODELS_DF["release_date"].min().to_period("
|
| 601 |
-
t1 = MODELS_DF["release_date"].max().to_period("
|
| 602 |
-
|
| 603 |
-
counts = df["release_date"].dt.to_period("
|
| 604 |
|
| 605 |
W, H, ML, MR, MT, MB = 920, 300, 44, 10, 12, 36
|
| 606 |
plot_h = H - MT - MB
|
|
@@ -609,12 +609,12 @@ def svg_benchmark_monthly_usage(df: pd.DataFrame) -> str:
|
|
| 609 |
step = max(1, math.ceil(vmax / 4))
|
| 610 |
ymax = step * 4
|
| 611 |
scale = plot_h / ymax
|
| 612 |
-
band = (W - ML - MR) / len(
|
| 613 |
-
bw = max(band -
|
| 614 |
|
| 615 |
parts = [
|
| 616 |
f'<svg class="viz" viewBox="0 0 {W} {H}" role="img" '
|
| 617 |
-
f'aria-label="
|
| 618 |
]
|
| 619 |
for k in range(5):
|
| 620 |
v = step * k
|
|
@@ -622,22 +622,23 @@ def svg_benchmark_monthly_usage(df: pd.DataFrame) -> str:
|
|
| 622 |
parts.append(f'<line x1="{ML}" y1="{y:.1f}" x2="{W - MR}" y2="{y:.1f}" stroke="var(--grid)" stroke-width="1"/>')
|
| 623 |
parts.append(f'<text x="{ML - 7}" y="{y + 4:.1f}" text-anchor="end" font-size="11" fill="var(--muted)">{v}</text>')
|
| 624 |
|
| 625 |
-
|
| 626 |
-
for
|
| 627 |
-
|
| 628 |
-
if
|
| 629 |
-
cx =
|
| 630 |
parts.append(
|
| 631 |
f'<text x="{cx:.1f}" y="{base + 20}" text-anchor="middle" font-size="11" fill="var(--muted)">'
|
| 632 |
-
f"{
|
| 633 |
)
|
| 634 |
-
|
|
|
|
| 635 |
if n == 0:
|
| 636 |
continue
|
| 637 |
h = n * scale
|
| 638 |
-
label = f"{
|
| 639 |
parts.append(
|
| 640 |
-
f'<path class="seg" d="{_rounded_top_rect(
|
| 641 |
f"<title>{esc(label)}</title></path>"
|
| 642 |
)
|
| 643 |
parts.append(f'<line x1="{ML}" y1="{base}" x2="{W - MR}" y2="{base}" stroke="var(--muted)" stroke-width="1"/>')
|
|
@@ -666,8 +667,8 @@ def benchmark_view(benchmark):
|
|
| 666 |
)
|
| 667 |
|
| 668 |
chart = (
|
| 669 |
-
f'<div class="viz-title">How often is “{esc(benchmark)}” used? Model releases reporting it per
|
| 670 |
-
+
|
| 671 |
)
|
| 672 |
|
| 673 |
rows = []
|
|
|
|
| 594 |
)
|
| 595 |
|
| 596 |
|
| 597 |
+
def svg_benchmark_weekly_usage(df: pd.DataFrame) -> str:
|
| 598 |
+
"""Bars of how many model releases reported this benchmark each week, spanning
|
| 599 |
+
the whole dataset time range (empty weeks stay visible as gaps)."""
|
| 600 |
+
t0 = MODELS_DF["release_date"].min().to_period("W")
|
| 601 |
+
t1 = MODELS_DF["release_date"].max().to_period("W")
|
| 602 |
+
weeks = pd.period_range(t0, t1, freq="W")
|
| 603 |
+
counts = df["release_date"].dt.to_period("W").value_counts().reindex(weeks, fill_value=0)
|
| 604 |
|
| 605 |
W, H, ML, MR, MT, MB = 920, 300, 44, 10, 12, 36
|
| 606 |
plot_h = H - MT - MB
|
|
|
|
| 609 |
step = max(1, math.ceil(vmax / 4))
|
| 610 |
ymax = step * 4
|
| 611 |
scale = plot_h / ymax
|
| 612 |
+
band = (W - ML - MR) / len(weeks)
|
| 613 |
+
bw = max(band - 1, 1.0) # 1px surface gap between adjacent bars (weekly bands are narrow)
|
| 614 |
|
| 615 |
parts = [
|
| 616 |
f'<svg class="viz" viewBox="0 0 {W} {H}" role="img" '
|
| 617 |
+
f'aria-label="Weekly count of model releases reporting this benchmark, over the whole dataset period">'
|
| 618 |
]
|
| 619 |
for k in range(5):
|
| 620 |
v = step * k
|
|
|
|
| 622 |
parts.append(f'<line x1="{ML}" y1="{y:.1f}" x2="{W - MR}" y2="{y:.1f}" stroke="var(--grid)" stroke-width="1"/>')
|
| 623 |
parts.append(f'<text x="{ML - 7}" y="{y + 4:.1f}" text-anchor="end" font-size="11" fill="var(--muted)">{v}</text>')
|
| 624 |
|
| 625 |
+
week0_start = weeks[0].start_time
|
| 626 |
+
for tick in month_ticks(week0_start, weeks[-1].end_time):
|
| 627 |
+
idx = (tick - week0_start).days // 7
|
| 628 |
+
if 0 <= idx < len(weeks):
|
| 629 |
+
cx = ML + idx * band + band / 2
|
| 630 |
parts.append(
|
| 631 |
f'<text x="{cx:.1f}" y="{base + 20}" text-anchor="middle" font-size="11" fill="var(--muted)">'
|
| 632 |
+
f"{tick.strftime('%b %Y')}</text>"
|
| 633 |
)
|
| 634 |
+
for i, week in enumerate(weeks):
|
| 635 |
+
n = int(counts.loc[week])
|
| 636 |
if n == 0:
|
| 637 |
continue
|
| 638 |
h = n * scale
|
| 639 |
+
label = f"Week of {week.start_time.strftime('%b %-d, %Y')}: {n} model{'s' if n != 1 else ''}"
|
| 640 |
parts.append(
|
| 641 |
+
f'<path class="seg" d="{_rounded_top_rect(ML + i * band + 0.5, base - h, bw, h, 2)}" fill="var(--accent)">'
|
| 642 |
f"<title>{esc(label)}</title></path>"
|
| 643 |
)
|
| 644 |
parts.append(f'<line x1="{ML}" y1="{base}" x2="{W - MR}" y2="{base}" stroke="var(--muted)" stroke-width="1"/>')
|
|
|
|
| 667 |
)
|
| 668 |
|
| 669 |
chart = (
|
| 670 |
+
f'<div class="viz-title">How often is “{esc(benchmark)}” used? Model releases reporting it per week</div>'
|
| 671 |
+
+ svg_benchmark_weekly_usage(df)
|
| 672 |
)
|
| 673 |
|
| 674 |
rows = []
|