better more commits than less...
This commit is contained in:
parent
b66e8a0681
commit
7c9e198311
43
metrics.go
43
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
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 904 B |
|
|
@ -20,7 +20,7 @@
|
|||
<nav class="navbar" aria-label="main navigation">
|
||||
<div class="navbar-brand">
|
||||
<a class="navbar-item" href="/">
|
||||
<img src="/static/images/wo-bisch-logo-28x28.png" alt="wo-bisch Logo" width="28" height="28">
|
||||
<img src="/static/images/wo-bisch-logo-mit-schrift.png" alt="wo-bisch Logo" width="154" height="28">
|
||||
</a>
|
||||
<a role="button" class="navbar-burger" data-target="navMenu" aria-label="menu" aria-expanded="false">
|
||||
<span aria-hidden="true"></span>
|
||||
|
|
|
|||
Loading…
Reference in New Issue