diff --git a/metrics.go b/metrics.go index ad061cd..d76e160 100644 --- a/metrics.go +++ b/metrics.go @@ -19,6 +19,7 @@ type OneMetric struct { Alias string Readonly bool Timestamp string + PosTimestamp string Lat string Lon string LatJS template.JS @@ -205,9 +206,10 @@ func getLastMetrics(deveui string) OneMetric { url := "http://localhost:8086/api/v2/query?org=wobischorg" data := []byte(fmt.Sprintf(`from(bucket:"wobischbucket") |> range(start:-365d) + |> tail(n:10) |> filter(fn: (r) => r._measurement == "measurement" and r.deveui == "%s") - |> filter(fn: (r) => r._field == "lat" or r._field == "lon" or r._field == "vbat" or r._field == "fw") - |> last(column: "_time") |> yield(name: "last")`, deveui)) + |> filter(fn: (r) => r._field == "lon" or r._field == "lat" or r._field == "vbat" or r._field == "fw") + |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")`, deveui)) req, err := http.NewRequest("POST", url, bytes.NewBuffer(data)) if err != nil { @@ -243,32 +245,39 @@ func getLastMetrics(deveui string) OneMetric { for scanner.Scan() { s := strings.Split(scanner.Text(), ",") fmt.Printf("BlaBla: %v\n", s) - if (len(s) >= 7) && !(strings.HasPrefix(s[5], "_")) { - mytime, err := time.Parse(time.RFC3339, s[5]) + if (len(s) >= 12) && !(strings.HasPrefix(s[3], "_")) { + t, err := time.Parse(time.RFC3339, s[3]) if err != nil { + fmt.Printf("error converting time: %s\n", s[3]) continue } - res.Timestamp = mytime.In(location).Format("02.01.2006 15:04") - value := s[6] - field := s[7] - if field == "lat" { - res.Lat = value - res.LatJS = template.JS(value) - } else if field == "lon" { - res.Lon = value - res.LonJS = template.JS(value) - } else if field == "vbat" { - res.Vbat = value - } else if field == "fw" { - res.Fw = value + + res.Fw = s[8] + res.Timestamp = t.In(location).Format("02.01.2006 15:04") + if s[9] != "0" { + res.Lat = s[9] + res.PosTimestamp = t.In(location).Format("02.01.2006 15:04") } + if s[10] != "0" { + res.Lon = s[10] + res.PosTimestamp = t.In(location).Format("02.01.2006 15:04") + } + res.BatteryPercent = s[11] + } + } + res.Deveui = deveui res.DeveuiJS = template.JS(deveui) + res.LatJS = template.JS(res.Lat) + res.LonJS = template.JS(res.Lon) + res.Alias = getDevAlias(deveui) res.Readonly = false res.ActiveUntil = getActiveUntil(deveui) res.DaysUntilDeactivated = CalcDaysUntil(res.ActiveUntil) + + fmt.Printf("Last Metrics: %v\n", res) return res } diff --git a/static/favicon.ico b/static/favicon.ico index 358d8c8..578b1b4 100644 Binary files a/static/favicon.ico and b/static/favicon.ico differ diff --git a/static/images/wo-bisch-logo-64x64.png b/static/images/wo-bisch-logo-64x64.png index ec3d735..629e8e8 100644 Binary files a/static/images/wo-bisch-logo-64x64.png and b/static/images/wo-bisch-logo-64x64.png differ diff --git a/static/images/wo-bisch-logo-mit-schrift.png b/static/images/wo-bisch-logo-mit-schrift.png new file mode 100644 index 0000000..c95166d Binary files /dev/null and b/static/images/wo-bisch-logo-mit-schrift.png differ diff --git a/static/images/wo-bisch-logo-spitz-28x28.png b/static/images/wo-bisch-logo-spitz-28x28.png new file mode 100644 index 0000000..ef867dc Binary files /dev/null and b/static/images/wo-bisch-logo-spitz-28x28.png differ diff --git a/templates/layout.html b/templates/layout.html index ef8cf8c..e982efb 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -20,7 +20,7 @@