Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash issue with best_price_discharge #403

Merged
merged 1 commit into from
Dec 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions apps/predbat/predbat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7079,7 +7079,8 @@ def optimise_all_windows(self, end_record, load_minutes_step, pv_forecast_minute
best_soc = self.soc_max
best_cost = best_metric
best_keep = metric_keep
best_price = 9999
best_price = 0
best_price_discharge = 0

# Optimise all windows by picking a price threshold default
if price_set and self.calculate_best_charge and self.charge_window_best:
Expand Down Expand Up @@ -7725,19 +7726,26 @@ def calculate_plan(self, recompute=True):
self.log("Force recompute due to start of day")
recompute = True

# Recompute as charge window ran out
if self.charge_window_best:
# Shift onto next charge window if required
while self.charge_window_best and not recompute:
window = self.charge_window_best[0]
if window["end"] <= self.minutes_now:
self.log("Force recompute as current charge window has expired")
recompute = True
del self.charge_window_best[0]
del self.charge_limit_best[0]
del self.charge_limit_percent_best[0]
self.log("Current charge window has expired, removing it")
else:
break

# Recompute as discharge window ran out
if self.discharge_window_best:
# Shift onto next discharge window if required
while self.discharge_window_best and not recompute:
window = self.discharge_window_best[0]
if window["end"] <= self.minutes_now:
self.log("Force recompute as current discharge window has expired")
recompute = True
del self.discharge_window_best[0]
del self.discharge_limits_best[0]
self.log("Current discharge window has expired, removing it")
else:
break

# Recompute?
if recompute:
Expand Down