Adding the recommendation scoring mechanisms

This commit is contained in:
Khalim Conn-Kowlessar 2024-07-08 20:41:51 +01:00
parent 1350d8ec9e
commit d303db2557
4 changed files with 38 additions and 3 deletions

View file

@ -174,6 +174,7 @@ class Property:
self.hot_water_energy_source = None self.hot_water_energy_source = None
self.recommendations_scoring_data = [] self.recommendations_scoring_data = []
self.simulation_epcs = {}
self.parse_kwargs(kwargs) self.parse_kwargs(kwargs)
@ -282,6 +283,7 @@ class Property:
""" """
self.recommendations_scoring_data = [] self.recommendations_scoring_data = []
self.simulation_epcs = {}
phases = sorted( phases = sorted(
[ [
r[0]["phase"] r[0]["phase"]
@ -336,6 +338,28 @@ class Property:
) )
self.recommendations_scoring_data.append(scoring_dict) self.recommendations_scoring_data.append(scoring_dict)
# We also use the representative recommendations to produce transformed EPCs
represenative_recs_to_this_phase = [
r for r in property_representative_recommendations
if r["phase"] <= phase
]
epc_transformations = [x["description_simulation"] for x in represenative_recs_to_this_phase]
# It is possible that we could have two simulations applied to the same descriptions
# We extract these out
phase_epc_transformation = {}
for config in epc_transformations:
for k, v in config.items():
if k in phase_epc_transformation:
raise NotImplementedError(
"Already have this key in the phase_epc_transformation - implement me")
phase_epc_transformation[k] = v
simulation_epc = self.epc_record.prepared_epc.copy()
# Replace the understores with hyphens
simulation_epc = {k.replace("_", "-"): v for k, v in simulation_epc.items()}
simulation_epc.update(simulation_epc)
self.simulation_epcs = simulation_epc
@staticmethod @staticmethod
def create_recommendation_scoring_data( def create_recommendation_scoring_data(
property_id, property_id,

View file

@ -227,6 +227,11 @@ class FloorRecommendations(Definitions):
"new_u_value": new_u_value, "new_u_value": new_u_value,
"sap_points": None, "sap_points": None,
"already_installed": already_installed, "already_installed": already_installed,
"description_simulation": {
"floor-description": "Solid, insulated" if
material["type"] == "solid_floor_insulation"
else "Suspended, insulated"
},
**cost_result **cost_result
} }
) )

View file

@ -221,6 +221,7 @@ class Recommendations:
has_u_value = recommendations_by_type[0].get("new_u_value") is not None has_u_value = recommendations_by_type[0].get("new_u_value") is not None
has_sap_points = recommendations_by_type[0].get("sap_points") is not None has_sap_points = recommendations_by_type[0].get("sap_points") is not None
has_rank = recommendations_by_type[0].get("rank") is not None
# When check if these recommendations have two different types, such as solid wall insulation # When check if these recommendations have two different types, such as solid wall insulation
# If we have multiple types, we group by type and then select the best recommendation for each type # If we have multiple types, we group by type and then select the best recommendation for each type
@ -238,6 +239,10 @@ class Recommendations:
# Sort the options by the cost per SAP point improvement - the lower the better # Sort the options by the cost per SAP point improvement - the lower the better
for rec in recommendations: for rec in recommendations:
rec["efficiency"] = rec["total"] / rec["sap_points"] rec["efficiency"] = rec["total"] / rec["sap_points"]
elif has_rank:
# Sort the options by rank - the lower the better
for rec in recommendations:
rec["efficiency"] = rec["rank"]
else: else:
# Sort the options by cost - the lower the better # Sort the options by cost - the lower the better
for rec in recommendations: for rec in recommendations:

View file

@ -109,9 +109,9 @@ class SolarPvRecommendations:
) )
n_units = self.property.solar_panel_configuration["n_units"] n_units = self.property.solar_panel_configuration["n_units"]
best_configurations = panel_performance.head(3) best_configurations = panel_performance.head(3).reset_index(drop=True)
for _, recommendation_config in best_configurations.iterrows(): for rank, recommendation_config in best_configurations.iterrows():
roof_coverage_percent = round(recommendation_config["panneled_roof_area"] / total_roof_area * 100) roof_coverage_percent = round(recommendation_config["panneled_roof_area"] / total_roof_area * 100)
# Spread the cost to the individual units # Spread the cost to the individual units
total_cost = recommendation_config["total_cost"] / n_units total_cost = recommendation_config["total_cost"] / n_units
@ -135,7 +135,8 @@ class SolarPvRecommendations:
# back up here # back up here
"photo_supply": roof_coverage_percent, "photo_supply": roof_coverage_percent,
"has_battery": False, "has_battery": False,
"description_simulation": {"photo-supply": roof_coverage_percent} "description_simulation": {"photo-supply": roof_coverage_percent},
"rank": rank # Rank is used to get the representative recommendation - rank 0 will be chosen
} }
) )