last vbat value not respecting invalid GPS positions
This commit is contained in:
parent
fbcebb980a
commit
c678fbe5cd
52
metrics.go
52
metrics.go
|
|
@ -411,10 +411,12 @@ func getLastMetrics(deveui string) OneMetric {
|
|||
var res OneMetric
|
||||
|
||||
url := "http://localhost:8086/api/v2/query?org=wobischorg"
|
||||
|
||||
data := []byte(fmt.Sprintf(`from(bucket:"wobischbucket")
|
||||
|> range(start:-365d)
|
||||
|> filter(fn: (r) => r._measurement == "measurement" and r.deveui == "%s")
|
||||
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
|
||||
|> filter(fn: (r) => r.lat != 0)
|
||||
|> sort(columns: ["_time"], desc: false)
|
||||
|> last(column: "_time")`, deveui))
|
||||
|
||||
|
|
@ -469,9 +471,57 @@ func getLastMetrics(deveui string) OneMetric {
|
|||
res.Lon = s[len(s)-2]
|
||||
res.PosTimestamp = t.In(location).Format("02.01.2006 15:04")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
data2 := []byte(fmt.Sprintf(`from(bucket:"wobischbucket")
|
||||
|> range(start:-365d)
|
||||
|> filter(fn: (r) => r._measurement == "measurement" and r.deveui == "%s")
|
||||
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
|
||||
|> sort(columns: ["_time"], desc: false)
|
||||
|> last(column: "_time")`, deveui))
|
||||
|
||||
req2, err := http.NewRequest("POST", url, bytes.NewBuffer(data2))
|
||||
if err != nil {
|
||||
log.Fatal("Error reading request. ", err)
|
||||
}
|
||||
|
||||
// Set headers
|
||||
req2.Header.Set("Authorization", "Token "+INFLUX_RO_TOKEN)
|
||||
req2.Header.Set("accept", "application/csv")
|
||||
req2.Header.Set("content-type", "application/vnd.flux")
|
||||
|
||||
// Send request
|
||||
resp2, err := client.Do(req2)
|
||||
if err != nil {
|
||||
log.Fatal("Error reading response. ", err)
|
||||
}
|
||||
defer resp2.Body.Close()
|
||||
|
||||
fmt.Println("response Status:", resp2.Status)
|
||||
fmt.Println("response Headers:", resp2.Header)
|
||||
|
||||
body2, err := ioutil.ReadAll(resp2.Body)
|
||||
if err != nil {
|
||||
log.Fatal("Error reading body. ", err)
|
||||
}
|
||||
fmt.Println("response Body 2:", string(body2))
|
||||
|
||||
scanner2 := bufio.NewScanner(strings.NewReader(string(body2)))
|
||||
for scanner2.Scan() {
|
||||
s := strings.Split(scanner2.Text(), ",")
|
||||
fmt.Printf("BlaBla: %v, elements: %d\n", s, len(s))
|
||||
if (len(s) >= 12) && !(strings.HasPrefix(s[5], "_")) {
|
||||
t, err := time.Parse(time.RFC3339, s[5])
|
||||
if err != nil {
|
||||
fmt.Printf("error converting time: %s\n", s[5])
|
||||
continue
|
||||
}
|
||||
|
||||
res.Timestamp = t.In(location).Format("02.01.2006 15:04")
|
||||
res.BatteryPercent = strconv.Itoa(vbat2percent(s[len(s)-1]))
|
||||
res.BatteryPercentHTML = template.HTML(vbat2html(s[len(s)-1]))
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue