"""Load the window once (cached pickle in work/), helpers.""" import os, sys, pickle from datetime import datetime, timedelta, timezone ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../..")) sys.path.insert(0, os.path.join(ROOT, "tools/scripts")) import data OUT = os.path.join(os.path.dirname(__file__), "..", "work") CACHE = os.path.join(OUT, "cache.pkl") T0 = datetime(2026, 9, 29, 18, tzinfo=timezone.utc) T1 = datetime(2026, 10, 13, 12, tzinfo=timezone.utc) def q(t): return t.replace(second=0, microsecond=0, minute=(t.minute // 15) * 15) if t.minute % 15 in (0,) or True else t def get(): if os.path.exists(CACHE): return pickle.load(open(CACHE, "rb")) folder = os.path.join(ROOT, "data/NORDEND") meas = {} for s, ms in data.load(folder).items(): for m in ms: t = m["t"].replace(second=0, microsecond=0) t = t.replace(minute=(t.minute // 15) * 15) if T0 <= t <= T1: m["rej"] = m["error_value"] is not None and m["error_threshold"] is not None and m["error_value"] > m["error_threshold"] meas.setdefault(t, {})[s] = m pose = {p["t"].replace(second=0, microsecond=0): p for p in data.load_camera(folder) if T0 <= p["t"] <= T1} temp = {t: v for t, v in data.load_temperature(folder) if T0 <= t <= T1} d = dict(meas=meas, pose=pose, temp=temp) pickle.dump(d, open(CACHE, "wb")) return d def T(s): return datetime.strptime(s, "%Y-%m-%dT%H:%MZ").replace(tzinfo=timezone.utc) def fmt(t): return t.strftime("%m-%d %H:%M")