mirror of
https://github.com/Hestia-Homes/survey-extraction.git
synced 2026-06-30 13:10:56 +00:00
956 lines
No EOL
35 KiB
Python
956 lines
No EOL
35 KiB
Python
from etl.pdfReader.reportType import ReportType
|
||
from etl.transform.preSiteNoteTypes import (
|
||
CompanyInfo, PreSiteNotesSummaryInfo, AssessorInfo,
|
||
PropertyDescription, PropertyDetail, Dimension,
|
||
Walls, Roofs, Floors, Door, VentilationAndCooling,
|
||
Lighting, WaterHeating, HotWaterCylinder, SolarWaterHeating,
|
||
ShowerAndBaths, FlueGasHeatRecoverySystem, PhotovoltaicPanel,
|
||
WindTurbine, OtherDetails, Windows, Heating, HeatingSystemControls,
|
||
HeatingType, Insulation
|
||
)
|
||
from datetime import datetime
|
||
|
||
class SiteNotesExtractor():
|
||
def __init__(self, data_list):
|
||
self.raw_data = data_list
|
||
def get_x_occurance(self, lst, value, x=1):
|
||
try:
|
||
return [i for i, v in enumerate(lst) if v == value][x]
|
||
except IndexError:
|
||
return None # Return None if the value does not occur twice
|
||
|
||
def two_columns_processor(self, data, sub_titles_to_gather, avoid, indexAdd = 1):
|
||
def get_value(key):
|
||
try:
|
||
index = data.index(key)
|
||
value = data[index + indexAdd]
|
||
return None if value in avoid else value
|
||
except (ValueError, IndexError):
|
||
return None
|
||
dict_ = {}
|
||
for items in data:
|
||
if items in avoid:
|
||
continue
|
||
elif items in sub_titles_to_gather:
|
||
dict_.update({f"{items.lower().replace('-', '_').replace(' ','_')}":get_value(items)})
|
||
return dict_
|
||
|
||
def get_data_between(self, a, b):
|
||
return self.raw_data[self.raw_data.index(a):self.raw_data.index(b)]
|
||
|
||
class CSR(SiteNotesExtractor):
|
||
def __init__(self, data_list):
|
||
super().__init__(data_list)
|
||
self.type = ReportType.CHARTED_SURVEYOR_REPORT
|
||
self.insulation_info = None
|
||
self.setup()
|
||
|
||
def setup(self):
|
||
self.get_materials()
|
||
|
||
def get_materials(self):
|
||
lst = self.get_data_between("Detailed description of existing Cavity Wall Insulation ", "Detailed description of Defects in existing Cavity Wall Insulation")
|
||
if len(lst) > 2:
|
||
self.insulation_info = Insulation(type=lst[-1])
|
||
else:
|
||
dict_ = self.two_columns_processor(lst, ["Detailed description of existing Cavity Wall Insulation "], ["Detailed description of Defects in existing Cavity Wall Insulation"])
|
||
|
||
self.insulation_info = Insulation(
|
||
type=dict_.get('detailed_description_of_existing_cavity_wall_insulation_', "")
|
||
) if dict_ is not None else None
|
||
|
||
|
||
|
||
|
||
class QuidosSiteNotesExtractor(SiteNotesExtractor):
|
||
def __init__(self, data_list):
|
||
super().__init__(data_list)
|
||
self.type = ReportType.QUIDOS_PRESITE_NOTE
|
||
self.company_information = None
|
||
self.survey_information = None
|
||
self.property_description = None
|
||
self.setup()
|
||
|
||
def setup(self):
|
||
"""
|
||
A function to read QUIDOS SITE REPORT and get all data
|
||
"""
|
||
self.transform_summary_information()
|
||
self.transform_sections()
|
||
|
||
# Heaters require thought so will complete later
|
||
# self.get_section_14()
|
||
# self.get_section_14_1()
|
||
# self.get_section_14_2()
|
||
|
||
|
||
def transform_summary_information(self):
|
||
# Summary Information
|
||
avoid = [
|
||
"Reference Number",
|
||
"EPC Language",
|
||
"UPRN",
|
||
"Postcode",
|
||
"Region",
|
||
"Address",
|
||
"Town",
|
||
"County",
|
||
"Property Tenure",
|
||
"Transaction Type",
|
||
"Inspection Date",
|
||
'Assessor’s accreditation number',
|
||
'Assessor’s name',
|
||
'Company name/trading name',
|
||
'Address',
|
||
'POST CODE',
|
||
'Phone number',
|
||
'Fax number',
|
||
'E-mail address',
|
||
'Related party disclosure',
|
||
'Current SAP rating',
|
||
'Potential SAP rating',
|
||
'Current EI rating',
|
||
'Current annual emissions',
|
||
'Current annual energy costs',
|
||
'Emission figures including 9.92 emission factor of 0.925',
|
||
]
|
||
get_value = lambda key: None if self.raw_data[self.raw_data.index(key) + 1] in avoid else self.raw_data[self.raw_data.index(key) + 1]
|
||
|
||
index = self.get_x_occurance(self.raw_data, "Current annual emissions")
|
||
if index:
|
||
including_9_92_emission_factor = self.raw_data[index + 1]
|
||
else:
|
||
including_9_92_emission_factor = None
|
||
|
||
self.survey_information = PreSiteNotesSummaryInfo(
|
||
reference_number = get_value('Reference Number'),
|
||
epc_language = get_value('EPC Language'),
|
||
uprn = get_value('UPRN'),
|
||
postcode = get_value('Postcode'),
|
||
region = get_value('Region'),
|
||
address = ','.join(get_value('Address').split(',')[:-1]).strip(),
|
||
town = get_value('Town'),
|
||
county = get_value('County'),
|
||
property_tenure = get_value('Property Tenure'),
|
||
transaction_type = get_value('Transaction Type'),
|
||
inspection_date = datetime.strptime(get_value('Inspection Date'), '%d %B %Y'),
|
||
current_sap = get_value('Current SAP rating'),
|
||
potential_sap = get_value('Potential SAP rating'),
|
||
current_ei = get_value('Current EI rating'),
|
||
potential_ei = get_value('Potential EI rating'),
|
||
current_annual_emissions = get_value('Current annual emissions'),
|
||
current_annual_energy_costs = get_value('Current annual energy costs'),
|
||
current_annual_emission_including_0925_multiplayer=including_9_92_emission_factor,
|
||
)
|
||
|
||
|
||
self.company_information = CompanyInfo(
|
||
address=self.raw_data[self.get_x_occurance(self.raw_data,'Address', 1) + 1],
|
||
trading_name = get_value('Company name/trading name'),
|
||
post_code = get_value('POST CODE'),
|
||
fax_number = get_value('Fax number'),
|
||
related_party_disclosure = get_value("Related party disclosure")
|
||
)
|
||
|
||
self.assessor_information = AssessorInfo(
|
||
accreditation_number = get_value("Assessor’s accreditation number"),
|
||
name = get_value("Assessor’s name"),
|
||
phone_number = get_value("Phone number"),
|
||
email_address = get_value("E-mail address"),
|
||
)
|
||
|
||
index = self.get_x_occurance(self.raw_data, "Address")
|
||
if index:
|
||
assessor_address = self.raw_data[index + 1]
|
||
else:
|
||
assessor_address = None
|
||
|
||
self.assessor_information = AssessorInfo(
|
||
accreditation_number = get_value("Assessor’s accreditation number"),
|
||
name = get_value("Assessor’s name"),
|
||
phone_number = get_value("Phone number"),
|
||
email_address = get_value("E-mail address"),
|
||
address = assessor_address,
|
||
)
|
||
|
||
def transform_sections(self):
|
||
# Section 1
|
||
data = self.get_data_between("1.0 Property Type","2.0 Number Of")
|
||
|
||
avoid = [
|
||
"1.0 Property Type",
|
||
"Built Form",
|
||
"Detachment/Position",
|
||
"2.0 Number Of"
|
||
]
|
||
|
||
get_value = lambda key: None if self.raw_data[self.raw_data.index(key) + 1] in avoid else self.raw_data[self.raw_data.index(key) + 1]
|
||
|
||
|
||
# Section 2
|
||
data = self.get_data_between("2.0 Number Of","3.0 Date Built")
|
||
|
||
avoid = [
|
||
'2.0 Number Of',
|
||
'Main Property',
|
||
'Extension 1',
|
||
'Extension 2',
|
||
'Extension 3',
|
||
'Extension 4',
|
||
'Number of Habitable Rooms',
|
||
'Number of Heated Habitable Rooms',
|
||
'Heated Basement',
|
||
'Conservatory Type',
|
||
'Terrain Type',
|
||
'Percentage of Draught Proofed(%)',
|
||
"3.0 Date Built",
|
||
]
|
||
|
||
# Section 3
|
||
age_bands = self.get_age_band()
|
||
|
||
# Section 4
|
||
no_of_main_property = int(get_value("Main Property"))
|
||
no_of_extension_1 = int(get_value('Extension 1') or 0)
|
||
no_of_extension_2 = int(get_value('Extension 2') or 0)
|
||
no_of_extension_3 = int(get_value('Extension 3') or 0)
|
||
no_of_extension_4 = int(get_value('Extension 4') or 0)
|
||
dimensions = self.get_dimensions(
|
||
no_of_main_property,
|
||
no_of_extension_1,
|
||
no_of_extension_2,
|
||
no_of_extension_3,
|
||
no_of_extension_4,
|
||
)
|
||
|
||
# Section 5
|
||
conservatory = self.is_there_a_conservatory()
|
||
|
||
# Section 7
|
||
walls = self.get_walls()
|
||
|
||
# Section 8
|
||
roofs = self.get_roof()
|
||
|
||
# Section 9
|
||
floors = self.get_floors()
|
||
|
||
# Section 10
|
||
door = self.get_door()
|
||
|
||
windows = self.get_windows()
|
||
|
||
# Section 12
|
||
ventilationAndCooling = self.get_ventilation_and_cooling()
|
||
|
||
# Section 13
|
||
lighting = self.get_lighting()
|
||
|
||
# Section 14.0
|
||
main_heating = self.get_main_heating()
|
||
|
||
# Section 14.1
|
||
secondary_heating = self.get_secondary_heating()
|
||
|
||
# Section 14.2
|
||
secondary_heating_type = self.get_secondary_heating_type()
|
||
|
||
# Section 15.0 Water Heating
|
||
waterHeating = self.get_water_heating()
|
||
|
||
# Section 15.1 Hot Water Cylinder
|
||
hotWaterCylinder = self.get_hot_water_cylinder()
|
||
|
||
# Section 16 Solar Water Heating
|
||
solarWaterHeating = self.get_solar_water_heating()
|
||
|
||
# Section 17.0
|
||
# ignored as it has nothing in the copy i'm using. Future todo clarity
|
||
|
||
# Section 18.0
|
||
showerAndBaths = self.get_shower_and_baths()
|
||
|
||
# Section 19.0
|
||
fghrs = self.get_fghrs()
|
||
|
||
# Section 20.0
|
||
photovoltaicPanel = self.get_photovoltaic_panel()
|
||
|
||
# Section 21.0
|
||
windTurbine = self.get_wind_turbine()
|
||
|
||
# Section 22.0
|
||
otherDetails = self.get_other_details()
|
||
|
||
self.property_description = PropertyDescription(
|
||
built_form = get_value("Built Form"),
|
||
detachment_or_position = get_value("Detachment/Position"),
|
||
no_of_main_property = no_of_main_property,
|
||
no_of_extension_1 = no_of_extension_1,
|
||
no_of_extension_2 = no_of_extension_2,
|
||
no_of_extension_3 = no_of_extension_3,
|
||
no_of_extension_4 = no_of_extension_4,
|
||
no_of_habitable_rooms = int(get_value('Number of Habitable Rooms')),
|
||
no_of_heated_rooms = int(get_value('Number of Heated Habitable Rooms')),
|
||
heated_basement = False if get_value('Heated Basement') == "NO" else True,
|
||
conservatory_type = get_value('Conservatory Type'),
|
||
terrain_type = get_value('Terrain Type'),
|
||
percentage_of_draught_proofed= int(get_value('Percentage of Draught Proofed(%)')),
|
||
main_property=PropertyDetail(
|
||
age_band=age_bands[0],
|
||
dimensions=dimensions["main"] if "main" in dimensions else [],
|
||
wall=walls[0],
|
||
roof=roofs[0],
|
||
floor=floors[0],
|
||
windows=windows.get("main_property", []),
|
||
)if no_of_main_property > 0 else None,
|
||
ex1_property=PropertyDetail(
|
||
age_band= age_bands[1],
|
||
dimensions= dimensions["ex1"] if "ex1" in dimensions else [],
|
||
wall=walls[1],
|
||
roof=roofs[1],
|
||
floor=floors[1],
|
||
windows=windows.get("extension_1", []),
|
||
)if no_of_extension_1 > 0 else None,
|
||
ex2_property=PropertyDetail(
|
||
age_band= age_bands[2],
|
||
dimensions= dimensions["ex2"] if "ex2" in dimensions else [],
|
||
wall=walls[2],
|
||
roof=roofs[2],
|
||
floor=floors[2],
|
||
windows=windows.get("extension_2", []),
|
||
)if no_of_extension_2 > 0 else None,
|
||
ex3_property=PropertyDetail(
|
||
age_band= age_bands[3],
|
||
dimensions=dimensions["ex3"] if "ex3" in dimensions else [],
|
||
wall=walls[3],
|
||
roof=roofs[3],
|
||
floor=floors[3],
|
||
windows=windows.get("extension_3", []),
|
||
)if no_of_extension_4 > 0 else None,
|
||
conservatory=conservatory,
|
||
door=door,
|
||
ventilationAndCooling=ventilationAndCooling,
|
||
lighting=lighting,
|
||
waterHeating=waterHeating,
|
||
hotWaterCylinder=hotWaterCylinder,
|
||
solarWaterHeating=solarWaterHeating,
|
||
showerAndBaths=showerAndBaths,
|
||
flueGasHeatRecoverySystem=fghrs,
|
||
photovoltaicPanel=photovoltaicPanel,
|
||
windTurbine=windTurbine,
|
||
otherDetails=otherDetails,
|
||
mainHeating=main_heating,
|
||
secondaryHeatingType=secondary_heating_type,
|
||
mainHeating2=secondary_heating,
|
||
)
|
||
|
||
|
||
def get_age_band(self):
|
||
data = self.raw_data[self.raw_data.index('3.0 Date Built'):self.raw_data.index('4.0 Dimensions')]
|
||
avoid = [
|
||
'3.0 Date Built',
|
||
'Age Band',
|
||
'Main Property',
|
||
'Extension 1',
|
||
'Extension 2',
|
||
'Extension 3',
|
||
'Extension 4',
|
||
'4.0 Dimensions',
|
||
]
|
||
property_age = []
|
||
get_value = lambda x: None if data[data.index(x) + 1] in avoid else data[data.index(x) + 1]
|
||
|
||
age = (get_value("Main Property"))
|
||
if age:
|
||
property_age.append(age)
|
||
else:
|
||
property_age.append(None)
|
||
|
||
for i in range(1,4):
|
||
if f"Extension {i}" in data:
|
||
property_age.append(get_value(f"Extension {i}"))
|
||
else:
|
||
property_age.append(None)
|
||
|
||
|
||
return property_age
|
||
|
||
|
||
def get_dimensions(self, main, ext1=0, ext2=0, ext3=0, ext4=0):
|
||
data = self.get_data_between('4.0 Dimensions','5.0 Conservatory')
|
||
|
||
avoid = [
|
||
'4.0 Dimensions',
|
||
'5.0 Conservatory',
|
||
'Dimension Type internal',
|
||
'Part',
|
||
'Floor Area (m2)',
|
||
'Room Height (m)',
|
||
'Loss Perimeter (m)',
|
||
'Party Wall Length (m)',
|
||
'Main Property',
|
||
'Extension 1 Property',
|
||
'Extension 2 Property',
|
||
'Extension 3 Property',
|
||
'Extension 4 Property',
|
||
]
|
||
|
||
def create_dimensions_array(key, no_of_property):
|
||
index = data.index(key) + 1
|
||
|
||
allNumbers = []
|
||
for propertyNo in range(no_of_property):
|
||
numbers = []
|
||
for i in range(4):
|
||
numbers.append(data[i + propertyNo*4 + index])
|
||
details = Dimension(
|
||
floor_area_m2=float(numbers[0]),
|
||
room_height_m=float(numbers[1]),
|
||
loss_perimeter_m=float(numbers[2]),
|
||
party_wall_length_m=float(numbers[3]),
|
||
)
|
||
allNumbers.append(details)
|
||
return allNumbers
|
||
|
||
return_dict = {}
|
||
|
||
return_dict.update({"main": create_dimensions_array("Main Property", main)})
|
||
|
||
ext = [ext1, ext2, ext3, ext4]
|
||
|
||
for i in range(1,5):
|
||
if f"Extension {i} Property" in data:
|
||
return_dict.update({f"ex{i}" : create_dimensions_array(f"Extension {i} Property", ext[i-1])})
|
||
return return_dict
|
||
|
||
def is_there_a_conservatory(self):
|
||
data = self.raw_data[self.raw_data.index('5.0 Conservatory'):self.raw_data.index('7.0 Walls')]
|
||
avoid = [
|
||
'Is there a conservatory?',
|
||
'7.0 Walls'
|
||
]
|
||
get_value = lambda key: None if self.raw_data[self.raw_data.index(key) + 1] in avoid else self.raw_data[self.raw_data.index(key) + 1]
|
||
|
||
return True if get_value("Is there a conservatory?").upper() == "YES" else False
|
||
|
||
|
||
def get_section_6(self):
|
||
pass
|
||
|
||
def get_walls(self):
|
||
data = self.get_data_between('7.0 Walls','8.0 Roofs')
|
||
|
||
sub_titles = [
|
||
"Construction",
|
||
"Insulation",
|
||
"Insulation Thickness(mm)",
|
||
"Wall Thickness Measured?",
|
||
"Wall Thickness Measured",
|
||
"Wall Thickness(mm)",
|
||
"U-value Known?",
|
||
"U-value Known",
|
||
"U-value (W/m²K)",
|
||
"Dry-lining?",
|
||
"Alternative Wall Present?",
|
||
"Alternative Wall Present",
|
||
]
|
||
|
||
main_titles = [
|
||
"Main Property",
|
||
"Extension 1",
|
||
"Extension 2",
|
||
"Extension 3",
|
||
"Extension 4",
|
||
]
|
||
lst = self.two_column_with_extension_processor(data, sub_titles, main_titles)
|
||
|
||
walls = []
|
||
for ext in lst:
|
||
walls.append(Walls(
|
||
construction=ext["construction"] if ext["construction"] is not None else "",
|
||
insulation=str(ext["insulation"]),
|
||
insulation_thickness_mm=str(ext["insulation_thickness(mm)"]),
|
||
wall_thickness_measured=True if ext["wall_thickness_measured"].upper() == "YES" else False,
|
||
wall_thickness_mm=int(ext.get("wall_thickness(mm)",-1)),
|
||
u_value_known=True if ext["u_value_known"].upper() == "YES" else False,
|
||
u_value_w_m2_k=float(ext.get("u_value_(w/m²k)", -1.0)),
|
||
dry_lining=True if ext.get("dry_lining", "NO").upper() == "YES" else False,
|
||
alternative_wall_present=True if ext.get("alternative_wall_present", "NO").upper() == "YES" else False,
|
||
))
|
||
return walls
|
||
|
||
|
||
def get_roof(self):
|
||
data = self.raw_data[self.raw_data.index('8.0 Roofs'): self.raw_data.index('9.0 Floors')]
|
||
sub_titles = [
|
||
"Construction",
|
||
"Insulation Type",
|
||
"Insulation Thickness",
|
||
"U-value Known",
|
||
]
|
||
|
||
titles = [
|
||
"Main Property",
|
||
"Extension 1",
|
||
"Extension 2",
|
||
"Extension 3",
|
||
"Extension 4",
|
||
]
|
||
|
||
lst = self.two_column_with_extension_processor(data, sub_titles, titles)
|
||
roofs = []
|
||
for roof in lst:
|
||
roofs.append(Roofs(
|
||
construction=roof["construction"] if roof["construction"] is not None else "",
|
||
insulation_type=str(roof["insulation_type"]),
|
||
insulation_thickness=str(roof["insulation_thickness"]),
|
||
u_value_known=True if roof["u_value_known"].upper() == "YES" else False,
|
||
))
|
||
return roofs
|
||
|
||
|
||
def two_column_with_extension_processor(self, data, sub_titles, main_titles):
|
||
def get_value(key):
|
||
try:
|
||
index = proc_data.index(key)
|
||
value = proc_data[index + 1]
|
||
return None if value in sub_titles else value
|
||
except (ValueError, IndexError):
|
||
return None
|
||
title = None
|
||
proc_data = data
|
||
return_dict = {}
|
||
group_data = []
|
||
for items in data:
|
||
if items in main_titles:
|
||
title = items.lower().replace(" ", "_").replace("-", "_")
|
||
index = main_titles.index(items)
|
||
if main_titles[index] in data:
|
||
if return_dict:
|
||
group_data.append(return_dict)
|
||
return_dict = {}
|
||
proc_data = data[data.index(main_titles[index]):]
|
||
continue
|
||
else:
|
||
if return_dict:
|
||
group_data.append(return_dict)
|
||
break
|
||
if title is None:
|
||
continue
|
||
if items in sub_titles:
|
||
return_dict.update({f"{items.lower().replace("?", "").replace(' ', '_').replace('-','_')}": get_value(items)})
|
||
|
||
if return_dict:
|
||
group_data.append(return_dict)
|
||
|
||
return group_data
|
||
|
||
def get_floors(self):
|
||
data = self.raw_data[self.raw_data.index('9.0 Floors'): self.raw_data.index('10.0 Doors')]
|
||
sub_titles = [
|
||
"Floor Type",
|
||
"Ground Floor Construction",
|
||
"Ground Floor Insulation Type",
|
||
"Floor Insulation Thickness (mm)",
|
||
"U-value Known",
|
||
]
|
||
|
||
titles = [
|
||
"Main Property",
|
||
"Extension 1",
|
||
"Extension 2",
|
||
"Extension 3",
|
||
"Extension 4",
|
||
]
|
||
|
||
|
||
lst = self.two_column_with_extension_processor(data, sub_titles, titles)
|
||
floors = []
|
||
for floor in lst:
|
||
floors.append(Floors(
|
||
floor_type=floor.get("floor_type", ""),
|
||
ground_floor_construction=floor.get("get_floor_construction", ""),
|
||
ground_floor_insulation_type=floor.get("ground_floor_insulation_type", ""),
|
||
floor_insulation_thickness_mm=floor.get("floor_insulation_thickness_(mm)", -1) if floor.get("floor_insulation_thickness_(mm)", -1) is not None else -1,
|
||
u_value_known=True if floor.get("u_value_known").upper() == "YES" else False,
|
||
))
|
||
return floors
|
||
|
||
def get_door(self):
|
||
data = self.raw_data[self.raw_data.index("10.0 Doors"): self.raw_data.index("11.0 Windows")]
|
||
avoid = [
|
||
"10.0 Doors",
|
||
"11.0 Windows",
|
||
]
|
||
sub_titles = [
|
||
"Number of Doors",
|
||
"Number of Insulated Doors",
|
||
"U-value (W/m²K)",
|
||
]
|
||
dict_ = self.two_columns_processor(data, sub_titles, avoid)
|
||
|
||
return Door(
|
||
no_of_doors=int(dict_.get("no_of_doors", -1)),
|
||
no_of_insulated_doors=int(dict_.get("number_of_insulated_doors", -1)),
|
||
u_value_w_m2_k=dict_.get("u_value_(w/m²k)", "") if dict_.get("u_value_(w/m²k), '')") is not None else "",
|
||
)
|
||
|
||
|
||
def get_windows(self):
|
||
data = self.get_data_between("11.0 Windows", "12.0 Ventilation & Cooling")
|
||
headers = data[:8]
|
||
data_entries = data[8:]
|
||
|
||
num_attributes = 5
|
||
subtitles=[
|
||
"Main Property",
|
||
"Extension 1",
|
||
"Extension 2",
|
||
"Extension 3",
|
||
"Extension 4",
|
||
]
|
||
|
||
orientation = [
|
||
"north",
|
||
"east",
|
||
"west",
|
||
"south",
|
||
"n",
|
||
"w",
|
||
"s",
|
||
"e",
|
||
"nw",
|
||
"ne",
|
||
"sw",
|
||
"se",
|
||
"south west",
|
||
"south east",
|
||
"north west",
|
||
"north east",
|
||
|
||
]
|
||
|
||
def find_compose_index(lst, compose):
|
||
for i, item in enumerate(lst):
|
||
if item.lower() in compose:
|
||
return i
|
||
return None
|
||
|
||
title = None
|
||
until = 0
|
||
dict_to_return = {}
|
||
for i, items in enumerate(data_entries):
|
||
if data_entries[i] in subtitles:
|
||
title = data_entries[i].lower().replace(" ", "_").replace("-", "_")
|
||
dict_to_return.update({f"{title}":[]})
|
||
if title and until == i:
|
||
entry = data_entries[i:]
|
||
index = find_compose_index(entry,orientation)
|
||
new_entry = entry[index-3:index+3]
|
||
window = Windows(
|
||
glazing_type= new_entry[0],
|
||
area_m2=float(new_entry[1]),
|
||
roof_window=True if new_entry[2].upper() == "YES" else False,
|
||
orientation=new_entry[3].upper(),
|
||
u_value_w_m2_k=int(new_entry[4]),
|
||
g_value=int(new_entry[5]),
|
||
)
|
||
dict_to_return[f"{title}"].append(window)
|
||
until = index + 3 + i
|
||
return dict_to_return
|
||
|
||
def get_ventilation_and_cooling(self):
|
||
data = self.raw_data[self.raw_data.index('12.0 Ventilation & Cooling'): self.raw_data.index('13.0 Lighting')]
|
||
avoid = [
|
||
'12.0 Ventilation & Cooling',
|
||
'13.0 Lighting'
|
||
]
|
||
sub_titles = [
|
||
"Number of Open Fireplaces",
|
||
"Ventilation Type",
|
||
"Space Cooling System Present",
|
||
]
|
||
|
||
dict_ = self.two_columns_processor(data, sub_titles, avoid)
|
||
return VentilationAndCooling(
|
||
no_of_open_fireplaces=int(dict_.get("number_of_open_fireplaces", -1)),
|
||
ventilation_type=str(dict_.get("ventilation_type", "")),
|
||
space_cooling_system_present=True if dict_.get("space_cooling_system_present").upper() == "YES" else False
|
||
)
|
||
|
||
def get_lighting(self):
|
||
data = self.raw_data[self.raw_data.index('13.0 Lighting'): self.raw_data.index('14.0 Main Heating1')]
|
||
avoid = [
|
||
"13.0 Lighting",
|
||
"14.0 Main Heating1"
|
||
]
|
||
sub_titles = [
|
||
"Total number of light fittings",
|
||
"Total number of L.E.L. fittings",
|
||
]
|
||
dict_ = self.two_columns_processor(data, sub_titles, avoid = avoid)
|
||
return Lighting(
|
||
total_no_of_light_fittings=int(dict_["total_number_of_light_fittings"]),
|
||
total_no_of_lel_fittings=int(dict_["total_number_of_l.e.l._fittings"]),
|
||
)
|
||
|
||
def get_main_heating(self):
|
||
data = self.raw_data[self.raw_data.index('14.0 Main Heating1'): self.raw_data.index('14.1 Main Heating2')]
|
||
main_titles = [
|
||
"Main Heating Type",
|
||
"Product Database"
|
||
"Main Heating System Controls",
|
||
]
|
||
sub_titles = [
|
||
"Heating Source",
|
||
"Efficiency Source",
|
||
"Heating Fuel",
|
||
"Brand Name",
|
||
"Model Name",
|
||
"Model Qualifier",
|
||
"Control Type",
|
||
"Flue Type",
|
||
"Fan Assisted Flue",
|
||
"Heat Emitter Type",
|
||
"Electricity Meter Type",
|
||
"Mains Gas Available",
|
||
]
|
||
|
||
lst_ = self.two_column_with_extension_processor(data, sub_titles, main_titles)
|
||
dict_ = lst_[0]
|
||
return Heating(
|
||
type="main",
|
||
heating_source=dict_.get("heating_source", ""),
|
||
efficiency_source=dict_.get("efficiency_source", ""),
|
||
heating_fuel=dict_.get("heating_fuel", ""),
|
||
brand_name=dict_.get("brand_name", ""),
|
||
model_name=dict_.get("model_name", ""),
|
||
model_qualifer=dict_.get("model_qualifier", ""),
|
||
controls=HeatingSystemControls(
|
||
control_type=dict_.get("control_type", "") if dict_.get("control_type", "") is not None else "",
|
||
flue_type=dict_.get("flue_type","") if dict_.get("flue_type", "") is not None else "",
|
||
fan_assisted_flue=True if dict_.get("fan_assisted_flue", "NO").upper() == "YES" else False,
|
||
heat_emitter_type=dict_.get("heat_emitter_type", "") if dict_.get("heat_emitter_type") is not None else "",
|
||
electricity_meter_type=dict_.get("electricity_meter_type", ""),
|
||
mains_gas_available=True if dict_.get("mains_gas_available", "NO").upper() == "YES" else False,
|
||
)
|
||
)
|
||
|
||
def get_secondary_heating(self):
|
||
data = self.raw_data[self.raw_data.index("14.1 Main Heating2"):self.raw_data.index("14.2 Secondary Heating Type")]
|
||
main_titles = [
|
||
"Second Main Heating Type",
|
||
"Main Heating System Controls",
|
||
]
|
||
sub_titles = [
|
||
"Percentage of Heated Floor Area Served (%)",
|
||
"Heating Source",
|
||
"Efficiency Source",
|
||
"Heating Fuel",
|
||
"SAP 2009 Table 4a/4b",
|
||
"Heating Type",
|
||
"Heating Description",
|
||
"Control Type",
|
||
"Flue Type",
|
||
"Fan Assisted Flue",
|
||
"Heat Emitter Type",
|
||
]
|
||
list = self.two_column_with_extension_processor(data, sub_titles, main_titles)
|
||
dict_ = list[0]
|
||
|
||
return Heating(
|
||
type="secondary",
|
||
percentage_of_heated_floor_area_served=dict_.get("percentage_of_heated_floor_area_served_(%)", ""),
|
||
heating_source=dict_.get("heating_source", "") if dict_["heating_source"] is not None else "",
|
||
efficiency_source=dict_.get("efficiency_source", "") if dict_["efficiency_source"] is not None else "",
|
||
heating_fuel=dict_.get("heating_fuel", "") if dict_.get("heating_fuel") is not None else "",
|
||
brand_name=dict_.get("brand_name", ""),
|
||
model_name=dict_.get("model_name", ""),
|
||
model_qualifer=dict_.get("model_qualifier", ""),
|
||
controls=HeatingSystemControls(
|
||
control_type=dict_.get("control_type", "") if dict_.get("control_type", "") is not None else "",
|
||
flue_type=dict_.get("flue_type","") if dict_.get("flue_type", "") is not None else "",
|
||
fan_assisted_flue=True if dict_.get("fan_assisted_flue", "NO").upper() == "YES" else False,
|
||
heat_emitter_type=dict_.get("heat_emitter_type", "") if dict_.get("heat_emitter_type") is not None else "",
|
||
electricity_meter_type=dict_.get("electricity_meter_type", "") if dict_.get("electricity_meter_type", "") is not None else "",
|
||
mains_gas_available=True if dict_.get("mains_gas_available", "NO").upper() == "YES" else False,
|
||
)
|
||
)
|
||
|
||
def get_secondary_heating_type(self):
|
||
data = self.raw_data[self.raw_data.index("14.2 Secondary Heating Type"):self.raw_data.index("15.0 Water Heating")]
|
||
avoid = [
|
||
"14.2 Secondary Heating Type",
|
||
"15.0 Water Heating",
|
||
]
|
||
sub_titles = [
|
||
"Heating Type",
|
||
"Fuel Type",
|
||
]
|
||
dict_ = self.two_columns_processor(data, sub_titles, avoid)
|
||
return HeatingType(
|
||
heating_type=dict_.get("heating_type", ""),
|
||
fuel_type=dict_.get("fuel_type", ""),
|
||
)
|
||
|
||
def get_water_heating(self):
|
||
data = self.raw_data[self.raw_data.index("15.0 Water Heating"):self.raw_data.index("15.1 Hot Water Cylinder")]
|
||
sub_titles = [
|
||
"Heating Type",
|
||
"Fuel Type",
|
||
]
|
||
avoid = [
|
||
"15.0 Water Heating",
|
||
"15.1 Hot Water Cylinder",
|
||
]
|
||
dict_ = self.two_columns_processor(data, sub_titles, avoid)
|
||
|
||
return WaterHeating(
|
||
heating_type=dict_.get("heating_type", ""),
|
||
fuel_type=dict_.get("fuel_type", ""),
|
||
)
|
||
|
||
def get_hot_water_cylinder(self):
|
||
data = self.raw_data[self.raw_data.index("15.1 Hot Water Cylinder"):self.raw_data.index("16.0 Solar Water Heating")]
|
||
sub_tites = [
|
||
"Volume",
|
||
"Insulation Type",
|
||
"Insulation Thickness",
|
||
"Thermostat",
|
||
]
|
||
avoid = [
|
||
"16.0 Solar Water Heating",
|
||
"15.1 Hot Water Cylinder"
|
||
]
|
||
dict_ = self.two_columns_processor(data, sub_tites, avoid)
|
||
|
||
return HotWaterCylinder(
|
||
volume=dict_.get("volume", ""),
|
||
insulation_type=dict_.get("insulation_type", ""),
|
||
insulation_thickness=dict_.get("insulation_thickness", ""),
|
||
thermostat=True if dict_.get("thermostat", "NO").upper() == "YES" else False,
|
||
)
|
||
|
||
def get_solar_water_heating(self):
|
||
data = self.raw_data[self.raw_data.index("16.0 Solar Water Heating"):self.raw_data.index("17.0 Waste Water Heat Recovery System")]
|
||
avoid = [
|
||
"16.0 Solar Water Heating",
|
||
"17.0 Waste Water Heat Recovery System",
|
||
]
|
||
sub_titles = [
|
||
"Solar Water Heating Details Known?"
|
||
]
|
||
|
||
dict_ = self.two_columns_processor(data, sub_titles, avoid)
|
||
|
||
return SolarWaterHeating(
|
||
solar_water_heating_details_known=True if dict_.get("solar_water_heating_details_known", "NO").upper() == "YES" else False
|
||
)
|
||
|
||
def get_section_17(self):
|
||
"""
|
||
Furture todo
|
||
"""
|
||
raise NotImplemented("Please contact Jun-te Kim to implement this")
|
||
|
||
def get_shower_and_baths(self):
|
||
data = self.get_data_between("18.0 Showers And Baths", "19.0 Flue Gas Heat Recovery System")
|
||
sub_titles = [
|
||
"Number of Rooms with Bath and/or Shower",
|
||
]
|
||
avoid = [
|
||
"18.0 Showers And Baths",
|
||
"19.0 Flue Gas Heat Recovery System",
|
||
]
|
||
|
||
dict_1 = self.two_columns_processor(data, sub_titles, avoid)
|
||
|
||
avoid = [
|
||
"18.0 Showers And Baths",
|
||
"19.0 Flue Gas Heat Recovery System",
|
||
]
|
||
sub_titles = [
|
||
"Number of Rooms with Mixer Shower and no", # Number of Rooms with Mixer Shower and no Bath
|
||
"Number of Rooms with Mixer Shower and", # Number of Rooms with Mixer Shower and Bath
|
||
]
|
||
dict_2 = self.two_columns_processor(data, sub_titles, avoid, 2)
|
||
|
||
return ShowerAndBaths(
|
||
no_of_rooms_with_baths_and_or_shower=int(dict_1.get("number_of_rooms_with_bath_and/or_shower", -1)),
|
||
no_of_rooms_with_mixer_shower_and_no_baths=int(dict_2.get("number_of_rooms_with_mixer_shower_and_no", -1)),
|
||
no_of_rooms_with_mixer_shower_and_baths=int(dict_2.get("number_of_rooms_with_mixer_shower_and", -1)),
|
||
)
|
||
|
||
|
||
|
||
def get_fghrs(self):
|
||
data = self.get_data_between("19.0 Flue Gas Heat Recovery System","20.0 Photovoltaic Panel")
|
||
sub_titles = [
|
||
"FGHRS Present",
|
||
]
|
||
avoid = [
|
||
"19.0 Flue Gas Heat Recovery System",
|
||
"20.0 Photovoltaic Panel",
|
||
]
|
||
|
||
dict_ = self.two_columns_processor(data, sub_titles, avoid)
|
||
|
||
return FlueGasHeatRecoverySystem(
|
||
fghrs_present=True if dict_.get("fghrs_present", "NO").upper() == "YES" else False
|
||
)
|
||
|
||
|
||
def get_photovoltaic_panel(self):
|
||
data = self.get_data_between("20.0 Photovoltaic Panel","21.0 Wind Turbine")
|
||
sub_titles = [
|
||
"Percentage of External Roof Area with PVs"
|
||
]
|
||
avoid = [
|
||
"20.0 Photovoltaic Panel",
|
||
"21.0 Wind Turbine",
|
||
]
|
||
dict_1 = self.two_columns_processor(data, sub_titles, avoid)
|
||
|
||
sub_titles = [
|
||
"PVs are connected to dwelling electricity" # PVs are connected to dwelling electricity meter
|
||
]
|
||
dict_2 = self.two_columns_processor(data, sub_titles, avoid, 2)
|
||
return PhotovoltaicPanel(
|
||
pvs_are_connected_to_dwelling_electricity_meter=True if dict_2.get("pvs_are_connected_to_dwelling_electricity", "NO").upper() == "YES" else False,
|
||
percentage_of_external_roof_area_with_pvs=dict_1.get("percentage_of_external_roof_area_with_pvs")
|
||
)
|
||
|
||
def get_wind_turbine(self):
|
||
data = self.get_data_between("21.0 Wind Turbine","22.0 Other Details")
|
||
sub_titles = [
|
||
"Wind Turbine",
|
||
]
|
||
avoid = [
|
||
"21.0 Wind Turbine",
|
||
"22.0 Other Details",
|
||
]
|
||
dict_ = self.two_columns_processor(data, sub_titles, avoid)
|
||
return WindTurbine(
|
||
wind_turbine=True if dict_.get("wind_turbine", "NO").upper()=="YES" else False
|
||
)
|
||
|
||
def get_other_details(self):
|
||
data = self.get_data_between("22.0 Other Details","Recommendations (Carbon Saving Figures Are For Guidance Only)")
|
||
sub_titles = [
|
||
"Electricity Meter Type",
|
||
"Mains Gas Available",
|
||
]
|
||
avoid = [
|
||
"22.0 Other Details",
|
||
"Recommendations (Carbon Saving Figures Are For Guidance Only)",
|
||
]
|
||
|
||
dict_ = self.two_columns_processor(data, sub_titles, avoid)
|
||
|
||
return OtherDetails(
|
||
electricity_meter_type=dict_.get("electricity_meter_type", ""),
|
||
main_gas_avalible=True if dict_.get("main_gas_available", "NO").upper() == "YES" else False,
|
||
)
|
||
|
||
|