time range is now displayed in the time range button
This commit is contained in:
parent
72ea619f6d
commit
9899b27e5f
1 changed files with 133 additions and 63 deletions
|
@ -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)
|
||||
|
@ -84,23 +90,27 @@ 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (s = 0; s < vals.length; s++) {
|
||||
avg += vals[s].measvalue / vals.length
|
||||
}
|
||||
|
||||
if (vals.length < 1) {
|
||||
continue
|
||||
}
|
||||
|
@ -111,7 +121,7 @@ class BlueWeatherDashboard {
|
|||
|
||||
// create table col
|
||||
var tableRow = document.createElement("tr")
|
||||
tableRow.innerHTML = "<td>" + sensor.sensorname + " (" + valueType.valuetype + ", " + valueType.valueunit + ")" + "</td><td>" + min + "</td><td>" + max + "</td><td>" + (Math.round((sum / vals.length)*100)/100) + "</td>"
|
||||
tableRow.innerHTML = "<td>" + sensor.sensorname + " (" + valueType.valuetype + ", " + valueType.valueunit + ")" + "</td><td>" + min + "</td><td>" + max + "</td><td>" + (Math.round((avg) * 100) / 100) + "</td>"
|
||||
tableBody.appendChild(tableRow)
|
||||
|
||||
// - create widget card -
|
||||
|
@ -218,9 +228,11 @@ class BlueWeatherDashboard {
|
|||
this.loadDashboard()
|
||||
}
|
||||
|
||||
setTimeRange(from = "", to = "") {
|
||||
setTimeRange(from = "", to = "", offset = true, autoReload = true) {
|
||||
// offset: if true the gien times will be substracted from the current time to get the target time
|
||||
this.blueweather.log("changing time range; form: " + from + "; to: " + to + "; (now is: " + new Date().getTime() + ")", 3)
|
||||
|
||||
if (offset) {
|
||||
if (from !== "") {
|
||||
from = new Date().getTime() / 1000 - from
|
||||
}
|
||||
|
@ -228,8 +240,37 @@ class BlueWeatherDashboard {
|
|||
if (to !== "") {
|
||||
to = new Date().getTime() / 1000 - parseInt(to)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(from !== ""){
|
||||
from = parseInt(from)
|
||||
}
|
||||
if(to !== ""){
|
||||
to = parseInt(to)
|
||||
}
|
||||
}
|
||||
|
||||
var tmpFrom = from
|
||||
var tmpTo = to
|
||||
|
||||
if(tmpFrom === "") {
|
||||
tmpFrom = Math.round( new Date().getTime() / 1000 - 60 * 60 * 24 )
|
||||
}
|
||||
|
||||
if(tmpTo === "") {
|
||||
tmpTo = Math.round(new Date().getTime() / 1000)
|
||||
}
|
||||
|
||||
var dateFromString = this.getDateTimeString(tmpFrom, tmpTo-tmpFrom)
|
||||
var dateToString = this.getDateTimeString(tmpTo, tmpTo-tmpFrom)
|
||||
|
||||
dropdownMenuButton.innerHTML = "<span data-feather=\"calendar\"></span> " + dateFromString + " - " + dateToString
|
||||
feather.replace()
|
||||
|
||||
|
||||
if (this.initDone && autoReload) {
|
||||
this.updateParams({ range: { to: to, from: from } })
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -468,6 +509,35 @@ class BlueWeatherDashboard {
|
|||
})
|
||||
}
|
||||
|
||||
getDateTimeString(unixTime, range = 0) {
|
||||
|
||||
if(Math.abs(unixTime - new Date().getTime() / 1000) <= 60 ) {
|
||||
return "now"
|
||||
}
|
||||
|
||||
var d = new Date(parseInt(unixTime) * 1000);
|
||||
var datestr = ""
|
||||
if (range <= 60 * 60 * 24 * 31) {
|
||||
// covers one month or less
|
||||
|
||||
datestr =
|
||||
("0" + d.getDate()).slice(-2) + "-" +
|
||||
("0" + (d.getMonth() + 1)).slice(-2) + " " +
|
||||
("0" + d.getHours()).slice(-2) + ":" +
|
||||
("0" + d.getMinutes()).slice(-2)
|
||||
}
|
||||
else {
|
||||
// covers more than a month
|
||||
|
||||
datestr =
|
||||
d.getFullYear() + "-" +
|
||||
("0" + d.getDate()).slice(-2) + "-" +
|
||||
("0" + (d.getMonth() + 1)).slice(-2)
|
||||
}
|
||||
|
||||
return datestr
|
||||
}
|
||||
|
||||
setPageTitle(title) {
|
||||
document.getElementById("titleH1").innerHTML = title
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue