-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
66 lines (54 loc) · 2.16 KB
/
util.js
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
// Funktion zum Speichern einer Klassifizierung in der Datenbank
function saveClassification(isCorrect) {
let data = {
label: resultDiv.elt.textContent.split(':')[1].trim(),
confidence: parseFloat(resultDiv.elt.textContent.split(':')[3].trim()),
thumbnailUrl: img.elt.src,
isCorrect: isCorrect
};
let classificationsKey = isCorrect ? 'correctClassifications' : 'incorrectClassifications';
let classifications = JSON.parse(localStorage.getItem(classificationsKey)) || [];
classifications.push(data);
localStorage.setItem(classificationsKey, JSON.stringify(classifications));
// Aktualisiere die Tabellen mit den letzten Klassifizierungen
loadLastClassifications();
}
// Funktion zum Laden der letzten Klassifizierungen in die Tabellen
function loadLastClassifications() {
let correctClassifications = JSON.parse(localStorage.getItem('correctClassifications')) || [];
let incorrectClassifications = JSON.parse(localStorage.getItem('incorrectClassifications')) || [];
fillTable('correctBody', correctClassifications);
fillTable('incorrectBody', incorrectClassifications);
}
// Hilfsfunktion zum Füllen einer Tabelle mit Klassifizierungsdaten
function fillTable(tableId, data) {
let tableBody = document.getElementById(tableId);
tableBody.innerHTML = ''; // Tabelle leeren
data.slice(-3).forEach(item => {
let row = tableBody.insertRow();
let thumbnailCell = row.insertCell(0);
let labelCell = row.insertCell(1);
let confidenceCell = row.insertCell(2);
thumbnailCell.innerHTML = `<img src="${item.thumbnailUrl}" width="100">`;
labelCell.textContent = item.label;
confidenceCell.textContent = nf(item.confidence, 0, 2);
});
}
// Drag-and-Drop-Stilfunktionen
function highlight() {
select('#drop_zone').style('background-color', '#eee');
}
function unhighlight() {
select('#drop_zone').style('background-color', '');
}
// Verhindern des Standardverhaltens beim Drag-and-Drop
window.ondragover = function (e) {
e.preventDefault();
return false;
};
window.ondrop = function (e) {
e.preventDefault();
return false;
};
// Laden der letzten Klassifizierungen beim Laden der Seite
window.onload = loadLastClassifications;