improve: S2

ranges.py --labels: each size line ends with >k, how many of the measurements inside are more than --k noises from the level before, of those inside: a single point is told from a sustained deviation without a script (existing columns unchanged)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maximeandClaude Opus 5.5 committed 2026-11-18 14:20:15 +01:00
1 parent 0677c3c341
commit f57e6ea045
1 file changed
+8 -6
+8 -6
View File
@@ -34,7 +34,8 @@ measurements, outside --outside).
and the number of instants inside where a sensor is more than --k noises from it; then the size of the label, up
to --top sensor-columns (default 5), largest first: the extreme inside from the level before the label (median of
the --margin before its start, default 6h; signed, in units and in noises, instant) and the net change (median of
the --margin after its end minus that level), with the number of measurements before and after; a label without
the --margin after its end minus that level), with the number of measurements before and after, and how many of
the measurements inside are more than --k noises from the level before (one: a single point; many: sustained); a label without
a measurement inside (an outage) gives the net change alone, largest first. Labels near the
edge of --start/--end: widen the window by --margin, or before/after lack measurements.
Each column is read at the measurements, never averaged per step. Gives values, not a verdict.
@@ -180,9 +181,9 @@ def main():
f"{' rolling ±' + roll if roll else ''} ({', '.join(columns)}), instants with a sensor more than {o.k:g} noises")
print(f"{'n':>4} {'id':<16}{'start':<18}{'end':<18}{'family':<22}{'inside':>7} largest deviation (noises, at) instants > k")
m = int(o.margin.total_seconds() // 60)
print(f"{'':6}{'sensor.column':<22}{'before':>7}{'extreme':>11}{'(n)':>8} {'at':<17}{'net':>11}{'(n)':>8}{'after':>6}"
print(f"{'':6}{'sensor.column':<22}{'before':>7}{'extreme':>11}{'(n)':>8} {'at':<17}{'net':>11}{'(n)':>8}{'after':>6}{'>k':>9}"
f" (then, up to {o.top} per label: extreme inside from the median of the {m} min before the start;"
f" net: median of the {m} min after the end minus it, alone when no measurement is inside; before, after: their measurements; n: noises)")
f" net: median of the {m} min after the end minus it, alone when no measurement is inside; before, after: their measurements; >k: measurements inside more than {o.k:g} noises from the level before, of those inside; n: noises)")
for n, (t0, t1, e) in enumerate(labels, 1):
ins = [d for d in deviations if t0 < minute(d[0]) < t1]
head = f"{n:4} {str(e.get('id', '-')):<16}{iso(t0):<18}{iso(t1):<18}{e.get('family', '-')[:21]:<22}"
@@ -202,11 +203,12 @@ def main():
before = statistics.median(pre)
t, d = max(((t, v - before) for t, v in inside), key=lambda x: abs(x[1])) if inside else (None, None)
net = statistics.median(post) - before if post else None
rows.append((abs(d if ins else net) / noise, s, col, d, noise, t, len(pre), net, len(post)))
for _, s, col, d, noise, t, n_pre, net, n_post in sorted(rows, key=lambda r: -r[0])[:o.top]:
beyond = f"{sum(abs(v - before) > o.k * noise for _, v in inside)}/{len(inside)}" if inside else "-"
rows.append((abs(d if ins else net) / noise, s, col, d, noise, t, len(pre), net, len(post), beyond))
for _, s, col, d, noise, t, n_pre, net, n_post, beyond in sorted(rows, key=lambda r: -r[0])[:o.top]:
ext = f"{d:+11.4g}{d / noise:+8.1f} {iso(t):<17}" if d is not None else f"{'-':>11}{'-':>8} {'-':<17}"
after = f"{net:+11.4g}{net / noise:+8.1f}{n_post:6}" if net is not None else f"{'-':>11}{'-':>8}{0:6}"
print(f"{'':6}{s + '.' + col:<22}{n_pre:7}{ext}{after}")
print(f"{'':6}{s + '.' + col:<22}{n_pre:7}{ext}{after}{beyond:>9}")
if __name__ == "__main__":
main()