Data: the selector chooses the source, Cloud (data/) or Emulator (the runs of data_diff/), then the run; a run listed right after its station
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d4d2e6b7b1
commit
cce6b850c6
2 files changed
+19
-7
No files matched your search
@@ -66,8 +66,8 @@ class Refusal(ValueError):
|
||||
|
||||
|
||||
def stations():
|
||||
runs = sorted(f"{d.parent.parent.name}{RUN}{d.name}" for d in DATA_DIFF.glob("*/runs/*") if d.is_dir())
|
||||
return sorted(d.name for d in DATA.iterdir() if d.is_dir()) + runs
|
||||
runs = [f"{d.parent.parent.name}{RUN}{d.name}" for d in DATA_DIFF.glob("*/runs/*") if d.is_dir()]
|
||||
return sorted([d.name for d in DATA.iterdir() if d.is_dir()] + runs) # a run right after its station
|
||||
|
||||
|
||||
def serial(station):
|
||||
|
||||
+17
-5
@@ -17,16 +17,28 @@ export async function call(path, method = "GET", body) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// The station and the range (UTC, To excluded; empty: the whole period), shared by the pages through the address
|
||||
// The station and the range (UTC, To excluded; empty: the whole period), shared by the pages through the address. Source:
|
||||
// Cloud, the stations of data/; Emulator, the runs of data_diff/, <SERIAL>@<run> for the server
|
||||
const SOURCES = [{ value: "cloud", label: "Cloud" }, { value: "emulator", label: "Emulator" }];
|
||||
const sourceOf = station => (station || "").includes("@") ? "emulator" : "cloud";
|
||||
|
||||
export function Selector({ selection, choose }) {
|
||||
const [stations, setStations] = useState([]), [s, setS] = useState(selection);
|
||||
const [stations, setStations] = useState([]), [s, setS] = useState(selection), [source, setSource] = useState(sourceOf(selection.station));
|
||||
useEffect(() => { call("/api/stations").then(l => l && setStations(l)); }, []);
|
||||
useEffect(() => setS(selection), [selection]); // a new object at each change of the address
|
||||
useEffect(() => { setS(selection); if (selection.station) setSource(sourceOf(selection.station)); }, [selection]); // a new object at each change of the address
|
||||
const [serial, run] = (s.station || "").split("@");
|
||||
const runsOf = st => stations.filter(n => n.startsWith(st + "@")).map(n => n.split("@")[1]);
|
||||
const names = source === "cloud" ? stations.filter(n => !n.includes("@"))
|
||||
: [...new Set(stations.filter(n => n.includes("@")).map(n => n.split("@")[0]))];
|
||||
return (
|
||||
<Card shadow="sm" withBorder>
|
||||
<Group align="flex-end" gap="md">
|
||||
<Select label="Station" placeholder="Choose" data={stations} value={s.station || null} searchable w={200}
|
||||
onChange={v => setS({ ...s, station: v || "" })} />
|
||||
<Select label="Source" data={SOURCES} value={source} allowDeselect={false} w={130}
|
||||
onChange={v => { setSource(v); setS({ ...s, station: "" }); }} />
|
||||
<Select label="Station" placeholder="Choose" data={names} value={serial || null} searchable w={200}
|
||||
onChange={v => setS({ ...s, station: !v ? "" : source === "cloud" ? v : `${v}@${runsOf(v)[0]}` })} />
|
||||
{source === "emulator" && <Select label="Run" placeholder="Choose" data={serial ? runsOf(serial) : []} value={run || null}
|
||||
allowDeselect={false} w={140} onChange={v => setS({ ...s, station: `${serial}@${v}` })} />}
|
||||
<TextInput label="From (UTC)" type="date" value={s.start} onChange={e => setS({ ...s, start: e.currentTarget.value })} />
|
||||
<TextInput label="To (excluded)" type="date" value={s.end} onChange={e => setS({ ...s, end: e.currentTarget.value })} />
|
||||
<Button onClick={() => choose(s)} disabled={!s.station}>Load</Button>
|
||||
|
||||
Reference in new issue
Block a user