"""Power, measured after both studies and NOT a test: how often would the sealed
verdict rule find a planted midweek excess, by window length and effect size?
Rotated-weekday calendars of the real south-east data (no weekly cycle), MID
days boosted by (1+e). Used to size a future sealed study, not to score one."""
import json, random, sys
from pathlib import Path
HERE = Path(__file__).parent
sys.path.insert(0, str(HERE))
import rule, analyse  # noqa: E402

data = {s: rule.load(s) for s in rule.STATIONS}
out = {}
for (y0, y1) in [(1998, 2025), (1960, 2025)]:
    t, _ = analyse.table(data, y0, y1)
    ys = sorted(t)
    for e in (0.05, 0.10):
        rng = random.Random(11); hit = 0; n = 200
        for i in range(n):
            sh = {y: rng.randrange(7) for y in ys}
            yp = {y: analyse.parts(t[y], shift=sh[y], boost=1 + e) for y in ys}
            d = rule.D(list(yp.values())); lo, hi = rule.boot(yp, 500, 9000 + i)
            hit += rule.verdict(d, lo, hi) == "SURVIVES"
        out[f"{y0}-{y1} summers={len(ys)} planted={e:.0%}"] = hit / n
        print(y0, y1, len(ys), e, hit / n, flush=True)
(HERE / "power.json").write_text(json.dumps(out, indent=1))
