diff --git a/metrics.go b/metrics.go
index 13981e8..3288677 100644
--- a/metrics.go
+++ b/metrics.go
@@ -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" {
diff --git a/snippets/graph.html b/snippets/graph.html
index edeb7a2..4a2357a 100644
--- a/snippets/graph.html
+++ b/snippets/graph.html
@@ -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: {
diff --git a/snippets/scales.html b/snippets/scales.html
index 9962366..d149bf0 100644
--- a/snippets/scales.html
+++ b/snippets/scales.html
@@ -95,7 +95,7 @@ Device ID:
-
{{.Weight}} g
+
{{.Weight_kg}} kg