-
Notifications
You must be signed in to change notification settings - Fork 0
/
resultTrain.js
142 lines (111 loc) · 4.03 KB
/
resultTrain.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
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
136
137
138
139
var acceptContainer = document.getElementById('acceptable');
var notAcceptContainer = document.getElementById('non-acceptable');
const xhr = new XMLHttpRequest();
var jsonData=[];
var acceptedItems=[];
var notAcceptedItems=[];
var acceptedNames=[];
var notAcceptedNames=[];
// Retrieve the JSON data from local storage
const savedJsonData = localStorage.getItem('resultArray');
// Check if there is any saved JSON data
if (savedJsonData) {
// Parse the JSON data back to a JavaScript object
jsonData = JSON.parse(savedJsonData);
console.log("json saved successfully");
console.log(jsonData);
} else {
console.log('No saved JSON data found.');
}
xhr.open('GET', 'https://raw.githubusercontent.com/VaishaliMahipal/ChemicalAI/main/labjsondata.json');
xhr.onload = () => {
if (xhr.status === 200) {
// jsonData2 = JSON.parse(xhr.responseText);
} else {
console.error('Failed to load JSON data');
}
console.log('Length of jsonData');
console.log(jsonData.length);
for (let j = 0; j < jsonData.length; j++) {
const obj = jsonData[j];
if (obj.label === 0) {
notAcceptedItems.push(
Object.assign({}, obj)
);
}
else if (obj.label === 1) {
acceptedItems.push(
Object.assign({}, obj)
);
}
}
console.log("acceptedItems");
console.log(acceptedItems);
var i=0;
acceptedItems.forEach(item => {
acceptedNames[i]=(item.Object);
i=i+1;
});
var k=0;
notAcceptedItems.forEach(item => {
notAcceptedNames[k]=(item.Object);
k=k+1;
});
console.log("notAcceptedNames");
console.log(notAcceptedNames);
console.log("acceptedNames");
console.log(acceptedNames);
displayImages();
};
xhr.send();
function displayImages() {
for (var i=0;i<acceptedNames.length;i++){
const checkboxWrapperDiv = document.createElement("div");
const checkboxDiv = document.createElement("div");
checkboxDiv.classList.add("formTest-elementTest");
var imgName = "ImageIcon/"+acceptedNames[i]+".jpg";
const encodedUrl = encodeURIComponent(imgName);
var label = document.createElement('label')
label.htmlFor = acceptedNames[i];
label.appendChild(document.createTextNode(acceptedNames[i]));
label.style.backgroundImage = `url(${encodedUrl})`;
label.style.backgroundSize = 'cover';
checkboxDiv.appendChild(label);
checkboxWrapperDiv.appendChild(checkboxDiv);
checkboxWrapperDiv.appendChild(document.createElement("br"));
acceptContainer.appendChild(checkboxWrapperDiv);
}
for (var i=0;i<notAcceptedNames.length;i++){
const checkboxWrapperDiv = document.createElement("div");
const checkboxDiv = document.createElement("div");
checkboxDiv.classList.add("formTest-elementTest");
var imgName = "ImageIcon/"+notAcceptedNames[i]+".jpg";
const encodedUrl = encodeURIComponent(imgName);
var label = document.createElement('label')
label.htmlFor = notAcceptedNames[i];
label.appendChild(document.createTextNode(notAcceptedNames[i]));
label.style.backgroundImage = `url(${encodedUrl})`;
label.style.backgroundSize = 'cover';
checkboxDiv.appendChild(label);
checkboxWrapperDiv.appendChild(checkboxDiv);
checkboxWrapperDiv.appendChild(document.createElement("br"));
notAcceptContainer.appendChild(checkboxWrapperDiv);
}
}
export function saveResponse() {
var resultArray = [];
var ele = document.getElementsByName('choice-radio');
for(var i = 0; i < ele.length; i++) {
if(ele[i].checked)
resultArray.push(ele[i].value);
}
var ajax = new XMLHttpRequest();
ajax.open("POST", "save_data_file.php", true);
ajax.setRequestHeader("Content-type", "application/json;charset=UTF-8");
ajax.send(JSON.stringify(resultArray));
ajax.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
}
};
}