From 2fc1a76a5b37fff2b563d6c6cc7730c108e5989d Mon Sep 17 00:00:00 2001 From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com> Date: Thu, 12 Dec 2024 19:52:31 +0000 Subject: [PATCH] Tidy up export slots (#1720) * Check local version matches repo * [pre-commit.ci lite] apply automatic fixes * Tidy up export slots * [pre-commit.ci lite] apply automatic fixes * Comments * Check prediction * [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/plan.py | 2 +- apps/predbat/unit_test.py | 45 +++++++++++++++++++++++++++++++++------ 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/apps/predbat/plan.py b/apps/predbat/plan.py index 6d32bd29..252410ce 100644 --- a/apps/predbat/plan.py +++ b/apps/predbat/plan.py @@ -1283,7 +1283,7 @@ def optimise_export(self, window_n, record_charge_windows, try_charge_limit, cha try_options = [] for loop_limit in loop_options: # Loop on window size - loop_start = window["end"] - 10 # Minimum export window size 10 minutes + loop_start = window["end"] - 5 # Minimum export window size 5 minutes while loop_start >= window["start"]: this_export_limit = loop_limit start = loop_start diff --git a/apps/predbat/unit_test.py b/apps/predbat/unit_test.py index b0885511..aaa91a06 100644 --- a/apps/predbat/unit_test.py +++ b/apps/predbat/unit_test.py @@ -897,6 +897,7 @@ def run_execute_test( def run_single_debug(my_predbat, debug_file): print("**** Running debug test {} ****\n".format(debug_file)) re_do_rates = True + reset_load_model = False reset_inverter(my_predbat) my_predbat.read_debug_yaml(debug_file) @@ -904,8 +905,12 @@ def run_single_debug(my_predbat, debug_file): my_predbat.save_restore_dir = "./" my_predbat.fetch_config_options() + # 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 + if re_do_rates: - my_predbat.combine_export_slots = False # XXX: This is a hack to make the test pass # Find discharging windows if my_predbat.rate_export: my_predbat.high_export_rates, lowest, highest = my_predbat.rate_scan_window(my_predbat.rate_export, 5, my_predbat.rate_export_cost_threshold, True) @@ -921,10 +926,34 @@ def run_single_debug(my_predbat, debug_file): if my_predbat.rate_low_threshold == 0 and highest >= my_predbat.rate_min: my_predbat.rate_import_cost_threshold = highest - end_record = my_predbat.end_record - print("minutes_now {}".format(my_predbat.minutes_now)) + print("minutes_now {} end_record {}".format(my_predbat.minutes_now, my_predbat.end_record)) failed = False + # Reset load model + if reset_load_model: + my_predbat.load_minutes_step = my_predbat.step_data_history( + my_predbat.load_minutes, + my_predbat.minutes_now, + forward=False, + scale_today=my_predbat.load_inday_adjustment, + scale_fixed=1.0, + type_load=True, + load_forecast=my_predbat.load_forecast, + load_scaling_dynamic=my_predbat.load_scaling_dynamic, + cloud_factor=my_predbat.metric_load_divergence, + ) + my_predbat.load_minutes_step10 = my_predbat.step_data_history( + my_predbat.load_minutes, + my_predbat.minutes_now, + forward=False, + scale_today=my_predbat.load_inday_adjustment, + scale_fixed=my_predbat.load_scaling10, + type_load=True, + 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 @@ -942,7 +971,7 @@ def run_single_debug(my_predbat, debug_file): # Pre-optimise all plan 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, end_record) + my_predbat.publish_html_plan(pv_step, pv10_step, load_step, load10_step, my_predbat.end_record) open("plan_orig.html", "w").write(my_predbat.html_plan) print("Wrote plan to plan_orig.html") @@ -968,6 +997,9 @@ def run_single_debug(my_predbat, debug_file): my_predbat.export_limits_best = [100.0 for i in range(len(my_predbat.export_window_best))] my_predbat.end_record = my_predbat.forecast_minutes + my_predbat.log("Initial charge window {}".format(my_predbat.window_as_text(my_predbat.charge_window_best, calc_percent_limit(my_predbat.charge_limit_best, my_predbat.soc_max)))) + my_predbat.log("Initial export window {}".format(my_predbat.window_as_text(my_predbat.export_window_best, my_predbat.export_limits_best))) + # Optimise windows best_metric, best_cost, best_keep, best_cycle, best_carbon, best_import = my_predbat.optimise_all_windows(metric, metric_keep, debug_mode=True) @@ -980,7 +1012,7 @@ def run_single_debug(my_predbat, debug_file): # Save plan 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, end_record) + my_predbat.publish_html_plan(pv_step, pv10_step, load_step, load10_step, my_predbat.end_record) open("plan_raw.html", "w").write(my_predbat.html_plan) print("Wrote plan to plan_raw.html") @@ -1008,8 +1040,9 @@ def run_single_debug(my_predbat, debug_file): metric, import_kwh_battery, import_kwh_house, export_kwh, soc_min, soc, soc_min_minute, battery_cycle, metric_keep, final_iboost, final_carbon_g = my_predbat.run_prediction( my_predbat.charge_limit_best, my_predbat.charge_window_best, my_predbat.export_window_best, my_predbat.export_limits_best, False, end_record=my_predbat.end_record, save="best" ) + 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, end_record) + my_predbat.publish_html_plan(pv_step, pv10_step, load_step, load10_step, my_predbat.end_record) open("plan_final.html", "w").write(my_predbat.html_plan) print("Wrote plan to plan_final.html")