Files
troupe-standup/wizard-work/ledger/extract_author_census.py
T

48 lines
1.3 KiB
Python

#!/usr/bin/env python3
"""extract_author_census.py
Extract-lane artifact: per-author commit census of the troupe repository.
Source (real tool call): `git -C /root/troupe-standup log --format=%an`
aggregated with a stdlib Counter. No LLM summarization, no fabricated rows.
Output: 2026-11-02-author-census.csv (rank,author,commits)
"""
import csv
import subprocess
from collections import Counter
REPO = "/root/troupe-standup"
OUT = "/root/troupe-standup/wizard-work/ledger/2026-11-02-author-census.csv"
TOP_N = 20
def main():
out = subprocess.run(
["git", "-C", REPO, "log", "--format=%an"],
check=True, capture_output=True, text=True,
).stdout
counts = Counter(out.splitlines())
total = sum(counts.values())
distinct = len(counts)
rows = sorted(counts.items(), key=lambda kv: (-kv[1], kv[0]))[:TOP_N]
with open(OUT, "w", newline="") as fh:
w = csv.writer(fh)
w.writerow(["rank", "author", "commits"])
for i, (author, n) in enumerate(rows, start=1):
w.writerow([i, author, n])
print(f"total commits : {total}")
print(f"distinct authors: {distinct}")
print(f"rows written : {len(rows)} -> {OUT}")
print("top 5:")
for author, n in rows[:5]:
print(f" {n:>5} {author}")
if __name__ == "__main__":
main()