function getNoiseData() { try { $.ajax({ type: "GET", url: '/NoiseRealTime', }).done(function (newdata) { convertdata(newdata); }); function convertdata(data) { flow = data; console.log(flow) for (var i = 0; i<= flow[0].sensordatavalues.length -1; i++){ if (flow[0].sensordatavalues[i].value_type == "noise_LAeq"){ document.getElementById("noise_laeq").innerHTML = flow[0].sensordatavalues[i].value; } else if(flow[0].sensordatavalues[i].value_type == "noise_LA_min") { document.getElementById("noise_lamin").innerHTML = flow[0].sensordatavalues[i].value; } else if(flow[0].sensordatavalues[i].value_type == "noise_LA_max") { document.getElementById("noise_lamax").innerHTML = flow[0].sensordatavalues[i].value; } } } return flow } catch (err) { console.log('loading Gas Values from DB failed!'); } } function noisemap(areatime){ var StreetD = false; var StreetN = false; var RailD = false; var RailN = false; if (areatime == "offS"){ StreetD = false; StreetN = false; } else if (areatime == "offR") { RailD = false; RailN = false; } else if (areatime == "Streetday") { StreetD = true; StreetN = false; RailD = false; RailN = false; } else if (areatime == "Streetnight") { StreetD = false; StreetN = true; RailD = false; RailN = false; } else if (areatime == "Railday") { StreetD = false; StreetN = false; RailD = true; RailN = false; } else if (areatime == "Railnight") { StreetD = false; StreetN = false; RailD = false; RailN = true; } var layerStreetD = ["Streetday"] var layerStreetN = ["Streetnight"] var layerRailD = ["Railday"] var layerRailN = ["Railnight"] var layers = framework.getLayers(); for (var i = 0; i< layers.length; i++) { var layer = layers[i]; if(layerStreetD.indexOf(layer.name) >= 0){ layer.activate(StreetD); } else if (layerStreetN.indexOf(layer.name) >= 0){ layer.activate(StreetN); } else if (layerRailD.indexOf(layer.name) >= 0){ layer.activate(RailD); } else if (layerRailN.indexOf(layer.name) >= 0){ layer.activate(RailN); } } } function noisesens(status){ var layerOn = ["NoiseLocation"] var layers = framework.getLayers(); for (var i = 0; i< layers.length; i++) { var layer = layers[i]; if(layerOn.indexOf(layer.name) >= 0){ if(status == "on"){ layer.activate(true); } else if (status == "off"){ layer.activate(false); } } } } let histNoise function HistNoiseData() { try { $.ajax({ async: false, type: "POST", url: '/getNoiseHist', data: "", }).done(function (histwinddata) { convertdata(histwinddata); }); function convertdata(histwinddt) { histNoise = histwinddt; showgraphNoise(); } console.log(histNoise[0]); } catch (err) { console.log('-> function gethistWind() failed!\n' + err); } } function showgraphNoise(){ var i; var noise_LA_max = 0 var noise_LA_maxnumb = 0 var noise_LA_min = 0 var noise_LAeq = 0 var datas = [] var datasMin = [] var dataseq = [] console.log(histNoise.length) var sDay = new Date('1995-12-17T03:24:00'); for (i = 0; i < histNoise.length; i++) { if (sameDay(sDay,new Date(histNoise[i].timestamp))){ noise_LA_max = noise_LA_max + parseFloat(histNoise[i].noise_LA_max) noise_LA_min = noise_LA_min + parseFloat(histNoise[i].noise_LA_min) noise_LAeq = noise_LAeq + parseFloat(histNoise[i].noise_LAeq) noise_LA_maxnumb = noise_LA_maxnumb + 1 // console.log(noise_LA_maxnumb) } else if (noise_LA_maxnumb != 0){ var valuestuff = noise_LA_max / noise_LA_maxnumb var valuemin = noise_LA_min / noise_LA_maxnumb var valueeq = noise_LAeq / noise_LA_maxnumb console.log(sDay.getFullYear() +"-"+(parseInt(sDay.getMonth()) + 1 )+"-"+sDay.getDate()) datas.push({x: new Date(sDay.getFullYear() +"-"+(parseInt(sDay.getMonth()) + 1 )+"-"+sDay.getDate()).getTime(), y: parseFloat(valuestuff.toFixed(2))}) datasMin.push({x: new Date(sDay.getFullYear() +"-"+(parseInt(sDay.getMonth()) + 1 )+"-"+sDay.getDate()).getTime(), y: parseFloat(valuemin.toFixed(2))}) dataseq.push({x: new Date(sDay.getFullYear() +"-"+(parseInt(sDay.getMonth()) + 1 )+"-"+sDay.getDate()).getTime(), y: parseFloat(valueeq.toFixed(2))}) noise_LA_max = 0 noise_LA_min = 0 noise_LAeq = 0 noise_LA_maxnumb = 0 } sDay = new Date(histNoise[i].timestamp) } console.log(dataseq) console.log("--------") console.log([{ x: new Date('2018-02-12').getTime(), y: 76 }, { x: new Date('2018-02-12').getTime(), y: 76 }]) var options = { chart: { type: "area", height: 300, foreColor: "#999", stacked: false, dropShadow: { enabled: true, enabledSeries: [0], top: -2, left: 2, blur: 5, opacity: 0.06 } }, colors: ['#7F0000','#00E396', '#0090FF'], stroke: { curve: "smooth", width: 3 }, dataLabels: { enabled: false }, series: [{ name: 'Noise_LA_max', data: datas }, { name: 'Noise_LAeq', data: dataseq }, { name: 'Noise_LA_min', data: datasMin }], markers: { size: 0, strokeColor: "#fff", strokeWidth: 3, strokeOpacity: 1, fillOpacity: 1, hover: { size: 6 } }, xaxis: { type: "datetime", axisBorder: { show: false }, axisTicks: { show: false } }, yaxis: { labels: { offsetX: 14, offsetY: -5 }, tooltip: { enabled: true } }, grid: { padding: { left: -5, right: 5 } }, tooltip: { x: { format: "dd MMM yyyy" }, }, legend: { position: 'top', horizontalAlign: 'left' }, fill: { type: 'gradient', gradient: { shadeIntensity: 1, inverseColors: false, opacityFrom: 0.5, opacityTo: 0, stops: [0, 90, 100] }, } }; document.getElementById("chartNoise").innerHTML = ""; var chart = new ApexCharts(document.querySelector("#chartNoise"), options); chart.render(); } function sameDay(d1, d2) { return d1.getFullYear() === d2.getFullYear() && d1.getMonth() === d2.getMonth() && d1.getDate() === d2.getDate(); }