File size: 4,789 Bytes
a2bbd94
 
 
 
 
 
 
 
 
 
 
 
fb23187
a2bbd94
 
 
 
 
 
 
fb23187
 
 
 
 
 
 
a2bbd94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fb23187
a2bbd94
 
fb23187
a2bbd94
fb23187
 
 
 
 
 
 
 
 
 
 
a2bbd94
 
 
fb23187
a2bbd94
 
 
 
 
 
 
 
 
fb23187
a2bbd94
 
 
 
fb23187
a2bbd94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fb23187
a2bbd94
 
 
 
 
 
 
 
 
 
 
 
 
 
fb23187
 
 
 
a2bbd94
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
 * Hero aggregates for a published run: population-scale counts followed by the
 * headline quality metrics. Precision/recall are annotated with sampling-verified
 * confidence intervals when review results exist.
 */
import Box from '@mui/material/Box';
import Chip from '@mui/material/Chip';
import type { EvaluationRunInfo, MetricEstimate, ReviewState } from '../../types/megaeval';
import { fmtCompact, queryEvaluations } from '../../services/megaeval';
import { usePoll } from '../../services/labeleval';
import { MetricCard, fmtNum, fmtPct } from '../labeleval/shared';
import { QueryBadge, rowNum } from './shared';
import { ExplainTip } from '../help/InfoTip';

function ciSub(est: MetricEstimate | undefined): string | null {
  if (!est) return null;
  return `95% CI ${fmtPct(est.ci_low)}–${fmtPct(est.ci_high)}, n=${est.n_reviewed.toLocaleString()} reviewed`;
}

const VERIFIED_CHIP = (
  <ExplainTip term="sampling_verified">
    <Chip
      size="small"
      label="sampling-verified"
      sx={{ height: 16, fontSize: 9, fontWeight: 700, bgcolor: '#12303f', color: '#81d4fa', ml: 0.5, cursor: 'help' }}
    />
  </ExplainTip>
);

export default function HeroRow({
  run,
  review,
  refreshKey,
}: {
  run: EvaluationRunInfo;
  review: ReviewState | null;
  refreshKey: number;
}) {
  const h = run.headline;
  // Reviewed / verified totals come from the aggregate query API (also shows provenance).
  const totals = usePoll(
    () =>
      queryEvaluations({
        evaluation_id: run.run_id,
        metrics: ['n', 'reviewed', 'verified', 'review_coverage'],
      }),
    null,
    [run.run_id, refreshKey]
  );
  const totalsRow = totals.data?.rows[0];
  const reviewed = totalsRow ? rowNum(totalsRow, 'reviewed') : null;
  const verified = totalsRow ? rowNum(totalsRow, 'verified') : null;

  const results = review?.results ?? null;
  const precisionCi = ciSub(results?.precision);
  const recallCi = ciSub(results?.recall);

  return (
    <Box sx={{ display: 'flex', flexDirection: 'column', gap: 1.5 }}>
      <Box sx={{ display: 'flex', gap: 1.5, flexWrap: 'wrap' }}>
        <MetricCard label="Objects evaluated" value={fmtCompact(h.n)} sub="exact (cube)" term="metric_cube" />
        <MetricCard
          label="Containers"
          term="container"
          value={fmtCompact(h.containers)}
          sub={
            h.containers_hll_estimate !== undefined ? (
              <ExplainTip term="hll">
                <Box component="span" sx={{ borderBottom: '1px dotted #5c6873', cursor: 'help' }}>
                  {`HLL est ${fmtCompact(h.containers_hll_estimate)} (approx)`}
                </Box>
              </ExplainTip>
            ) : (
              'exact'
            )
          }
        />
        <MetricCard
          label="Reviewed"
          term="review_sample"
          value={fmtCompact(reviewed)}
          sub={
            <Box component="span" sx={{ display: 'inline-flex', alignItems: 'center', gap: 0.5 }}>
              <span>human reviews</span>
              <QueryBadge meta={totals.data?.meta} />
            </Box>
          }
          accent="#42a5f5"
        />
        <MetricCard label="Verified" value={fmtCompact(verified)} accent="#66bb6a" sub="human-verified" term="status_verified" />
      </Box>
      <Box sx={{ display: 'flex', gap: 1.5, flexWrap: 'wrap' }}>
        <MetricCard
          label="Precision"
          term="precision"
          value={fmtPct(h.precision)}
          sub={
            precisionCi ? (
              <Box component="span" sx={{ display: 'inline-flex', alignItems: 'center', flexWrap: 'wrap' }}>
                <span>
                  {fmtPct(results?.precision.estimate)} ({precisionCi})
                </span>
                {VERIFIED_CHIP}
              </Box>
            ) : (
              'point estimate'
            )
          }
        />
        <MetricCard
          label="Recall"
          term="recall"
          value={fmtPct(h.recall)}
          sub={
            recallCi ? (
              <Box component="span" sx={{ display: 'inline-flex', alignItems: 'center', flexWrap: 'wrap' }}>
                <span>
                  {fmtPct(results?.recall.estimate)} ({recallCi})
                </span>
                {VERIFIED_CHIP}
              </Box>
            ) : (
              'point estimate'
            )
          }
        />
        <MetricCard label="F1" value={fmtPct(h.f1)} term="f1" />
        <MetricCard label="Mean IoU" value={fmtNum(h.mean_iou, 3)} term="iou_3d" />
        <MetricCard label="Anomaly rate" value={fmtPct(h.anomaly_rate)} accent="#ffa726" term="anomaly_rate" />
        <MetricCard label="Safety recall" value={fmtPct(h.safety_recall)} accent="#ef5350" term="safety_recall" />
      </Box>
    </Box>
  );
}