From 4eec9619a36e08888f01ffe95f04e656f16ac46f Mon Sep 17 00:00:00 2001 From: Ted Pearson Date: Tue, 11 Oct 2022 13:03:53 -0400 Subject: [PATCH] track watts (instant usage) instead of watt-hours per point --- internal/app/metrics.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/app/metrics.go b/internal/app/metrics.go index 47ccdcc..3ff0175 100644 --- a/internal/app/metrics.go +++ b/internal/app/metrics.go @@ -24,13 +24,14 @@ func WriteMetrics(records []*ElectricUsage, config InfluxDB, existingPoints map[ points := make([]*write.Point, 0, 15*2*len(records)) for _, record := range records { divisor := record.EndTime.Sub(record.StartTime).Minutes() + multiplier := 60 / divisor for t := record.StartTime; record.EndTime.After(t); t = t.Add(time.Minute) { if _, ok := existingPoints[t.UnixMilli()]; ok { continue } watts := influxdb2.NewPointWithMeasurement("electric"). SetTime(t). - AddField("usage", float64(record.WattHours)/divisor) + AddField("watts", float64(record.WattHours)*multiplier) cost := influxdb2.NewPointWithMeasurement("electric"). SetTime(t). AddField("cost", float64(record.CostInCents)/divisor)