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 <noreply@anthropic.com>
This commit is contained in:
1 parent
d34828ab5e
commit
7332306b79
1 file changed
+13
-24
+13
-24
@@ -7,7 +7,6 @@ labeling/{auto,manual}/. What brings data in (the pumping, the list of the track
|
|||||||
"""
|
"""
|
||||||
import bisect
|
import bisect
|
||||||
import functools
|
import functools
|
||||||
import csv
|
|
||||||
import glob
|
import glob
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
@@ -51,8 +50,6 @@ PLOTS = (("error_value", "Error value"), ("x", "X [px]"), ("y", "Y [px]"),
|
|||||||
("reproj_err", "References (reproj. error)"))
|
("reproj_err", "References (reproj. error)"))
|
||||||
QUALITY = (("peak", "Quality: Peak"), ("flux", "Quality: Flux"), ("sharpness", "Quality: Sharpness"),
|
QUALITY = (("peak", "Quality: Peak"), ("flux", "Quality: Flux"), ("sharpness", "Quality: Sharpness"),
|
||||||
("fwhm", "Quality: FWHM [px]"), ("dominance", "Quality: Dominance"), ("snr", "Quality: SNR"))
|
("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):
|
class Refusal(ValueError):
|
||||||
@@ -122,24 +119,14 @@ def image(station, name):
|
|||||||
|
|
||||||
# --- the curves of the Data page
|
# --- the curves of the Data page
|
||||||
|
|
||||||
def metrics(d, a, b):
|
def holes(points, step=timedelta(hours=1)):
|
||||||
"""The numeric system metrics of metrics/ over [a, b) -> {name: {t: value or None}} (an empty value: None, the gap
|
"""[(t, v)] sorted -> the same, with (t + step, None) after a point followed by nothing during more than a step."""
|
||||||
shows), without the text metrics, the identifiers, or those with no value at all."""
|
out = []
|
||||||
station, series, text = d.name + "_", {}, set()
|
for t, v in points:
|
||||||
for p in sorted(glob.glob(str(d / "metrics" / "*.csv"))):
|
if out and t - out[-1][0] > step:
|
||||||
if not (m := METRIC.match(os.path.basename(p))) or IDENTIFIER.match(name := m.group(1).removeprefix(station)):
|
out.append((out[-1][0] + step, None))
|
||||||
continue
|
out.append((t, v))
|
||||||
with open(p, newline="") as f:
|
return out
|
||||||
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 span(measurements, start, end):
|
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]})
|
"line": {"width": 1.2, "color": col}} for c, col in POSE]})
|
||||||
per_sensor(QUALITY)
|
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()}}
|
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):
|
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",
|
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]}}]})
|
"line": {"width": 1.2, "color": COLORS[0]}}]})
|
||||||
if not out:
|
if not out:
|
||||||
raise Refusal(f"no measurement of {station} in this range")
|
raise Refusal(f"no measurement of {station} in this range")
|
||||||
|
|||||||
Reference in new issue
Block a user