From cf3b603a367cac9a04e372cba834d5dd8944e5d1 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Mon, 29 Jul 2024 18:07:16 +0100 Subject: [PATCH] filling constituency --- backend/Property.py | 20 ++++++++----------- .../functions/energy_assessment_functions.py | 3 ++- backend/app/db/models/energy_assessments.py | 6 +++--- backend/app/plan/router.py | 1 + etl/xml_survey_extraction/app.py | 4 +++- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/backend/Property.py b/backend/Property.py index f15a0d7b..1586835a 100644 --- a/backend/Property.py +++ b/backend/Property.py @@ -728,14 +728,14 @@ class Property: energy_consumption_client.data = None heating_prediction = ( - float(condition_data["space_heating_kwh"]) if condition_data["space_heating_kwh"] + float(condition_data["space_heating_kwh"]) if condition_data.get("space_heating_kwh") is not None else energy_consumption_client.score_new_data( new_data=scoring_df, target="heating_kwh" )[0] ) hot_water_prediction = ( - float(condition_data["water_heating_kwh"]) if condition_data["water_heating_kwh"] + float(condition_data["water_heating_kwh"]) if condition_data.get("water_heating_kwh") is not None else energy_consumption_client.score_new_data( new_data=scoring_df, target="hot_water_kwh" )[0] @@ -1051,18 +1051,18 @@ class Property: # We can update the number of floors if we have this information in the condition data self.number_of_floors = int(self.energy_assessment_condition_data["number_of_floors"]) \ - if condition_data["number_of_floors"] is not None \ + if condition_data.get("number_of_floors") is not None \ else self.number_of_floors self.perimeter = float(self.energy_assessment_condition_data["perimeter"]) \ - if condition_data["perimeter"] is not None \ + if condition_data.get("perimeter") is not None \ else estimate_perimeter( floor_area=self.floor_area / self.number_of_floors, num_rooms=self.number_of_rooms / self.number_of_floors ) self.insulation_wall_area = float(self.energy_assessment_condition_data["insulation_wall_area"]) \ - if condition_data["insulation_wall_area"] is not None \ + if condition_data.get("insulation_wall_area") is not None \ else estimate_external_wall_area( num_floors=self.number_of_floors, floor_height=self.floor_height, @@ -1071,13 +1071,9 @@ class Property: ) self.insulation_floor_area = float(self.energy_assessment_condition_data["main_dwelling_ground_floor_area"]) \ - if condition_data["main_dwelling_ground_floor_area"] is not None \ + if condition_data.get("main_dwelling_ground_floor_area") is not None \ else self.floor_area / self.number_of_floors - # self.pitched_roof_area = esimtate_pitched_roof_area( - # floor_area=self.insulation_floor_area, floor_height=self.floor_height - # ) - def set_floor_level(self): self.floor_level = ( FLOOR_LEVEL_MAP[self.data["floor-level"]] @@ -1177,7 +1173,7 @@ class Property: condition_data = self.energy_assessment_condition_data.copy() self.number_of_windows = int(condition_data["number_of_windows"]) \ - if condition_data["number_of_windows"] is not None \ + if condition_data.get("number_of_windows") is not None \ else estimate_windows( property_type=self.data["property-type"], built_form=self.data["built-form"], @@ -1187,7 +1183,7 @@ class Property: ) self.windows_area = float(condition_data["windows_area"]) \ - if condition_data["windows_area"] is not None \ + if condition_data.get("windows_area") is not None \ else None def set_energy_source(self): diff --git a/backend/app/db/functions/energy_assessment_functions.py b/backend/app/db/functions/energy_assessment_functions.py index 45fb2b8b..b223d2f5 100644 --- a/backend/app/db/functions/energy_assessment_functions.py +++ b/backend/app/db/functions/energy_assessment_functions.py @@ -55,7 +55,8 @@ def get_latest_assessment_by_uprn(session: Session, uprn: int) -> Optional[Energ # Query the EnergyAssessment model, filter by uprn, order by inspection_date in descending order latest_assessment = session.query(EnergyAssessment).filter_by(uprn=uprn).order_by( desc(EnergyAssessment.inspection_date)).first() - return latest_assessment.to_dict() if latest_assessment else latest_assessment.empty_response() + + return latest_assessment.to_dict() if latest_assessment else EnergyAssessment.empty_response() except Exception as e: print(f"An error occurred: {e}") return None diff --git a/backend/app/db/models/energy_assessments.py b/backend/app/db/models/energy_assessments.py index 2c3cc144..3928f9fa 100644 --- a/backend/app/db/models/energy_assessments.py +++ b/backend/app/db/models/energy_assessments.py @@ -1,4 +1,4 @@ -from sqlalchemy import Column, Integer, BigInteger, Text, Float, DateTime, Boolean +from sqlalchemy import Column, Integer, BigInteger, Text, Float, DateTime, Boolean, Date from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() @@ -94,8 +94,8 @@ class EnergyAssessment(Base): hot_water_cost_potential = Column(Text, nullable=False) lighting_cost_current = Column(Text, nullable=False) energy_consumption_current = Column(Text, nullable=False) - lodgement_date = Column(DateTime(timezone=True), nullable=False) - lodgement_datetime = Column(DateTime(timezone=True), nullable=False) + lodgement_date = Column(Date, nullable=False) + lodgement_datetime = Column(DateTime(timezone=False), nullable=False) mainheat_description = Column(Text, nullable=False) floor_height = Column(Float, nullable=False) glazed_type = Column(Text, nullable=False) diff --git a/backend/app/plan/router.py b/backend/app/plan/router.py index f5eba1de..2d024f21 100644 --- a/backend/app/plan/router.py +++ b/backend/app/plan/router.py @@ -244,6 +244,7 @@ def create_epc_records(epc_searcher: SearchEpc, energy_assessment: dict): # We insert county into the epc, since right now this isn't something that we pull out from the energy # assessment epc["county"] = epc_searcher.newest_epc["county"] + epc["constituency"] = epc_searcher.newest_epc["constituency"] # We check if the energy assessment is newer than the newest EPC if pd.to_datetime(energy_assessment_date) > pd.to_datetime(epc_searcher.newest_epc["inspection-date"]): diff --git a/etl/xml_survey_extraction/app.py b/etl/xml_survey_extraction/app.py index 18f84ba2..73551d09 100644 --- a/etl/xml_survey_extraction/app.py +++ b/etl/xml_survey_extraction/app.py @@ -30,7 +30,9 @@ def main(): # We'll need to get the uprn from the folder name, which we can do with EpcSearcher class # TODO: Pull out county, as in create_epc_records in the router, we pull it from the latest EPC, but we should - # be able to deduce it from just the address + # be able to deduce it from just the address. Same for constituency and constituency_label + + # TODO: Store the project code in the database # energy_assessments = list_files_and_subfolders_in_s3_folder( bucket_name=BUCKET, folder_name=f"{SURVEYORS}/{PROJECT_CODE}/"