import { useEffect, useRef, useState } from "react"; import { Badge, Button, Card, Group, Loader, SegmentedControl, Select, Stack, Text, Title, useComputedColorScheme } from "@mantine/core"; import { call, Selector } from "../common.jsx"; // Points: the point labels (labeling/points/, labeling/scripts/points.py), one boolean per measurement of a range, valid or // not, set by hand: the ground truth of the benchmarks. Mainly on the runs of the emulator: the page starts on that source. A dataset per station and range, created with every point valid; // one target at a time, corr_x above corr_y; a click on a point switches it, a box sets every point inside it (mode). // Each change is saved at once. const VALID = "#2f9e44", INVALID = "#e03131"; const FONT = "Roboto, sans-serif"; export default function Points({ selection, choose }) { const { station, start, end } = selection, name = `${station}_${start}_${end}`; const [list, setList] = useState([]), [d, setD] = useState(null), [loading, setLoading] = useState(false); const [sensor, setSensor] = useState(null), [mode, setMode] = useState("invalid"); const refresh = () => station ? call(`/api/points?${new URLSearchParams({ station })}`).then(l => l && setList(l)) : setList([]); const exists = list.some(x => x.name === name); useEffect(() => { refresh(); }, [station]); useEffect(() => { setD(null); if (!exists) return; setLoading(true); call(`/api/points/${name}`).then(r => { setLoading(false); if (r) { setD(r); setSensor(s => (s in r.sensors ? s : Object.keys(r.sensors)[0])); } }); }, [name, exists]); const create = () => { setLoading(true); call("/api/points", "POST", { station, start, end }).then(r => { setLoading(false); r && refresh(); }); }; // set the points (indices of the target's series) valid or not: at once on the page, then in the file; a refusal reloads function set(indices, valid) { const o = d.sensors[sensor], times = indices.filter(i => o.valid[i] !== valid).map(i => o.t[i]); if (!times.length) return; const v = o.valid.slice(); indices.forEach(i => { v[i] = valid; }); setD({ ...d, invalid: d.invalid + (valid ? -times.length : times.length), sensors: { ...d.sensors, [sensor]: { ...o, valid: v } } }); call(`/api/points/${name}`, "PUT", { sensor, times, valid }).then(r => { if (r) setList(l => l.map(x => (x.name === name ? r : x))); else call(`/api/points/${name}`).then(r2 => r2 && setD(r2)); }); } const invalidOf = s => d.sensors[s].valid.filter(v => !v).length; return (
Points Each measurement of a range, valid or not, set by hand: the ground truth of the benchmarks (labeling/points/). A click on a point switches it; a box sets every point inside it.
{list.length > 0 && Datasets of {station}: {list.map(x => )} } {loading && } {station && !exists && !loading && No dataset for {station} from {start} to {end} (excluded). } {d &&