find the temp history for the last week (by default). Smooth out data using aggregate window for hourly numbers. Better temp casting during influx data inflating.

This commit is contained in:
Jason Kulatunga
2021-11-16 19:07:37 -08:00
parent b776fb8886
commit 772063a843
2 changed files with 8 additions and 3 deletions
@@ -522,9 +522,9 @@ func (sr *scrutinyRepository) GetSmartTemperatureHistory(ctx context.Context) (m
queryStr := fmt.Sprintf(` queryStr := fmt.Sprintf(`
import "influxdata/influxdb/schema" import "influxdata/influxdb/schema"
from(bucket: "%s") from(bucket: "%s")
|> range(start: -3y, stop: now()) |> range(start: -1w, stop: now())
|> filter(fn: (r) => r["_measurement"] == "temp" ) |> filter(fn: (r) => r["_measurement"] == "temp" )
|> filter(fn: (r) => r["_field"] == "temp") |> aggregateWindow(every: 1h, fn: mean, createEmpty: false)
|> schema.fieldsAsCols() |> schema.fieldsAsCols()
|> group(columns: ["device_wwn"]) |> group(columns: ["device_wwn"])
|> yield(name: "last") |> yield(name: "last")
@@ -24,6 +24,11 @@ func (st *SmartTemperature) Inflate(key string, val interface{}) {
} }
if key == "temp" { if key == "temp" {
st.Temp = val.(int64) switch t := val.(type) {
case int64:
st.Temp = t
case float64:
st.Temp = int64(t)
}
} }
} }