restructured output of heating and heating control recommendations

This commit is contained in:
Khalim Conn-Kowlessar 2024-04-19 18:38:16 +01:00
parent 8bd899bcba
commit 7bdf2147ba
3 changed files with 32 additions and 23 deletions

View file

@ -282,16 +282,16 @@ async def trigger_plan(body: PlanTriggerRequest):
property_id, is_new = create_property(
session, body.portfolio_id, epc_searcher.address_clean, epc_searcher.postcode_clean, epc_searcher.uprn
)
if not is_new:
continue
create_property_targets(
session,
property_id=property_id,
portfolio_id=body.portfolio_id,
epc_target=body.goal_value,
heat_demand_target=None
)
# if not is_new:
# continue
#
# create_property_targets(
# session,
# property_id=property_id,
# portfolio_id=body.portfolio_id,
# epc_target=body.goal_value,
# heat_demand_target=None
# )
epc_records = {
'original_epc': epc_searcher.newest_epc.copy(),

View file

@ -15,7 +15,8 @@ class HeatingRecommender:
self.property = property_instance
self.costs = Costs(self.property)
self.recommendations = []
self.heating_recommendations = []
self.heating_control_recommendations = []
def recommend(self, phase=0):
@ -23,7 +24,8 @@ class HeatingRecommender:
# the boiler, but instead flushing the system will make it run more efficiently. There is a cost for this
# in the Costs class, stored as SYSTEM_FLUSH_COST
self.recommendations = []
self.heating_recommendations = []
self.heating_control_recommendations = []
# This first iteration of the recommender will provide very basic recommendation
# We recommend heating controls based on the main heating system
@ -254,7 +256,7 @@ class HeatingRecommender:
system_change=system_change
)
self.recommendations.extend(recommendations)
self.heating_recommendations.extend(recommendations)
@staticmethod
def estimate_boiler_size(property_type, built_form, floor_area, floor_height, num_heated_rooms):
@ -399,7 +401,7 @@ class HeatingRecommender:
if not system_change and len(boiler_recommendation):
# If there is not a system change, we add the boiler recommendation at point.
self.recommendations.append([boiler_recommendation])
self.heating_recommendations.extend([boiler_recommendation])
if system_change:
# We combine the heating and controls recommendations, in the case of a system change
@ -417,12 +419,12 @@ class HeatingRecommender:
combined_recommendations.extend(combined_recommendation)
# Overwrite the existing boiler recommendation
self.recommendations.append(combined_recommendations)
self.heating_recommendations.extend(combined_recommendations)
else:
# We increment the recommendation phase, since the heating controls are separate from the boiler upgrade
# but we'll only upgrade if we have a heating recommendation
has_heating_recommendation = any(
rec["type"] == "heating" for recommendation in self.recommendations for rec in recommendation
rec["type"] == "heating" for rec in self.heating_recommendations
)
if has_heating_recommendation:
recommendation_phase += 1
@ -431,6 +433,6 @@ class HeatingRecommender:
for recommendation in controls_recommender.recommendation:
recommendation["phase"] = recommendation_phase
self.recommendations.append(controls_recommender.recommendation)
self.heating_control_recommendations.extend(controls_recommender.recommendation)
return

View file

@ -110,16 +110,23 @@ class Recommendations:
# Heating and Electical systems
if "heating" not in self.exclusions:
self.heating_recommender.recommend(phase=phase)
if self.heating_recommender.recommendations:
if len(self.heating_recommender.recommendations) == 1:
property_recommendations.append(self.heating_recommender.recommendations)
else:
property_recommendations.extend(self.heating_recommender.recommendations)
if (
self.heating_recommender.heating_recommendations or
self.heating_recommender.heating_control_recommendations
):
if self.heating_recommender.heating_recommendations:
property_recommendations.append(self.heating_recommender.heating_recommendations)
if self.heating_recommender.heating_control_recommendations:
property_recommendations.append(self.heating_recommender.heating_control_recommendations)
# We check if we have distinct heating and heating controls recommendations
# If so, we increment by 2 (one of the heating system, one for the heating controls)
# otherwise we incremenet by 1
max_used_phase = max(
[rec["phase"] for recs in self.heating_recommender.recommendations for rec in recs]
[rec["phase"] for rec in
self.heating_recommender.heating_recommendations +
self.heating_recommender.heating_control_recommendations]
)
amount_to_increment = max_used_phase - phase + 1
phase += amount_to_increment