Skip to content

Commit

Permalink
track watts (instant usage) instead of watt-hours per point
Browse files Browse the repository at this point in the history
  • Loading branch information
tedpearson committed Oct 11, 2022
1 parent f1412c8 commit 4eec961
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/app/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4eec961

Please sign in to comment.