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