fix last time 2

This commit is contained in:
Joerg Lehmann 2021-04-16 10:35:42 +02:00
parent b0067f6679
commit aec94f85b0
1 changed files with 4 additions and 4 deletions

View File

@ -287,9 +287,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:-5d) |> range(start:-5d)
|> 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 == "vbat") |> 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))
@ -328,9 +328,9 @@ func getLastMetrics(deveui string) OneMetric {
for scanner.Scan() { for scanner.Scan() {
s := strings.Split(scanner.Text(), ",") s := strings.Split(scanner.Text(), ",")
if (len(s) >= 9) && !(strings.HasPrefix(s[3], "_")) { if (len(s) >= 9) && !(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
} }