Skip to content

Commit e726ace

Browse files
Add prediction comparison feature
1 parent ed677fb commit e726ace

2 files changed

Lines changed: 41 additions & 10 deletions

File tree

src/frontend/components/RecentPredictions.js

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { getPredictions, clearPredictions } from "../js/predictionStorage.js";
1+
import {
2+
getPredictions,
3+
clearPredictions,
4+
comparePredictions
5+
} from "../js/predictionStorage.js";
26

37
export default function RecentPredictions() {
48
const history = getPredictions();
@@ -11,16 +15,35 @@ export default function RecentPredictions() {
1115
container.appendChild(title);
1216

1317
history.forEach((item, i) => {
14-
const div = document.createElement("div");
15-
div.className = "prediction-item";
16-
div.innerHTML = `
17-
<p><strong>${item.timestamp}</strong></p>
18-
<p>Input: ${item.input}</p>
19-
<p>Output: ${item.output}</p>
20-
`;
21-
container.appendChild(div);
22-
});
18+
const div = document.createElement("div");
19+
div.className = "prediction-item";
2320

21+
div.innerHTML = `
22+
<p><strong>${item.timestamp}</strong></p>
23+
<p>Input: ${item.input}</p>
24+
<p>Output: ${item.output}</p>
25+
`;
26+
27+
const compareBtn = document.createElement("button");
28+
compareBtn.textContent = "Compare";
29+
30+
compareBtn.onclick = () => {
31+
if (i + 1 < history.length) {
32+
const result = comparePredictions(i + 1, i);
33+
34+
alert(
35+
`Previous Output: ${result.previous.output}
36+
Latest Output: ${result.latest.output}`
37+
);
38+
} else {
39+
alert("No previous prediction available");
40+
}
41+
};
42+
43+
div.appendChild(compareBtn);
44+
45+
container.appendChild(div);
46+
});
2447
if (history.length > 0) {
2548
const clearBtn = document.createElement("button");
2649
clearBtn.textContent = "Clear History";

src/frontend/js/predictionStorage.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,11 @@ export function getPredictions() {
1212
export function clearPredictions() {
1313
localStorage.removeItem("predictions");
1414
}
15+
export function comparePredictions(index1, index2) {
16+
const history = getPredictions();
17+
18+
return {
19+
previous: history[index1],
20+
latest: history[index2]
21+
};
22+
}

0 commit comments

Comments
 (0)