"""Draw the spot-check samples S1 and S2 (RULES_spotcheck.txt) and list each row's URLs.""" import os import random import re import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import lib_ee as L # noqa: E402 ev = L.load_events() rows = sorted(ev, key=lambda e: int(e["sheet_row"])) all_sr = [int(e["sheet_row"]) for e in rows] S1 = random.Random(20261107).sample(all_sr, 25) t0s = [L.di(L.pdate(r["t0_peak_date"])) for r in L.read_csv(L.drive_file("PipelineA_storm_episodes_G3plus"))] win = {t + k for t in t0s for k in (1, 2, 3) if t + k < L.N} win_sr = [int(e["sheet_row"]) for e in rows if L.di(L.pdate(e["date_utc"])) in win] pool = [s for s in win_sr if s not in set(S1)] S2 = random.Random(20261108).sample(pool, 10) by = {int(e["sheet_row"]): e for e in ev} os.makedirs(L.RES, exist_ok=True) with open(os.path.join(L.RES, "spotcheck_sample.txt"), "w", encoding="utf-8", newline="\n") as f: f.write("# Spot-check sample (RULES_spotcheck.txt). window rows available for S2: %d\n" % len(win_sr)) f.write("# sample\tsheet_row\tdate_utc\tdate_certainty\turls\n") for lab, ss in (("S1", S1), ("S2", S2)): for s in ss: e = by[s] urls = re.findall(r"https?://[^\s;,|]+", e["source_links"]) f.write("%s\t%d\t%s\t%s\t%s\n" % (lab, s, e["date_utc"], e["date_certainty"], " ".join(urls))) print("S1", S1) print("S2", S2, "pool", len(win_sr))