From f9e9cb59a69841a953563e342fa9990c8e4f7640 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Tue, 21 May 2024 19:08:44 +0100 Subject: [PATCH] adding scoring data --- backend/Property.py | 23 +++++++++++++++++++++++ backend/app/plan/router.py | 21 +++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/backend/Property.py b/backend/Property.py index f2e6590c..94861a3f 100644 --- a/backend/Property.py +++ b/backend/Property.py @@ -230,6 +230,29 @@ class Property: # self.base_difference_record.df + def simulate_all_representative_recommendations( + self, property_representative_recommendations, + ): + """ + This method was put together to simulate the impact of the representative recommendations on the property + all at once, for usage within the mds report + :return: + """ + + recommendation_record = self.base_difference_record.df.to_dict("records")[ + 0 + ].copy() + + scoring_dict = self.create_recommendation_scoring_data( + property_id=self.id, + recommendation_record=recommendation_record, + recommendations=property_representative_recommendations, + primary_recommendation_id=self.id, + non_invasive_recommendations=self.non_invasive_recommendations, + ) + + return scoring_dict + def adjust_difference_record_with_recommendations( self, property_recommendations, property_representative_recommendations ): diff --git a/backend/app/plan/router.py b/backend/app/plan/router.py index e11dded8..1bbd6a7d 100644 --- a/backend/app/plan/router.py +++ b/backend/app/plan/router.py @@ -641,9 +641,14 @@ async def build_mds(body: PlanTriggerRequest): input_properties = [] for property_id, config in tqdm(enumerate(plan_input), total=len(plan_input)): # We validate each record in the file. If the record is NOT valid, we need to handle this accordingly - uprn = config.get("uprn", None) - if uprn: - uprn = int(float(uprn)) + + if config["address"] in ["Flat Over 20 Holborough Road", "Flat above 7 Malling Road"]: + print("TEMP - not using uprn") + uprn = None + else: + uprn = config.get("uprn", None) + if uprn: + uprn = int(float(uprn)) epc_searcher = SearchEpc( address1=config["address"], @@ -728,7 +733,6 @@ async def build_mds(body: PlanTriggerRequest): p.get_spatial_data(uprn_filenames) logger.info("Getting components and epc recommendations") - recommendations = {} recommendations_scoring_data = [] representative_recommendations = {} @@ -741,6 +745,15 @@ async def build_mds(body: PlanTriggerRequest): if errors: logger.info("Errors occurred during MDS build") + representative_recommendations[p.id] = property_representative_recommendations + + # Build the scoring data + p.create_base_difference_epc_record(cleaned_lookup=cleaned) + p.simulate_all_representative_recommendations(property_representative_recommendations) + + recommendations_scoring_data.extend(p.recommendations_scoring_data) + + except IntegrityError: logger.error("Database integrity error occurred", exc_info=True)