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 <noreply@anthropic.com>
This commit is contained in:
1 parent
cccdeae67e
commit
cae07a2787
3 files changed
+35
-18
No files matched your search
@@ -78,8 +78,9 @@ def curves(station_: str = Query(alias="station"), start: str = "", end: str = "
|
|||||||
|
|
||||||
|
|
||||||
@app.get("/api/detectors")
|
@app.get("/api/detectors")
|
||||||
def detectors(station_: str = Query(alias="station"), start: str = "", end: str = "", targets: str = "", set_: str = Query("classic", alias="set")):
|
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_)
|
sensitivity: int = 0):
|
||||||
|
return station.detectors(station_, start, end, targets, set_, sensitivity)
|
||||||
|
|
||||||
|
|
||||||
@app.get("/api/tracked")
|
@app.get("/api/tracked")
|
||||||
|
|||||||
+12
-6
@@ -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)")
|
"pickle.dump(categories.window(*pickle.load(sys.stdin.buffer)), out)")
|
||||||
|
|
||||||
|
|
||||||
def window(set_, every, a, b):
|
def window(set_, every, a, b, sensitivity=0):
|
||||||
"""categories.window of the chosen set."""
|
"""categories.window of the chosen set; sensitivity (1 to 10, 0: the default of the code): the manual set only."""
|
||||||
if set_ != "manual":
|
if set_ != "manual":
|
||||||
return categories.window(every, a, b)
|
return categories.window(every, a, b)
|
||||||
if not (MANUAL / "categories.py").is_file():
|
if not (MANUAL / "categories.py").is_file():
|
||||||
raise Refusal("no manual detectors: detectors/manual/ has no categories.py")
|
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"))
|
sys.stderr.write(run.stderr.decode(errors="replace"))
|
||||||
if run.returncode:
|
if run.returncode:
|
||||||
raise Refusal("the manual detectors failed: " + (run.stderr.decode(errors="replace").strip().splitlines() or ["?"])[-1])
|
raise Refusal("the manual detectors failed: " + (run.stderr.decode(errors="replace").strip().splitlines() or ["?"])[-1])
|
||||||
return pickle.loads(run.stdout)
|
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
|
# 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)
|
@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,
|
"""-> 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
|
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)
|
d = folder(station)
|
||||||
every = data.load(d)
|
every = data.load(d)
|
||||||
if targets:
|
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"],
|
"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],
|
"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)}
|
"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
|
# --- the labels
|
||||||
|
|||||||
+20
-10
@@ -1,6 +1,6 @@
|
|||||||
import { useEffect, useMemo, useRef, useState } from "react";
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
import {
|
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,
|
useComputedColorScheme,
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import { IconPlus, IconX } from "@tabler/icons-react";
|
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,
|
// labels), or Support (LLM's labels; dragging selects a range, on which the support answers a question); elsewhere,
|
||||||
// dragging zooms; a click opens a
|
// dragging zooms; a click opens a
|
||||||
// label and highlights it. On the right, the images of the station, and under them the diagnostic settings.
|
// 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" };
|
"Target issue": "#e6d46a", "No data": "#c4c4be", "None": "#a8d5a2" };
|
||||||
const FAMILY_NAME = f => (f === "None" ? "None (curves intact)" : f);
|
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)" },
|
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
|
// 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)
|
// 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" },
|
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 [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 [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 [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 [cut, setCut] = useState(false); // the points under a label of the checked families removed, the curves joined
|
||||||
const { station, start, end } = selection;
|
const { station, start, end } = selection;
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -76,7 +78,7 @@ export default function Data({ selection, choose, analysis, setAnalysis, support
|
|||||||
{loading && <Loader />}
|
{loading && <Loader />}
|
||||||
{data && <TargetFilter d={data} hidden={hidden} setHidden={setHidden} />}
|
{data && <TargetFilter d={data} hidden={hidden} setHidden={setHidden} />}
|
||||||
{data && <Curves key={`${station}${start}${end}`} selection={selection} d={data} setImage={(t, nearest) => setMoment({ t, nearest })}
|
{data && <Curves key={`${station}${start}${end}`} selection={selection} d={data} setImage={(t, nearest) => setMoment({ t, nearest })}
|
||||||
source={source} setSource={setSource} families={families} targets={targets} focus={focus} hidden={hidden} cut={cut} set={set}
|
source={source} setSource={setSource} families={families} targets={targets} focus={focus} hidden={hidden} cut={cut} set={set} sensitivity={sensitivity}
|
||||||
analysis={analysis} setAnalysis={setAnalysis} support={support} setSupport={setSupport} />}
|
analysis={analysis} setAnalysis={setAnalysis} support={support} setSupport={setSupport} />}
|
||||||
</Stack>
|
</Stack>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
@@ -86,7 +88,8 @@ export default function Data({ selection, choose, analysis, setAnalysis, support
|
|||||||
<StationImages selection={selection} compact wide={wide} toggle={() => setWide(!wide)} moment={moment} />
|
<StationImages selection={selection} compact wide={wide} toggle={() => setWide(!wide)} moment={moment} />
|
||||||
{data && <Settings key={`${station}${start}${end}`} d={data} families={families} setFamilies={setFamilies}
|
{data && <Settings key={`${station}${start}${end}`} d={data} families={families} setFamilies={setFamilies}
|
||||||
targets={targets} setTargets={setTargets} detect={source === "detectors"}
|
targets={targets} setTargets={setTargets} detect={source === "detectors"}
|
||||||
focus={focus} setFocus={setFocus} cut={cut} setCut={setCut} set={set} setSet={setSet} />}
|
focus={focus} setFocus={setFocus} cut={cut} setCut={setCut} set={set} setSet={setSet}
|
||||||
|
sensitivity={sensitivity} setSensitivity={setSensitivity} />}
|
||||||
</Stack>
|
</Stack>
|
||||||
</div>
|
</div>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
@@ -118,7 +121,7 @@ function TargetFilter({ d, hidden, setHidden }) {
|
|||||||
|
|
||||||
// The families apply at once (filter of the page, Detectors and LLM); the targets, with the button: each set of targets
|
// The families apply at once (filter of the page, Detectors and LLM); the targets, with the button: each set of targets
|
||||||
// runs the detectors again (the LLM labels do not state their sensors: they do not filter them)
|
// runs the detectors again (the LLM labels do not state their sensors: they do not filter them)
|
||||||
function Settings({ d, families, setFamilies, targets, setTargets, detect, focus, setFocus, cut, setCut, set, setSet }) {
|
function Settings({ d, families, setFamilies, targets, setTargets, detect, focus, setFocus, cut, setCut, set, setSet, sensitivity, setSensitivity }) {
|
||||||
const sensors = Object.keys(d.T).filter(k => k && !k.startsWith("system:"));
|
const sensors = Object.keys(d.T).filter(k => k && !k.startsWith("system:"));
|
||||||
const refs = new Set(d.plots.flatMap(p => p.traces).filter(t => t.name.endsWith(" (ref.)")).map(t => t.t));
|
const refs = new Set(d.plots.flatMap(p => p.traces).filter(t => t.name.endsWith(" (ref.)")).map(t => t.t));
|
||||||
const [checked, setChecked] = useState(targets ? targets.split(",") : sensors);
|
const [checked, setChecked] = useState(targets ? targets.split(",") : sensors);
|
||||||
@@ -132,6 +135,13 @@ function Settings({ d, families, setFamilies, targets, setTargets, detect, focus
|
|||||||
<SegmentedControl size="xs" mt={4} value={set} onChange={setSet}
|
<SegmentedControl size="xs" mt={4} value={set} onChange={setSet}
|
||||||
data={[{ value: "classic", label: "Classic" }, { value: "manual", label: "Manual (detectors/manual/)" }]} />
|
data={[{ value: "classic", label: "Classic" }, { value: "manual", label: "Manual (detectors/manual/)" }]} />
|
||||||
</div>
|
</div>
|
||||||
|
{set === "manual" && <div>
|
||||||
|
<Text size="sm" fw={500}>Sensitivity: {sensitivity}</Text>
|
||||||
|
<Text size="xs" c="dimmed">1 tolerant, 10 severe: the limits of the manual detectors halved every 2 steps (5: as written)</Text>
|
||||||
|
{/* key: the slider starts again from the value kept when the set is chosen again; onChangeEnd: the detectors run on release */}
|
||||||
|
<Slider key={set} mt={6} mb={18} min={1} max={10} step={1} defaultValue={sensitivity} onChangeEnd={setSensitivity}
|
||||||
|
marks={[1, 5, 10].map(v => ({ value: v, label: String(v) }))} />
|
||||||
|
</div>}
|
||||||
<Switch label="Focus on event curves" description="With an event open, the plots show only its sensors"
|
<Switch label="Focus on event curves" description="With an event open, the plots show only its sensors"
|
||||||
checked={focus} onChange={e => setFocus(e.currentTarget.checked)} />
|
checked={focus} onChange={e => setFocus(e.currentTarget.checked)} />
|
||||||
<Switch label="Remove labeled points" description="The points under a label of the families shown leave the plots; the curves join over the holes"
|
<Switch label="Remove labeled points" description="The points under a label of the families shown leave the plots; the curves join over the holes"
|
||||||
@@ -169,7 +179,7 @@ const mentions = (text, s) => new RegExp(`(^|[^\\w])${s.replace(/[^\w]/g, "\\$&"
|
|||||||
const sensorsOf = (l, names) => l.sensors ?? names.filter(s => mentions(l.description, s));
|
const sensorsOf = (l, names) => l.sensors ?? names.filter(s => mentions(l.description, s));
|
||||||
|
|
||||||
// analysis, support: the folder of the analysis, of the support request shown, held by App (the sidebar opens one)
|
// analysis, support: the folder of the analysis, of the support request shown, held by App (the sidebar opens one)
|
||||||
function Curves({ selection: { station, start, end }, d, setImage, source, setSource, families, targets, focus, hidden, cut, set, analysis, setAnalysis,
|
function Curves({ selection: { station, start, end }, d, setImage, source, setSource, families, targets, focus, hidden, cut, set, sensitivity, analysis, setAnalysis,
|
||||||
support, setSupport }) {
|
support, setSupport }) {
|
||||||
const { A, B, T, plots: PLOTS } = d;
|
const { A, B, T, plots: PLOTS } = d;
|
||||||
const plotIndex = (title, otherwise) => { const i = PLOTS.findIndex(p => p.title === title); return i < 0 ? otherwise : i; };
|
const plotIndex = (title, otherwise) => { const i = PLOTS.findIndex(p => p.title === title); return i < 0 ? otherwise : i; };
|
||||||
@@ -361,14 +371,14 @@ function Curves({ selection: { station, start, end }, d, setImage, source, setSo
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let alive = true;
|
let alive = true;
|
||||||
setReading(true);
|
setReading(true);
|
||||||
const url = source === "detectors" ? `/api/detectors?${new URLSearchParams({ station, start, end, targets, set })}`
|
const url = source === "detectors" ? `/api/detectors?${new URLSearchParams({ station, start, end, targets, set, ...(set === "manual" && { sensitivity }) })}`
|
||||||
: `/api/labels?${new URLSearchParams({ station, folder })}`;
|
: `/api/labels?${new URLSearchParams({ station, folder })}`;
|
||||||
call(url).then(l => {
|
call(url).then(l => {
|
||||||
if (!alive) return; // another source was chosen in the meantime
|
if (!alive) return; // another source was chosen in the meantime
|
||||||
setReading(false); setAllLabels(l || []);
|
setReading(false); setAllLabels(l || []);
|
||||||
});
|
});
|
||||||
return () => { alive = false; };
|
return () => { alive = false; };
|
||||||
}, [source, targets, set, rev]);
|
}, [source, targets, set, sensitivity, rev]);
|
||||||
|
|
||||||
// One more plot: the first one the page does not show yet, vertical displacement first
|
// One more plot: the first one the page does not show yet, vertical displacement first
|
||||||
function addPlot() {
|
function addPlot() {
|
||||||
|
|||||||
Reference in new issue
Block a user