modify display of weight
This commit is contained in:
parent
6d3c69e967
commit
274c5dc9e7
|
|
@ -9,6 +9,7 @@ import (
|
|||
"io/ioutil"
|
||||
"bufio"
|
||||
"strings"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type OneMetric struct {
|
||||
|
|
@ -20,6 +21,7 @@ type OneMetric struct {
|
|||
Temperature string
|
||||
Humidity string
|
||||
Weight string
|
||||
Weight_kg string
|
||||
Pressure string
|
||||
BatteryPercent string
|
||||
ActiveUntil string
|
||||
|
|
@ -324,6 +326,12 @@ func getLastMetrics(deveui string) OneMetric {
|
|||
res.Humidity = value
|
||||
} else if field == "w" {
|
||||
res.Weight = value
|
||||
i, err := strconv.Atoi(value)
|
||||
if (err == nil) {
|
||||
res.Weight_kg = fmt.Sprintf("%.2f",float64(i) / 1000.0)
|
||||
} else {
|
||||
res.Weight_kg = "ERR"
|
||||
}
|
||||
} else if field == "p" {
|
||||
res.Pressure = value
|
||||
} else if field == "vp" {
|
||||
|
|
|
|||
|
|
@ -160,34 +160,46 @@ function drawGraph(deveui, alias, property, start, stop, create_graph) {
|
|||
range = range + "&stop=" + stop;
|
||||
|
||||
var label;
|
||||
var labels = {};
|
||||
$(".button").removeClass("is-success");
|
||||
if (property=="t") {
|
||||
$("#btn_t").addClass("is-success");
|
||||
label = 'Temperatur';
|
||||
mysubtitle = 'Temperatur in °C';
|
||||
minfunc = function(min) { if (min > 0) { return 0 } else { return min } }
|
||||
maxfunc = function(max) { return max + 5 }
|
||||
} else if (property=="vp") {
|
||||
$("#btn_vp").addClass("is-success");
|
||||
label = 'Akkuladung';
|
||||
mysubtitle = 'Akkuladung in Prozent';
|
||||
minfunc = function(min) { return 0 }
|
||||
maxfunc = function(max) { return 100 }
|
||||
} else if (property=="w") {
|
||||
$("#btn_w").addClass("is-success");
|
||||
label = 'Gewicht';
|
||||
mysubtitle = 'Gewicht in Kilogramm';
|
||||
minfunc = function(min) { if (min > 40000) { return min - 2000 } else { return 0 } }
|
||||
maxfunc = function(max) { return max + 2000 }
|
||||
labels = {
|
||||
formatter: function(val, index) {
|
||||
return (val / 1000.0).toFixed(2);
|
||||
}
|
||||
};
|
||||
} else if (property==="h") {
|
||||
$("#btn_h").addClass("is-success");
|
||||
label = 'Luftfeuchtigkeit';
|
||||
mysubtitle = 'Luftfeuchtigkeit in Prozent';
|
||||
minfunc = function(min) { return 0 }
|
||||
maxfunc = function(max) { return 100 }
|
||||
} else if (property=="p") {
|
||||
$("#btn_p").addClass("is-success");
|
||||
label = 'Luftdruck';
|
||||
mysubtitle = 'Luftdruck in Hektopascal';
|
||||
minfunc = function(min) { return 900 }
|
||||
maxfunc = function(max) { return 1060 }
|
||||
} else {
|
||||
label = 'Unknown';
|
||||
mysubtitle = 'Unknown';
|
||||
}
|
||||
|
||||
$.getJSON('https://mini-beieli.ch/metrics?deveui=' + deveui + '&alias=' + alias + '&property=' + property + range, function(mydata) {
|
||||
|
|
@ -209,6 +221,14 @@ function drawGraph(deveui, alias, property, start, stop, create_graph) {
|
|||
fontSize: '32px'
|
||||
}
|
||||
},
|
||||
subtitle: {
|
||||
text: mysubtitle,
|
||||
align: 'center',
|
||||
offsetY: 60,
|
||||
style: {
|
||||
fontSize: '12px'
|
||||
}
|
||||
},
|
||||
xaxis: {
|
||||
type: "datetime",
|
||||
labels: {
|
||||
|
|
@ -217,7 +237,9 @@ function drawGraph(deveui, alias, property, start, stop, create_graph) {
|
|||
},
|
||||
yaxis: {
|
||||
min: minfunc,
|
||||
max: maxfunc
|
||||
max: maxfunc,
|
||||
forceNiceScale: true,
|
||||
labels: labels
|
||||
},
|
||||
tooltip: {
|
||||
x: {
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ Device ID: <span id="deveui"></span>
|
|||
<a class="block-link" href="/graph.html?deveui={{.Deveui}}&alias={{.Alias}}&property=w">
|
||||
<div>
|
||||
<p class="icon"><i class="fa fa-balance-scale"></i></p>
|
||||
<p id="weight_{{.Deveui}}" class="title is-size-2 has-text-weight-bold">{{.Weight}} g</p>
|
||||
<p id="weight_{{.Deveui}}" class="title is-size-2 has-text-weight-bold">{{.Weight_kg}} kg</p>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue