improve: S1

ranges.py: the sensor column is as wide as the longest name, the numeric columns one character wider: a 10-character name or a value like -1.137e-13 no longer runs into the next column (contents 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:19:36 +01:00
1 parent af6cf23f94
commit 0677c3c341
1 file changed
+7 -6
+7 -6
View File
@@ -96,6 +96,7 @@ def main():
check("sensors", names, by)
check("columns", columns, COLUMNS)
series = {s: filter_window(by[s], o.start, o.end) for s in names}
w = max(9, max(len(s) for s in names) + 1) # sensor column: a long name never runs into the next column
if not any(series.values()):
sys.exit("No measurement in the requested window.")
roll = (f"{o.rolling} measurements" if isinstance(o.rolling, int) else f"{int(o.rolling.total_seconds() // 60)} min") if o.rolling is not None else ""
@@ -105,17 +106,17 @@ def main():
for col in columns:
print(f"\n== {col}: level, noise, largest jump from one measurement to the next ==")
print(f"{'sensor':9}{'n':>5}{'level':>10}{'noise':>10}{'jump':>10}{'(noises)':>9} between")
print(f"{'sensor':{w}}{'n':>5}{'level':>11}{'noise':>11}{'jump':>11}{'(noises)':>9} between")
ranges = []
for s in names:
ms = [(m["t"], m[col]) for m in series[s] if m[col] is not None]
rej = {m["t"] for m in series[s] if rejected(m)}
if len(ms) < 2:
print(f"{s:9}{len(ms):5} (fewer than 2 values)")
print(f"{s:{w}}{len(ms):5} (fewer than 2 values)")
continue
ref = [x for x in ms if kept(x[0])]
if len(ref) < 2:
print(f"{s:9}{len(ms):5} (fewer than 2 values outside --outside)")
print(f"{s:{w}}{len(ms):5} (fewer than 2 values outside --outside)")
continue
lvl = statistics.median(v for _, v in ref)
jumps = [(b[1] - a_[1], a_[0], b[0]) for a_, b in zip(ms, ms[1:])]
@@ -123,7 +124,7 @@ def main():
d, t1, t2 = max(jumps, key=lambda x: abs(x[0]))
in_noises = f"{d / noise:9.1f}" if noise else f"{'-':>9}"
flagged = [iso(x) for x in (t1, t2) if x in rej]
print(f"{s:9}{len(ms):5}{lvl:10.4g}{noise:10.3g}{d:+10.4g}{in_noises} {iso(t1)} and {iso(t2)}"
print(f"{s:{w}}{len(ms):5}{lvl:11.4g}{noise:11.3g}{d:+11.4g}{in_noises} {iso(t1)} and {iso(t2)}"
+ (f" (rejected: {', '.join(flagged)})" if flagged else ""))
if not noise:
continue
@@ -145,10 +146,10 @@ def main():
ranges = [p for p in ranges if len(p[1]) >= o.min_measurements]
print(f"\n{col}: ranges more than {o.k:g} noises from the level{' rolling ±' + roll + ' (median of the neighbours)' if roll else ''}{' (level outside ' + o.outside + ')' if o.outside and not roll else ''}{' (noise outside ' + o.outside + ')' if o.outside and roll else ''} (merge {int(o.merge.total_seconds() // 60)} min)"
+ (f"; {len(ranges)} of at least {o.min_measurements} measurements out of {total}" if o.min_measurements > 1 else ""))
print(f"{'sensor':9}{'start':<18}{'end':<18}{'measurements':>13}{'extreme':>10}{'(noises)':>9} {'at':<17}{'rejected':>9}")
print(f"{'sensor':{w}}{'start':<18}{'end':<18}{'measurements':>13}{'extreme':>11}{'(noises)':>9} {'at':<17}{'rejected':>9}")
for s, g, noise, rej in ranges:
t, d = max(g, key=lambda x: abs(x[1]))
print(f"{s:9}{iso(g[0][0]):<18}{iso(g[-1][0]):<18}{len(g):13}{d:+10.4g}{d / noise:9.1f} {iso(t):<17}"
print(f"{s:{w}}{iso(g[0][0]):<18}{iso(g[-1][0]):<18}{len(g):13}{d:+11.4g}{d / noise:9.1f} {iso(t):<17}"
f"{sum(x[0] in rej for x in g):9}{' rejected extreme' if t in rej else ''}")
if not ranges:
print("(none)")