Skip to content

Commit

Permalink
Put back metric keep weighting on discharge (#1276)
Browse files Browse the repository at this point in the history
* Keep weighting put back to 1.0

Metric keep was too weak, put weighting back to 1.0

* Put keep formula back

* [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 Jun 30, 2024
1 parent c155929 commit acf0f20
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion apps/predbat/prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ def run_prediction(self, charge_limit, charge_window, discharge_window, discharg
if soc < self.best_soc_keep:
# Apply keep as a percentage of the time in the future so it gets stronger over an 4 hour period
# Weight to 50% chance of the scenario
keep_diff = get_diff(0, 0, pv_now, load_yesterday, inverter_loss)
keep_diff = max(get_diff(0, 0, pv_now, load_yesterday, inverter_loss), battery_draw)
if keep_diff > 0:
metric_keep += rate_import[minute_absolute] * keep_diff * keep_minute_scaling

Expand Down
39 changes: 33 additions & 6 deletions apps/predbat/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
from prediction import Prediction
from prediction import wrapped_run_prediction_single

KEEP_SCALE = 0.5


class TestHAInterface:
def __init__(self):
Expand Down Expand Up @@ -1041,7 +1043,17 @@ def run_model_tests(my_predbat):
)
failed |= simple_scenario("battery_discharge", my_predbat, 0, 0, assert_final_metric=-export_rate * 10, assert_final_soc=0, with_battery=True, discharge=0, battery_soc=10)
failed |= simple_scenario(
"battery_discharge_keep", my_predbat, 0, 0, assert_final_metric=-export_rate * 10, assert_final_soc=0, with_battery=True, discharge=0, battery_soc=10, assert_keep=0, keep=1
"battery_discharge_keep",
my_predbat,
0,
0,
assert_final_metric=-export_rate * 10,
assert_final_soc=0,
with_battery=True,
discharge=0,
battery_soc=10,
assert_keep=1 * import_rate * KEEP_SCALE,
keep=1,
)
failed |= simple_scenario(
"battery_discharge_loss",
Expand Down Expand Up @@ -1089,11 +1101,11 @@ def run_model_tests(my_predbat):
with_battery=True,
discharge=0,
battery_soc=10,
assert_keep=15 * import_rate * 0.5 * 0.5,
assert_keep=14 * import_rate * 0.5 * KEEP_SCALE + 1 * import_rate * KEEP_SCALE,
keep=1.0,
)
failed |= simple_scenario(
"battery_discharge_load_keep_mode_test",
"battery_discharge_load_keep_mode_test1",
my_predbat,
0.5,
0,
Expand All @@ -1102,12 +1114,12 @@ def run_model_tests(my_predbat):
with_battery=True,
discharge=0,
battery_soc=10,
assert_keep=15 * import_rate * 0.5 * 0.5,
assert_keep=14 * import_rate * 0.5 * KEEP_SCALE + 1 * import_rate * KEEP_SCALE,
keep=1.0,
save="test",
)
failed |= simple_scenario(
"battery_discharge_load_keep_mode_test",
"battery_discharge_load_keep_mode_test2",
my_predbat,
0.5,
0,
Expand All @@ -1116,7 +1128,7 @@ def run_model_tests(my_predbat):
with_battery=True,
discharge=0,
battery_soc=10,
assert_keep=15 * import_rate * 0.5 * 0.5,
assert_keep=14 * import_rate * 0.5 * KEEP_SCALE + 1 * import_rate * KEEP_SCALE,
keep=1.0,
save="none",
)
Expand Down Expand Up @@ -1533,6 +1545,21 @@ def run_model_tests(my_predbat):
iboost_charging=True,
assert_final_iboost=0,
)
failed |= simple_scenario(
"keep_discharge1",
my_predbat,
0.5,
0,
assert_final_metric=-export_rate * 10 * 0.5 + import_rate * 14 * 0.5,
assert_final_soc=0,
battery_soc=10,
with_battery=True,
discharge=0,
battery_size=10,
keep=1.0,
assert_final_iboost=0,
assert_keep=import_rate * 14 * 0.5 * KEEP_SCALE + import_rate * 1 * KEEP_SCALE,
)

if failed:
print("**** ERROR: Some Model tests failed ****")
Expand Down

0 comments on commit acf0f20

Please sign in to comment.