From b132f7e8a7475db077e421fffc5367462533b8b5 Mon Sep 17 00:00:00 2001 From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com> Date: Sun, 2 Jun 2024 15:14:46 +0100 Subject: [PATCH] Clipping fixes (#1166) * Clipping fixes Over calculated load and pv divergence, tweaked down https://github.com/springfall2008/batpred/issues/1152 * [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> --- apps/predbat/predbat.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/predbat/predbat.py b/apps/predbat/predbat.py index 79257211..00754962 100644 --- a/apps/predbat/predbat.py +++ b/apps/predbat/predbat.py @@ -1874,6 +1874,7 @@ def run_prediction(self, charge_limit, charge_window, discharge_window, discharg battery_draw = max(-charge_rate_now_curve * step, battery_draw - above_limit) # Account for inverter limit, clip battery draw if possible to avoid going over + diff_tmp = load_yesterday - (battery_draw + pv_dc + pv_ac) if self.inverter_hybrid and diff_tmp < 0 and abs(diff_tmp) > (self.inverter_limit * step): above_limit = abs(diff_tmp + self.inverter_limit * step) battery_draw = max(-charge_rate_now_curve * step, battery_draw - above_limit) @@ -1888,7 +1889,10 @@ def run_prediction(self, charge_limit, charge_window, discharge_window, discharg pv_ac -= extra_pv pv_dc += extra_pv - battery_state = "f-" + if battery_draw < 0: + battery_state = "f/" + else: + battery_state = "f-" # Once force discharge starts the four hour rule is disabled four_hour_rule = False @@ -6175,7 +6179,7 @@ def get_load_divergence(self, minutes_now, load_minutes): load_count = 0 load_min = 99999 load_max = 0 - look_over = 60 * 4 + look_over = 60 * 8 for minute in range(0, look_over, PREDICT_STEP): load, load_raw = self.get_filtered_load_minute(load_minutes, minute, historical=True, step=PREDICT_STEP) @@ -6195,8 +6199,8 @@ def get_load_divergence(self, minutes_now, load_minutes): load_diff_total += load_diff load_std_dev = math.sqrt(load_diff_total / load_count) - load_divergence = load_std_dev / load_mean - load_divergence = min(load_divergence, 2.0) + load_divergence = load_std_dev / load_mean / 2.0 + load_divergence = min(load_divergence, 1.0) self.log( "Load divergence over {} hours mean {} W, min {} W, max {} W, std dev {} W, divergence {}%".format( look_over / 60.0, self.dp2(load_mean), self.dp2(load_min), self.dp2(load_max), self.dp2(load_std_dev), self.dp2(load_divergence * 100.0) @@ -6220,7 +6224,7 @@ def get_cloud_factor(self, minutes_now, pv_data, pv_data10): pv_factor = None if pv_total > 0 and (pv_total > pv_total10): pv_diff = pv_total - pv_total10 - pv_factor = self.dp2(pv_diff / pv_total) + pv_factor = self.dp2(pv_diff / pv_total) / 2.0 pv_factor = min(pv_factor, 1.0) if self.metric_cloud_enable: