From 7c902c6c823a502c3906414869ed8f52333436e7 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Thu, 5 Sep 2024 16:37:22 +0100 Subject: [PATCH] handling divising by zero sap points --- recommendations/Recommendations.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/recommendations/Recommendations.py b/recommendations/Recommendations.py index 184f0240..fa02c2c8 100644 --- a/recommendations/Recommendations.py +++ b/recommendations/Recommendations.py @@ -242,13 +242,13 @@ class Recommendations: # We also need to create the representative recommendations for each recommendation type property_representative_recommendations = self.create_representative_recommendations( - property_recommendations, non_invasive_recommendations=self.property_instance.non_invasive_recommendations + property_recommendations, ) return property_recommendations, property_representative_recommendations @staticmethod - def create_representative_recommendations(property_recommendations, non_invasive_recommendations): + def create_representative_recommendations(property_recommendations): """ This method will create a representative recommendation for each recommendation type In order to create a representative recommendation, we choose the recommendation that has: @@ -302,7 +302,10 @@ class Recommendations: elif not has_u_value and has_sap_points: # Sort the options by the cost per SAP point improvement - the lower the better for rec in recommendations: - rec["efficiency"] = rec["total"] / rec["sap_points"] + if rec["sap_points"] == 0: + rec["efficiency"] = 0 + else: + rec["efficiency"] = rec["total"] / rec["sap_points"] elif has_rank: # Sort the options by rank - the lower the better for rec in recommendations: @@ -581,7 +584,7 @@ class Recommendations: "heating_cop": mapped["cop"], "hotwater_cop": 1 } - mapped_hotwater = DESCRIPTIONS_TO_FUEL_TYPES[hotwater_description] + mapped_hotwater = assumptions.DESCRIPTIONS_TO_FUEL_TYPES[hotwater_description] return { "heating_fuel_type": heating_fuel, "hotwater_fuel_type": mapped_hotwater["fuel"],