Points: a page to set each measurement of a range valid or not, saved in labeling/points/ (labeling/scripts/points.py), the ground truth of the benchmarks point by point
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1133a91078
commit
dcd255ab1f
6 files changed
+228
-5
No files matched your search
+23
-1
@@ -47,6 +47,8 @@ def check_server():
|
||||
assert call("/api/stations") == 200
|
||||
assert call("/api/analyses") == 200
|
||||
assert call("/api/support") == 200
|
||||
assert call("/api/points") == 200
|
||||
assert call("/api/points/..%2Fx") in (400, 404)
|
||||
assert call("/api/support", {"station": "x"}) == 400
|
||||
assert call("/api/analyses/UNKNOWN/optimize", {}) == 400
|
||||
finally:
|
||||
@@ -427,7 +429,27 @@ def check_conversations():
|
||||
shutil.rmtree(root)
|
||||
|
||||
|
||||
CHECKS = [check_server, check_station, check_optimization, check_analysis, check_validation, check_support, check_conversations]
|
||||
def check_points():
|
||||
# the Points page: a dataset of the real data in a temporary folder; its format and its rules, labeling/scripts/points.py --test
|
||||
import validity
|
||||
before, validity.points.FOLDER = validity.points.FOLDER, str(temp_folder())
|
||||
try:
|
||||
n = validity.create({"station": "NIEDERHORN", "start": "2026-09-25", "end": "2026-09-26"})
|
||||
assert n["points"] and not n["invalid"] and validity.listing("NIEDERHORN") == [n], n
|
||||
d = validity.dataset(n["name"])
|
||||
s, o = next(iter(d["sensors"].items()))
|
||||
assert validity.mark(n["name"], {"sensor": s, "times": o["t"][:2], "valid": False})["invalid"] == 2
|
||||
refuses(validity.create, {"station": "NIEDERHORN", "start": "2026-09-25", "end": "2026-09-26"}) # exists
|
||||
refuses(validity.create, {"station": "NIEDERHORN@run", "start": "2026-09-25", "end": "2026-09-26"})
|
||||
refuses(validity.dataset, "../x")
|
||||
refuses(validity.mark, n["name"], {"sensor": s, "times": ["2026-09-27 00:00:00"], "valid": False})
|
||||
finally:
|
||||
shutil.rmtree(validity.points.FOLDER)
|
||||
validity.points.FOLDER = before
|
||||
|
||||
|
||||
CHECKS = [check_server, check_station, check_optimization, check_analysis, check_validation, check_support, check_conversations,
|
||||
check_points]
|
||||
|
||||
if __name__ == "__main__":
|
||||
name = sys.argv[1] if len(sys.argv) > 1 else None
|
||||
|
||||
@@ -23,6 +23,7 @@ import analysis
|
||||
import conversations
|
||||
import station
|
||||
import support
|
||||
import validity
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
APP = Path(__file__).resolve().parents[1]
|
||||
@@ -202,6 +203,28 @@ def support_file(name: str, path: str):
|
||||
return FileResponse(analysis.file(name, path, support.FOLDER))
|
||||
|
||||
|
||||
# --- the Points page (validity.py): the point labels of labeling/points/, valid or not, set by the user
|
||||
|
||||
@app.get("/api/points")
|
||||
def points_list(station_: str = Query("", alias="station")):
|
||||
return validity.listing(station_)
|
||||
|
||||
|
||||
@app.post("/api/points")
|
||||
def points_create(body: dict):
|
||||
return validity.create(body)
|
||||
|
||||
|
||||
@app.get("/api/points/{name}")
|
||||
def points_dataset(name: str):
|
||||
return validity.dataset(name)
|
||||
|
||||
|
||||
@app.put("/api/points/{name}")
|
||||
def points_mark(name: str, body: dict):
|
||||
return validity.mark(name, body)
|
||||
|
||||
|
||||
# --- the Conversations page (conversations.py): the LibreDesk conversations, pumped read-only, and their transcripts
|
||||
|
||||
CSP = "default-src 'none'; img-src 'self'; style-src 'unsafe-inline'" # a client's mail: no script, no remote image
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
"""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
|
||||
tools/scripts/data.py, as everywhere. A station of data/ only (a run of data_diff/ refused).
|
||||
"""
|
||||
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)]
|
||||
|
||||
|
||||
@refused
|
||||
def create(body):
|
||||
st, start, end = body.get("station", ""), body.get("start", ""), body.get("end", "")
|
||||
station.pumped(st)
|
||||
n = points.name(st, start, end)
|
||||
a, b = station.bounds(start, end)
|
||||
points.create(n, {s: [m["t"] for m in ms if a <= m["t"] < b and m["corr_x"] is not None and m["corr_y"] is not None]
|
||||
for s, ms in data.load(station.folder(st)).items()})
|
||||
return summary(n)
|
||||
|
||||
|
||||
@refused
|
||||
def dataset(n):
|
||||
"""-> {name, station, start, end, sensors: {sensor: {t, x, y, valid}}}: corr_x, corr_y (px, the curves labelled) of
|
||||
each point, None where the data no longer have it (a pumping again)."""
|
||||
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()):
|
||||
m, o = now.get((s, t), {}), out.setdefault(s, {"t": [], "x": [], "y": [], "valid": []})
|
||||
o["t"].append(t[:19].replace("T", " ")) # as Plotly shows it, UTC
|
||||
o["x"].append(m.get("corr_x"))
|
||||
o["y"].append(m.get("corr_y"))
|
||||
o["valid"].append(v)
|
||||
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)
|
||||
Reference in new issue
Block a user