English: the app (server/, analysis.py, routes and JSON fields), instructions/analyst.md, docs; the table of shared renames
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1d80a77cb1
commit
a3e6ade845
24 files changed
+1959
-1835
No files matched your search
+66
-66
@@ -5,40 +5,40 @@ import {
|
||||
import { useDisclosure } from "@mantine/hooks";
|
||||
import { IconChartLine, IconFolder, IconMoon, IconSun } from "@tabler/icons-react";
|
||||
|
||||
const Data = lazy(() => import("./pages/Data.jsx")); // Plotly, chargé seulement ici
|
||||
const Data = lazy(() => import("./pages/Data.jsx")); // Plotly, loaded only here
|
||||
const PAGES = [["data", "Data", IconChartLine]];
|
||||
|
||||
// L'adresse : #/<page>?station=…&du=…&au=… ; recharger garde la page et la sélection, Retour marche ; sans dates, les 5 derniers
|
||||
// jours UTC, aujourd'hui compris (au exclu : demain)
|
||||
const jour = n => new Date(Date.now() + n * 864e5).toISOString().slice(0, 10);
|
||||
function lireAdresse() {
|
||||
// The address: #/<page>?station=…&start=…&end=…; reloading keeps the page and the selection, Back works; without dates, the
|
||||
// last 5 UTC days, today included (end excluded: tomorrow)
|
||||
const day = n => new Date(Date.now() + n * 864e5).toISOString().slice(0, 10);
|
||||
function readAddress() {
|
||||
const [page, q = ""] = location.hash.replace(/^#\/?/, "").split("?");
|
||||
const p = new URLSearchParams(q);
|
||||
return { page: PAGES.some(([n]) => n === page) ? page : "data",
|
||||
selection: { station: p.get("station") || "", du: p.get("du") || jour(-4), au: p.get("au") || jour(1) } };
|
||||
selection: { station: p.get("station") || "", start: p.get("start") || day(-4), end: p.get("end") || day(1) } };
|
||||
}
|
||||
|
||||
function adresse(page, s) {
|
||||
function address(page, s) {
|
||||
const q = new URLSearchParams(Object.entries(s).filter(([, v]) => v)).toString();
|
||||
return `#/${page}${q ? "?" + q : ""}`;
|
||||
}
|
||||
|
||||
function Entete({ mobile, bureau, basculer }) {
|
||||
const { setColorScheme } = useMantineColorScheme(), schema = useComputedColorScheme("light");
|
||||
function Header({ mobile, desktop, toggle }) {
|
||||
const { setColorScheme } = useMantineColorScheme(), scheme = useComputedColorScheme("light");
|
||||
return (
|
||||
<AppShell.Header className="entete">
|
||||
<AppShell.Header className="header">
|
||||
<Group h="100%" px="md" justify="space-between" wrap="nowrap">
|
||||
<Group gap="sm" wrap="nowrap">
|
||||
<Burger opened={mobile} onClick={basculer.mobile} hiddenFrom="sm" size="sm" color="white" aria-label="Menu" />
|
||||
<Burger opened={bureau} onClick={basculer.bureau} visibleFrom="sm" size="sm" color="white" aria-label="Barre latérale" />
|
||||
<Burger opened={mobile} onClick={toggle.mobile} hiddenFrom="sm" size="sm" color="white" aria-label="Menu" />
|
||||
<Burger opened={desktop} onClick={toggle.desktop} visibleFrom="sm" size="sm" color="white" aria-label="Sidebar" />
|
||||
<Text fw={700} size="lg">AIMsight</Text>
|
||||
<Text size="sm" opacity={0.6}>Diagnostic</Text>
|
||||
</Group>
|
||||
<Group gap="sm" wrap="nowrap">
|
||||
<Tooltip label={schema === "dark" ? "Mode clair" : "Mode sombre"}>
|
||||
<ActionIcon variant="subtle" color="white" size="lg" aria-label="Changer de thème"
|
||||
onClick={() => setColorScheme(schema === "dark" ? "light" : "dark")}>
|
||||
{schema === "dark" ? <IconSun size={20} /> : <IconMoon size={20} />}
|
||||
<Tooltip label={scheme === "dark" ? "Light mode" : "Dark mode"}>
|
||||
<ActionIcon variant="subtle" color="white" size="lg" aria-label="Change theme"
|
||||
onClick={() => setColorScheme(scheme === "dark" ? "light" : "dark")}>
|
||||
{scheme === "dark" ? <IconSun size={20} /> : <IconMoon size={20} />}
|
||||
</ActionIcon>
|
||||
</Tooltip>
|
||||
</Group>
|
||||
@@ -47,37 +47,37 @@ function Entete({ mobile, bureau, basculer }) {
|
||||
);
|
||||
}
|
||||
|
||||
// Les analyses de la page Data (labeling/auto/analyses/), relues toutes les 3 s : un dossier par station, ouvert d'office s'il en
|
||||
// a une en cours, et dedans une analyse par plage ; un clic ouvre Data sur sa station et ses jours, et y montre son rapport
|
||||
// La plage d'une analyse sur une ligne : « 01.11 · 10:30–11:40 » dans le jour, sinon « 04.11 21:12 – 07.11 14:12 » (UTC)
|
||||
const jourMois = t => `${t.slice(8, 10)}.${t.slice(5, 7)}`, heure = t => t.slice(11, 16);
|
||||
const plage = a => (a.debut.slice(0, 10) === a.fin.slice(0, 10)
|
||||
? `${jourMois(a.debut)} · ${heure(a.debut)}–${heure(a.fin)}` : `${jourMois(a.debut)} ${heure(a.debut)} – ${jourMois(a.fin)} ${heure(a.fin)}`);
|
||||
const COULEUR_ETAT = { fini: "teal", erreur: "red", interrompue: "gray" };
|
||||
// L'état : une roue qui tourne en cours, sinon une pastille de couleur (son nom dans la bulle)
|
||||
const Pastille = ({ etat }) => (etat === "en cours" ? <Loader size={10} color="orange" />
|
||||
: <Tooltip label={etat}><ColorSwatch size={8} color={`var(--mantine-color-${COULEUR_ETAT[etat] || "gray"}-6)`} withShadow={false} /></Tooltip>);
|
||||
function Analyses({ ouvrir }) {
|
||||
const [liste, setListe] = useState([]);
|
||||
// The analyses of the Data page (labeling/auto/analyses/), read again every 3 s: one folder per station, open by default if
|
||||
// it has one running, and inside one analysis per range; a click opens Data on its station and its days, and shows its report there
|
||||
// The range of an analysis on one line: "01.11 · 10:30–11:40" within the day, otherwise "04.11 21:12 – 07.11 14:12" (UTC)
|
||||
const dayMonth = t => `${t.slice(8, 10)}.${t.slice(5, 7)}`, hour = t => t.slice(11, 16);
|
||||
const range = a => (a.start.slice(0, 10) === a.end.slice(0, 10)
|
||||
? `${dayMonth(a.start)} · ${hour(a.start)}–${hour(a.end)}` : `${dayMonth(a.start)} ${hour(a.start)} – ${dayMonth(a.end)} ${hour(a.end)}`);
|
||||
const STATE_COLOR = { done: "teal", error: "red", interrupted: "gray" };
|
||||
// The state: a spinning wheel while running, otherwise a coloured dot (its name in the tooltip)
|
||||
const Dot = ({ state }) => (state === "running" ? <Loader size={10} color="orange" />
|
||||
: <Tooltip label={state}><ColorSwatch size={8} color={`var(--mantine-color-${STATE_COLOR[state] || "gray"}-6)`} withShadow={false} /></Tooltip>);
|
||||
function Analyses({ open }) {
|
||||
const [list, setList] = useState([]);
|
||||
useEffect(() => {
|
||||
const lire = () => fetch("/api/analyses").then(r => r.ok && r.json()).then(l => l && setListe(l)).catch(() => {}); // en silence : toutes les 3 s
|
||||
lire();
|
||||
const minuterie = setInterval(lire, 3000);
|
||||
return () => clearInterval(minuterie);
|
||||
const read = () => fetch("/api/analyses").then(r => r.ok && r.json()).then(l => l && setList(l)).catch(() => {}); // silently: every 3 s
|
||||
read();
|
||||
const timer = setInterval(read, 3000);
|
||||
return () => clearInterval(timer);
|
||||
}, []);
|
||||
if (!liste.length) return null;
|
||||
const stations = [...new Set(liste.map(a => a.station))].sort();
|
||||
if (!list.length) return null;
|
||||
const stations = [...new Set(list.map(a => a.station))].sort();
|
||||
return <>
|
||||
<Text size="xs" fw={700} tt="uppercase" c="dimmed" px="sm" pt="lg" pb="xs">Analyses (UTC)</Text>
|
||||
{stations.map(st => {
|
||||
const siennes = liste.filter(a => a.station === st), occupee = siennes.some(a => a.etat === "en cours");
|
||||
// le chevron du dossier reste celui de Mantine : un rightSection prendrait sa place, et tournerait avec lui
|
||||
const its = list.filter(a => a.station === st), busy = its.some(a => a.state === "running");
|
||||
// the chevron of the folder stays Mantine's: a rightSection would take its place, and rotate with it
|
||||
return (
|
||||
<NavLink key={st} defaultOpened={occupee} childrenOffset={22} leftSection={<IconFolder size={16} />}
|
||||
label={<Group gap={6} wrap="nowrap">{st}<Text span size="xs" c="dimmed">{siennes.length}</Text>{occupee && <Loader size={10} color="orange" />}</Group>}>
|
||||
{siennes.map(a => (
|
||||
<NavLink key={a.nom} py={4} onClick={() => ouvrir(a)} leftSection={<Pastille etat={a.etat} />}
|
||||
label={<Text size="xs" ff="monospace" style={{ whiteSpace: "nowrap" }}>{plage(a)}</Text>} />
|
||||
<NavLink key={st} defaultOpened={busy} childrenOffset={22} leftSection={<IconFolder size={16} />}
|
||||
label={<Group gap={6} wrap="nowrap">{st}<Text span size="xs" c="dimmed">{its.length}</Text>{busy && <Loader size={10} color="orange" />}</Group>}>
|
||||
{its.map(a => (
|
||||
<NavLink key={a.name} py={4} onClick={() => open(a)} leftSection={<Dot state={a.state} />}
|
||||
label={<Text size="xs" ff="monospace" style={{ whiteSpace: "nowrap" }}>{range(a)}</Text>} />
|
||||
))}
|
||||
</NavLink>
|
||||
);
|
||||
@@ -85,49 +85,49 @@ function Analyses({ ouvrir }) {
|
||||
</>;
|
||||
}
|
||||
|
||||
function Barre({ page, selection, fermer, ouvrir }) {
|
||||
const titre = t => <Text size="xs" fw={700} tt="uppercase" c="dimmed" px="sm" pt="lg" pb="xs">{t}</Text>;
|
||||
function Sidebar({ page, selection, close, open }) {
|
||||
const title = t => <Text size="xs" fw={700} tt="uppercase" c="dimmed" px="sm" pt="lg" pb="xs">{t}</Text>;
|
||||
return (
|
||||
<AppShell.Navbar p="xs">
|
||||
<ScrollArea type="scroll">
|
||||
{titre("Pages")}
|
||||
{PAGES.map(([n, nom, Icone]) => (
|
||||
<NavLink key={n} label={nom} leftSection={<Icone size={18} />} active={page === n} onClick={fermer}
|
||||
href={adresse(n, selection)} />
|
||||
{title("Pages")}
|
||||
{PAGES.map(([n, name, Icon]) => (
|
||||
<NavLink key={n} label={name} leftSection={<Icon size={18} />} active={page === n} onClick={close}
|
||||
href={address(n, selection)} />
|
||||
))}
|
||||
<Analyses ouvrir={a => { fermer(); ouvrir(a); }} />
|
||||
<Analyses open={a => { close(); open(a); }} />
|
||||
</ScrollArea>
|
||||
</AppShell.Navbar>
|
||||
);
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const [{ page, selection }, setLieu] = useState(lireAdresse);
|
||||
const [mobile, { toggle: basculerMobile, close: fermerMobile }] = useDisclosure(false);
|
||||
const [bureau, { toggle: basculerBureau }] = useDisclosure(true);
|
||||
const [analyse, setAnalyse] = useState(null); // l'analyse dont Data montre le rapport
|
||||
const [{ page, selection }, setPlace] = useState(readAddress);
|
||||
const [mobile, { toggle: toggleMobile, close: closeMobile }] = useDisclosure(false);
|
||||
const [desktop, { toggle: toggleDesktop }] = useDisclosure(true);
|
||||
const [analysis, setAnalysis] = useState(null); // the analysis whose report Data shows
|
||||
|
||||
useEffect(() => {
|
||||
const suivre = () => setLieu(lireAdresse());
|
||||
addEventListener("hashchange", suivre);
|
||||
return () => removeEventListener("hashchange", suivre);
|
||||
const follow = () => setPlace(readAddress());
|
||||
addEventListener("hashchange", follow);
|
||||
return () => removeEventListener("hashchange", follow);
|
||||
}, []);
|
||||
|
||||
const choisir = s => { location.hash = adresse(page, s); };
|
||||
// Une analyse de la barre : Data sur sa station, des jours qui couvrent sa plage (sauf si la plage affichée les couvre déjà)
|
||||
function ouvrirAnalyse(a) {
|
||||
const s = selection, couvre = s.station === a.station && s.du <= a.debut.slice(0, 10) && a.fin < s.au;
|
||||
const au = new Date(Date.parse(a.fin.slice(0, 10)) + 864e5).toISOString().slice(0, 10);
|
||||
setAnalyse(a.nom);
|
||||
location.hash = adresse("data", couvre ? s : { station: a.station, du: a.debut.slice(0, 10), au });
|
||||
const choose = s => { location.hash = address(page, s); };
|
||||
// An analysis of the sidebar: Data on its station, days that cover its range (unless the range shown already covers them)
|
||||
function openAnalysis(a) {
|
||||
const s = selection, covers = s.station === a.station && s.start <= a.start.slice(0, 10) && a.end < s.end;
|
||||
const end = new Date(Date.parse(a.end.slice(0, 10)) + 864e5).toISOString().slice(0, 10);
|
||||
setAnalysis(a.name);
|
||||
location.hash = address("data", covers ? s : { station: a.station, start: a.start.slice(0, 10), end });
|
||||
}
|
||||
return (
|
||||
<AppShell header={{ height: 64 }} padding="lg"
|
||||
navbar={{ width: 260, breakpoint: "sm", collapsed: { mobile: !mobile, desktop: !bureau } }}>
|
||||
<Entete mobile={mobile} bureau={bureau} basculer={{ mobile: basculerMobile, bureau: basculerBureau }} />
|
||||
<Barre page={page} selection={selection} fermer={fermerMobile} ouvrir={ouvrirAnalyse} />
|
||||
navbar={{ width: 260, breakpoint: "sm", collapsed: { mobile: !mobile, desktop: !desktop } }}>
|
||||
<Header mobile={mobile} desktop={desktop} toggle={{ mobile: toggleMobile, desktop: toggleDesktop }} />
|
||||
<Sidebar page={page} selection={selection} close={closeMobile} open={openAnalysis} />
|
||||
<AppShell.Main bg="var(--mantine-color-default-hover)">
|
||||
<Suspense fallback={<Loader m="xl" />}><Data selection={selection} choisir={choisir} analyse={analyse} setAnalyse={setAnalyse} /></Suspense>
|
||||
<Suspense fallback={<Loader m="xl" />}><Data selection={selection} choose={choose} analysis={analysis} setAnalysis={setAnalysis} /></Suspense>
|
||||
</AppShell.Main>
|
||||
</AppShell>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user