Skip to content

Commit 258cc0a

Browse files
committed
implement instrument similarities in front end
1 parent e5f03ca commit 258cc0a

5 files changed

Lines changed: 69 additions & 3 deletions

File tree

src/components/AppBar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ function HarmonyAppBar() {
4848
.then((ver) => {
4949
setApiVersion(ver);
5050
})
51-
.catch((e) => setError("ERROR: API unreachable"));
51+
.catch((e) => setError("ERROR: API unreachable (version)"));
5252
}, [getVersion]);
5353

5454
React.useEffect(() => {
5555
getModels()
5656
.then((models) => {
5757
setAllModels(models);
5858
})
59-
.catch((e) => setError("ERROR: API unreachable"));
59+
.catch((e) => setError("ERROR: API unreachable (models)"));
6060
}, [getModels]);
6161

6262
const handleModelSelect = (event) => {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
}

src/components/Results.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useParams } from "react-router-dom";
55
import { useData } from "../contexts/DataContext";
66
import AlertDialogSlide from "./Dialog";
77
import InlineFeedback from "./InlineFeedback";
8+
import InstrumentSimilarities from "./InstrumentSimilarities";
89

910
import { parse, test } from "liqe";
1011

@@ -296,6 +297,11 @@ export default function Results({
296297
state={computedMatches && computedMatches.length > 0}
297298
/>
298299
)}
300+
301+
{/* New: Instrument-to-instrument similarities */}
302+
{apiData && apiData.instrumentSimilarities && (
303+
<InstrumentSimilarities similarities={apiData.instrumentSimilarities} />
304+
)}
299305
{topics && topics.length > 0 && (
300306
<Card
301307
variant="outlined"

src/contexts/DataContext.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export function DataProvider({ children }) {
5757

5858
// Handle other non-200 responses
5959
if (!response.ok) {
60+
console.error("GET failed:", url, "status:", response.status);
6061
throw new Error(`HTTP error! status: ${response.status}`);
6162
}
6263

@@ -84,6 +85,7 @@ export function DataProvider({ children }) {
8485
try {
8586
const controller = new AbortController();
8687
const id = setTimeout(() => controller.abort(), timeout);
88+
console.log("GET:", url);
8789
response = await fetch(url, {
8890
method: "GET",
8991
mode: "cors",

src/utilities/simplifyApi.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,9 @@ export function simplifyApi(apiResult, apiCall) {
2929
});
3030
instruments.push(instrument);
3131
});
32-
return { instruments: instruments };
32+
// Pass through instrument-to-instrument similarities if present from API
33+
// Expecting shape: [{ instrument_1_name, instrument_2_name, precision, recall, f1, ... }]
34+
const instrumentSimilarities =
35+
apiResult.instrument_to_instrument_similarities || [];
36+
return { instruments: instruments, instrumentSimilarities };
3337
}

0 commit comments

Comments
 (0)