diff --git a/backend/app/db/functions/property_functions.py b/backend/app/db/functions/property_functions.py index 4e214dcf..94c4734a 100644 --- a/backend/app/db/functions/property_functions.py +++ b/backend/app/db/functions/property_functions.py @@ -82,3 +82,18 @@ def create_property_targets(property_id: int, portfolio_id: int, epc_target=None session.commit() return True + + +def update_property_data(property_data): + Session = sessionmaker(bind=db_engine) + now = datetime.datetime.now() + with Session() as session: + new_target = PropertyTargetsModel( + property_id=property_id, + portfolio_id=portfolio_id, + created_at=now, + epc=epc_target, + heat_demand=heat_demand_target + ) + session.add(new_target) + session.commit() diff --git a/backend/app/plan/router.py b/backend/app/plan/router.py index d63ffed7..1d86cba8 100644 --- a/backend/app/plan/router.py +++ b/backend/app/plan/router.py @@ -70,6 +70,12 @@ walls_decile_data = { 'Decile 9', 'Decile 10'], 'decile_boundaries': [6., 49., 51., 55., 64., 71., 76., 83., 96., 120., 2279.]} +lighting_averages = [ + {'lighting-description': 'good lighting efficiency', 'low-energy-lighting': 99.26666666666667}, + {'lighting-description': 'excellent lighting efficiency', 'low-energy-lighting': 100.0}, + {'lighting-description': 'below average lighting efficiency', 'low-energy-lighting': 0.0} +] + @router.post("/trigger") async def trigger_plan(body: PlanTriggerRequest): @@ -128,6 +134,7 @@ async def trigger_plan(body: PlanTriggerRequest): ) p.set_is_in_conservation_area(in_conservation_area) + # TODO: This won't work perfectly as we need the table of lighting averages by constituency cleaner = EpcClean(data=[x.data for x in input_properties]) cleaner.clean() diff --git a/model_data/EpcClean.py b/model_data/EpcClean.py index eddaa932..c8594de8 100644 --- a/model_data/EpcClean.py +++ b/model_data/EpcClean.py @@ -31,7 +31,8 @@ class EpcClean: "lighting-description" ] - def __init__(self, data: List[Dict[str, Any]]) -> None: + def __init__(self, data: List[Dict[str, Any]], + lighting_averages: List[Dict[str, str | float]] | None = None) -> None: """ EpcClean constructor. @@ -41,7 +42,10 @@ class EpcClean: self.unique_vals: Dict[str, Any] = {} self.cleaned: Dict[str, List[Any]] = {} - self.lighting_averages = self._calculate_lighting_averages() + if not lighting_averages: + self.lighting_averages = self._calculate_lighting_averages() + else: + self.lighting_averages = lighting_averages def _calculate_lighting_averages(self): diff --git a/model_data/app.py b/model_data/app.py index bfe11ce3..ae4bc5b0 100644 --- a/model_data/app.py +++ b/model_data/app.py @@ -74,6 +74,8 @@ def app(): # Incorporate input data into cleaning cleaner = EpcClean(data) + lighting_averages = cleaner.lighting_averages + # TODO: WE need to store lighting_averages to a db cleaner.clean() # TODO: cleaner.cleaned datasets to a db diff --git a/model_data/epc_attributes/LightingAttributes.py b/model_data/epc_attributes/LightingAttributes.py index 62aa7e46..92c03846 100644 --- a/model_data/epc_attributes/LightingAttributes.py +++ b/model_data/epc_attributes/LightingAttributes.py @@ -22,10 +22,12 @@ class LightingAttributes: if ('good lighting efficiency' in description) or ('excellent lighting efficiency' in description) or \ ('below average lighting efficiency' in description): + average = [ + x for x in self.averages if x["lighting-description"] == description + ][0]["low-energy-lighting"] + return { - "low_energy_proportion": self.averages[ - self.averages["lighting-description"] == description - ]["low-energy-lighting"].values[0] + "low_energy_proportion": average } match = re.search(r'\d+', description)