// 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 final_url = url + '?user_query=' + user_query
console.log(final_url)
let predictions = await fetch(final_url);
console.log(predictions)
return predictions.json()
} catch (error) {
console.log(error)
}
}
//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';
let response = predictions['predictions']
//loop through number of results
html = ''
var w = 0
for(let i=0; i < response.length; i++){
html += '
';
html += '
';
html += '
';
// library name and description
html += '
';
html += '
'+ response[i]["library_name"] +'
';
html += '
'+ response[i]["Description"] +'
';
html += '
';
// end library name and description
// group button bottom (View GitHub and See Usage Patterns and Configs)
html += '';
html += '
';
html += '
';
// end card group button
html += '
';
html += '
';
//begin accordion outer
html += '
';
// first item
html += '
';
html += '
';
html += '';
html += '
';
html += '
'
html += '
'
// 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 += '
'
//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 += '
';
//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 += '
';
}
html += '
';
// end interface configuration
html += '
'
html += '
'
html += '
'
// end first item
//second item
html += '
';
html += '
';
html += '';
html += '
';
html += '
'
html += '
'
// 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 += '
'
// begin item
html += '
'
html += '
'
if (w == 0){
html += '
'
if (w == 0){
html += '
'
}
else {
html += '
'
}
html += '
'
// being accordion inner
html += '
'; //1
for (let x=0; x < usages_arr.length; x++){
let pattern = usages_arr[x].split("[API-SEP]")
html += '
'; //2
html += '
'; //3
html += '
';
if (x == 0){
html += '';
}
else {
html += '';
}
html += 'Pattern ' + (x+1);
html += '';
html += '
';
//4
if (x== 0){
html += '
';
} else {
html += '
';
}
html += '
' //5
html += '
';
for (let y=0; y' + pattern[y] + '';
}
html += '
';
html += '
' //5
html += '
'; //4
html += '
'; //3
html += '
'; //2
}
html += '
' //1
html += '
'
html += '
'
html += '
'
//end item
html += '
'
// end accordion inner
w += 1
});
// end usage pattern
html += '
'
html += '
'
html += '
'
//end second item
html += '
';
// end accordion outer
//button close
html += '
'
html += '';
html += '
';
// end button close
html += '
';
html += '
';
}
//append the html to the container
document.getElementById("main-parent").innerHTML = (html);
html2 = '
';
//append footer to allow going back to the top
document.getElementById("footer").innerHTML = (html2);
}
else {
document.getElementById("spinner").style.display = 'none';
}
}