Skip to content

Commit

Permalink
Name
Browse files Browse the repository at this point in the history
  • Loading branch information
springfall2008 authored Dec 26, 2024
1 parent 305128c commit 77445e4
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions apps/predbat/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1673,15 +1673,15 @@ def run_execute_test(
return failed


def run_single_debug(testname, my_predbat, debug_file, expected_file=None):
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
load_override = 1.0
my_predbat.load_user_config()
failed = False

print("**** Test {} ****".format(testname))
print("**** Test {} ****".format(test_name))
reset_inverter(my_predbat)
my_predbat.read_debug_yaml(debug_file)
my_predbat.config_root = "./"
Expand All @@ -1694,7 +1694,7 @@ def run_single_debug(testname, my_predbat, debug_file, expected_file=None):
if not expected_file:
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 Down Expand Up @@ -1763,7 +1763,7 @@ def run_single_debug(testname, my_predbat, debug_file, expected_file=None):
my_predbat.charge_limit_percent_best = calc_percent_limit(my_predbat.charge_limit_best, my_predbat.soc_max)
my_predbat.update_target_values()
my_predbat.publish_html_plan(pv_step, pv10_step, load_step, load10_step, my_predbat.end_record)
filename = testname + ".plan_orig.html"
filename = test_name + ".plan_orig.html"
open(filename, "w").write(my_predbat.html_plan)
print("Wrote plan to {}".format(filename))

Expand All @@ -1778,12 +1778,17 @@ def run_single_debug(testname, my_predbat, debug_file, expected_file=None):
my_predbat.log("Final plan soc_min {} final_soc {}".format(soc_min, soc))

my_predbat.publish_html_plan(pv_step, pv10_step, load_step, load10_step, my_predbat.end_record)
filename = testname + ".plan_final.html"
filename = test_name + ".plan_final.html"
open(filename, "w").write(my_predbat.html_plan)
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 +1802,11 @@ def run_single_debug(testname, my_predbat, debug_file, expected_file=None):
print("ERROR: Actual plan does not match expected plan")
failed = True
# Write actual plan
filename = testname + "_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

0 comments on commit 77445e4

Please sign in to comment.