2026-11-20 08:28:19 +01:00
|
|
|
"""The Points page: the point labels of labeling/points/, one boolean per measurement (valid or not) on a range, set by
|
|
|
|
|
the user. Their format, their files and their check are labeling/scripts/points.py; the measurements are read by
|
2026-11-20 08:31:18 +01:00
|
|
|
tools/scripts/data.py, as everywhere. A station of data/ or a run of the emulator (<SERIAL>@<run>), each its own points.
|
2026-11-20 08:28:19 +01:00
|
|
|
"""
|
|
|
|
|
import threading
|
|
|
|
|
|
|
|
|
|
import station
|
|
|
|
|
from station import Refusal, data
|
|
|
|
|
|
|
|
|
|
import points # noqa: E402 (labeling/scripts, on the path through station)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def refused(f):
|
|
|
|
|
def wrapped(*a):
|
|
|
|
|
try:
|
|
|
|
|
return f(*a)
|
|
|
|
|
except (ValueError, FileNotFoundError) as e:
|
|
|
|
|
raise Refusal(str(e)) from e
|
|
|
|
|
return wrapped
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def summary(n):
|
|
|
|
|
p = points.read(n)
|
|
|
|
|
s, start, end = points.parts(n)
|
|
|
|
|
return {"name": n, "station": s, "start": start, "end": end, "points": len(p), "invalid": sum(not v for v in p.values())}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@refused
|
|
|
|
|
def listing(st=""):
|
|
|
|
|
return [summary(n) for n in points.datasets(st or None)]
|
|
|
|
|
|
|
|
|
|
|
2026-11-20 08:41:06 +01:00
|
|
|
def measured(st, a, b):
|
|
|
|
|
"""-> {sensor: [t]}: the points of [a, b), every measurement with a relative position, the rejected ones included
|
|
|
|
|
(labeling/scripts/points.py)."""
|
|
|
|
|
return {s: [m["t"] for m in ms if a <= m["t"] < b and m["relative_x"] is not None and m["relative_y"] is not None]
|
|
|
|
|
for s, ms in data.load(station.folder(st)).items()}
|
|
|
|
|
|
|
|
|
|
|
2026-11-20 08:28:19 +01:00
|
|
|
@refused
|
|
|
|
|
def create(body):
|
|
|
|
|
st, start, end = body.get("station", ""), body.get("start", ""), body.get("end", "")
|
|
|
|
|
n = points.name(st, start, end)
|
2026-11-20 08:41:06 +01:00
|
|
|
points.create(n, measured(st, *station.bounds(start, end)))
|
2026-11-20 08:28:19 +01:00
|
|
|
return summary(n)
|
|
|
|
|
|
|
|
|
|
|
2026-11-20 08:41:06 +01:00
|
|
|
# the plots of the page, in their order: rx, ry, the recognition error and its threshold, the image quality
|
|
|
|
|
COLUMNS = ("relative_x", "relative_y", "error_value", "error_threshold", "peak", "flux", "sharpness", "fwhm", "dominance", "snr")
|
|
|
|
|
|
|
|
|
|
|
2026-11-20 08:28:19 +01:00
|
|
|
@refused
|
|
|
|
|
def dataset(n):
|
2026-11-20 08:41:06 +01:00
|
|
|
"""-> {name, station, start, end, sensors: {sensor: {t, valid, columns: {column: [value]}}}}: the COLUMNS of each
|
|
|
|
|
point, None where the data no longer have it (a pumping or a run again); a column empty for the sensor left out."""
|
2026-11-20 08:28:19 +01:00
|
|
|
p, st = points.read(n), points.parts(n)[0]
|
|
|
|
|
now = {(s, points.time(m["t"])): m for s, ms in data.load(station.folder(st)).items() for m in ms}
|
|
|
|
|
out = {}
|
|
|
|
|
for (s, t), v in sorted(p.items()):
|
2026-11-20 08:41:06 +01:00
|
|
|
m, o = now.get((s, t), {}), out.setdefault(s, {"t": [], "valid": [], "columns": {c: [] for c in COLUMNS}})
|
2026-11-20 08:28:19 +01:00
|
|
|
o["t"].append(t[:19].replace("T", " ")) # as Plotly shows it, UTC
|
|
|
|
|
o["valid"].append(v)
|
2026-11-20 08:41:06 +01:00
|
|
|
for c in COLUMNS:
|
|
|
|
|
o["columns"][c].append(m.get(c))
|
|
|
|
|
for o in out.values():
|
|
|
|
|
o["columns"] = {c: vs for c, vs in o["columns"].items() if any(x is not None for x in vs)}
|
2026-11-20 08:28:19 +01:00
|
|
|
return {**summary(n), "sensors": out}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LOCK = threading.Lock() # the requests run in threads: two marks never read and write the file at the same time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@refused
|
|
|
|
|
def mark(n, body):
|
|
|
|
|
"""{sensor, times (as the page shows them), valid} -> the summary."""
|
|
|
|
|
times = [t.replace(" ", "T") + "Z" for t in body.get("times", [])]
|
|
|
|
|
with LOCK:
|
|
|
|
|
points.mark(n, body.get("sensor", ""), times, bool(body.get("valid")))
|
|
|
|
|
return summary(n)
|