"""Robustness: country shares by year using only roots attributed through their own namespace (no name rule), and excluding the 100 largest uploader accounts. results/robustness.json""" import json, re, sys import pandas as pd sys.argv = ["x"] exec(open("code/04_analyse.py", encoding="utf-8-sig").read().split("S = {}")[0]) # reuse loading + attribution DER = DER.assign(y=DER.month.str[:4]) out = {} def shares(d): a = d.groupby(["y", "country"]).author.nunique().unstack(fill_value=0) a = a.div(a.sum(1), axis=0) return {y: {"US": round(float(a.loc[y].get("US", 0)), 4), "CN": round(float(a.loc[y].get("CN", 0)), 4)} for y in ("2023", "2024", "2025", "2026") if y in a.index} out["accounts_declared_only"] = shares(DER[DER.how == "declared"]) big = DER.groupby("author").id.nunique().sort_values(ascending=False).head(100).index m = DER[~DER.author.isin(big)] mm = m.groupby(["y", "country"]).weight.sum().unstack(fill_value=0); mm = mm.div(mm.sum(1), axis=0) out["models_without_top100_uploaders"] = {y: {"US": round(float(mm.loc[y].get("US", 0)), 4), "CN": round(float(mm.loc[y].get("CN", 0)), 4)} for y in ("2023", "2024", "2025", "2026")} # direct children only (depth 1), accounts out["accounts_direct_children_only"] = shares(DER[DER.depth == 1]) json.dump(out, open("results/robustness.json", "w"), indent=1) print(json.dumps(out, indent=1))