#!/usr/bin/env python3 """Descriptive numbers for a threads CSV (published format). Usage: python3 -I scripts/stats.py data/threads.csv [--relevant-only]""" import csv, sys, statistics, collections rows = list(csv.DictReader(open(sys.argv[1]))) if "--relevant-only" in sys.argv and rows and "relevance" in rows[0]: rows = [r for r in rows if r["relevance"] == "yes"] n = len(rows) print(f"threads: {n}") def pct(k, tot): return f"{100 * k / tot:.0f}%" if tot else "-" def med(vals): v = [float(x) for x in vals if x not in ("", None)] return (f"{statistics.median(v):.1f} h (n={len(v)})") if v else "-" print(f"resolved: {pct(sum(r['resolved'] == 'yes' for r in rows), n)}") print(f"maintainer replied: {pct(sum(r['maintainer_replied'] == 'yes' for r in rows), n)}") print(f"no reply at all (no time_to_first_response): {pct(sum(r['time_to_first_response_h'] == '' for r in rows), n)}") print(f"median time to first response: {med(r['time_to_first_response_h'] for r in rows)}") print(f"median time to close (closed only): {med(r['time_to_close_h'] for r in rows)}") for col in ["thread_type", "repo_group", "target_host", "app_type", "framework", "topic", "error_type", "resolution_type", "ai_generated_app", "ai_tool", "coding_confidence"]: c = collections.Counter(r[col] or "(empty)" for r in rows) print(f"\n{col}: " + ", ".join(f"{k} {v} ({pct(v, n)})" for k, v in c.most_common(20))) prov = collections.Counter(p for r in rows for p in (r["model_provider"] or "unspecified").split(";")) print("\nmodel_provider (multi): " + ", ".join(f"{k} {v}" for k, v in prov.most_common(12))) # topic x resolution / response, for the categories with >= 20 threads print("\nby topic: n, resolved, median first response") by = collections.defaultdict(list) for r in rows: by[r["topic"]].append(r) for k, lst in sorted(by.items(), key=lambda kv: -len(kv[1])): if len(lst) >= 20: print(f" {k:22s} {len(lst):5d} {pct(sum(x['resolved'] == 'yes' for x in lst), len(lst)):>5s} {med(x['time_to_first_response_h'] for x in lst)}") print("\nby target_host (>= 20): n, resolved, maintainer replied, median first response") by = collections.defaultdict(list) for r in rows: by[r["target_host"]].append(r) for k, lst in sorted(by.items(), key=lambda kv: -len(kv[1])): if len(lst) >= 20: print(f" {k:22s} {len(lst):5d} {pct(sum(x['resolved'] == 'yes' for x in lst), len(lst)):>5s} " f"{pct(sum(x['maintainer_replied'] == 'yes' for x in lst), len(lst)):>5s} {med(x['time_to_first_response_h'] for x in lst)}") if rows and "thread_type" in rows[0]: types = ["problem", "feature", "docs", "question", "pr_ci", "other"] print("\nby thread_type: n, resolved, maintainer replied, no reply, median first response") for tt in types: lst = [r for r in rows if r["thread_type"] == tt] if lst: print(f" {tt:10s} {len(lst):5d} {pct(sum(x['resolved'] == 'yes' for x in lst), len(lst)):>5s} " f"{pct(sum(x['maintainer_replied'] == 'yes' for x in lst), len(lst)):>5s} " f"{pct(sum(x['time_to_first_response_h'] == '' for x in lst), len(lst)):>5s} {med(x['time_to_first_response_h'] for x in lst)}") print("\nthread_type by target_host (hosts >= 20): n, then share of each type") by = collections.defaultdict(list) for r in rows: by[r["target_host"]].append(r) print(" " + " " * 22 + " n " + " ".join(f"{t:>8s}" for t in types)) for k, lst in sorted(by.items(), key=lambda kv: -len(kv[1])): if len(lst) >= 20: print(f" {k:22s} {len(lst):5d} " + " ".join(f"{pct(sum(x['thread_type'] == t for x in lst), len(lst)):>8s}" for t in types)) for tt in ("feature", "docs"): c = collections.Counter(r["target_host"] for r in rows if r["thread_type"] == tt) print(f"\nhosts with the most {tt} threads: " + ", ".join(f"{k} {v}" for k, v in c.most_common(8))) print("\nthread_type by repo_group: " + "; ".join( f"{g}: " + ", ".join(f"{t} {pct(sum(x['thread_type'] == t for x in rows if x['repo_group'] == g), sum(x['repo_group'] == g for x in rows))}" for t in types) for g in sorted({r['repo_group'] for r in rows}))) print("\nby year: n") c = collections.Counter(r["created_at"][:4] for r in rows) print(" " + ", ".join(f"{k}: {v}" for k, v in sorted(c.items())))