diff --git a/app/README.md b/app/README.md index ad98102..a93215f 100644 --- a/app/README.md +++ b/app/README.md @@ -1,6 +1,6 @@ # The AIMsight web app -The tool of the manual diagnostic: a single page, **Data**. +The tool of the manual diagnostic: two pages, **Data** and **Stations**. ## The Data page @@ -14,11 +14,14 @@ The tool of the manual diagnostic: a single page, **Data**. - **The camera images**, on the right, on the same station and the same range: slider, ◀ ▶ and keyboard arrows; wheel to zoom, drag to move, double click for the whole image; Names box; a range on the bar under the slider draws the displacement arrow of each sensor. An arrow at the top left enlarges the image and pushes the plots to the left; the reverse arrow brings it back. - **The diagnostic settings**, under the image: "Focus on event curves" (with an event open, the plots show only its sensors: those of the detectors, or those the text of a label names), the families shown and, for Detectors only, the targets considered, the others removed before the detectors ("Rerun the detectors", parameter `targets` of `/api/detectors`). -- **Stations and pumping** (button of the selector): the tracked stations, `extraction/stations.txt` of `~/aimsight-data` (`SERIAL [position]`), to edit (serial, position: `lat,lon` or a Swiss place), and the checked ones pumped (`extraction/pump.sh`, `--delay 300`) over a range (by default from 3 days before the range shown, the history of the detectors) or, without dates, their missing days up to now; the end of `out/pump.log` follows, and the page loads again at the end of the pumping. - **The weather**: a station with a position gets, at Load, the hourly measurements of the nearest MeteoSwiss station (`weather/meteoswiss.py`) as plots "Weather: …", next to the "System: …" ones; the place found and the station chosen are written under the selector (check them: the search of a place always returns its best match). The address keeps the station and the range (UTC, `end` excluded): `#/data?station=NIEDERHORN&start=2026-09-25&end=2026-10-08`; without dates, the last 5 UTC days, today included. +## The Stations page + +The tracked stations, `extraction/stations.txt` of `~/aimsight-data` (`SERIAL [position]`), to edit (serial, position: `lat,lon` or a Swiss place, for the weather of Data), and the checked ones pumped (`extraction/pump.sh`, `--delay 300`) over a range (by default the station and the range of the address, from 3 days before: the history of the detectors) or, without dates, their missing days up to now; the end of `out/pump.log` follows. The end of a pumping launched by the app empties the cache of the detectors' events. + ## The Analysis tab - **Analyze the range**: a range selected, optional hints, then `server/analysis.py` launches the analyst of the agents repository by `claude -p` (non-interactive), with its instructions (`instructions/analyst.md`) and without the detectors (`DETECTORS: no`). It writes in `labeling/auto/analyses/__/` its labels and a diagnostic report (`report.md` and its figures; its work and claude's log in `work/`, outside git). The page follows its progress, then shows the report; the server submits its labels to `labeling/auto/.jsonl` (field `analysis`). "View the report" on such a label opens it again. diff --git a/app/web/src/App.jsx b/app/web/src/App.jsx index 372f0a7..2f58ae6 100644 --- a/app/web/src/App.jsx +++ b/app/web/src/App.jsx @@ -3,10 +3,11 @@ import { ActionIcon, AppShell, Burger, ColorSwatch, Group, Loader, NavLink, ScrollArea, Text, Tooltip, useComputedColorScheme, useMantineColorScheme, } from "@mantine/core"; import { useDisclosure } from "@mantine/hooks"; -import { IconChartLine, IconFolder, IconMoon, IconSun } from "@tabler/icons-react"; +import { IconChartLine, IconFolder, IconMoon, IconSatellite, IconSun } from "@tabler/icons-react"; const Data = lazy(() => import("./pages/Data.jsx")); // Plotly, loaded only here -const PAGES = [["data", "Data", IconChartLine]]; +const Stations = lazy(() => import("./pages/Stations.jsx")); +const PAGES = [["data", "Data", IconChartLine], ["stations", "Stations", IconSatellite]]; // The address: #/?station=…&start=…&end=…; reloading keeps the page and the selection, Back works; without dates, the // last 5 UTC days, today included (end excluded: tomorrow) @@ -113,7 +114,7 @@ export default function App() { return () => removeEventListener("hashchange", follow); }, []); - // the same address again (Load, the end of a pumping): read again, a new selection loads the data again + // the same address again (Load): read again, a new selection loads the data again const choose = s => { const a = address(page, s); if (location.hash === a) setPlace(readAddress()); else location.hash = a; }; // An analysis of the sidebar: Data on its station, days that cover its range (unless the range shown already covers them) function openAnalysis(a) { @@ -128,7 +129,10 @@ export default function App() {
- }> + }> + {page === "stations" ? + : } + ); diff --git a/app/web/src/common.jsx b/app/web/src/common.jsx index 67c3812..8f1ceea 100644 --- a/app/web/src/common.jsx +++ b/app/web/src/common.jsx @@ -1,7 +1,6 @@ -import { useEffect, useRef, useState } from "react"; -import { ActionIcon, Button, Card, Checkbox, Code, Group, Modal, ScrollArea, Select, Stack, Table, Text, TextInput } from "@mantine/core"; +import { useEffect, useState } from "react"; +import { Button, Card, Group, Select, TextInput } from "@mantine/core"; import { notifications } from "@mantine/notifications"; -import { IconPlus, IconX } from "@tabler/icons-react"; // A request to the API; a refusal of the server shows as a notification -> the JSON returned, or null export async function call(path, method = "GET", body) { @@ -19,9 +18,9 @@ export async function call(path, method = "GET", body) { // The station and the range (UTC, To excluded; empty: the whole period), shared by the pages through the address export function Selector({ selection, choose }) { - const [stations, setStations] = useState([]), [s, setS] = useState(selection), [editing, setEditing] = useState(false); - useEffect(() => { call("/api/stations").then(l => l && setStations(l)); }, [selection]); // a pumping may add one - useEffect(() => setS(selection), [selection]); // a new object at each change of the address, or at each Load + const [stations, setStations] = useState([]), [s, setS] = useState(selection); + useEffect(() => { call("/api/stations").then(l => l && setStations(l)); }, []); + useEffect(() => setS(selection), [selection]); // a new object at each change of the address return ( @@ -30,80 +29,7 @@ export function Selector({ selection, choose }) { setS({ ...s, start: e.currentTarget.value })} /> setS({ ...s, end: e.currentTarget.value })} /> - - setEditing(false)} selection={s} reload={() => choose(selection)} /> ); } - -const shift = (d, n) => (d ? new Date(Date.parse(d) + n * 864e5).toISOString().slice(0, 10) : ""); - -// The tracked stations (extraction/stations.txt of ~/aimsight-data): serial and position (for the weather of the Data page); -// the checked ones pumped (extraction/pump.sh) over a range, or without range their missing days up to now. The state of -// the pumping read every 2 s while the window is open or a pumping runs; at its end, the page loads again -function Stations({ opened, close, selection, reload }) { - const [rows, setRows] = useState([]), [checked, setChecked] = useState([]), [range, setRange] = useState({}); - const [images, setImages] = useState(true), [state, setState] = useState(null); - useEffect(() => { - if (!opened) return; - call("/api/tracked").then(l => l && setRows(l)); - setChecked(selection.station ? [selection.station] : []); - setRange({ start: shift(selection.start, -3), end: selection.end }); // 3 days before: the history of the detectors - }, [opened]); - const watch = opened || !!state?.running; - useEffect(() => { - if (!watch) return; - const read = () => fetch("/api/pump").then(r => r.ok && r.json()).then(p => p && setState(p)).catch(() => {}); // silently - read(); - const timer = setInterval(read, 2000); - return () => clearInterval(timer); - }, [watch]); - const running = !!state?.running, was = useRef(false); - useEffect(() => { if (was.current && !running) reload(); was.current = running; }, [running]); - - const set = (i, k, v) => setRows(rows.map((r, n) => (n === i ? { ...r, [k]: v } : r))); - const save = () => call("/api/tracked", "PUT", { stations: rows.filter(r => r.serial) }).then(l => l && setRows(l)); - const pump = () => call("/api/pump", "POST", { stations: checked, ...range, images }).then(p => p && setState(p)); - return ( - - - - PumpSerial - Position (lat,lon or a Swiss place, for the weather) - - {rows.map((r, i) => ( - - setChecked(e.currentTarget.checked ? [...checked, r.serial] : checked.filter(c => c !== r.serial))} /> - set(i, "serial", e.currentTarget.value.trim())} /> - set(i, "position", e.currentTarget.value)} /> - setRows(rows.filter((_, n) => n !== i))}> - - - ))} - -
- - - - - - setRange({ ...range, start: e.currentTarget.value })} /> - setRange({ ...range, end: e.currentTarget.value })} /> - setImages(e.currentTarget.checked)} mb={8} /> - - - From is 3 days before the range shown (the history of the detectors); without dates, the missing days of - each station up to now. Read-only on the platform; a long range, outside busy hours. - {state?.log?.length > 0 && ( - v && (v.scrollTop = v.scrollHeight)}> - {state.log.join("\n")} - - )} -
-
- ); -} diff --git a/app/web/src/pages/Stations.jsx b/app/web/src/pages/Stations.jsx new file mode 100644 index 0000000..6eae141 --- /dev/null +++ b/app/web/src/pages/Stations.jsx @@ -0,0 +1,79 @@ +import { useEffect, useState } from "react"; +import { ActionIcon, Button, Card, Checkbox, Code, Group, ScrollArea, Stack, Table, Text, TextInput, Title } from "@mantine/core"; +import { IconPlus, IconX } from "@tabler/icons-react"; +import { call } from "../common.jsx"; + +const shift = (d, n) => (d ? new Date(Date.parse(d) + n * 864e5).toISOString().slice(0, 10) : ""); + +// The tracked stations (extraction/stations.txt of ~/aimsight-data): serial and position (for the weather of the Data page); +// the checked ones pumped (extraction/pump.sh) over a range, or without range their missing days up to now. The state of +// the pumping read every 2 s. By default, the station and the range of the address (From 3 days before: the history of +// the detectors) +export default function Stations({ selection }) { + const [rows, setRows] = useState([]), [checked, setChecked] = useState(selection.station ? [selection.station] : []); + const [range, setRange] = useState({ start: shift(selection.start, -3), end: selection.end }); + const [images, setImages] = useState(true), [state, setState] = useState(null); + useEffect(() => { call("/api/tracked").then(l => l && setRows(l)); }, []); + useEffect(() => { + const read = () => fetch("/api/pump").then(r => r.ok && r.json()).then(p => p && setState(p)).catch(() => {}); // silently + read(); + const timer = setInterval(read, 2000); + return () => clearInterval(timer); + }, []); + const running = !!state?.running; + const set = (i, k, v) => setRows(rows.map((r, n) => (n === i ? { ...r, [k]: v } : r))); + const save = () => call("/api/tracked", "PUT", { stations: rows.filter(r => r.serial) }).then(l => l && setRows(l)); + const pump = () => call("/api/pump", "POST", { stations: checked, ...range, images }).then(p => p && setState(p)); + return ( + +
+ Stations + The tracked stations and their position (for the weather of the Data page); the checked ones pumped from + the platform, read-only. +
+ + + + PumpSerial + Position (lat,lon or a Swiss place, for the weather) + + {rows.map((r, i) => ( + + setChecked(e.currentTarget.checked ? [...checked, r.serial] : checked.filter(c => c !== r.serial))} /> + set(i, "serial", e.currentTarget.value.trim())} /> + set(i, "position", e.currentTarget.value)} /> + setRows(rows.filter((_, n) => n !== i))}> + + + ))} + +
+ + + + +
+
+ + + + setRange({ ...range, start: e.currentTarget.value })} /> + setRange({ ...range, end: e.currentTarget.value })} /> + setImages(e.currentTarget.checked)} mb={8} /> + + + By default From is 3 days before the range of the Data page (the history of the detectors); + without dates, the missing days of each station up to now. A long range, outside busy hours. + {state?.log?.length > 0 && ( + v && (v.scrollTop = v.scrollHeight)}> + {state.log.join("\n")} + + )} + + +
+ ); +}