testing different weight methods - to run full test on

This commit is contained in:
Khalim Conn-Kowlessar 2024-01-04 14:56:33 +00:00
parent 15ec6460d2
commit 1b4ae239a3
2 changed files with 18 additions and 8 deletions

View file

@ -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):

View file

@ -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