Metrics: interpolate single missing slots (#26800)

This commit is contained in:
andig 2026-01-19 11:16:49 +01:00 • committed by GitHub
parent 74cb3c7087
commit b3448b6b04
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,6 +5,7 @@ import (
"time"
"github.com/evcc-io/evcc/server/db"
"github.com/evcc-io/evcc/tariff"
"gorm.io/gorm"
)
@ -51,6 +52,7 @@ func Profile(from time.Time) (*[96]float64, error) {
}
defer rows.Close()
var prev time.Time
res := make([]float64, 0, 96)
for rows.Next() {
@ -61,6 +63,12 @@ func Profile(from time.Time) (*[96]float64, error) {
return nil, err
}
// interpolate single missing value, maybe due to regular restarts?
if time.Time(ts).Sub(prev) == 2*tariff.SlotDuration {
res = append(res, (val+res[len(res)-1])/2)
}
prev = time.Time(ts)
res = append(res, val)
}
@ -74,8 +82,3 @@ func Profile(from time.Time) (*[96]float64, error) {
return (*[96]float64)(res), nil
}
func SlotNum(ts time.Time) int {
ts = ts.Local()
return ts.Hour()*4 + ts.Minute()/15
}