From 772063a84389bef1cb699b9cdf2340da83161596 Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Tue, 16 Nov 2021 19:07:37 -0800 Subject: [PATCH] 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. --- webapp/backend/pkg/database/scrutiny_repository.go | 4 ++-- .../backend/pkg/models/measurements/smart_temperature.go | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/webapp/backend/pkg/database/scrutiny_repository.go b/webapp/backend/pkg/database/scrutiny_repository.go index 530348b..6c31c83 100644 --- a/webapp/backend/pkg/database/scrutiny_repository.go +++ b/webapp/backend/pkg/database/scrutiny_repository.go @@ -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") diff --git a/webapp/backend/pkg/models/measurements/smart_temperature.go b/webapp/backend/pkg/models/measurements/smart_temperature.go index 06f4d74..e29e79e 100644 --- a/webapp/backend/pkg/models/measurements/smart_temperature.go +++ b/webapp/backend/pkg/models/measurements/smart_temperature.go @@ -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) + } } }