From 1b4ae239a3a052d49835d902aaefb68758b97e9c Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Thu, 4 Jan 2024 14:56:33 +0000 Subject: [PATCH] testing different weight methods - to run full test on --- backend/SearchEpc.py | 24 ++++++++++++++++-------- recommendations/Recommendations.py | 2 ++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/backend/SearchEpc.py b/backend/SearchEpc.py index 6e17d200..b3f58b04 100644 --- a/backend/SearchEpc.py +++ b/backend/SearchEpc.py @@ -472,13 +472,21 @@ class SearchEpc: epc_data["house_number_distance"] = abs( epc_data["numeric_house_number"] - self.numeric_house_number ) - # We add 1, just in case we have a 0 weight (e.g. comparing house number 7a to 7b, or 9A to 9) - epc_data["weight"] = 1 / (epc_data["house_number_distance"] + 1) - # If we have a home without a house number, fill that weight with average - epc_data["weight"] = epc_data["weight"].fillna(epc_data["weight"].mean()) - # Finally, we might not have any house numbers whatsoever so everything could be - # missing, so we fill with 1 - epc_data["weight"] = epc_data["weight"].fillna(1) + # # We add 1, just in case we have a 0 weight (e.g. comparing house number 7a to 7b, or 9A to 9) + # epc_data["weight"] = 1 / (epc_data["house_number_distance"] + 1) + # # If we have a home without a house number, fill that weight with average + # epc_data["weight"] = epc_data["weight"].fillna(epc_data["weight"].mean()) + # # Finally, we might not have any house numbers whatsoever so everything could be + # # missing, so we fill with 1 + # epc_data["weight"] = epc_data["weight"].fillna(1) + # TODO: Testing + # If the postcode is different from the initial postcode, it doesn't make sense to have + # any weightings + if all(pd.isnull(epc_data["house_number_distance"])) or (postcode != initial_postcode): + epc_data["weight"] = 1 + else: + epc_data["weight"] = 1 / np.sqrt(epc_data["house_number_distance"] + 1) + epc_data["weight"] = epc_data["weight"].fillna(epc_data["weight"].mean()) estimation_property_type = self._estimate_str( key="property-type", estimation_data=epc_data @@ -621,7 +629,7 @@ class SearchEpc: @staticmethod def _estimate_float(estimation_data, key): - return np.average(a=estimation_data[key], weights=estimation_data["weight"]) + return round(np.average(a=estimation_data[key], weights=estimation_data["weight"]), 2) @staticmethod def _estimate_str(estimation_data, key): diff --git a/recommendations/Recommendations.py b/recommendations/Recommendations.py index 4b54cb52..a5d1f35c 100644 --- a/recommendations/Recommendations.py +++ b/recommendations/Recommendations.py @@ -155,6 +155,8 @@ class Recommendations: # For the moment, we cap the number of SAP points that can be achieved by ventilation at 2 rec["sap_points"] = min(rec["sap_points"], VentilationRecommendations.SAP_LIMIT) + # Round to 2 decimal places + rec["sap_points"] = round(rec["sap_points"], 2) rec["co2_equivalent_savings"] = float(property_instance.data["co2-emissions-current"]) - new_carbon # Energy consumption current is per meter squared, so we need to multiply by the floor area to get