|
| 1 | +import React from "react"; |
| 2 | +import { Card, Box, Typography, Chip, Stack, Divider } from "@mui/material"; |
| 3 | + |
| 4 | +export default function InstrumentSimilarities({ similarities }) { |
| 5 | + if (!similarities || !similarities.length) return null; |
| 6 | + |
| 7 | + return ( |
| 8 | + <Card |
| 9 | + variant="outlined" |
| 10 | + sx={{ |
| 11 | + display: "flex", |
| 12 | + width: "100%", |
| 13 | + padding: "1rem", |
| 14 | + margin: "0 0 1rem 0", |
| 15 | + flexDirection: "column", |
| 16 | + gap: 1, |
| 17 | + }} |
| 18 | + > |
| 19 | + <Typography variant="h6" sx={{ mb: 1 }}> |
| 20 | + Instrument similarities |
| 21 | + </Typography> |
| 22 | + <Typography variant="body2" color="text.secondary" sx={{ mb: 1 }}> |
| 23 | + These scores indicate how similar each pair of instruments is overall. |
| 24 | + </Typography> |
| 25 | + |
| 26 | + <Stack direction="column" divider={<Divider flexItem />} spacing={1}> |
| 27 | + {similarities.map((s, idx) => ( |
| 28 | + <Box key={idx} sx={{ display: "flex", alignItems: "center", gap: 2, flexWrap: "wrap" }}> |
| 29 | + <Typography variant="subtitle2" sx={{ minWidth: 200 }}> |
| 30 | + {s.instrument_1_name} ↔ {s.instrument_2_name} |
| 31 | + </Typography> |
| 32 | + <Stack direction="row" spacing={1}> |
| 33 | + {typeof s.f1 !== "undefined" && ( |
| 34 | + <Chip label={`F1: ${roundPct(s.f1)}`} color="primary" variant="outlined" /> |
| 35 | + )} |
| 36 | + {typeof s.precision !== "undefined" && ( |
| 37 | + <Chip label={`Precision: ${roundPct(s.precision)}`} variant="outlined" /> |
| 38 | + )} |
| 39 | + {typeof s.recall !== "undefined" && ( |
| 40 | + <Chip label={`Recall: ${roundPct(s.recall)}`} variant="outlined" /> |
| 41 | + )} |
| 42 | + </Stack> |
| 43 | + </Box> |
| 44 | + ))} |
| 45 | + </Stack> |
| 46 | + </Card> |
| 47 | + ); |
| 48 | +} |
| 49 | + |
| 50 | +function roundPct(value) { |
| 51 | + // If value appears already in percentage form (0-100), cap and show; otherwise convert from 0-1 |
| 52 | + const v = value > 1 ? value : value * 100; |
| 53 | + return `${Math.round(v)}%`; |
| 54 | +} |
0 commit comments