Scripts: shared helpers in common.py, no tool imports another; CLI and outputs unchanged

data.py stays the reader (METRIC_RE now also captures the file date, same matches);
common.py holds columns, steps, noise, sensor list, runs, file names. Duplicated
run grouping, pose gaps, step bucketing, --table/--outside parsing removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maximeandClaude Opus 5.5 committed 2026-11-16 15:48:42 +01:00
1 parent c1719cbd1d
commit 6ed4c420e1
13 files changed
+308 -359

No files matched your search

+4 -47
View File
@@ -34,10 +34,8 @@ matplotlib.use("Agg")
import matplotlib.dates as mdates # noqa: E402
import matplotlib.pyplot as plt # noqa: E402
from data import POSE, filter_window, is_reference, iso, load, load_camera, load_temperature, parse_time # noqa: E402
from inventory import METRIC_RE # noqa: E402
from plot import bound # noqa: E402
from summary import STATS, duration # noqa: E402
from common import STATS, bound, cut, duration, group, targets # noqa: E402
from data import METRIC_RE, POSE, filter_window, iso, load, load_camera, load_temperature, parse_time # noqa: E402
def is_identifier(name):
@@ -76,20 +74,6 @@ def read_metrics(folder, start, end):
return {n: filter_window([{"t": t, "v": s[t]} for t in sorted(s)], start, end) for n, s in by_name.items()}
def targets(by_sensor, col, start, end):
"""At each measurement, median over the targets of col minus the target's own level (median over the window)."""
deviations = {}
for s, ms in by_sensor.items():
if is_reference(ms):
continue
ms = [m for m in filter_window(ms, start, end) if m[col] is not None]
if ms:
level = statistics.median(m[col] for m in ms)
for m in ms:
deviations.setdefault(m["t"], []).append(m[col] - level)
return [{"t": t, "v": statistics.median(v)} for t, v in sorted(deviations.items())]
def smooth(series, width):
"""Moving average centred over width (numeric values)."""
pts = [p for p in series if isinstance(p["v"], float)]
@@ -101,33 +85,6 @@ def fmt(v):
return "-" if v is None else f"{v:.6g}" if isinstance(v, float) else str(v)
def runs(empty_steps, step):
"""[t] sorted -> [(start, end, n)] of consecutive steps."""
out = []
for t in empty_steps:
if out and t - out[-1][1] == step:
out[-1] = (out[-1][0], t, out[-1][2] + 1)
else:
out.append((t, t, 1))
return out
def cut(series):
"""Times and numeric values, NaN inserted over a gap of more than 1.5 times the usual step (the line breaks)."""
pts = [(p["t"], p["v"]) for p in series if isinstance(p["v"], float)]
if len(pts) < 3:
return [t for t, _ in pts], [v for _, v in pts]
step = statistics.median(b[0] - a[0] for a, b in zip(pts, pts[1:]))
ts, vs = [pts[0][0]], [pts[0][1]]
for (a, _), (b, v) in zip(pts, pts[1:]):
if b - a > 1.5 * step:
ts.append(a + (b - a) / 2)
vs.append(float("nan"))
ts.append(b)
vs.append(v)
return ts, vs
def main():
a = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
a.add_argument("folder")
@@ -229,8 +186,8 @@ def main():
empty = [k for k in grid if all(k not in table.get(c, {}) for c in metric_cols)]
print(f"\nSteps without any metric ({', '.join(metric_cols)}): {len(empty)} of {len(grid)}")
for d, f, n in runs(empty, step):
print(f" {iso(d)} → {iso(f)} ({n} steps)")
for g in group(empty, lambda a, b: b - a == step):
print(f" {iso(g[0])} → {iso(g[-1])} ({len(g)} steps)")
panels = {} # title -> columns
for c in columns: