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.

pull/228/head
Jason Kulatunga 3 years ago
parent b776fb8886
commit 772063a843

@ -522,9 +522,9 @@ func (sr *scrutinyRepository) GetSmartTemperatureHistory(ctx context.Context) (m
queryStr := fmt.Sprintf(`
import "influxdata/influxdb/schema"
from(bucket: "%s")
|> range(start: -3y, stop: now())
|> range(start: -1w, stop: now())
|> filter(fn: (r) => r["_measurement"] == "temp" )
|> filter(fn: (r) => r["_field"] == "temp")
|> aggregateWindow(every: 1h, fn: mean, createEmpty: false)
|> schema.fieldsAsCols()
|> group(columns: ["device_wwn"])
|> yield(name: "last")

@ -24,6 +24,11 @@ func (st *SmartTemperature) Inflate(key string, val interface{}) {
}
if key == "temp" {
st.Temp = val.(int64)
switch t := val.(type) {
case int64:
st.Temp = t
case float64:
st.Temp = int64(t)
}
}
}

Loading…
Cancel
Save