save work

This commit is contained in:
Jun-te Kim 2025-06-30 15:46:46 +00:00
parent f9242b8aaf
commit ebb2443a5c
2 changed files with 199 additions and 86 deletions

View file

@ -306,4 +306,81 @@ class Occupant(BaseModel, table=True):
are_there_any_vulnerable_people: bool
is_there_anyone_with_a_disability: bool
status_of_occupant: str
landlord_wrote_that_the_tenent_agrees_assessment_been_supplied: bool
landlord_wrote_that_the_tenent_agrees_assessment_been_supplied: bool
class EnergyUse(BaseModel, table=True):
property_tenure: str
who_is_the_electricity_payer: str
class HeatingFromConditionReport(BaseModel, table=True):
room_stat_in_temperature_in_celsius: Optional[str] = None
room_stat_location: Optional[str] = None
is_the_heating_pattern_known: Optional[str] = None
class ShowerAndBath(BaseModel, table=True):
shower_type: str
do_you_know_the_no_of_showers_per_day_per_week: bool
please_input_no_of_showers_and_specify_a_day_or_a_week: str
do_you_know_the_number_of_baths_per_day_or_per_week: str
class FridgeAndFreezers(BaseModel, table=True):
no_of_stand_alone_seperate_fridges: int
no_of_stand_alone_seperate_freezers: int
no_of_stand_alone_or_integrated_fridge_freezers: int
class Cooker(BaseModel,table=True):
range_fuel: str
normal_large_range: str
cooker_type: str
class TumbleDryer(BaseModel, table=True):
percentage_of_annual_use: int
space_for_outdoor_drying: bool
class OccupantAssessment(BaseModel, table=True):
occupant_id: uuid.UUID = Field(foreign_key="occupant.id")
occupant: Occupant = Relationship()
energy_use_id: uuid.UUID = Field(foreign_key="energyuse.id")
energy_use: EnergyUse = Relationship()
heating_id: uuid.UUID = Field(foreign_key="heatingfromconditionreport.id")
heating: HeatingFromConditionReport = Relationship()
shower_and_bath_id: uuid.UUID = Field(foreign_key="showerandbath.id")
shower_and_bath: ShowerAndBath = Relationship()
# appliances: Optional[Appliances]
# appliances_id
fridge_and_freezers_id: uuid.UUID = Field(foreign_key="fridgeandfreezers.id")
fridge_and_freezers: FridgeAndFreezers = Relationship()
cooker_id: uuid.UUID = Field(foreign_key="cooker.id")
cooker: Cooker = Relationship()
tumble_dryer_id: uuid.UUID = Field(foreign_key="tumbledryer.id")
tumble_dryer: TumbleDryer = Relationship()
class ConditionReportModel(BaseModel, table=True):
project_site_name: str
property_reference_code: str
property_address: str
postcode: str
general_information_id: uuid.UUID = Field(foreign_key="generalinformation.id")
general_information: GeneralInformation = Relationship()
access_and_elevations_id: uuid.UUID = Field(foreign_key="accessandelevations.id")
access_and_elevations: AccessAndElevations = Relationship()
rooms_id: uuid.UUID = Field(foreign_key="rooms.id")
rooms: Rooms = Relationship()
heating_system_id: uuid.UUID = Field(foreign_key="heatingsystem.id")
heating_system: HeatingSystem = Relationship()
occupancy_assessment_id: uuid.UUID = Field(foreign_key="occupantassessment.id")
occupancy_assessment: OccupantAssessment = Relationship()

View file

@ -13,43 +13,17 @@ from etl.models.preSiteNoteTypes import (
from pprint import pprint
from etl.models.conditionReport import (
AssessorDetails,
InspectionAndProject,
TheProperty, ElevationInfo,
MainElevation,
Elevation,
GeneralInformation,
PropertyAccess,
ExternalElevation,
ExternalElevationFront,
ExternalElevationRear,
ExternalElevationGableOne,
ExternalElevationGableTwo,
ConservatoryOrOutbuilding,
AccessAndElevations,
Hallway,
VentilationInfo,
WindowsInfo,
RoomInfo,
LivingRoom,
DiningRoom,
Kitchen,
Utility,
WC,
Landing,
LoftSpace,
RoomInRoof,
Bedroom,
Bathroom,
Rooms,
GeneralConditionHeatingSystem,
MainHeatingOne,
MainHeatingTwo,
SecondaryHeating,
HeatingByRoom,
Renewables,
HeatingSystem,
Occupant
AssessorDetails, InspectionAndProject, TheProperty, ElevationInfo,
MainElevation, Elevation,GeneralInformation,
PropertyAccess, ExternalElevation,
ExternalElevationFront, ExternalElevationRear, ExternalElevationGableOne,
ExternalElevationGableTwo, ConservatoryOrOutbuilding, AccessAndElevations,Hallway,
VentilationInfo,WindowsInfo,RoomInfo,LivingRoom, DiningRoom, Kitchen, Utility, WC,
Landing,LoftSpace,RoomInRoof, Bedroom,Bathroom, Rooms,
GeneralConditionHeatingSystem, MainHeatingOne, MainHeatingTwo,
SecondaryHeating, HeatingByRoom, Renewables, HeatingSystem, Occupant, EnergyUse,
HeatingFromConditionReport, ShowerAndBath, FridgeAndFreezers, Cooker, TumbleDryer,
OccupantAssessment, ConditionReportModel
)
from etl.models.topLevel import(
@ -81,47 +55,123 @@ class surveyedDataProcessor():
self.condition_report = pdf.get_reader()
def load_condition_report(self, db_session):
# My task to complete load
# [x] general_information = self.get_section_1()
# [x] access_and_elevations = self.get_section_2()
# [x] rooms = self.get_section_3()
# [x] heating_system = self.get_section_4()
# [] occupant_assessment = self.get_section_5()
# [] site_name, reference_code, address, postcode = self.get_section_0()
# return ConditionReportModel(
# project_site_name=site_name,
# property_reference_code=reference_code,
# property_address=address,
# postcode=postcode,
# general_information=general_information,
# access_and_elevations=access_and_elevations,
# rooms=rooms,
# heating_system=heating_system,
# occupancy_assessment=occupant_assessment,
# )
# class HeatingSystem(BaseModel):
# heating_by_room: HeatingByRoom
# renewables: Renewables
general_information = self.load_general_information_from_condition_report(db_session)
access_and_elevations = self.load_access_and_elevations_from_condition_report(db_session)
rooms = self.load_rooms_from_condition_report(db_session)
heating_system = self.load_heating_system_from_condition_report(db_session)
occupant_assessment = self.load_occupant_info_from_condition_report(db_session)
condition_report = self.get_attribute_and_load(
self.condition_report,
"master_obj",
ConditionReportModel,
db_session,
additional_fields={
"general_information_id": general_information.id,
"access_and_elevations_id": access_and_elevations.id,
"rooms_id": rooms.id,
"heating_system_id": heating_system.id,
"occupancy_assessment_id": occupant_assessment.id,
},
)
# Create building table
data = {
"address": self.pre_site_note.survey_information.address,
"postcode": self.pre_site_note.survey_information.postcode,
"UPRN": self.pre_site_note.survey_information.uprn,
"landlord_id": landlord_id,
"domna_id": domna_id
}
building = self.upsert_record(
db_session=db_session,
model_class=Buildings,
data_dict=data,
lookup_field="UPRN",
)
return building
# Create document table
def load_occupant_info_from_condition_report(self, db_session):
"""
occupant: Occupant
energy_use: EnergyUse
heating: HeatingFromConditionReport
shower_and_bath: ShowerAndBath
appliances: Optional[Appliances]
fridge_and_freezers: FridgeAndFreezers
cooker: Cooker
tumble_dryer: TumbleDryer
"""
self.load_occupant_information_from_condition_report(db_session)
occupant_info = self.load_occupant_information_from_condition_report(db_session)
energy_use = self.load_energy_use_from_condition_report(db_session)
heating = self.load_heating_from_condition_report(db_session)
showerAndBath = self.load_shower_and_bath_from_condition_report(db_session)
# The example I (Jun-te) had, had no appliances so skipped until I have one that needs this information
appliances = self.load_appliances_from_condition_report(db_session)
fridgeAndFreezers = self.load_fridge_and_freezer_from_condition_report(db_session)
cooker = self.load_cooker_from_condition_report(db_session)
tumble_dryer = self.load_tumble_dryer_from_condition_report(db_session)
return self.get_attribute_and_load(
self.condition_report.master_obj,
"occupancy_assessment",
OccupantAssessment,
db_session,
additional_fields={
"occupant_id": occupant_info.id,
"energy_use_id": energy_use.id,
"heating_id": heating.id,
"shower_and_bath_id": showerAndBath.id,
"fridge_and_freezers_id": fridgeAndFreezers.id,
"cooker_id": cooker.id,
"tumble_dryer_id": tumble_dryer.id
}
)
def load_tumble_dryer_from_condition_report(self, db_session):
return self.get_attribute_and_load(
self.condition_report.master_obj.occupancy_assessment,
"tumble_dryer",
TumbleDryer,
db_session,
)
def load_cooker_from_condition_report(self, db_session):
return self.get_attribute_and_load(
self.condition_report.master_obj.occupancy_assessment,
"cooker",
Cooker,
db_session,
)
def load_fridge_and_freezer_from_condition_report(self, db_session):
return self.get_attribute_and_load(
self.condition_report.master_obj.occupancy_assessment,
"fridge_and_freezers",
FridgeAndFreezers,
db_session,
)
def load_appliances_from_condition_report(self, db_session):
print("Appliances was not done, please contact jun-te to complete this!")
return None
def load_shower_and_bath_from_condition_report(self, db_session):
return self.get_attribute_and_load(
self.condition_report.master_obj.occupancy_assessment,
"shower_and_bath",
ShowerAndBath,
db_session
)
def load_heating_from_condition_report(self, db_session):
return self.get_attribute_and_load(
self.condition_report.master_obj.occupancy_assessment,
"heating",
HeatingFromConditionReport,
db_session
)
def load_energy_use_from_condition_report(self, db_session):
return self.get_attribute_and_load(
self.condition_report.master_obj.occupancy_assessment,
"energy_use",
EnergyUse,
db_session,
)
def load_occupant_information_from_condition_report(self, db_session):
return self.get_attribute_and_load(
@ -634,20 +684,6 @@ class surveyedDataProcessor():
lookup_field="reference_number"
)
def create_building_table(self, db_session):
return self.upsert_record(
db_session=db_session,
model_class=Buildings,
data_dict={
"address":"foo",
"potcode": "foobar",
"UPRN": self.pre_site_note.survey_information.uprn,
"landlord_id": "landlord_id",
"domna_id": "landlord_id",
},
lookup_field="UPRN",
)
def get_attribute_and_load(self, obj, attr_string, pydanticModel, db_session, lookup_field=None, additional_fields={}, exclude_list=True):
found = getattr(obj, attr_string, None)
if found: