fix last time

This commit is contained in:
Joerg Lehmann 2021-04-15 21:59:17 +02:00
parent 36381c5903
commit b0067f6679
1 changed files with 3 additions and 3 deletions

View File

@ -389,9 +389,9 @@ 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 == "lon" or r._field == "lat" 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")
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")`, 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))
@ -429,9 +429,9 @@ func getLastMetrics(deveui string) OneMetric {
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) >= 12) && !(strings.HasPrefix(s[3], "_")) { if (len(s) >= 12) && !(strings.HasPrefix(s[3], "_")) {
t, err := time.Parse(time.RFC3339, s[3]) t, err := time.Parse(time.RFC3339, s[5])
if err != nil { if err != nil {
fmt.Printf("error converting time: %s\n", s[3]) fmt.Printf("error converting time: %s\n", s[5])
continue continue
} }