Optimizer: fix panic on plan overrun (#25227)

This commit is contained in:
RenatusRo 2025-11-11 12:26:34 +01:00 • committed by GitHub
parent f0887f8f5b
commit 88bc112486
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -219,11 +219,11 @@ func (site *Site) optimizerUpdate(battery []measurement) error {
if ts := lp.EffectivePlanTime(); !ts.IsZero() {
// TODO precise slot placement
if slot := int(time.Until(ts) / tariff.SlotDuration); slot < minLen {
if slot := int(time.Until(ts) / tariff.SlotDuration); slot < minLen && slot >= 0 {
bat.SGoal = lo.RepeatBy(minLen, func(_ int) float32 { return 0 })
bat.SGoal[slot] = float32(goal)
} else {
site.log.DEBUG.Printf("plan beyond forecast range: %.1f at %v", goal, ts.Round(time.Minute))
site.log.DEBUG.Printf("plan beyond forecast range or overrun: %.1f at %v slot %d", goal, ts.Round(time.Minute), slot)
}
}