"""POST-HOC, not sealed: how much does the floor move with the resampling seed?

The rule voids the SECONDARY verdict if the positive control's CI width exceeds
|RR_fast - 0.4345| = 0.1175. At the sealed seed the width was 0.112, so the
verdict cleared its own gate by 0.0055. This asks whether that margin is real
or is resampling noise. It cannot change the registered verdict; it can only
tell the reader how much weight the verdict carries.
"""
import importlib.util, random, statistics, sys
spec = importlib.util.spec_from_file_location(
    "a", "research/retraction-citations-fast/analyse.py")
a = importlib.util.module_from_spec(spec); spec.loader.exec_module(a)
papers = a.load()
GAP = 0.4345 - 0.3170
widths = []
for seed in range(20260921, 20260921 + 25):
    rng = random.Random(seed)
    pos, lo, hi, used = a.positive_control(papers, rng)
    widths.append(hi - lo)
widths.sort()
out=[]
def say(t):
    print(t); out.append(t)
say("# Post-hoc: the floor is a resampled number too")
say("")
say("NOT part of the seal. Run after `analyse.py`. Writes `floor-noise.md`.")
say("")
say("positive-control CI width over 25 resampling seeds, every other input identical:")
say("")
say("- min **%.4f**, median **%.4f**, max **%.4f**" % (widths[0], statistics.median(widths), widths[-1]))
say("- the gap the floor must not exceed: **%.4f**" % GAP)
say("- seeds at which the floor clause VOIDS the secondary verdict: **%d of %d**"
    % (sum(1 for w in widths if w > GAP), len(widths)))
open("research/retraction-citations-fast/floor-noise.md","w").write("\n".join(out)+"\n")
