Skip to content

Instantly share code, notes, and snippets.

@eth-limo
Last active September 9, 2026 20:34
Show Gist options
  • Select an option

  • Save eth-limo/83b7f71e12d4920e2becbc4c4122300d to your computer and use it in GitHub Desktop.

Select an option

Save eth-limo/83b7f71e12d4920e2becbc4c4122300d to your computer and use it in GitHub Desktop.
Reproduce PSL PR queue stats
#!/usr/bin/env python3
"""Reproduce the publicsuffix/list PR-queue statistics.
Companion to the eth.limo PSL blog post. Reproduces every queue figure as
published (snapshot 2026-08-28, PRs #1-#3205). Python 3.8+, stdlib only.
Usage:
1) Fetch the raw data (28 pages, unauthenticated; ~60 req/hr limit applies):
mkdir -p prs
for p in $(seq 1 50); do
curl -s "https://api.github.com/repos/publicsuffix/list/pulls?state=all&per_page=100&page=$p" \
-o "prs/page_$p.json"
[ "$(python3 -c 'import json,sys;print(len(json.load(open(sys.argv[1]))))' prs/page_$p.json)" -lt 100 ] && break
done
2) python3 psl_queue_stats.py
Methodology (matches the post):
- Snapshot: the published numbers describe the queue as of 2026-08-28,
PRs #1-#3205. Running later still reproduces them, because PRs numbered
above MAX_PR are dropped and any close/merge that happened after AS_OF
is ignored (the PR is treated as still open at the snapshot). Two
reconstruction limits: closed_at reflects only a PR's LATEST close, so a
PR closed before the snapshot and reopened after it reads as open; and
the draft flag is current state, not state at the snapshot. Both are
worth at most +/-1 on any count.
- "External" excludes bot authors (login ending "[bot]", plus
tld-update-bot) and maintainer/reviewer accounts (MAINTAINERS below).
PRs by deleted accounts ("ghost") are external. Note: the GitHub UI's
closed-PR count is lower than the REST total because the UI's search
index hides PRs from deleted/spam-flagged accounts.
- Wait = calendar days, created_at -> merged_at/closed_at (AS_OF if open).
- Per-year rows bucket by SUBMISSION year (created_at). "Median days" is
over merged PRs of that cohort. Still-open PRs are in no per-year column.
- Set MAX_PR = None and AS_OF to today to compute current numbers instead.
Expected output vs the published figures: every count, median, and percentage
matches exactly except three snapshot-instant figures. The post was computed
at the original fetch moment during 2026-08-28; this script uses end-of-day
AS_OF, so each of the 48 still-open PRs accrues the remaining fraction of
that day. That moves the grand total of waiting days from 137,818 to
137,866 (+0.03%), the still-open median age from 26 d to 27.2 d, and the
oldest open PR from 436 d to 437 d. Any AS_OF instant within 2026-08-28
lands in 137.8k; "377 PR-years" and every other figure are invariant.
"""
import glob
import json
import statistics as st
from datetime import datetime, timezone
AS_OF = datetime(2026, 8, 28, 23, 59, 59, tzinfo=timezone.utc)
MAX_PR = 3205
MAINTAINERS = {"weppos", "dnsguru", "simon-friedberger", "sleevi", "danderson", "wdhdev"}
def d(s):
return datetime.fromisoformat(s.replace("Z", "+00:00"))
prs = []
for f in sorted(glob.glob("prs/page_*.json")):
page = json.load(open(f, encoding="utf-8"))
if not isinstance(page, list): # GitHub error object, e.g. rate limit
raise SystemExit(f"{f} is not a PR list — API said: {page.get('message', page)!r}. "
"Delete it and re-fetch (unauthenticated limit is 60 requests/hour).")
prs.extend(page)
prs = {p["number"]: p for p in prs}.values() # dedupe across pages
snap = [p for p in prs if (MAX_PR is None or p["number"] <= MAX_PR) and d(p["created_at"]) <= AS_OF]
if not snap:
raise SystemExit("no PRs in snapshot window — did the fetch into prs/ succeed?")
print(f"snapshot: {len(snap)} PRs through #{max(p['number'] for p in snap)}")
ext = []
for p in snap:
u = p["user"]["login"] if p["user"] else "ghost"
if u.endswith("[bot]") or u == "tld-update-bot" or u in MAINTAINERS:
continue
closed = bool(p["closed_at"]) and d(p["closed_at"]) <= AS_OF
merged = bool(p["merged_at"]) and d(p["merged_at"]) <= AS_OF
end = d(p["closed_at"]) if closed else AS_OF
ext.append({
"n": p["number"], "year": d(p["created_at"]).year, "draft": bool(p.get("draft")),
"merged": merged, "closed": closed,
"wait": (end - d(p["created_at"])).total_seconds() / 86400,
})
mg = [p for p in ext if p["merged"]]
cu = [p for p in ext if p["closed"] and not p["merged"]]
op = [p for p in ext if not p["closed"]]
res = len(mg) + len(cu)
total = sum(p["wait"] for p in ext)
dm, dc = sum(p["wait"] for p in mg), sum(p["wait"] for p in cu)
mw = sorted(p["wait"] for p in mg)
cw = [p["wait"] for p in cu]
ow = sorted(p["wait"] for p in op)
print(f"external: {len(ext)} (merged {len(mg)} / closed-unmerged {len(cu)} / open {len(op)})")
print(f"total waiting: {total:,.0f} days = {total/365.25:.1f} PR-years mean/PR {total/len(ext):.1f}d")
print(f"of resolved ({res}): accepted {100*len(mg)/res:.1f}% refused {100*len(cu)/res:.1f}%")
print(f"waiting-day split: merged {100*dm/total:.1f}% refused {100*dc/total:.1f}% open {100*(total-dm-dc)/total:.1f}%")
print(f"merged: median {st.median(mw):.1f}d mean {st.mean(mw):.1f}d "
f">90d {sum(w > 90 for w in mw)} ({100*sum(w > 90 for w in mw)/len(mw):.1f}%) "
f">1yr {sum(w > 365 for w in mw)} 8 longest: {[round(w) for w in mw[-8:]]}")
print(f"closed-unmerged: median {st.median(cw):.1f}d mean {st.mean(cw):.1f}d "
f">90d {sum(w > 90 for w in cw)} ({100*sum(w > 90 for w in cw)/len(cw):.1f}%)")
print(f"resolved >90d: {100*(sum(w > 90 for w in mw)+sum(w > 90 for w in cw))/res:.1f}%")
if op:
print(f"open: {len(op)} ({sum(p['draft'] for p in op)} drafts) "
f"median age {st.median(ow):.1f}d oldest {max(ow):.0f}d")
print("\nyear merged median-days closed-unmerged acceptance")
for y in sorted({p["year"] for p in ext}):
ym = [p["wait"] for p in mg if p["year"] == y]
yc = sum(1 for p in cu if p["year"] == y)
r = len(ym) + yc
print(f"{y} {len(ym):5d} {st.median(ym):10.1f} {yc:14d} {100*len(ym)/r:8.1f}%" if ym
else f"{y} 0 - {yc:14d}")
Y = AS_OF.year
cens = [p for p in op if p["year"] == Y]
mY = sum(1 for p in mg if p["year"] == Y)
rY = mY + sum(1 for p in cu if p["year"] == Y)
if rY + len(cens):
print(f"\n{Y} censoring: {len(cens)} cohort PRs still open; acceptance ceiling "
f"({mY}+{len(cens)})/({rY}+{len(cens)}) = {100*(mY+len(cens))/(rY+len(cens)):.1f}%")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment