Spaces:
Build error
Build error
File size: 16,700 Bytes
766a3cf e10f5bd 4ef3e67 e10f5bd 8e49510 9656e53 766a3cf 4ef3e67 e10f5bd 4ef3e67 e10f5bd 766a3cf e10f5bd 766a3cf e10f5bd 766a3cf e10f5bd 4ef3e67 33b9322 0b3a476 4ef3e67 33b9322 4ef3e67 e10f5bd 4ef3e67 e10f5bd 4ef3e67 e10f5bd 4ef3e67 e10f5bd 4ef3e67 e10f5bd 4ef3e67 e10f5bd 4ef3e67 e10f5bd 4ef3e67 e10f5bd 4ef3e67 e10f5bd 4ef3e67 e10f5bd 766a3cf e10f5bd |
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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
// const response = [
// {
// "id": 446929723,
// "library_name": "DHT20",
// "hw_config": {
// "protocol": "I2C",
// "pin_connection_from_hw_to_arduino": {
// "arduino_mega": [["SDA", "21"], ["SCL", "21"]],
// "arduino_uno": [["SDA", "A4"], ["SCL", "A5"]],
// }
// },
// "usage_patterns": {
// "DHT20": [
// "DHT20.begin DHT20.lastRead DHT20.read DHT20.getHumidity DHT20.getTemperature",
// "DHT20.begin DHT20.read DHT20.getHumidity DHT20.getTemperature",
// "DHT20.begin DHT20.read DHT20.getHumidity"
// ],
// "DHT12": [
// "DHT12.begin",
// "DHT12.begin DHT12.lastRead DHT12.read DHT12.getHumidity DHT12.getTemperature",
// "DHT12.begin DHT12.read DHT12.getHumidity DHT12.getTemperature"
// ]
// },
// "Sensor Type": "Sensors",
// "Github URL": "https://github.com/RobTillaart/DHT20",
// "Description": "Arduino library for I2C DHT20 temperature and humidity sensor."
// },
// {
// "id": 255120181,
// "library_name": "DHT12",
// "hw_config": {
// "protocol": "I2C",
// "pin_connection_from_hw_to_arduino": {
// "arduino_mega": [["SDA", "20"], ["SCL", "21"]],
// "arduino_uno": [["SDA", "A4"], ["SCL", "A5"]],
// }
// },
// "usage_patterns": {
// "DHT12": [
// "DHT12.begin",
// "DHT12.begin DHT12.lastRead DHT12.read DHT12.getHumidity DHT12.getTemperature",
// "DHT12.begin DHT12.read DHT12.getHumidity DHT12.getTemperature"
// ]
// },
// "Sensor Type": "Sensors",
// "Github URL": "https://github.com/RobTillaart/DHT12",
// "Description": "Arduino library for I2C DHT12 temperature and humidity sensor."
// }
// ];
//display the pop up with more information
function onClickMore(string){
document.getElementById(string).style.display ='block';
}
//hide the pop up with more information
function onOut(string){
document.getElementById(string).style.display ='none';
}
// async function getResponse(url, user_query){
// try {
// let predictions = await fetch(url,{
// method: 'POST',
// body: JSON.stringify({'user_query': user_query}),
// headers: {
// 'Content-type': 'application/json; charset=UTF-8',
// 'Access-Control-Allow-Origin': '*',
// 'Access-Control-Allow-Methods': 'POST, GET',
// }
// });
// return predictions.json()
// } catch (error) {
// console.log(error)
// }
// }
// async function getResponse(url, user_query){
// try {
// let final_url = url + '?user_query=' + user_query
// console.log(final_url)
// let predictions = await fetch(final_url);
// console.log(predictions)
// if (predictions.status == 200){
// return predictions.json()
// }
// else{
// document.getElementById("spinner").style.display = 'none';
// let error_msg = "Error, return code: " + predictions.status
// alert(error_msg);
// }
// } catch (error) {
// document.getElementById("spinner").style.display = 'none';
// console.log("error")
// console.log(error)
// let error_msg = "Error, return code: " + predictions.status
// alert(error_msg);
// }
// }
async function getResponse(url, user_query){
let final_url = url + '?user_query=' + user_query
console.log(final_url)
let predictions = await fetch(final_url)
.then(res => {
if (res.ok){
return res.json()
} else {
throw new Error(res.text())
}
})
.catch(error => alert(error))
return predictions
}
//when retrieve is clicked
async function onSubmit(){
document.getElementById("spinner").style.display = 'none';
document.getElementById("spinner").style.display = 'block';
document.getElementById("main-parent").innerHTML = '';
let user_query = document.getElementById("exampleFormControlInput1").value
// let url_query = "http://10.27.32.183:8111/predict"
if (user_query != ''){
document.getElementById("spinner").style.display = 'block';
let url_query = "/predict"
let predictions = await getResponse(url_query, user_query)
document.getElementById("spinner").style.display = 'none';
// document.getElementById("grey-container").className = 'album py-5 bg-light';
if (typeof predictions['predictions'] == "string"){
alert("Library not found in the database. Please try another query!")
document.getElementById("footer").innerHTML = '';
} else {
let response = predictions['predictions']
//loop through number of results
html = ''
var w = 0
for(let i=0; i < response.length; i++){
html += '<div class="row g-4 m-2" id="predictions">';
html += '<div class="col-6">';
html += '<div class="card border-primary mb-3">';
// library name and description
html += '<div class="card-body">';
html += '<h5 class="card-title text-primary">'+ response[i]["library_name"] +'</h5>';
html += '<p class="card-text">'+ response[i]["Description"] +'</p>';
html += '</div>';
// end library name and description
// group button bottom (View GitHub and See Usage Patterns and Configs)
html += '<div class="card-footer">';
html += '<div class=" d-flex justify-content-between align-items-center">';
html += '<div class="btn-group">'
html += '<a type="button" class="btn btn-sm btn-outline-secondary" href='+ response[i]["Github URL"] +'>View Github</a>';
html += '</div>'
html += '<a href="javascript:void(0)" id="myTooltip" data-bs-toggle="tooltip" data-bs-placement="right" onclick="onClickMore('+ response[i]["id"] +')">See Usage Patterns and Interface Configs</a>';
html += '</div>';
html += '</div>';
html += '</div>';
html += '</div>';
// end card group button
html += '<div class="col-6"><div id="'+ response[i]["id"] +'" style="display: none;" class="card border-primary mb-3">';
html += '<div class="card-body">';
//begin accordion outer
html += '<div class="accordion" id="accordionOuter'+ i + '">';
// first item
html += '<div class="accordion-item">';
html += '<h2 class="accordion-header" id="headingOneOuter"'+ i + '>';
html += '<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne'+ i +'" aria-expanded="true" aria-controls="collapseOne'+ i +'">'
html += 'Interface Configuration';
html += '</button>';
html += '</h2>';
html += '<div id="collapseOne'+ i +'" class="accordion-collapse collapse show" aria-labelledby="headingOneOuter"'+ i +'data-bs-parent="#accordionOuter'+ i + '">'
html += '<div class="accordion-body">'
// html += 'Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven\'t heard of them accusamus labore sustainable VHS.'
// interface configuration begin
html += '<h6>Library Configuration: '+ response[i]["hw_config"]["protocol"]+ '</h6>';
html += '<table class="table table-hover"><thead><tr><th>Controller Type</th><th>I/O hardware --> Arduino</th></tr></thead><tbody>'
//loop through hardware config
for (const property in response[i]["hw_config"]["pin_connection_from_hw_to_arduino"]){
// let firstLetter = property.charAt(0).toUpperCase();
// let remLetter = property.substring(1).split("_");
html += '<tr><td>' + property +'</td><td>';
//loop through the arduino type
for (let y=0; y < response[i]["hw_config"]["pin_connection_from_hw_to_arduino"][property].length; y++){
// html += '(' + (response[i]["hw_config"]["pin_connection_from_hw_to_arduino"][property][y][0] + ',' + response[i]["hw_config"]["pin_connection_from_hw_to_arduino"][property][y][1]) + ') ';
html += '(' + response[i]["hw_config"]["pin_connection_from_hw_to_arduino"][property][y] +') ';
}
html += ' </td></tr>';
}
html += '</tbody></table> ';
// end interface configuration
html += '</div>'
html += '</div>'
html += '</div>'
// end first item
//second item
html += '<div class="accordion-item">';
html += '<h2 class="accordion-header" id="headingTwoOuter'+ i +'">';
html += '<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo'+ i +'" aria-expanded="false" aria-controls="collapseTwo'+ i +'">'
html += 'Usage Patterns';
html += '</button>';
html += '</h2>';
html += '<div id="collapseTwo'+ i +'" class="accordion-collapse collapse" aria-labelledby="headingTwoOuter'+ i +'" data-bs-parent="#accordionOuter'+ i + '">'
html += '<div class="accordion-body">'
// html += 'Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven\'t heard of them accusamus labore sustainable VHS.'
// begin usage pattern
let w = 0
Object.keys(response[i]["usage_patterns"]).forEach(function(key) {
let usages_arr = response[i]["usage_patterns"][key]
// begin accordion inner
html += '<div class="accordion" id="accordionInner">'
// begin item
html += ' <div class="accordion-item">'
html += ' <h2 class="accordion-header" id="headingOneInner'+ key + i +'">'
if (w == 0){
html += ' <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOneInner'+ key + i +'" aria-expanded="true" aria-controls="collapseOneInner'+ key + i +'">'
}
else {
html += ' <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOneInner'+ key + i +'" aria-expanded="false" aria-controls="collapseOneInner'+ key + i +'">'
}
html += ' Sensor Object: '+ key
html += ' </button>'
html += ' </h2>'
if (w == 0){
html += ' <div id="collapseOneInner'+ key + i +'" class="accordion-collapse collapse show" aria-labelledby="headingOneInner'+ key + i +'">'
}
else {
html += ' <div id="collapseOneInner'+ key + i +'" class="accordion-collapse collapse" aria-labelledby="headingOneInner'+ key + i +'">'
}
html += ' <div class="accordion-body">'
// being accordion inner
html += '<div style="margin-bottom: 15px" class="accordion" id="accordionPanelsStayOpenExample"' + response[i]["id"] + key + '>'; //1
for (let x=0; x < usages_arr.length; x++){
let pattern = usages_arr[x].split("[API-SEP]")
html += '<div data-bs-toggle="collapse" data-bs-target="#patternCollapse' + response[i]["id"] + key + x + '">'; //2
html += '<div class="accordion-item">'; //3
html += '<h2 class="accordion-header" id="panelsStayOpen-heading' + response[i]["id"] + key +'">';
if (x == 0){
html += '<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#panelsStayOpen-collapse' + response[i]["id"] + key + x + '" aria-expanded="true" aria-controls="panelsStayOpen-collapse' + response[i]["id"] + key + x + '">';
}
else {
html += '<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#panelsStayOpen-collapse' + response[i]["id"] + key + x + '" aria-expanded="false" aria-controls="panelsStayOpen-collapse' + response[i]["id"] + key + x + '">';
}
html += 'Pattern ' + (x+1);
html += '</button>';
html += '</h2>';
//4
if (x== 0){
html += '<div id="panelsStayOpen-collapse' + response[i]["id"] + key + x + '" class="accordion-collapse collapse show" aria-labelledby="panelsStayOpen-heading' + response[i]["id"] + key + x + '">';
} else {
html += '<div id="panelsStayOpen-collapse' + response[i]["id"] + key + x + '" class="accordion-collapse collapse" aria-labelledby="panelsStayOpen-heading' + response[i]["id"] + key + x + '">';
}
html += '<div class="accordion-body">' //5
html += '<ul>';
for (let y=0; y<pattern.length; y++){
html += '<li>' + pattern[y] + '</li>';
}
html += '</ul>';
html += '</div>' //5
html += '</div>'; //4
html += '</div>'; //3
html += '</div>'; //2
}
html += '</div>' //1
html += ' </div>'
html += ' </div>'
html += ' </div>'
//end item
html += '</div>'
// end accordion inner
w += 1
});
// end usage pattern
html += '</div>'
html += '</div>'
html += '</div>'
//end second item
html += '</div>';
// end accordion outer
//button close
html += '<div class="position-absolute top-0 end-0">'
html += '<button type="button" class="btn-close" aria-label="Close" onclick="onOut('+ response[i]["id"] +')"></button>';
html += '</div>';
// end button close
html += '</div></div>';
html += '</div></div>';
}
//append the html to the container
document.getElementById("main-parent").innerHTML = (html);
html2 = '<div class="container"><p class="float-right"><a href="#">Back to top</a></p>';
//append footer to allow going back to the top
document.getElementById("footer").innerHTML = (html2);
}
}
else {
document.getElementById("spinner").style.display = 'none';
}
}
|