File size: 4,581 Bytes
b3b12cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"""Test B+S sub-composite against every available external proxy."""
import csv, json, math, sqlite3
from pathlib import Path
import sys
sys.path.insert(0, "/tmp/AgentPulse-Data-v6/code")
from reproduce_table3 import (load_latest_scores, load_latest_signals, load_registry,
                               benchmark_sentiment_subcomposite, spearman, two_sided_p)

csv_dir = Path("/tmp/AgentPulse-Data-v6/data/csv")
scores = load_latest_scores(csv_dir)
signals = load_latest_signals(csv_dir)
registry = load_registry(csv_dir)


def factors(name):
    s = scores[name]
    sub = json.loads(s.get("sub_scores") or "[0.5,0,0]")
    b = sub[0] if sub else 0.5
    sent = float(s.get("sentiment") or 0)
    sn = max(0, min(1, (sent+1)/2))
    return b, sn


def bs(name):
    b, s = factors(name)
    return 0.6364*b + 0.3636*s


def b_only(name):
    return factors(name)[0]


# Pull pypi history aggregates
conn = sqlite3.connect("/tmp/AgentPulse-Data-v6/data/sqlite/arena_agent_subset.db")
pypi_total = {}; pypi_recent_30 = {}
for r in conn.execute("SELECT agent_name, SUM(downloads) FROM agent_pypi_history GROUP BY agent_name"):
    pypi_total[r[0]] = r[1]
for r in conn.execute("SELECT agent_name, SUM(downloads) FROM agent_pypi_history WHERE date >= '2026-04-01' GROUP BY agent_name"):
    pypi_recent_30[r[0]] = r[1]
conn.close()

# Eligibility: agents with B+S computable + github_repo
eligible_all = [n for n in registry if registry[n].get("github_repo") and n in scores and n in signals]
print(f"Total eligible: {len(eligible_all)}\n")


PROXIES = [
    # (label, value_fn, log_transform, requires_nonzero)
    ("vscode_installs",       lambda n: signals[n].get("vscode_installs", 0),       True,  True),
    ("vscode_installs (zero-impute)", lambda n: signals[n].get("vscode_installs", 0), True,  False),
    ("vscode_rating",         lambda n: signals[n].get("vscode_rating", 0),         False, True),
    ("vscode_rating_count",   lambda n: signals[n].get("vscode_rating_count", 0),   True,  True),

    ("github_stars",          lambda n: signals[n].get("github_stars", 0),          True,  True),
    ("github_forks",          lambda n: signals[n].get("github_forks", 0),          True,  True),
    ("github_open_issues",    lambda n: signals[n].get("github_open_issues", 0),    True,  True),
    ("github_watchers",       lambda n: signals[n].get("github_watchers", 0),       True,  True),
    ("github_contributors",   lambda n: signals[n].get("github_contributors", 0),   True,  True),
    ("issue_close_rate",      lambda n: signals[n].get("issue_close_rate", 0),      False, True),
    ("days_since_update (inv)", lambda n: -1 * signals[n].get("days_since_update", 0), False, True),

    ("pypi_downloads_week",   lambda n: signals[n].get("pypi_downloads_week", 0),   True,  True),
    ("pypi_downloads_month",  lambda n: signals[n].get("pypi_downloads_month", 0),  True,  True),
    ("pypi_history_total",    lambda n: pypi_total.get(n, 0),                       True,  True),
    ("pypi_history_recent30", lambda n: pypi_recent_30.get(n, 0),                   True,  True),

    ("so_questions",          lambda n: signals[n].get("so_questions", 0),          False, False),
    ("so_questions (log)",    lambda n: signals[n].get("so_questions", 0),          True,  False),
    ("mention_count",         lambda n: int(scores[n].get("mention_count") or 0),   True,  False),
]


def correlate_with(sub_name, sub_fn):
    print(f"\n{'='*100}")
    print(f" Sub-composite: {sub_name}")
    print(f"{'='*100}")
    print(f"  {'proxy':<40}  {'rho_s':>7}  {'p':>8}  {'n':>4}  notes")
    print(f"  {'-'*40}  {'-'*7}  {'-'*8}  {'-'*4}")
    for label, fn, log_xform, require_nonzero in PROXIES:
        elig = []
        for n in eligible_all:
            v = fn(n)
            if require_nonzero and (v is None or v == 0): continue
            if v is None: v = 0
            elig.append((n, v))
        if len(elig) < 4:
            print(f"  {label:<40}  (n={len(elig)} too small)")
            continue
        xs = [sub_fn(n) for n,_ in elig]
        ys = [(math.log10(v+1) if log_xform else v) for _,v in elig]
        rho = spearman(xs, ys); p = two_sided_p(rho, len(elig))
        sig = "***" if p<0.001 else "** " if p<0.01 else "*  " if p<0.05 else "   "
        note = ""
        if rho > 0.3 and p < 0.05: note = "<-- candidate"
        if abs(rho) < 0.10: note = "(null)"
        print(f"  {label:<40}  {rho:+7.3f}  {p:>8.4f}  {len(elig):>4}  {sig}{note}")

correlate_with("B+S (paper's pre-specified)", bs)
correlate_with("B-only (capability alone)",   b_only)