Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
springfall2008 authored Dec 26, 2024
1 parent 27f074c commit 481336d
Showing 1 changed file with 40 additions and 7 deletions.
47 changes: 40 additions & 7 deletions apps/predbat/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1675,8 +1675,8 @@ def run_execute_test(

def run_single_debug(test_name, my_predbat, debug_file, expected_file=None):
print("**** Running debug test {} ****\n".format(debug_file))
re_do_rates = True
reset_load_model = True
re_do_rates = False
reset_load_model = False
load_override = 1.0
my_predbat.load_user_config()
failed = False
Expand All @@ -1692,9 +1692,10 @@ def run_single_debug(test_name, my_predbat, debug_file, expected_file=None):
# Force off combine export XXX:
print("Combined export slots {} min_improvement_export {} set_export_freeze_only {}".format(my_predbat.combine_export_slots, my_predbat.metric_min_improvement_export, my_predbat.set_export_freeze_only))
if not expected_file:
my_predbat.combine_export_slots = False
pass
#my_predbat.combine_export_slots = False
# my_predbat.best_soc_keep = 1.0
# my_predbat.metric_min_improvement_export = 5
#my_predbat.metric_min_improvement_export = 5

if re_do_rates:
# Set rate thresholds
Expand All @@ -1720,6 +1721,7 @@ def run_single_debug(test_name, my_predbat, debug_file, expected_file=None):

# Reset load model
if reset_load_model:
print("Reset load model")
my_predbat.load_minutes_step = my_predbat.step_data_history(
my_predbat.load_minutes,
my_predbat.minutes_now,
Expand Down Expand Up @@ -1783,7 +1785,12 @@ def run_single_debug(test_name, my_predbat, debug_file, expected_file=None):
print("Wrote plan to {}".format(filename))

# Expected
actual_data = {"charge_limit_best": my_predbat.charge_limit_best, "charge_window_best": my_predbat.charge_window_best, "export_window_best": my_predbat.export_window_best, "export_limits_best": my_predbat.export_limits_best}
actual_data = {
"charge_limit_best": my_predbat.charge_limit_best,
"charge_window_best": my_predbat.charge_window_best,
"export_window_best": my_predbat.export_window_best,
"export_limits_best": my_predbat.export_limits_best
}
actual_json = json.dumps(actual_data)
if expected_file:
print("Compare with {}".format(expected_file))
Expand All @@ -1797,12 +1804,11 @@ def run_single_debug(test_name, my_predbat, debug_file, expected_file=None):
print("ERROR: Actual plan does not match expected plan")
failed = True
# Write actual plan
filename = test_name + "_actual.json"
filename = test_name + ".actual.json"
open(filename, "w").write(actual_json)
print("Wrote plan json to {}".format(filename))
return failed


def run_execute_tests(my_predbat):
print("**** Running execute tests ****\n")
reset_inverter(my_predbat)
Expand Down Expand Up @@ -4116,6 +4122,20 @@ def run_model_tests(my_predbat):
keep=1,
keep_weight=0.5,
)
failed |= simple_scenario(
"battery_discharge_keep2",
my_predbat,
0,
0,
assert_final_metric=-export_rate * 1,
assert_final_soc=0,
with_battery=True,
discharge=0,
battery_soc=1,
assert_keep=23 * import_rate * 0.5 + ((1 + (1 / 12)) * import_rate * 0.5 * 0.5),
keep=1,
keep_weight=0.5,
)
failed |= simple_scenario(
"battery_discharge_loss",
my_predbat,
Expand Down Expand Up @@ -4166,6 +4186,19 @@ def run_model_tests(my_predbat):
keep=1.0,
keep_weight=1.0,
)
failed |= simple_scenario(
"battery_load_keep_four_hour",
my_predbat,
1.0,
0,
assert_final_metric=import_rate * 20,
assert_final_soc=0,
with_battery=True,
battery_soc=4,
assert_keep=20 * import_rate * 4 + 53,
keep=4.0,
keep_weight=1.0,
)
failed |= simple_scenario(
"battery_discharge_load_keep_mode_test1",
my_predbat,
Expand Down

0 comments on commit 481336d

Please sign in to comment.