Skip to content

Commit

Permalink
Fix crash in discharge mode only (no charging)
Browse files Browse the repository at this point in the history
With discharge only mode there was an undefined variable crash
  • Loading branch information
springfall2008 authored Jun 5, 2023
1 parent ee558c9 commit 3803e2f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions apps/predbat/predbat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2298,7 +2298,7 @@ def update_pred(self):
best_discharge, best_metric, best_cost, soc_min, soc_min_minute = self.optimise_discharge(0, record_discharge_windows, self.charge_limit_best, self.charge_window_best, self.discharge_window_best, self.discharge_limits_best, load_minutes, pv_forecast_minute, pv_forecast_minute10, all_n = record_discharge_windows, end_record = end_record)

self.discharge_limits_best = [best_discharge if n < record_discharge_windows else 100.0 for n in range(0, len(self.discharge_limits_best))]
self.log("Best all discharge limit all windows n={} (adjusted) discharge limit {} soc calculated at {} min {} @ {} (margin added {} and min {}) with metric {} cost {} windows {}".format(record_discharge_windows, best_discharge, self.dp2(best_soc), self.dp2(soc_min), self.time_abs_str(soc_min_minute), self.best_soc_margin, self.best_soc_min, self.dp2(best_metric), self.dp2(best_cost), self.charge_limit_best))
self.log("Best all discharge limit all windows n={} (adjusted) discharge limit {} min {} @ {} (margin added {} and min {}) with metric {} cost {} windows {}".format(record_discharge_windows, best_discharge, self.dp2(soc_min), self.time_abs_str(soc_min_minute), self.best_soc_margin, self.best_soc_min, self.dp2(best_metric), self.dp2(best_cost), self.charge_limit_best))

if record_discharge_windows > 1:
# Optimise in price order, most expensive first try to increase each one, only required for more than 1 window
Expand All @@ -2308,7 +2308,7 @@ def update_pred(self):

self.discharge_limits_best[window_n] = best_discharge
if self.debug_enable or 1:
self.log("Best discharge limit window {} discharge {} (adjusted) soc calculated at {} min {} @ {} (margin added {} and min {}) with metric {} cost {}".format(window_n, best_discharge, self.dp2(best_soc), self.dp2(soc_min), self.time_abs_str(soc_min_minute), self.best_soc_margin, self.best_soc_min, self.dp2(best_metric), self.dp2(best_cost)))
self.log("Best discharge limit window {} discharge {} (adjusted) min {} @ {} (margin added {} and min {}) with metric {} cost {}".format(window_n, best_discharge, self.dp2(soc_min), self.time_abs_str(soc_min_minute), self.best_soc_margin, self.best_soc_min, self.dp2(best_metric), self.dp2(best_cost)))

if self.get_arg('calculate_best', False):
# Final simulation of best, do 10% and normal scenario
Expand Down

0 comments on commit 3803e2f

Please sign in to comment.