Something went wrong. Try again.
Something went wrong. Try again.
9.9 kB · 201 lines
Python
at typo-stack
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202import json, statistics, datetime, collections, re, osSD="/tmp/claude-1000/-home-jmm-Code-blogposts/7ba1f72e-807b-4749-bcd3-a065da793e6d/scratchpad"H=json.load(open(f"{SD}/handles.json"))def name(d): return H.get(d) or dME="did:plc:nlzmjyfv6loqtxyzvdcznwgf"AUG=("2026-08-01T00:00:00Z","2026-09-01T00:00:00Z")def inaug(ts): return bool(ts) and AUG[0] <= ts < AUG[1]
pulls=[]; repo_n={}for l in open(f"{SD}/pulls.jsonl"): d=json.loads(l); repo_n[d["repoDid"]]=d["n"] for p in d["pulls"]: p["author"]=p["uri"].split("/")[2]; p["repoDid"]=d["repoDid"]; pulls.append(p)commits={}for l in open(f"{SD}/commits.jsonl"): c=json.loads(l); commits[c["uri"]]=c
out={}out["scope"]={"reposScanned":len(repo_n),"reposWithPulls":sum(1 for v in repo_n.values() if v), "totalPulls":len(pulls),"authors":len({p["author"] for p in pulls}), "mergedPulls":sum(1 for p in pulls if p["state"]=="merged"), "openPulls":sum(1 for p in pulls if p["state"]=="open"), "closedPulls":sum(1 for p in pulls if p["state"]=="closed"), "patchesParsed":len(commits),"commitsCounted":sum(c["commits"] for c in commits.values())}
# leaderboardsdef lb(pred, key): c=collections.Counter() for p in pulls: if pred(p): c[p["author"]]+=key(p) return cmerged_all=lb(lambda p:p["state"]=="merged", lambda p:1)merged_aug=lb(lambda p:p["state"]=="merged" and inaug(p["stateUpdatedAt"]), lambda p:1)opened_all=lb(lambda p:True, lambda p:1)opened_aug=lb(lambda p:inaug(p["createdAt"]), lambda p:1)
com_all=collections.Counter(); com_aug=collections.Counter()for u,c in commits.items(): com_all[c["author"]]+=c["commits"] if inaug(c["stateUpdatedAt"] or c["createdAt"]): com_aug[c["author"]]+=c["commits"]
def top(c,n=15): return [{"did":d,"handle":name(d),"n":v,"me":d==ME} for d,v in c.most_common(n)]def pie(c,n=4): mc=c.most_common(); tot=sum(c.values()) head=[{"handle":name(d),"n":v,"me":d==ME} for d,v in mc[:n]] rest=tot-sum(x["n"] for x in head) if rest>0: head.append({"handle":f"other ({len(mc)-n} people)","n":rest,"me":False}) return {"total":tot,"slices":head}
out["leaderboards"]={ "mergedAllTime":top(merged_all), "mergedAugust":top(merged_aug), "commitsAllTime":top(com_all), "commitsAugust":top(com_aug), "openedAllTime":top(opened_all), "openedAugust":top(opened_aug)}out["pies"]={"mergedAllTime":pie(merged_all),"mergedAugust":pie(merged_aug), "commitsAllTime":pie(com_all),"commitsAugust":pie(com_aug)}
# monthly timelinetl=collections.defaultdict(lambda: {"opened":0,"merged":0,"minemerged":0,"mineopened":0})for p in pulls: k=(p["createdAt"] or "")[:7] if k: tl[k]["opened"]+=1; tl[k]["mineopened"]+= (p["author"]==ME) if p["state"]=="merged" and p["stateUpdatedAt"]: k2=p["stateUpdatedAt"][:7]; tl[k2]["merged"]+=1; tl[k2]["minemerged"]+= (p["author"]==ME)out["timeline"]=[{"month":k,**v} for k,v in sorted(tl.items()) if k>="2025-08"]
# my statsmine=[p for p in pulls if p["author"]==ME]mycom=[c for c in commits.values() if c["author"]==ME]def ttm(p): if p["state"]!="merged" or not p["stateUpdatedAt"] or not p["createdAt"]: return None f="%Y-%m-%dT%H:%M:%S" try: a=datetime.datetime.fromisoformat(p["createdAt"].replace("Z","+00:00")) b=datetime.datetime.fromisoformat(p["stateUpdatedAt"].replace("Z","+00:00")) return (b-a).total_seconds()/60 except Exception: return Nonemt=[t for t in (ttm(p) for p in mine) if t is not None and t>=0]at=[t for t in (ttm(p) for p in pulls if p["author"]!=ME) if t is not None and t>=0]out["me"]={"handle":name(ME),"did":ME,"pulls":len(mine), "merged":sum(1 for p in mine if p["state"]=="merged"), "closed":sum(1 for p in mine if p["state"]=="closed"), "open":sum(1 for p in mine if p["state"]=="open"), "augOpened":sum(1 for p in mine if inaug(p["createdAt"])), "augMerged":sum(1 for p in mine if p["state"]=="merged" and inaug(p["stateUpdatedAt"])), "commits":sum(c["commits"] for c in mycom), "commitsPerPull":round(statistics.mean([c["commits"] for c in mycom]),2) if mycom else 0, "medianTimeToMergeMin":round(statistics.median(mt),1) if mt else None, "medianRounds":statistics.median([p["rounds"] for p in mine]) if mine else None, "repos":len({p["repoDid"] for p in mine}), "medianBodyLen":statistics.median([p["bodyLen"] for p in mine]) if mine else None, "comments":sum(p["comments"] for p in mine), "decided":sum(1 for p in mine if p["state"]!="open"), "medianCommitsPerPull":statistics.median([c["commits"] for c in mycom]) if mycom else 0, "patchCoverage":round(100*len(mycom)/max(1,sum(1 for p in mine if p["state"]=="merged")),1)}others=[p for p in pulls if p["author"]!=ME]ocom=[c for c in commits.values() if c["author"]!=ME]out["others"]={"pulls":len(others),"merged":sum(1 for p in others if p["state"]=="merged"), "commits":sum(c["commits"] for c in ocom), "commitsPerPull":round(statistics.mean([c["commits"] for c in ocom]),2) if ocom else 0, "medianTimeToMergeMin":round(statistics.median(at),1) if at else None, "medianBodyLen":statistics.median([p["bodyLen"] for p in others]) if others else None, "open":sum(1 for p in others if p["state"]=="open"), "decided":sum(1 for p in others if p["state"]!="open"), "medianCommitsPerPull":statistics.median([c["commits"] for c in ocom]) if ocom else 0, "patchCoverage":round(100*len(ocom)/max(1,sum(1 for p in others if p["state"]=="merged")),1)}
# distribution: how many authors have >=N mergeddist=sorted(merged_all.values(),reverse=True)out["distribution"]={"authorsWithMerged":len(dist), "top1Share":round(100*dist[0]/sum(dist),1) if dist else 0, "top5Share":round(100*sum(dist[:5])/sum(dist),1) if dist else 0, "median":statistics.median(dist) if dist else 0}
# august daily for medaily=collections.Counter()for p in mine: if p["state"]=="merged" and inaug(p["stateUpdatedAt"]): daily[p["stateUpdatedAt"][:10]]+=1out["myAugustDaily"]=[{"day":k,"n":v} for k,v in sorted(daily.items())]
# ---- provenance & data-integrity figures used in the prose ----import os, datetime as _dtprov={}prov["asOf"]=_dt.datetime.now(_dt.timezone.utc).strftime("%-d %B %Y")try: prov["knot1Repos"]=len(json.load(open(f"{SD}/closure_repos.json")))except Exception: prov["knot1Repos"]=Nonetry: prov["knots"]=len(json.load(open(f"{SD}/closure_knots.json"))) prov["extraRepos"]=Noneexcept Exception: prov["extraRepos"]=None
_merged=[p for p in pulls if p["state"]=="merged"]# August totals + author countprov["augMergedTotal"]=sum(1 for p in _merged if inaug(p["stateUpdatedAt"]))prov["augAuthors"]=len({p["author"] for p in _merged if inaug(p["stateUpdatedAt"])})prov["allTimeAuthors"]=len({p["author"] for p in _merged})prov["commitAuthorsAllTime"]=len({c["author"] for c in commits.values()})
# monthly merge counts -> record multiple_tl=collections.Counter(p["stateUpdatedAt"][:7] for p in _merged if p["stateUpdatedAt"])_aug=_tl.get("2026-08",0)_prev=max([v for k,v in _tl.items() if k<"2026-08"] or [0])prov["augMerged"]=_aug; prov["prevRecord"]=_prevprov["recordMultiple"]=round(_aug/_prev,1) if _prev else Noneprov["prevRecordMonth"]=max([k for k,v in _tl.items() if k<"2026-08" and v==_prev] or [""])
# timestamp integritydef _delta(p): if not (p["createdAt"] and p["stateUpdatedAt"]): return None try: a=datetime.datetime.fromisoformat(p["createdAt"].replace("Z","+00:00")) b=datetime.datetime.fromisoformat(p["stateUpdatedAt"].replace("Z","+00:00")) return (b-a).total_seconds() except Exception: return None_o=[p for p in _merged if p["author"]!=ME]_d=[(_delta(p),p) for p in _o]_valid=[x for x,_ in _d if x is not None]_neg=[x for x in _valid if x<0]prov["othMergedWithTs"]=len(_valid)prov["othNegative"]=len(_neg)prov["othNegativePct"]=round(100*len(_neg)/len(_valid),1) if _valid else 0_dmine=[_delta(p) for p in _merged if p["author"]==ME]prov["myNegative"]=sum(1 for x in _dmine if x is not None and x<0)# month bucketing disagreement between the two timestamp fields_dis=sum(1 for p in _merged if inaug(p["stateUpdatedAt"])!=inaug(p["createdAt"]))prov["monthDisagree"]=_disprov["monthDisagreePct"]=round(100*_dis/len(_merged),1) if _merged else 0
# biggest open-PR backlog, for the merge-rate caveat_open=[p for p in pulls if p["state"]=="open"]_byrepo=collections.Counter(p["repoDid"] for p in _open)prov["openTotal"]=len(_open)prov["backlogTopCount"]=_byrepo.most_common(1)[0][1] if _byrepo else 0prov["oldestOpen"]=min((p["createdAt"][:7] for p in _open if p["createdAt"]), default="")try: prov["peopleCrawled"]=sum(1 for _ in open(f"{SD}/alt_pull_records.jsonl"))except Exception: prov["peopleCrawled"]=Nonetry: import collections as _c g=0 for _l in open(f"{SD}/alt_pull_records.jsonl"): for _r in json.loads(_l)["records"]: if not (_r.get("value") or {}).get("target"): g+=1 prov["noTargetRecords"]=gexcept Exception: prov["noTargetRecords"]=Nonetry: _r=json.load(open(f"{SD}/closure_repos.json")); _o=json.load(open(f"{SD}/closure_owners.json")) prov["unattributedRepos"]=sum(1 for x in _r if x not in _o)except Exception: prov["unattributedRepos"]=Noneout["prov"]=prov
json.dump(out,open(f"{SD}/stats.json","w"),indent=1)print(json.dumps({k:out[k] for k in ("scope","me","others","distribution")},indent=1))print("\nMERGED ALL-TIME"); [print(f"{x['n']:>6} {x['handle']}") for x in out["leaderboards"]["mergedAllTime"][:12]]print("\nMERGED AUGUST 2026"); [print(f"{x['n']:>6} {x['handle']}") for x in out["leaderboards"]["mergedAugust"][:12]]print("\nCOMMITS ALL-TIME"); [print(f"{x['n']:>6} {x['handle']}") for x in out["leaderboards"]["commitsAllTime"][:12]]print("\nCOMMITS AUGUST"); [print(f"{x['n']:>6} {x['handle']}") for x in out["leaderboards"]["commitsAugust"][:12]]print("\nTIMELINE"); [print(t) for t in out["timeline"]]