Skip to content

Commit

Permalink
Discharge freeze region fixes (#1473)
Browse files Browse the repository at this point in the history
* Discharge freeze region fixes

* Fix

* [pre-commit.ci lite] apply automatic fixes

* Updated

* [pre-commit.ci lite] apply automatic fixes

* Remove option for freeze region

* [pre-commit.ci lite] apply automatic fixes

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
  • Loading branch information
springfall2008 and pre-commit-ci-lite[bot] authored Sep 22, 2024
1 parent 1a273e3 commit 612ad23
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
7 changes: 0 additions & 7 deletions apps/predbat/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,13 +514,6 @@
"enable": "expert_mode",
"default": True,
},
{
"name": "calculate_freeze_region",
"friendly_name": "Calculation freeze in regions",
"type": "switch",
"enable": "expert_mode",
"default": False,
},
{
"name": "calculate_second_pass",
"friendly_name": "Calculate full second pass (slower)",
Expand Down
34 changes: 19 additions & 15 deletions apps/predbat/predbat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4187,7 +4187,7 @@ def publish_html_plan(self, pv_forecast_minute_step, pv_forecast_minute_step10,
plan_debug = self.get_arg("plan_debug")
html = "<table>"
html += "<tr>"
html += "<td colspan=10> Plan starts: {} last updated: {} version: {} status: {}</td>".format(
html += "<td colspan=10> Plan starts: {} last updated: {} version: {} previous status: {}</td>".format(
self.now_utc.strftime("%Y-%m-%d %H:%M"), self.now_utc_real.strftime("%H:%M:%S"), THIS_VERSION, self.current_status
)
config_str = f"best_soc_min {self.best_soc_min} best_soc_max {self.best_soc_max} best_soc_keep {self.best_soc_keep} carbon_metric {self.carbon_metric} metric_self_sufficiency {self.metric_self_sufficiency} metric_battery_value_scaling {self.metric_battery_value_scaling}"
Expand Down Expand Up @@ -5381,7 +5381,7 @@ def optimise_charge_limit_price_threads(

for loop_price in all_prices:
pred_table = []
freeze_options = [True, False] if self.calculate_freeze_region else [False]
freeze_options = [True, False]
for freeze in freeze_options:
for modulo in [2, 3, 4, 6, 8, 16, 32]:
for divide in [96, 48, 32, 16, 8, 4, 3, 2, 1]:
Expand All @@ -5397,18 +5397,24 @@ def optimise_charge_limit_price_threads(
window_n = window_index[key]["id"]
typ = window_index[key]["type"]
if typ == "c":
window_prices[window_n] = price
all_n.append(window_n)
if region_start and (charge_window[window_n]["start"] > region_end or charge_window[window_n]["end"] < region_start):
pass
else:
window_prices[window_n] = price
all_n.append(window_n)
elif discharge_enable:
# For prices above threshold try discharge
for key in links:
typ = window_index[key]["type"]
window_n = window_index[key]["id"]
if typ == "d":
window_prices_discharge[window_n] = price
if (int(divide_count_d / divide) % modulo) == 0:
all_d.append(window_n)
divide_count_d += 1
if region_start and (discharge_window[window_n]["start"] > region_end or discharge_window[window_n]["end"] < region_start):
pass
else:
if (int(divide_count_d / divide) % modulo) == 0:
all_d.append(window_n)
divide_count_d += 1

# Sort for print out
all_n.sort()
Expand Down Expand Up @@ -6729,12 +6735,12 @@ def optimise_all_windows(self, best_metric, metric_keep):
quiet=True,
)
if self.calculate_regions:
self.end_record = self.record_length(self.charge_window_best, self.charge_limit_best, best_price)
region_size = int(16 * 60)
while region_size >= 2 * 60:
self.log(">> Region optimisation pass width {}".format(region_size))
for region in range(0, self.end_record + self.minutes_now, region_size):
region_end = min(region + region_size, self.end_record + self.minutes_now)

if region_end < self.minutes_now:
continue
(
Expand Down Expand Up @@ -6779,10 +6785,9 @@ def optimise_all_windows(self, best_metric, metric_keep):
region_size = int(region_size / 2)

# Keep the freeze but not the full discharge as that will be re-introduced later
if self.calculate_freeze_region:
for window_n in range(len(ignore_discharge_limits)):
if ignore_discharge_limits[window_n] == 99.0:
self.discharge_limits_best[window_n] = 99.0
for window_n in range(len(ignore_discharge_limits)):
if ignore_discharge_limits[window_n] == 99.0:
self.discharge_limits_best[window_n] = 99.0

# Set the new end record and blackout period based on the levelling
self.end_record = self.record_length(self.charge_window_best, self.charge_limit_best, best_price)
Expand Down Expand Up @@ -6813,8 +6818,8 @@ def optimise_all_windows(self, best_metric, metric_keep):
# then optimise those above the threshold lowest to highest (to turn up values)
# Do the opposite for discharge.
self.log(
"Starting second optimisation end_record {} best_price {} best_price_discharge {} lowest_price_charge {} with charge limits {}".format(
self.time_abs_str(self.end_record + self.minutes_now), best_price, best_price_discharge, lowest_price_charge, self.charge_limit_best
"Starting second optimisation end_record {} best_price {} best_price_discharge {} lowest_price_charge {} with charge limits {} discharge limits {}".format(
self.time_abs_str(self.end_record + self.minutes_now), best_price, best_price_discharge, lowest_price_charge, self.charge_limit_best, self.discharge_limits_best
)
)
for pass_type in ["freeze", "normal", "low"]:
Expand Down Expand Up @@ -9789,7 +9794,6 @@ def fetch_config_options(self):
self.log("Predbat mode is set to {}".format(self.predbat_mode))

self.calculate_discharge_oncharge = self.get_arg("calculate_discharge_oncharge")
self.calculate_freeze_region = self.get_arg("calculate_freeze_region")
self.calculate_second_pass = self.get_arg("calculate_second_pass")
self.calculate_inday_adjustment = self.get_arg("calculate_inday_adjustment")
self.calculate_tweak_plan = self.get_arg("calculate_tweak_plan")
Expand Down

0 comments on commit 612ad23

Please sign in to comment.