"""For windows T1/T2, list the instants where targets exceed K noises (rolling +-N level) on corr_x or corr_y: count, median of corr_x and corr_y deviations, and the sensors. usage: touched.py FOLDER START END T1/T2 [T1/T2 ...]""" import sys, statistics as st sys.path.insert(0, "tools/scripts") import data folder, start, end = sys.argv[1:4]; wins = sys.argv[4:]; N, K = 8, 5 D = data.load(folder); S, E = data.parse_time(start), data.parse_time(end) tg = [s for s in D if not data.is_reference(D[s])] dev = {} for col in ("corr_x", "corr_y"): for s in tg: vals = [(m["t"], m[col]) for m in D[s] if S <= m["t"] <= E] v = [x for _, x in vals if x is not None] noise = st.median(abs(a - b) for a, b in zip(v[1:], v[:-1])) for i, (t, x) in enumerate(vals): if x is None: continue nb = [y for _, y in vals[max(0, i - N):i] + vals[i + 1:i + 1 + N] if y is not None] dev.setdefault(t, {}).setdefault(col, {})[s] = (x - st.median(nb)) / noise for w in wins: a, b = map(data.parse_time, w.split("/")) print("==", w) for t in sorted(dev): if not a <= t <= b: continue d = dev[t]; out = [] for col in ("corr_x", "corr_y"): out += [f"{s}.{col[-1]}{d[col][s]:+.0f}" for s in tg if s in d.get(col, {}) and abs(d[col][s]) > K] mx = st.median(d["corr_x"].values()); my = st.median(d["corr_y"].values()) print(" ", data.iso(t), f"med x {mx:+.1f} y {my:+.1f}", len(out), " ".join(out))