"""After the data, not sealed: the share if "groups" were still linked.

Tonight's steps.csv, with one change: Branches of science's next title is
"Groups", as at revision 1372482236 (before "removed link to common word",
2026-09-08). The pages after it were fetched at 21:3x Rome on 2026-09-15 with
fetch.page and are written in below. Output: counterfactual.txt.
"""
import os
from collections import Counter

import analyse
import rule

EXTRA = {  # asked -> (resolved, next), fetched 2026-09-15 evening
    "Groups": ("Group", "Number"),
    "Number": ("Number", "Mathematical object"),
    "Mathematical object": ("Mathematical object", "Abstract and concrete"),
    "Abstract and concrete": ("Abstract and concrete", "Philosophy"),
    "Philosophy": ("Philosophy", None),
}
starts, steps = analyse.load()
steps["Branches of science"] = ("Branches of science", "Groups")
for k, v in EXTRA.items():
    steps.setdefault(k, v)
out = Counter(analyse.chain(s, steps)[0] for s in starts)
v = rule.verdicts(out["philosophy"], len(starts))
L = ["outcomes " + ", ".join(f"{k} {out[k]}" for k in ("philosophy", "loop", "dead_end", "cap")),
     f"share {v['p']:.3f}, Wilson 95 % {v['lo']:.3f} to {v['hi']:.3f}; A would be {v['A']}, B {v['B']}"]
open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "counterfactual.txt"), "w").write("\n".join(L) + "\n")
print("\n".join(L))
