Skip to content

Commit

Permalink
Testing and version
Browse files Browse the repository at this point in the history
  • Loading branch information
springfall2008 authored Dec 13, 2024
1 parent c27a730 commit a9f71dc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 32 deletions.
4 changes: 1 addition & 3 deletions apps/predbat/predbat.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
try:
import adbase as ad
import appdaemon.plugins.hass.hassapi as hass

IS_APPDAEMON = True
except:
import hass as hass

IS_APPDAEMON = False

import pytz
Expand All @@ -38,7 +36,7 @@
import asyncio
import json

THIS_VERSION = "v8.8.5"
THIS_VERSION = "v8.8.6"

# fmt: off
PREDBAT_FILES = ["predbat.py", "config.py", "prediction.py", "gecloud.py","utils.py", "inverter.py", "ha.py", "download.py", "unit_test.py", "web.py", "predheat.py", "futurerate.py", "octopus.py", "solcast.py","execute.py", "plan.py", "fetch.py", "output.py", "userinterface.py"]
Expand Down
61 changes: 32 additions & 29 deletions apps/predbat/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,8 +907,9 @@ def run_single_debug(my_predbat, debug_file):

# Force off combine export XXX:
print("Combined export slots {}".format(my_predbat.combine_export_slots))
# my_predbat.combine_export_slots = False
my_predbat.best_soc_keep = 1.0
#my_predbat.combine_export_slots = False
#my_predbat.best_soc_keep = 1.0
my_predbat.metric_min_improvement_export = 5

if re_do_rates:
# Find discharging windows
Expand Down Expand Up @@ -952,13 +953,13 @@ def run_single_debug(my_predbat, debug_file):
load_forecast=my_predbat.load_forecast,
load_scaling_dynamic=my_predbat.load_scaling_dynamic,
cloud_factor=min(my_predbat.metric_load_divergence + 0.5, 1.0) if my_predbat.metric_load_divergence else None,
)
)

pv_step = my_predbat.pv_forecast_minute_step
pv10_step = my_predbat.pv_forecast_minute10_step
load_step = my_predbat.load_minutes_step
load10_step = my_predbat.load_minutes_step10

my_predbat.prediction = Prediction(my_predbat, pv_step, pv_step, load_step, load_step)
my_predbat.debug_enable = True

Expand Down Expand Up @@ -1047,6 +1048,7 @@ def run_single_debug(my_predbat, debug_file):
print("Wrote plan to plan_final.html")



def run_execute_tests(my_predbat):
print("**** Running execute tests ****\n")
reset_inverter(my_predbat)
Expand Down Expand Up @@ -1297,22 +1299,22 @@ def run_execute_tests(my_predbat):
return failed

my_predbat.battery_charge_power_curve = {
100: 0.50,
99: 0.50,
98: 0.50,
97: 0.50,
96: 0.50,
95: 0.50,
94: 1.00,
93: 1.00,
92: 1.00,
91: 1.00,
90: 1.00,
89: 1.00,
88: 1.00,
87: 1.00,
86: 1.00,
85: 1.00,
100 : 0.50,
99 : 0.50,
98 : 0.50,
97 : 0.50,
96 : 0.50,
95 : 0.50,
94 : 1.00,
93 : 1.00,
92 : 1.00,
91 : 1.00,
90 : 1.00,
89 : 1.00,
88 : 1.00,
87 : 1.00,
86 : 1.00,
85 : 1.00,
}

# 60 minutes - 10 minute margin = 50 minutes to add 0.75kWh to each battery (x2 inverters)
Expand Down Expand Up @@ -2436,7 +2438,7 @@ def run_optimise_all_windows(
expect_export_limit=[],
expect_best_price=0.0,
rate_import=10.0,
rate_export=5.0,
rate_export=5.5,
battery_size=100.0,
battery_soc=0.0,
hybrid=False,
Expand Down Expand Up @@ -2939,10 +2941,10 @@ def run_model_tests(my_predbat):
failed |= simple_scenario("load_only", my_predbat, 1, 0, assert_final_metric=import_rate * 24, assert_final_soc=0, with_battery=False)
failed |= simple_scenario("load_bat_ac", my_predbat, 4, 0, assert_final_metric=import_rate * 24 * 3.2, assert_final_soc=100 - 24, with_battery=True, battery_soc=100.0, inverter_loss=0.8)
failed |= simple_scenario("load_bat_dc", my_predbat, 4, 0, assert_final_metric=import_rate * 24 * 3.2, assert_final_soc=100 - 24, with_battery=True, battery_soc=100.0, inverter_loss=0.8, hybrid=True)
failed |= simple_scenario("load_bat_ac2", my_predbat, 0.5, 0, assert_final_metric=0, assert_final_soc=100 - 12 / 0.8, with_battery=True, battery_soc=100.0, inverter_loss=0.8)
failed |= simple_scenario("load_bat_dc2", my_predbat, 0.5, 0, assert_final_metric=0, assert_final_soc=100 - 12 / 0.8, with_battery=True, battery_soc=100.0, inverter_loss=0.8, hybrid=True)
failed |= simple_scenario("load_bat_ac3", my_predbat, 1.0, 0, assert_final_metric=import_rate * 0.2 * 24, assert_final_soc=100 - 24, with_battery=True, battery_soc=100.0, inverter_loss=0.8)
failed |= simple_scenario("load_bat_dc3", my_predbat, 1.0, 0, assert_final_metric=import_rate * 0.2 * 24, assert_final_soc=100 - 24, with_battery=True, battery_soc=100.0, inverter_loss=0.8, hybrid=True)
failed |= simple_scenario("load_bat_ac2", my_predbat, 0.5, 0, assert_final_metric=0, assert_final_soc=100 - 12/0.8, with_battery=True, battery_soc=100.0, inverter_loss=0.8)
failed |= simple_scenario("load_bat_dc2", my_predbat, 0.5, 0, assert_final_metric=0, assert_final_soc=100 - 12/0.8, with_battery=True, battery_soc=100.0, inverter_loss=0.8, hybrid=True)
failed |= simple_scenario("load_bat_ac3", my_predbat, 1.0, 0, assert_final_metric=import_rate * 0.2*24, assert_final_soc=100 - 24, with_battery=True, battery_soc=100.0, inverter_loss=0.8)
failed |= simple_scenario("load_bat_dc3", my_predbat, 1.0, 0, assert_final_metric=import_rate * 0.2*24, assert_final_soc=100 - 24, with_battery=True, battery_soc=100.0, inverter_loss=0.8, hybrid=True)

failed |= simple_scenario(
"load_bat_dc_pv",
Expand Down Expand Up @@ -3384,7 +3386,7 @@ def run_model_tests(my_predbat):
with_battery=True,
discharge=0,
battery_soc=10,
assert_keep=14 * import_rate * 0.5 * KEEP_SCALE + 1 * import_rate * KEEP_SCALE,
assert_keep=1 * import_rate * KEEP_SCALE,
keep=1.0,
)
failed |= simple_scenario(
Expand All @@ -3397,7 +3399,7 @@ def run_model_tests(my_predbat):
with_battery=True,
discharge=0,
battery_soc=10,
assert_keep=14 * import_rate * 0.5 * KEEP_SCALE + 1 * import_rate * KEEP_SCALE,
assert_keep=1 * import_rate * KEEP_SCALE,
keep=1.0,
save="test",
)
Expand All @@ -3411,7 +3413,7 @@ def run_model_tests(my_predbat):
with_battery=True,
discharge=0,
battery_soc=10,
assert_keep=14 * import_rate * 0.5 * KEEP_SCALE + 1 * import_rate * KEEP_SCALE,
assert_keep=1 * import_rate * KEEP_SCALE,
keep=1.0,
save="none",
)
Expand Down Expand Up @@ -4056,7 +4058,7 @@ def run_model_tests(my_predbat):
battery_size=10,
keep=1.0,
assert_final_iboost=0,
assert_keep=import_rate * 14 * 0.5 * KEEP_SCALE + import_rate * 1 * KEEP_SCALE,
assert_keep=import_rate * 1 * KEEP_SCALE,
)

# Alternating high/low rates
Expand Down Expand Up @@ -4138,6 +4140,7 @@ def main():
parser = argparse.ArgumentParser(description="Predbat unit tests")
parser.add_argument("--debug_file", action="store", help="Enable debug output")
args = parser.parse_args()


print("**** Starting Predbat tests ****")
my_predbat = PredBat()
Expand Down

0 comments on commit a9f71dc

Please sign in to comment.