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
|
Alias string
|
||||||
Readonly bool
|
Readonly bool
|
||||||
Timestamp string
|
Timestamp string
|
||||||
|
PosTimestamp string
|
||||||
Lat string
|
Lat string
|
||||||
Lon string
|
Lon string
|
||||||
LatJS template.JS
|
LatJS template.JS
|
||||||
|
|
@ -205,9 +206,10 @@ func getLastMetrics(deveui string) OneMetric {
|
||||||
url := "http://localhost:8086/api/v2/query?org=wobischorg"
|
url := "http://localhost:8086/api/v2/query?org=wobischorg"
|
||||||
data := []byte(fmt.Sprintf(`from(bucket:"wobischbucket")
|
data := []byte(fmt.Sprintf(`from(bucket:"wobischbucket")
|
||||||
|> range(start:-365d)
|
|> range(start:-365d)
|
||||||
|
|> tail(n:10)
|
||||||
|> filter(fn: (r) => r._measurement == "measurement" and r.deveui == "%s")
|
|> 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")
|
|> filter(fn: (r) => r._field == "lon" or r._field == "lat" or r._field == "vbat" or r._field == "fw")
|
||||||
|> last(column: "_time") |> yield(name: "last")`, deveui))
|
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")`, deveui))
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", url, bytes.NewBuffer(data))
|
req, err := http.NewRequest("POST", url, bytes.NewBuffer(data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -243,32 +245,39 @@ func getLastMetrics(deveui string) OneMetric {
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
s := strings.Split(scanner.Text(), ",")
|
s := strings.Split(scanner.Text(), ",")
|
||||||
fmt.Printf("BlaBla: %v\n", s)
|
fmt.Printf("BlaBla: %v\n", s)
|
||||||
if (len(s) >= 7) && !(strings.HasPrefix(s[5], "_")) {
|
if (len(s) >= 12) && !(strings.HasPrefix(s[3], "_")) {
|
||||||
mytime, err := time.Parse(time.RFC3339, s[5])
|
t, err := time.Parse(time.RFC3339, s[3])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Printf("error converting time: %s\n", s[3])
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
res.Timestamp = mytime.In(location).Format("02.01.2006 15:04")
|
|
||||||
value := s[6]
|
res.Fw = s[8]
|
||||||
field := s[7]
|
res.Timestamp = t.In(location).Format("02.01.2006 15:04")
|
||||||
if field == "lat" {
|
if s[9] != "0" {
|
||||||
res.Lat = value
|
res.Lat = s[9]
|
||||||
res.LatJS = template.JS(value)
|
res.PosTimestamp = t.In(location).Format("02.01.2006 15:04")
|
||||||
} 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
|
|
||||||
}
|
}
|
||||||
|
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.Deveui = deveui
|
||||||
res.DeveuiJS = template.JS(deveui)
|
res.DeveuiJS = template.JS(deveui)
|
||||||
|
res.LatJS = template.JS(res.Lat)
|
||||||
|
res.LonJS = template.JS(res.Lon)
|
||||||
|
|
||||||
res.Alias = getDevAlias(deveui)
|
res.Alias = getDevAlias(deveui)
|
||||||
res.Readonly = false
|
res.Readonly = false
|
||||||
res.ActiveUntil = getActiveUntil(deveui)
|
res.ActiveUntil = getActiveUntil(deveui)
|
||||||
res.DaysUntilDeactivated = CalcDaysUntil(res.ActiveUntil)
|
res.DaysUntilDeactivated = CalcDaysUntil(res.ActiveUntil)
|
||||||
|
|
||||||
|
fmt.Printf("Last Metrics: %v\n", res)
|
||||||
return 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">
|
<nav class="navbar" aria-label="main navigation">
|
||||||
<div class="navbar-brand">
|
<div class="navbar-brand">
|
||||||
<a class="navbar-item" href="/">
|
<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>
|
||||||
<a role="button" class="navbar-burger" data-target="navMenu" aria-label="menu" aria-expanded="false">
|
<a role="button" class="navbar-burger" data-target="navMenu" aria-label="menu" aria-expanded="false">
|
||||||
<span aria-hidden="true"></span>
|
<span aria-hidden="true"></span>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue