diff --git a/js/dashboard.js b/js/dashboard.js
index a19f4ea..563c474 100644
--- a/js/dashboard.js
+++ b/js/dashboard.js
@@ -29,6 +29,8 @@ class BlueWeatherDashboard {
loadDashboard() {
window.history.pushState("object or string", "Title", this.buildUrl({ "params": JSON.stringify(this.params) }));
+ this.setTimeRange(this.params.from, this.params.to, false, false)
+
// page: -1 for dashboard or sensor id
var mainContent = document.getElementById('mainContent')
var loader = document.getElementById('loader')
@@ -39,6 +41,10 @@ class BlueWeatherDashboard {
var page = this.params.page
+ if(this.initDone){
+ document.getElementById("navbarPage" + page + "Link").classList.add("active")
+ }
+
this.blueweather.getLocationData(this.params.loc, { from: this.params.range.from, to: this.params.range.to }, this.params.maxVals, true, function (locationData) {
// refresh sensors list
dashboard.loadSensors(locationData.sensors)
@@ -59,14 +65,14 @@ class BlueWeatherDashboard {
var table = document.createElement("table")
tableContainer.appendChild(table)
table.classList.add("table", "table-hover")
-
+
// create forst row of table
var tableHead = document.createElement("thead")
table.appendChild(tableHead)
tableHead.innerHTML = "
Sensor
Minimum
Maximum
Average
"
var tableBody = document.createElement("tbody")
table.appendChild(tableBody)
-
+
for (var i = 0; i < locationData.sensors.length; i++) {
var sensor = locationData.sensors[i]
@@ -84,34 +90,38 @@ class BlueWeatherDashboard {
// get all relevant meassurement values
var vals = []
var sum = 0
- var min
- var max
+ var min = undefined
+ var max = undefined
+ var avg = 0
for (s = 0; s < locationData["measvalues"].length; s++) {
var thisValue = locationData["measvalues"][s]
if (parseInt(thisValue['sensorid']) === parseInt(sensor.id)) {
vals.push(thisValue)
- sum += thisValue.measvalue
- if(thisValue.measvalue < min || min === undefined) {
- min = thisValue.measvalue
+ if (parseFloat(thisValue.measvalue) < min || min === undefined) {
+ min = parseFloat(thisValue.measvalue)
}
- if(thisValue.measvalue > max || max === undefined) {
- max = thisValue.measvalue
+ if (parseFloat(thisValue.measvalue) > max || max === undefined) {
+ max = parseFloat(thisValue.measvalue)
}
}
}
- if(vals.length < 1) {
+ for (s = 0; s < vals.length; s++) {
+ avg += vals[s].measvalue / vals.length
+ }
+
+ if (vals.length < 1) {
continue
}
- vals.sort(function(a,b){
+ vals.sort(function (a, b) {
return b.timestamp - a.timestamp
})
// create table col
var tableRow = document.createElement("tr")
- tableRow.innerHTML = "