From 7332306b7999dbc8bb63ea279e09931dc0dd1869 Mon Sep 17 00:00:00 2001 From: maxime Date: Tue, 17 Nov 2026 09:20:17 +0100 Subject: [PATCH] Data: the system metrics read by tools/scripts/data.py (load_metrics), the copy of the app removed; a hole breaks the line Co-Authored-By: Claude Opus 5.5 --- app/server/station.py | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/app/server/station.py b/app/server/station.py index bd380fb..0c2585c 100644 --- a/app/server/station.py +++ b/app/server/station.py @@ -7,7 +7,6 @@ labeling/{auto,manual}/. What brings data in (the pumping, the list of the track """ import bisect import functools -import csv import glob import json import os @@ -51,8 +50,6 @@ PLOTS = (("error_value", "Error value"), ("x", "X [px]"), ("y", "Y [px]"), ("reproj_err", "References (reproj. error)")) QUALITY = (("peak", "Quality: Peak"), ("flux", "Quality: Flux"), ("sharpness", "Quality: Sharpness"), ("fwhm", "Quality: FWHM [px]"), ("dominance", "Quality: Dominance"), ("snr", "Quality: SNR")) -IDENTIFIER = re.compile(r"(SIM_CCID|ip(_.*)?)$") # never read (CLAUDE.md, "data/") -METRIC = re.compile(r"^(.+?)_\d{4}_\d{2}_\d{2}_") class Refusal(ValueError): @@ -122,24 +119,14 @@ def image(station, name): # --- the curves of the Data page -def metrics(d, a, b): - """The numeric system metrics of metrics/ over [a, b) -> {name: {t: value or None}} (an empty value: None, the gap - shows), without the text metrics, the identifiers, or those with no value at all.""" - station, series, text = d.name + "_", {}, set() - for p in sorted(glob.glob(str(d / "metrics" / "*.csv"))): - if not (m := METRIC.match(os.path.basename(p))) or IDENTIFIER.match(name := m.group(1).removeprefix(station)): - continue - with open(p, newline="") as f: - for r in csv.DictReader(f): - t, v = data.parse_time(r["time_utc"]), (r.get("metric") or "").strip("[]'\" ") - if not a <= t < b: - continue - try: - series.setdefault(name, {})[t] = float(v) if v else None - except ValueError: - text.add(name) # link, mode…: no curve - return {n: dict(sorted(s.items())) for n, s in series.items() - if n not in text and any(v is not None for v in s.values())} +def holes(points, step=timedelta(hours=1)): + """[(t, v)] sorted -> the same, with (t + step, None) after a point followed by nothing during more than a step.""" + out = [] + for t, v in points: + if out and t - out[-1][0] > step: + out.append((out[-1][0] + step, None)) + out.append((t, v)) + return out def span(measurements, start, end): @@ -178,11 +165,13 @@ def curves(station, start, end): "line": {"width": 1.2, "color": col}} for c, col in POSE]}) per_sensor(QUALITY) T = {"": [hour(p["t"]) for p in poses], **{s: [hour(m["t"]) for m in ms] for s, ms in inside.items()}} - system = metrics(d, a, b) + # the numeric system metrics (data.load_metrics: without the text metrics and the identifiers), over [a, b); an + # hour without value breaks the line (None), the hole shows + system = {n: holes(kept) for n, vs in data.load_metrics(d).items() if (kept := [(t, v) for t, v in vs if a <= t < b])} for name in sorted(system, key=str.lower): - T["system:" + name] = [hour(t) for t in system[name]] + T["system:" + name] = [hour(t) for t, _ in system[name]] out.append({"title": "System: " + name, "traces": [{"name": name, "t": "system:" + name, "mode": "lines+markers", - "y": [None if v is None else round(v, 5) for v in system[name].values()], + "y": [None if v is None else round(v, 5) for _, v in system[name]], "line": {"width": 1.2, "color": COLORS[0]}}]}) if not out: raise Refusal(f"no measurement of {station} in this range")