SaylorTwift HF Staff commited on
Commit
a275ba1
·
verified ·
1 Parent(s): 2ee0594

Switch benchmark usage chart from monthly to weekly buckets

Browse files
Files changed (1) hide show
  1. app.py +22 -21
app.py CHANGED
@@ -594,13 +594,13 @@ def _rounded_top_rect(x, y, w, h, r) -> str:
594
  )
595
 
596
 
597
- def svg_benchmark_monthly_usage(df: pd.DataFrame) -> str:
598
- """Bars of how many model releases reported this benchmark each month, spanning
599
- the whole dataset time range (empty months stay visible as gaps)."""
600
- t0 = MODELS_DF["release_date"].min().to_period("M")
601
- t1 = MODELS_DF["release_date"].max().to_period("M")
602
- months = pd.period_range(t0, t1, freq="M")
603
- counts = df["release_date"].dt.to_period("M").value_counts().reindex(months, fill_value=0)
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(months)
613
- bw = max(band - 2, 1.5) # 2px surface gap between adjacent bars
614
 
615
  parts = [
616
  f'<svg class="viz" viewBox="0 0 {W} {H}" role="img" '
617
- f'aria-label="Monthly count of model releases reporting this benchmark, over the whole dataset period">'
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
- tick_months = {t.to_period("M") for t in month_ticks(months[0].to_timestamp(), months[-1].to_timestamp(how="end"))}
626
- for i, month in enumerate(months):
627
- x0 = ML + i * band
628
- if month in tick_months:
629
- cx = x0 + 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"{month.to_timestamp().strftime('%b %Y')}</text>"
633
  )
634
- n = int(counts.loc[month])
 
635
  if n == 0:
636
  continue
637
  h = n * scale
638
- label = f"{month.to_timestamp().strftime('%b %Y')}: {n} model{'s' if n != 1 else ''}"
639
  parts.append(
640
- f'<path class="seg" d="{_rounded_top_rect(x0 + 1, base - h, bw, h, 4)}" fill="var(--accent)">'
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 month</div>'
670
- + svg_benchmark_monthly_usage(df)
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 = []