diff --git a/backend/engine/engine.py b/backend/engine/engine.py index 2427ca8a..8410024d 100644 --- a/backend/engine/engine.py +++ b/backend/engine/engine.py @@ -405,6 +405,29 @@ def check_duplicate_uprns(plan_input): return True +def check_duplicate_property_ids(input_properties): + """ + Simple function to check if the input data contains duplicated property IDs. This will happen in very rare + cases where we have properties across different servers, where the input UPRN is possibly incorrect and we + find the right property via an address search, instead of a UPRN search and so we end up with the same property + twice. + :param input_properties: + :return: + """ + + input_property_ids = [x.id for x in input_properties] + + if input_property_ids: + # Check for dupes + if len(input_property_ids) != len(set(input_property_ids)): + # Find the duplicate property IDs + duplicates = set([x for x in input_property_ids if input_property_ids.count(x) > 1]) + # de-dupe input_uprns + raise ValueError(f"Duplicate property IDs in the input data: {duplicates}") + + return True + + def averages_cleaning(prepared_epc: EPCRecord, cleaning_data: pd.DataFrame): """ Placeholder cleaning function to handle edge cases where we have missing data for @@ -780,6 +803,8 @@ async def model_engine(body: PlanTriggerRequest): if not input_properties: return Response(status_code=204) + check_duplicate_property_ids(input_properties) + # We check if we have inspections data and store it in the database if so. We'll update or create # aginst each property if if inspections_map: diff --git a/recommendations/WindowsRecommendations.py b/recommendations/WindowsRecommendations.py index bc5e6066..a5561d20 100644 --- a/recommendations/WindowsRecommendations.py +++ b/recommendations/WindowsRecommendations.py @@ -190,7 +190,7 @@ class WindowsRecommendations: raise ValueError("Invalid glazing type - implement me") if self.property.data["windows-energy-eff"] == "Very Good": - raise ValueError("Very Good energy efficiency is not supported") + windows_energy_eff = "Very Good" # For post 2002 windows, the energy efficiency is "Good" and so for the simulation, we simulate with "Good"