From cae07a278708dc228fde56e3755874883cdfff6a Mon Sep 17 00:00:00 2001 From: maxime Date: Wed, 25 Nov 2026 11:45:39 +0100 Subject: [PATCH] Detectors of the Data page: a sensitivity setting (1 to 10, 0 = the code's default) passed to categories.window of the manual set Co-Authored-By: Claude Opus 5.5 --- app/server/server.py | 5 +++-- app/server/station.py | 18 ++++++++++++------ app/web/src/pages/Data.jsx | 30 ++++++++++++++++++++---------- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/app/server/server.py b/app/server/server.py index 531e3e3..be136b5 100644 --- a/app/server/server.py +++ b/app/server/server.py @@ -78,8 +78,9 @@ def curves(station_: str = Query(alias="station"), start: str = "", end: str = " @app.get("/api/detectors") -def detectors(station_: str = Query(alias="station"), start: str = "", end: str = "", targets: str = "", set_: str = Query("classic", alias="set")): - return station.detectors(station_, start, end, targets, set_) +def detectors(station_: str = Query(alias="station"), start: str = "", end: str = "", targets: str = "", set_: str = Query("classic", alias="set"), + sensitivity: int = 0): + return station.detectors(station_, start, end, targets, set_, sensitivity) @app.get("/api/tracked") diff --git a/app/server/station.py b/app/server/station.py index c269b77..8d1f974 100644 --- a/app/server/station.py +++ b/app/server/station.py @@ -273,25 +273,31 @@ CHILD = ("import pickle, sys; out, sys.stdout = sys.stdout.buffer, sys.stderr; s "pickle.dump(categories.window(*pickle.load(sys.stdin.buffer)), out)") -def window(set_, every, a, b): - """categories.window of the chosen set.""" +def window(set_, every, a, b, sensitivity=0): + """categories.window of the chosen set; sensitivity (1 to 10, 0: the default of the code): the manual set only.""" if set_ != "manual": return categories.window(every, a, b) if not (MANUAL / "categories.py").is_file(): raise Refusal("no manual detectors: detectors/manual/ has no categories.py") - run = subprocess.run([sys.executable, "-c", CHILD, str(MANUAL)], input=pickle.dumps((every, a, b)), capture_output=True, cwd=ROOT) + run = subprocess.run([sys.executable, "-c", CHILD, str(MANUAL)], input=pickle.dumps((every, a, b, sensitivity or None)), capture_output=True, cwd=ROOT) sys.stderr.write(run.stderr.decode(errors="replace")) if run.returncode: raise Refusal("the manual detectors failed: " + (run.stderr.decode(errors="replace").strip().splitlines() or ["?"])[-1]) return pickle.loads(run.stdout) +def detectors(station, start, end, targets="", set_="classic", sensitivity=0): + """journal(), from the cache for the classic set; the manual set, being written, computed again at each call.""" + return (journal.__wrapped__ if set_ == "manual" else journal)(station, start, end, targets, set_, sensitivity) + + # ponytail: kept until the server restarts (a minute or more per range); restart it after an /optimize run outside the app @functools.lru_cache(maxsize=32) -def detectors(station, start, end, targets="", set_="classic"): +def journal(station, start, end, targets="", set_="classic", sensitivity=0): """-> the detectors' events over the range, in the label format (start, end, family, description); plus kind, sensors, ignore (greyed area of the journal). targets: the sensors kept, comma-separated (empty: all); the others are - removed before the detectors, as if they did not exist. set_: classic (detectors/scripts/) or manual (detectors/manual/).""" + removed before the detectors, as if they did not exist. set_: classic (detectors/scripts/) or manual (detectors/manual/); + sensitivity: of the manual set, 1 (tolerant) to 10 (severe), 0: the default of the code.""" d = folder(station) every = data.load(d) if targets: @@ -305,7 +311,7 @@ def detectors(station, start, end, targets="", set_="classic"): "description": f"{ep['label']}. {v['text']}", "sensors": v["sensors"], "ignore": v["ignore"], "targets": [s for s in v["sensors"] if s not in refs], "references": [s for s in v["sensors"] if s in refs], "message": client.message(v["text"]), "action": client.action(v["category"], ep["label"], ep.get("level"), advice)} - for i, v in enumerate(window(set_, every, a, b))] + for i, v in enumerate(window(set_, every, a, b, sensitivity))] # --- the labels diff --git a/app/web/src/pages/Data.jsx b/app/web/src/pages/Data.jsx index cee68b2..25125eb 100644 --- a/app/web/src/pages/Data.jsx +++ b/app/web/src/pages/Data.jsx @@ -1,6 +1,6 @@ import { useEffect, useMemo, useRef, useState } from "react"; import { - ActionIcon, Badge, Button, Card, Checkbox, Grid, Group, Loader, NativeSelect, SegmentedControl, SimpleGrid, Stack, Switch, Text, Textarea, TextInput, Title, Tooltip, + ActionIcon, Badge, Button, Card, Checkbox, Grid, Group, Loader, NativeSelect, SegmentedControl, SimpleGrid, Slider, Stack, Switch, Text, Textarea, TextInput, Title, Tooltip, useComputedColorScheme, } from "@mantine/core"; import { IconPlus, IconX } from "@tabler/icons-react"; @@ -13,12 +13,13 @@ import { StationImages } from "./Images.jsx"; // labels), or Support (LLM's labels; dragging selects a range, on which the support answers a question); elsewhere, // dragging zooms; a click opens a // label and highlights it. On the right, the images of the station, and under them the diagnostic settings. -const FAMILIES = { "Visibility": "#8ec5e8", "Obstruction": "#f0b072", "Thermal displacement": "#f08a7e", "Displacement": "#b39ddb", "Perturbation": "#9fd8d0", +const FAMILIES = { "Anomaly": "#e03131", "Visibility": "#8ec5e8", "Obstruction": "#f0b072", "Thermal displacement": "#f08a7e", "Displacement": "#b39ddb", "Perturbation": "#9fd8d0", "Target issue": "#e6d46a", "No data": "#c4c4be", "None": "#a8d5a2" }; const FAMILY_NAME = f => (f === "None" ? "None (curves intact)" : f); -// A label of auto/ has one of the seven families (labeling/scripts/validate.py); None is the expert's, in manual/ +// A label of auto/ has one of the seven families (labeling/scripts/validate.py); None is the expert's, in manual/; +// Anomaly, the detectors' alone (detectors/manual/events.py: something happened, without saying what) const FAMILY_CHOICES = [{ value: "", label: "(choose a family)" }, - ...Object.keys(FAMILIES).filter(f => f !== "None").map(f => ({ value: f, label: f }))]; + ...Object.keys(FAMILIES).filter(f => f !== "None" && f !== "Anomaly").map(f => ({ value: f, label: f }))]; // LLM and Analysis: the same labels, labeling/auto/; LLM reads them, Analysis edits, deletes them, and has the analyst make // some on a range (app/server/analysis.py); Support reads them, and asks the support a question on a range (support.py) const SOURCES = [{ value: "detectors", label: "Detectors" }, { value: "auto", label: "LLM" }, { value: "analysis", label: "Analysis" }, @@ -51,6 +52,7 @@ export default function Data({ selection, choose, analysis, setAnalysis, support const [focus, setFocus] = useState(false); // with an event open, the plots show only its sensors const [hidden, setHidden] = useState([]); // the targets removed from the plots (the detectors still read them) const [set, setSet] = useState("classic"); // the detectors: classic (detectors/scripts/) or manual (detectors/manual/) + const [sensitivity, setSensitivity] = useState(5); // of the manual set: 1 (tolerant) to 10 (severe); 5, its limits as written const [cut, setCut] = useState(false); // the points under a label of the checked families removed, the curves joined const { station, start, end } = selection; useEffect(() => { @@ -76,7 +78,7 @@ export default function Data({ selection, choose, analysis, setAnalysis, support {loading && } {data &&