#!/usr/bin/env python3
"""
Generate the figures embedded in the dataset card.
python make_charts.py # summary-derived figures only
python make_charts.py --parquet data/train-00000-of-00001.parquet
Writes theme-neutral SVG into assets/. No matplotlib: the output is plain,
diffable SVG with a transparent background, so it reads on both the light and
dark Hugging Face themes and stays reviewable in git.
Figures 01-03 need only summary.json. Figures 04-06 need the parquet.
Re-run after every release so the card can never describe stale data.
"""
from __future__ import annotations
import argparse
import json
from collections import Counter, defaultdict
from pathlib import Path
# ---------------------------------------------------------------- palette ---
INK = "#8b95a5" # labels — legible on white and on #0f172a
MUTED = "#9aa3b2" # secondary text
GRID = "#8b95a566" # axis rules, translucent
AGENT = "#6366f1"
HUMAN = "#b4bcca"
ASSISTED = "#6366f1"
AUTONOMOUS = "#f59e0b"
PATTERN_COLORS = {
"none": "#b4bcca",
"individual": "#f59e0b",
"team": "#34a0a4",
"org-wide": "#6366f1",
}
FONT = "system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif"
MONO = "ui-monospace, SFMono-Regular, Menlo, monospace"
def esc(s: str) -> str:
return (str(s).replace("&", "&").replace("<", "<").replace(">", ">"))
def text(x, y, s, size=12, fill=INK, anchor="start", weight="400", font=FONT):
return (f'{esc(s)}')
def rect(x, y, w, h, fill, rx=2, opacity=1.0):
if w <= 0:
return ""
return (f'')
def svg(width, height, body) -> str:
return (f'\n')
def write(out_dir: Path, name: str, content: str) -> None:
path = out_dir / name
path.write_text(content)
print(f" wrote {path} ({len(content):,} bytes)")
# --------------------------------------------------- 01 · ecosystem spread ---
def fig_ecosystems(summary: dict, out: Path, min_n: int = 10) -> None:
rows = [e for e in summary["ecosystems"] if e["n"] >= min_n]
rows.sort(key=lambda e: e["median"], reverse=True)
left, right, top = 132, 58, 62
row_h, gap = 30, 8
plot_w = 760 - left - right
height = top + len(rows) * (row_h + gap) + 46
scale = max(e["mean"] for e in rows) * 1.06
b = [text(0, 22, "Agent-share floor by ecosystem", 15, INK, weight="600"),
text(0, 40, f"median vs mean, n \u2265 {min_n} \u00b7 the gap is the skew",
11.5, MUTED)]
# legend
b.append(rect(left + plot_w - 150, 30, 9, 9, AGENT))
b.append(text(left + plot_w - 136, 39, "median", 11, MUTED))
b.append(rect(left + plot_w - 78, 30, 9, 9, AGENT, opacity=0.32))
b.append(text(left + plot_w - 64, 39, "mean", 11, MUTED))
for i, e in enumerate(rows):
y = top + i * (row_h + gap)
b.append(text(left - 12, y + 13, e["ecosystem"], 12, INK, "end", "500"))
b.append(text(left - 12, y + 26, f'n={e["n"]}', 10, MUTED, "end"))
b.append(rect(left, y + 15, plot_w * e["mean"] / scale, 11,
AGENT, opacity=0.28))
b.append(rect(left, y + 1, plot_w * e["median"] / scale, 12, AGENT))
b.append(text(left + plot_w * e["mean"] / scale + 8, y + 17,
f'{e["median"]:.1f} / {e["mean"]:.1f}%', 10.5, MUTED,
font=MONO))
axis_y = top + len(rows) * (row_h + gap) + 6
b.append(f'')
for tick in range(0, int(scale) + 1, 5):
x = left + plot_w * tick / scale
b.append(f'')
b.append(text(x, axis_y + 17, f"{tick}%", 10, MUTED, "middle"))
write(out, "01-ecosystems.svg", svg(760, height, "\n".join(b)))
# ------------------------------------------------- 02 · adoption patterns ---
def fig_patterns(summary: dict, out: Path) -> None:
counts = summary["summary"]["patternCounts"]
order = ["none", "individual", "team", "org-wide"]
total = sum(counts.values())
blurb = {"none": "no signature observed",
"individual": "one person's workflow",
"team": "a small group",
"org-wide": "broad adoption"}
width, bar_y, bar_h, pad = 760, 74, 46, 3
b = [text(0, 22, "How adoption is distributed", 15, INK, weight="600"),
text(0, 40, f"{total} repositories, classified by how concentrated "
"agent commits are across contributors", 11.5, MUTED)]
x = 0.0
for key in order:
w = width * counts[key] / total - pad
b.append(rect(x, bar_y, w, bar_h, PATTERN_COLORS[key], rx=3))
if w > 58:
b.append(text(x + 11, bar_y + 21, str(counts[key]), 15, "#ffffff",
weight="600", font=MONO))
b.append(text(x + 11, bar_y + 36, key, 11, "#ffffffcc"))
x += w + pad
y = bar_y + bar_h + 30
for i, key in enumerate(order):
cx = (i % 2) * 380
cy = y + (i // 2) * 22
b.append(rect(cx, cy - 9, 9, 9, PATTERN_COLORS[key]))
b.append(text(cx + 15, cy, f"{key} \u2014 {blurb[key]}", 11.5, MUTED))
b.append(text(cx + 330, cy, f"{counts[key] / total * 100:.0f}%", 11.5,
INK, "end", font=MONO))
note = (f'Among individual repositories the median top contributor accounts '
f'for {summary["summary"]["individualMedianTopShare"]}% of all agent commits.')
b.append(text(0, y + 62, note, 11.5, MUTED))
write(out, "02-adoption-patterns.svg", svg(width, y + 76, "\n".join(b)))
# --------------------------------------------- 03 · composition of commits ---
def fig_composition(summary: dict, out: Path) -> None:
s = summary["summary"]
assisted, autonomous = s["assistedSharePct"], s["autonomousSharePct"]
unsigned = 100 - assisted - autonomous
width, bar_y, bar_h = 760, 92, 40
b = [text(0, 22, "Where the 8.5% floor comes from", 15, INK, weight="600"),
text(0, 40, f'{s["totalCommits"]:,} considered commits \u00b7 merges and '
"CI/dependency bots already excluded", 11.5, MUTED)]
x = 0.0
for share, colour, label in ((assisted, ASSISTED, "assisted"),
(autonomous, AUTONOMOUS, "autonomous"),
(unsigned, HUMAN, "no signature")):
w = width * share / 100
b.append(rect(x, bar_y, max(w - 2, 2), bar_h, colour, rx=3))
x += w
b.append(f'')
b.append(text(width * (assisted + autonomous) / 100 + 10, bar_y - 6,
f'{s["aggregateSharePct"]}% floor', 12, INK, weight="600",
font=MONO))
rows = [("assisted", ASSISTED, assisted,
"a developer's identity authored the commit; the agent signed it"),
("autonomous", AUTONOMOUS, autonomous,
"a bot identity is the author \u2014 no human in the loop"),
("no signature", HUMAN, unsigned,
"manual commits, and any assistance the metadata cannot see")]
y = bar_y + bar_h + 34
for label, colour, share, blurb in rows:
b.append(rect(0, y - 10, 10, 10, colour))
b.append(text(18, y, label, 12, INK, weight="500"))
b.append(text(120, y, f"{share:.1f}%", 12, INK, font=MONO))
b.append(text(180, y, blurb, 11.5, MUTED))
y += 24
b.append(text(0, y + 14, f'{s["assistedOfAgentPct"]}% of matched commits still '
"have a human author. The floor is not a measure of "
"autonomous AI.", 11.5, MUTED))
write(out, "03-commit-composition.svg", svg(width, y + 28, "\n".join(b)))
# ------------------------------------------------- 04 · floor distribution ---
def fig_distribution(df, out: Path) -> None:
edges = [0, 0.001, 1, 2.5, 5, 10, 20, 35, 50, 75, 100.01]
labels = ["0%", "0\u20131", "1\u20132.5", "2.5\u20135", "5\u201310",
"10\u201320", "20\u201335", "35\u201350", "50\u201375", "75\u2013100"]
vals = df.agent_share_pct_floor.tolist()
counts = [sum(1 for v in vals if lo <= v < hi)
for lo, hi in zip(edges, edges[1:])]
width, left, top, bar_w, gap = 760, 44, 66, 60, 12
plot_h, base = 190, 66 + 190
scale = max(counts) * 1.12
b = [text(0, 22, "Distribution of repository floors", 15, INK, weight="600"),
text(0, 40, f"{len(vals)} repositories \u00b7 heavily right-skewed; "
"the median is not the mean", 11.5, MUTED)]
for i, (c, lab) in enumerate(zip(counts, labels)):
x = left + i * (bar_w + gap)
h = plot_h * c / scale
colour = HUMAN if i == 0 else AGENT
b.append(rect(x, base - h, bar_w, h, colour, rx=3))
b.append(text(x + bar_w / 2, base - h - 8, str(c), 11.5, INK, "middle",
font=MONO))
b.append(text(x + bar_w / 2, base + 17, lab, 10.5, MUTED, "middle"))
b.append(f'')
b.append(text(left + len(counts) * (bar_w + gap) / 2, base + 40,
"agent-share floor", 11, MUTED, "middle"))
write(out, "04-floor-distribution.svg", svg(width, base + 54, "\n".join(b)))
# ----------------------------------------------------- 05 · adoption curve ---
def fig_timeline(df, out: Path) -> None:
agent, total = Counter(), Counter()
for raw in df.timeline_json:
for m in json.loads(raw):
agent[m["month"]] += m.get("agent", 0)
total[m["month"]] += m.get("total", 0)
months = sorted(total)
pcts = [agent[m] / total[m] * 100 if total[m] else 0 for m in months]
width, left, right, top, plot_h = 760, 44, 24, 70, 200
plot_w = width - left - right
base = top + plot_h
scale = max(max(pcts) * 1.2, 5)
step = plot_w / max(len(months) - 1, 1)
b = [text(0, 22, "Signed share by month", 15, INK, weight="600"),
text(0, 40, "pooled across all repositories \u2014 commit-weighted, "
"not an average of percentages", 11.5, MUTED)]
for frac in (0, 0.5, 1):
y = base - plot_h * frac
b.append(f'')
b.append(text(left - 10, y + 4, f"{scale * frac:.0f}%", 10, MUTED, "end"))
pts = [(left + i * step, base - plot_h * p / scale)
for i, p in enumerate(pcts)]
area = (f'M{pts[0][0]:.1f},{base} '
+ " ".join(f"L{x:.1f},{y:.1f}" for x, y in pts)
+ f" L{pts[-1][0]:.1f},{base} Z")
b.append(f'')
b.append('')
for (x, y), m, p in zip(pts, months, pcts):
b.append(f'')
b.append(text(x, y - 11, f"{p:.1f}", 10, INK, "middle", font=MONO))
b.append(text(x, base + 18, m[5:] + "/" + m[2:4], 10, MUTED, "middle"))
write(out, "05-monthly-curve.svg", svg(width, base + 40, "\n".join(b)))
# ------------------------------------------------ 06 · share vs. spread ---
def fig_concentration(df, out: Path) -> None:
d = df[(~df.low_activity) & (df.agent_attributed_commits > 0)]
width, left, top, plot_w, plot_h = 760, 52, 72, 640, 250
base = top + plot_h
b = [text(0, 22, "A share means nothing without its spread", 15, INK,
weight="600"),
text(0, 40, f"{len(d)} repositories with \u2265100 considered commits "
"and at least one signed commit", 11.5, MUTED)]
for frac in (0, 0.25, 0.5, 0.75, 1):
y = base - plot_h * frac
b.append(f'')
b.append(text(left - 10, y + 4, f"{frac * 100:.0f}%", 10, MUTED, "end"))
xmax = max(d.agent_share_pct_floor.max(), 10)
for row in d.itertuples():
x = left + plot_w * row.agent_share_pct_floor / xmax
y = base - plot_h * row.top_author_share_of_agent_commits / 100
r = 2.4 + min((row.commits_considered / 2000) ** 0.5 * 3.2, 7)
b.append(f'')
for tick in range(0, int(xmax) + 1, 10):
x = left + plot_w * tick / xmax
b.append(text(x, base + 18, f"{tick}%", 10, MUTED, "middle"))
b.append(text(left + plot_w / 2, base + 38, "agent-share floor \u2192",
11, MUTED, "middle"))
b.append(f''
'top contributor\u2019s share of agent commits')
for i, (key, colour) in enumerate(
[(k, PATTERN_COLORS[k]) for k in ("individual", "team", "org-wide")]):
cx = left + plot_w - 250 + i * 88
b.append(f'')
b.append(text(cx + 10, top - 18, key, 11, MUTED))
b.append(text(0, base + 60, "Bubble area is commits considered. Two "
"repositories with the same share sit at "
"opposite ends of this axis.", 11.5, MUTED))
write(out, "06-share-vs-concentration.svg", svg(width, base + 74, "\n".join(b)))
# ------------------------------------------------------------------- main ---
def main() -> int:
ap = argparse.ArgumentParser()
ap.add_argument("--summary", default="summary.json")
ap.add_argument("--parquet", default="data/train-00000-of-00001.parquet")
ap.add_argument("--out", default="assets")
args = ap.parse_args()
out = Path(args.out)
out.mkdir(parents=True, exist_ok=True)
summary = json.loads(Path(args.summary).read_text())
print("summary-derived figures")
fig_ecosystems(summary, out)
fig_patterns(summary, out)
fig_composition(summary, out)
parquet = Path(args.parquet)
if not parquet.exists():
print(f"\n{parquet} not found \u2014 skipping figures 04-06.")
print("Run again from the dataset root to generate the full set.")
return 0
import pandas as pd # imported late so 01-03 need no dependencies
df = pd.read_parquet(parquet)
print(f"\nparquet figures ({len(df)} rows)")
fig_distribution(df, out)
fig_timeline(df, out)
fig_concentration(df, out)
return 0
if __name__ == "__main__":
raise SystemExit(main())