Metrics: interpolate single missing slots (#26800)
This commit is contained in:
parent
74cb3c7087
commit
b3448b6b04
1 changed files with 8 additions and 5 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue