From 22a3e21f523b79da4ec65fa12d8d901242c5cfb6 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Thu, 28 Mar 2024 14:52:24 +0000 Subject: [PATCH] update validation of PlanTriggerRequest to use cls rather than self --- backend/app/plan/router.py | 4 +--- backend/app/plan/schemas.py | 12 ++++++------ recommendations/Recommendations.py | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/backend/app/plan/router.py b/backend/app/plan/router.py index 5456cdb6..e25c04a5 100644 --- a/backend/app/plan/router.py +++ b/backend/app/plan/router.py @@ -170,9 +170,7 @@ async def trigger_plan(body: PlanTriggerRequest): p.get_components(cleaned, photo_supply_lookup, floor_area_decile_thresholds) recommender = Recommendations(property_instance=p, materials=materials) - # TODO: portfolio id as an input is temp - print("DELETE PORTFOLIO ID AS AN INPUT!!") - property_recommendations, property_representative_recommendations = recommender.recommend(body.portfolio_id) + property_recommendations, property_representative_recommendations = recommender.recommend() if not property_recommendations: continue diff --git a/backend/app/plan/schemas.py b/backend/app/plan/schemas.py index c13e754e..b8a99704 100644 --- a/backend/app/plan/schemas.py +++ b/backend/app/plan/schemas.py @@ -31,21 +31,21 @@ class PlanTriggerRequest(BaseModel): # Validator to ensure exclusions are within the pre-defined possibilities @validator('exclusions', each_item=True) - def check_exclusions(self, v): - if v not in self._allowed_exclusions: + def check_exclusions(cls, v): + if v not in cls._allowed_exclusions: raise ValueError(f"{v} is not an allowed exclusion") return v # Validator to ensure that the goal is within the pre-defined possibilities @validator('goal') - def check_goal(self, v): - if v not in self._allowed_goals: + def check_goal(cls, v): + if v not in cls._allowed_goals: raise ValueError(f"{v} is not a valid goal") return v # Validator to ensure that the housing type is within the pre-defined possibilities @validator('housing_type') - def check_housing_type(self, v): - if v not in self.allowed_housing_types: + def check_housing_type(cls, v): + if v not in cls._allowed_housing_types: raise ValueError(f"{v} is not a valid housing type") return v diff --git a/recommendations/Recommendations.py b/recommendations/Recommendations.py index d3436ef0..b2e6d991 100644 --- a/recommendations/Recommendations.py +++ b/recommendations/Recommendations.py @@ -47,7 +47,7 @@ class Recommendations: self.heating_recommender = HeatingRecommender(property_instance=property_instance) self.hotwater_recommender = HotwaterRecommendations(property_instance=property_instance) - def recommend(self, portfolio_id): + def recommend(self): """ This method runs the recommendations for the individual measures and then appends them to a list for output