/** * Container explorer ("Quality by Container"): sortable container table with * risk presets. Drilling into a container opens the forensic object table — * intentionally the deepest level of the app — plus nearest-neighbor * "similar containers" retrieval for casting a wider net. */ import { useState } from 'react'; import Box from '@mui/material/Box'; import Button from '@mui/material/Button'; import CircularProgress from '@mui/material/CircularProgress'; import MenuItem from '@mui/material/MenuItem'; import Table from '@mui/material/Table'; import TableBody from '@mui/material/TableBody'; import TableCell from '@mui/material/TableCell'; import TableHead from '@mui/material/TableHead'; import TableRow from '@mui/material/TableRow'; import TextField from '@mui/material/TextField'; import Typography from '@mui/material/Typography'; import { ArrowLeft, Search, ShieldAlert } from 'lucide-react'; import type { ContainerSortPreset, SimilarityResponse } from '../../types/megaeval'; import { findSimilarContainers, fmtCompact, getContainerObjects, getRunContainers, } from '../../services/megaeval'; import { usePoll } from '../../services/labeleval'; import { ErrorNote, LoadingBox, SectionCard, fmtNum, fmtPct } from '../labeleval/shared'; import { HeadCell } from '../help/InfoTip'; import { ContainerStatusIcon, DimChips, OutcomeChip } from './shared'; const SORT_PRESETS: Array<{ value: ContainerSortPreset; label: string }> = [ { value: 'highest_risk', label: 'Highest risk' }, { value: 'worst_recall', label: 'Worst recall' }, { value: 'worst_precision', label: 'Worst precision' }, { value: 'worst_iou', label: 'Worst IoU' }, { value: 'most_anomalies', label: 'Most anomalies' }, { value: 'least_verified', label: 'Least verified' }, ]; // ---------------------------------------------------------------- forensic view function ForensicView({ runId, containerId, onBack, onDrill, }: { runId: string; containerId: number; onBack: () => void; onDrill: (cid: number) => void; }) { const objects = usePoll(() => getContainerObjects(runId, containerId), null, [runId, containerId]); const [similar, setSimilar] = useState(null); const [simBusy, setSimBusy] = useState(false); const [simError, setSimError] = useState(null); const findSimilar = async () => { setSimBusy(true); setSimError(null); try { setSimilar(await findSimilarContainers({ run_id: runId, container_id: containerId, k: 10 })); } catch (err) { setSimError(err instanceof Error ? err.message : String(err)); } finally { setSimBusy(false); } }; return ( Forensic object table · container #{containerId} } action={ } help="Every annotation in this one container with its evaluation outcome. This is the deepest level of the app — per-object data is loaded on demand only here, never scanned in aggregate views. The shield icon marks safety-critical objects." sx={{ flex: '2 1 620px' }} > Deepest drill-down level: individual annotations, loaded on demand for this container only. {objects.error ? : null} {objects.loading && !objects.data ? : null} {objects.data ? ( Class {objects.data.objects.map((o) => ( {o.safety_critical ? : null} {o.class} {fmtNum(o.iou, 3)} {fmtNum(o.confidence, 2)} {o.anomaly ? ( ● ) : ( ○ )} ))}
) : null} {simError ? ( ) : null} {similar ? ( Container Similarity Context FN/FP Risk {similar.results.map((s) => ( onDrill(s.container_id)} sx={{ cursor: 'pointer' }}> #{s.container_id} {fmtPct(s.similarity)} {s.fn}/{s.fp} {fmtNum(s.risk_score, 2)} ))}
) : null} ); } // ---------------------------------------------------------------- containers table export default function ContainersTab({ runId, refreshKey, drillContainerId, onDrill, }: { runId: string; refreshKey: number; drillContainerId: number | null; onDrill: (cid: number | null) => void; }) { const [sort, setSort] = useState('highest_risk'); const containers = usePoll(() => getRunContainers(runId, sort, 50), null, [runId, sort, refreshKey]); if (drillContainerId !== null) { return ( onDrill(null)} onDrill={(cid) => onDrill(cid)} /> ); } return ( {containers.data ? ( {fmtCompact(containers.data.total)} containers (exact) · showing top {containers.data.rows.length} ) : null} setSort(e.target.value as ContainerSortPreset)} sx={{ minWidth: 180 }} > {SORT_PRESETS.map((p) => ( {p.label} ))} } > {containers.error ? : null} {containers.loading && !containers.data ? : null} {containers.data ? ( Context Objects {containers.data.rows.map((c) => ( onDrill(c.container_id)} sx={{ cursor: 'pointer' }}> #{c.container_id} {fmtCompact(c.n_objects)} {c.verified} {fmtPct(c.precision)} {fmtPct(c.recall)} {fmtNum(c.mean_iou, 3)} 0 ? '#ec407a' : undefined }}> {c.anomalies} {fmtNum(c.risk_score, 2)} ))}
) : null} Click a container to open its forensic object table (deepest drill-down).
); }