Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy up export slots #1720

Merged
merged 7 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/predbat/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 39 additions & 6 deletions apps/predbat/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,15 +897,20 @@ 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)
my_predbat.config_root = "./"
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)
Expand All @@ -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
Expand All @@ -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")

Expand All @@ -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)

Expand All @@ -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")

Expand Down Expand Up @@ -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")

Expand Down
Loading