"""Hourly median of chosen target columns, in own noises, relative to a level window. usage: start end lvl_start lvl_end sensor:col ...""" import sys, statistics from datetime import timedelta sys.path.insert(0, 'tools/scripts') from data import load, parse_time from common import own_noise s, e, l0, l1 = map(parse_time, sys.argv[1:5]) by = load('data/LENZSPITZE') specs = [a.split(':') for a in sys.argv[5:]] B0, B1 = parse_time('2026-10-23T23:55Z'), parse_time('2026-11-01T11:40Z') cols = [] for name, c in specs: ms = by[name] noise = own_noise([m[c] for m in ms if B0 <= m['t'] <= B1 and m[c] is not None]) lvl = statistics.median([m[c] for m in ms if l0 <= m['t'] < l1 and m[c] is not None]) cols.append((name, c, ms, noise, lvl)) print('hour ' + ' '.join(f"{n}{c[-1]:>1}".rjust(8) for n, c, *_ in cols)) h = s while h < e: row = [] for n, c, ms, noise, lvl in cols: v = [m[c] for m in ms if h <= m['t'] < h + timedelta(hours=1) and m[c] is not None] row.append(f"{(statistics.median(v)-lvl)/noise:8.1f}" if len(v) >= 4 else ' -') print(f"{h:%m-%d %H}h " + ' '.join(row)); h += timedelta(hours=1)