From 748dc142714384813add7bf155f8d2b9d9f46313 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Tue, 2 Jan 2024 18:15:29 +0000 Subject: [PATCH] handling missing weight possibilities and 0 weights --- backend/SearchEpc.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/SearchEpc.py b/backend/SearchEpc.py index 6a0f3389..07a7de23 100644 --- a/backend/SearchEpc.py +++ b/backend/SearchEpc.py @@ -450,7 +450,10 @@ class SearchEpc: epc_data["house_number_distance"] = abs( epc_data["numeric_house_number"] - self.numeric_house_number ) - epc_data["weight"] = 1 / epc_data["house_number_distance"] + # 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()) epc_built_form = self._estimate_str(key="built-form", estimation_data=epc_data) epc_property_type = self._estimate_str(key="property-type", estimation_data=epc_data)