Fixed unit tests for recommendations where we have new cost data - to be complete

This commit is contained in:
Khalim Conn-Kowlessar 2023-12-04 15:05:10 +00:00
parent b30dfd9ead
commit b232d91439
5 changed files with 495 additions and 542 deletions

View file

@ -0,0 +1,79 @@
"""
This script will create an input csv for the recommendation engine and upload it to S3, which can be used for
testing
"""
import os
import numpy as np
import pandas as pd
from epc_api.client import EpcClient
from utils.s3 import save_csv_to_s3
FILE_SIZE = 5
EPC_AUTH_TOKEN = os.getenv("EPC_AUTH_TOKEN", None)
USER_ID = 8
PORTFOLIO_ID = 54
def app():
# For this dataset, we want 3 properties, all hourses. A mid-terrace, and end-terrace and a semi-detached
epc_client = EpcClient(auth_token=EPC_AUTH_TOKEN)
# Birmingham has a Local Authority Code of E08000025
# Let's take an EPC D property
example_1_reponse = epc_client.domestic.search(
params={
"local-authority": "E08000025",
"property-type": "house",
}
)
g_data = epc_client.domestic.search(params={"energy-band": "g"}, size=n_g)
f_data = epc_client.domestic.search(params={"energy-band": "f"}, size=n_f)
e_data = epc_client.domestic.search(params={"energy-band": "e"}, size=n_e)
d_data = epc_client.domestic.search(params={"energy-band": "d"}, size=n_d)
c_data = epc_client.domestic.search(params={"energy-band": "c"}, size=n_c)
b_data = epc_client.domestic.search(params={"energy-band": "b"}, size=n_b)
a_data = epc_client.domestic.search(params={"energy-band": "a"}, size=n_a)
# Combine the final data
final_data = (
g_data["rows"] + f_data["rows"] + e_data["rows"] + d_data["rows"] + c_data["rows"] + b_data["rows"]
+ a_data["rows"]
)
# TODO: We also take homes with just a specific type of wall
final_data = [
x for x in final_data if ("cavity wall" in x["walls-description"].lower()) or (
"solid brick" in x["walls-description"].lower()
) or ("average thermal transmittance" in x["walls-description"].lower())
]
# TODO: For the moment, don't use park homes
final_csv_data = pd.DataFrame(
[{"address": x["address"], "postcode": x["postcode"], "Notes": None} for x
in final_data if
x["property-type"] not in ["Park home"]]
)
final_csv_data = pd.concat([starting_csv, final_csv_data]).reset_index(drop=True)
# Store the data in s3
filename = f"{USER_ID}/{PORTFOLIO_ID}/test_inputs.csv"
save_csv_to_s3(
dataframe=final_csv_data,
bucket_name="retrofit-plan-inputs-dev",
file_name=filename
)
body = {
"portfolio_id": str(PORTFOLIO_ID),
"housing_type": "Social",
"goal": "Increase EPC",
"goal_value": "B",
"trigger_file_path": filename
}
print(body)

View file

@ -5,14 +5,14 @@ from recommendations.county_to_region import county_to_region_map
regional_labour_variations = [ regional_labour_variations = [
{"Region": "Outer London", "Adjustment_Factor": 1.00}, {"Region": "Outer London", "Adjustment_Factor": 1.00},
{"Region": "Inner London", "Adjustment_Factor": 1.05}, {"Region": "Inner London", "Adjustment_Factor": 1.05},
{"Region": "South East", "Adjustment_Factor": 0.96}, {"Region": "South East England", "Adjustment_Factor": 0.96},
{"Region": "South West", "Adjustment_Factor": 0.90}, {"Region": "South West England", "Adjustment_Factor": 0.90},
{"Region": "East of England", "Adjustment_Factor": 0.93}, {"Region": "East of England", "Adjustment_Factor": 0.93},
{"Region": "East Midlands", "Adjustment_Factor": 0.88}, {"Region": "East Midlands", "Adjustment_Factor": 0.88},
{"Region": "West Midlands", "Adjustment_Factor": 0.87}, {"Region": "West Midlands", "Adjustment_Factor": 0.87},
{"Region": "North East England", "Adjustment_Factor": 0.83}, {"Region": "North East England", "Adjustment_Factor": 0.83},
{"Region": "North West England", "Adjustment_Factor": 0.88}, {"Region": "North West England", "Adjustment_Factor": 0.88},
{"Region": "Yorkshire and Humberside", "Adjustment_Factor": 0.86}, {"Region": "Yorkshire and the Humber", "Adjustment_Factor": 0.86},
{"Region": "Wales", "Adjustment_Factor": 0.88}, {"Region": "Wales", "Adjustment_Factor": 0.88},
{"Region": "Scotland", "Adjustment_Factor": 0.88}, {"Region": "Scotland", "Adjustment_Factor": 0.88},
{"Region": "Northern Ireland", "Adjustment_Factor": 0.76} {"Region": "Northern Ireland", "Adjustment_Factor": 0.76}
@ -71,13 +71,16 @@ class Costs:
self.property = property_instance self.property = property_instance
self.regional_labour_variations = regional_labour_variations self.regional_labour_variations = regional_labour_variations
self.county = county_to_region_map.get(self.property.data["county"], None) self.region = county_to_region_map.get(self.property.data["county"], None)
if self.county is None: if self.region is None:
raise ValueError("County not found in county map") # Try and grab using the local-authority-label
self.region = county_to_region_map.get(self.property.data["local-authority-label"], None)
if self.region is None:
raise ValueError("Region not found in county map")
self.labour_adjustment_factor = [ self.labour_adjustment_factor = [
x["Adjustment_Factor"] for x in self.regional_labour_variations if x["Adjustment_Factor"] for x in self.regional_labour_variations if
x["Region"] == self.county x["Region"] == self.region
][0] ][0]
if not self.labour_adjustment_factor: if not self.labour_adjustment_factor:

View file

@ -35,15 +35,6 @@ county_to_region_map = {
'Tendring': 'East of England', 'Three Rivers': 'East of England', 'Thurrock': 'East of England', 'Tendring': 'East of England', 'Three Rivers': 'East of England', 'Thurrock': 'East of England',
'Uttlesford': 'East of England', 'Watford': 'East of England', 'Waveney': 'East of England', 'Uttlesford': 'East of England', 'Watford': 'East of England', 'Waveney': 'East of England',
'Welwyn Hatfield': 'East of England', 'Welwyn Hatfield': 'East of England',
# 'Barking and Dagenham': 'London', 'Barnet': 'London', 'Bexley': 'London',
# 'Brent': 'London', 'Bromley': 'London', 'Camden': 'London', 'City of London': 'London',
# 'City of Westminster': 'London', 'Croydon': 'London', 'Ealing': 'London', 'Enfield': 'London',
# 'Greater London': 'London', 'Greenwich': 'London', 'Hackney': 'London', 'Hammersmith and Fulham': 'London',
# 'Haringey': 'London', 'Harrow': 'London', 'Havering': 'London', 'Hillingdon': 'London', 'Hounslow': 'London',
# 'Islington': 'London', 'Kensington and Chelsea': 'London', 'Kingston upon Thames': 'London', 'Lambeth': 'London',
# 'Lewisham': 'London', 'Merton': 'London', 'Newham': 'London', 'Redbridge': 'London', 'Richmond': 'London',
# 'Southwark': 'London', 'Sutton': 'London', 'Tower Hamlets': 'London', 'Waltham Forest': 'London',
# 'Wandsworth': 'London', 'Westminster': 'London',
'County Durham': 'North East England', 'County Durham': 'North East England',
'Darlington': 'North East England', 'Durham': 'North East England', 'Gateshead': 'North East England', 'Darlington': 'North East England', 'Durham': 'North East England', 'Gateshead': 'North East England',
'Hartlepool': 'North East England', 'Middlesbrough': 'North East England', 'Hartlepool': 'North East England', 'Middlesbrough': 'North East England',
@ -168,5 +159,21 @@ county_to_region_map = {
'York': 'Yorkshire and the Humber', 'York': 'Yorkshire and the Humber',
# Additional mappings requried, based on what we find in the EPC database # Additional mappings requried, based on what we find in the EPC database
'Greater London Authority': 'Inner London' 'Greater London Authority': 'Inner London',
# We have a bunch of inner London local authority mappings, which can be used if the county is not found
'Barking and Dagenham': 'Inner London', 'Barnet': 'Inner London', 'Bexley': 'Inner London',
'Brent': 'Inner London', 'Bromley': 'Inner London', 'Camden': 'Inner London', 'City of London': 'Inner London',
'City of Westminster': 'Inner London', 'Croydon': 'Inner London', 'Ealing': 'Inner London',
'Enfield': 'Inner London',
'Greater London': 'Inner London', 'Greenwich': 'Inner London', 'Hackney': 'Inner London',
'Hammersmith and Fulham': 'Inner London',
'Haringey': 'Inner London', 'Harrow': 'Inner London', 'Havering': 'Inner London', 'Hillingdon': 'Inner London',
'Hounslow': 'Inner London',
'Islington': 'Inner London', 'Kensington and Chelsea': 'Inner London', 'Kingston upon Thames': 'Inner London',
'Lambeth': 'Inner London',
'Lewisham': 'Inner London', 'Merton': 'Inner London', 'Newham': 'Inner London', 'Redbridge': 'Inner London',
'Richmond': 'Inner London',
'Southwark': 'Inner London', 'Sutton': 'Inner London', 'Tower Hamlets': 'Inner London',
'Waltham Forest': 'Inner London',
'Wandsworth': 'Inner London', 'Westminster': 'Inner London',
} }

View file

@ -3,90 +3,15 @@ import pytest
import os import os
from unittest.mock import Mock from unittest.mock import Mock
from recommendations.FloorRecommendations import FloorRecommendations from recommendations.FloorRecommendations import FloorRecommendations
from recommendations.tests.test_data.materials import materials
from backend.Property import Property from backend.Property import Property
# with open( # with open(
# os.path.abspath(os.path.dirname(__file__)) + "/recommendations/tests/test_data/input_properties.pkl", "rb" # os.path.abspath(os.path.dirname(__file__)) + "/recommendations/tests/test_data/input_properties.pkl", "rb"
# ) as f: # ) as f:
# input_properties = pickle.load(f) # input_properties = pickle.load(f)
suspended_floor_insulation_parts = [
{
# Example product
# https://www.insulationsuperstore.co.uk/product/recticel-eurothane-general-purpose-pir-insulation-board-2400
# -x-1200-x-100mm.html
# All product data_types here:
# https://www.insulationsuperstore.co.uk/browse/insulation/brand/recticel/filterby/application/floors.html
"type": "suspended_floor_insulation",
"description": "Rigid Insulation Foam Boards",
"depths": [25, 30, 40, 50, 60, 70, 75, 80, 90, 100, 110, 120, 130, 140, 150],
"depth_unit": "mm",
"cost": [25, 30, 40, 50, 60, 70, 75, 80, 90, 100, 110, 120, 130, 140, 150],
"cost_unit": "gbp_sq_meter",
"r_value_per_mm": 0.04545454545454546,
"r_value_unit": "square_meter_kelvin_per_watt",
"thermal_conductivity": 0.022,
"thermal_conductivity_unit": "watt_per_meter_kelvin"
},
{
# Example product
# https://www.insulationsuperstore.co.uk/product/rockwool-rwa45-acoustic-insulation-slab-100mm-2-88m2-pack.html
# All product data_types here:
# https://www.insulationsuperstore.co.uk/browse/insulation/brand/rockwool/filterby/application/floors
# /material/mineral-wool.html
"type": "suspended_floor_insulation",
"description": "Mineral Wool Floor Insulation",
"depths": [25, 40, 50, 60, 75, 100],
"depth_unit": "mm",
"cost": [25, 40, 50, 60, 75, 100],
"cost_unit": "gbp_sq_meter",
"r_value_per_mm": 0.02857142857142857,
"r_value_unit": "square_meter_kelvin_per_watt",
"thermal_conductivity": 0.035,
"thermal_conductivity_unit": "watt_per_meter_kelvin"
},
]
solid_floor_insulation_parts = [
{
# Example product
# https://www.insulationexpress.co.uk/floor-insulation/solid-floor-insulation/k103-100mm
# All product data_types here:
# https://www.insulationexpress.co.uk/floor-insulation/solid-floor-insulation?brand=7015&p=1
# Example screed https://www.screwfix.com/p/mapei-ultraplan-3240-self-levelling-compound-25kg/4959f
"type": "solid_floor_insulation",
"description": "Rigid Insulation Foam Boards with floor screed",
"depths": [25, 50, 70, 75, 100],
"depth_unit": "mm",
"cost": [25, 40, 50, 60, 75, 100],
"cost_unit": "gbp_sq_meter",
"r_value_per_mm": 0.04545454545454546,
"r_value_unit": "square_meter_kelvin_per_watt",
"thermal_conductivity": 0.052631578947368425,
"thermal_conductivity_unit": "watt_per_meter_kelvin"
},
]
exposed_floor_insulation_parts = [
{
"type": "exposed_floor_insulation",
"description": "Rockwool Stone Wool insulation",
"depths": [50, 100, 140],
"depth_unit": "mm",
"cost": [8, 11, 15],
"cost_unit": "gbp_sq_meter",
"r_value_per_mm": 0.026315789473684213,
"r_value_unit": "square_meter_kelvin_per_watt",
"thermal_conductivity": 0.038,
"thermal_conductivity_unit": "watt_per_meter_kelvin",
"link": "https://insulation4less.co.uk/products/rockwool-flexi-slab-all-sizes?variant=33409590853685"
},
]
parts = suspended_floor_insulation_parts + solid_floor_insulation_parts + exposed_floor_insulation_parts
class TestFloorRecommendations: class TestFloorRecommendations:
@pytest.fixture @pytest.fixture
@ -100,26 +25,29 @@ class TestFloorRecommendations:
def mock_floor_rec_instance(self): def mock_floor_rec_instance(self):
# Creating a mock instance of WallRecommendations with the necessary attributes # Creating a mock instance of WallRecommendations with the necessary attributes
property_mock = Mock() property_mock = Mock()
property_mock.full_sap_epc = {"lodgement-date": "2000-01-01"} # or any date you want property_mock.full_sap_epc = {"lodgement-date": "2000-01-01"}
property_mock.data = {"construction-age-band": "1950"} # or any other data that fits your tests property_mock.data = {"county": "York"}
mock_wall_rec_instance = FloorRecommendations(property_mock, parts) mock_wall_rec_instance = FloorRecommendations(property_mock, materials)
return mock_wall_rec_instance return mock_wall_rec_instance
def test_init(self, input_properties): def test_init(self, input_properties):
input_properties[0].insulation_floor_area = 50
input_properties[0].insulation_wall_area = 90
obj = FloorRecommendations( obj = FloorRecommendations(
property_instance=input_properties[0], property_instance=input_properties[0],
materials=parts materials=materials
) )
assert obj assert obj
assert obj.property assert obj.property
def test_other_premises_below(self, input_properties): def test_other_premises_below(self, input_properties):
input_properties[0].floor_area = 100 input_properties[0].insulation_floor_area = 100
input_properties[0].insulation_wall_area = 999
input_properties[0].number_of_floors = 1 input_properties[0].number_of_floors = 1
recommender = FloorRecommendations( recommender = FloorRecommendations(
property_instance=input_properties[0], property_instance=input_properties[0],
materials=parts materials=materials
) )
recommender.recommend() recommender.recommend()
assert recommender.property.floor["another_property_below"] assert recommender.property.floor["another_property_below"]
@ -132,7 +60,8 @@ class TestFloorRecommendations:
:return: :return:
""" """
input_properties[2].floor_area = 50 input_properties[2].insulation_floor_area = 50
input_properties[2].insulation_wall_area = 50
input_properties[2].walls["is_park_home"] = False input_properties[2].walls["is_park_home"] = False
input_properties[2].age_band = "A" input_properties[2].age_band = "A"
input_properties[2].perimeter = 20 input_properties[2].perimeter = 20
@ -140,10 +69,7 @@ class TestFloorRecommendations:
input_properties[2].floor_type = "suspended" input_properties[2].floor_type = "suspended"
input_properties[2].number_of_floors = 1 input_properties[2].number_of_floors = 1
recommender = FloorRecommendations( recommender = FloorRecommendations(property_instance=input_properties[2], materials=materials)
property_instance=input_properties[2],
materials=parts
)
assert recommender.estimated_u_value is None assert recommender.estimated_u_value is None
recommender.recommend() recommender.recommend()
assert recommender.property.floor["is_suspended"] assert recommender.property.floor["is_suspended"]
@ -154,18 +80,20 @@ class TestFloorRecommendations:
assert types == {"suspended_floor_insulation"} assert types == {"suspended_floor_insulation"}
assert len(recommender.recommendations) == 6
assert recommender.recommendations[0]["total"] == 4596.858
assert recommender.recommendations[0]["new_u_value"] == 0.21
def test_uvalue_0_12(self, input_properties): def test_uvalue_0_12(self, input_properties):
""" """
This is a home that doesn't have a property below but it's highly performant already and therefore This is a home that doesn't have a property below but it's highly performant already and therefore
does not need floor insulation does not need floor insulation
:return: :return:
""" """
input_properties[3].floor_area = 100 input_properties[3].insulation_floor_area = 100
input_properties[3].insulation_wall_area = 100
input_properties[3].number_of_floors = 1 input_properties[3].number_of_floors = 1
recommender = FloorRecommendations( recommender = FloorRecommendations(property_instance=input_properties[3], materials=materials)
property_instance=input_properties[3],
materials=parts
)
assert recommender.estimated_u_value is None assert recommender.estimated_u_value is None
recommender.recommend() recommender.recommend()
assert not recommender.property.floor["is_suspended"] assert not recommender.property.floor["is_suspended"]
@ -178,7 +106,8 @@ class TestFloorRecommendations:
:return: :return:
""" """
input_properties[4].floor_area = 100 input_properties[4].insulation_floor_area = 100
input_properties[4].insulation_wall_area = 100
input_properties[4].walls["is_park_home"] = False input_properties[4].walls["is_park_home"] = False
input_properties[4].age_band = "B" input_properties[4].age_band = "B"
input_properties[4].perimeter = 50 input_properties[4].perimeter = 50
@ -186,10 +115,9 @@ class TestFloorRecommendations:
input_properties[4].floor_type = "solid" input_properties[4].floor_type = "solid"
input_properties[4].number_of_floors = 1 input_properties[4].number_of_floors = 1
recommender = FloorRecommendations( # In this case, we have no county, so in this case, it should yse the local-authority-label if possible
property_instance=input_properties[4], input_properties[4].data["county"] = ""
materials=parts recommender = FloorRecommendations(property_instance=input_properties[4], materials=materials)
)
assert recommender.estimated_u_value is None assert recommender.estimated_u_value is None
recommender.recommend() recommender.recommend()
assert not recommender.property.floor["is_suspended"] assert not recommender.property.floor["is_suspended"]
@ -201,17 +129,22 @@ class TestFloorRecommendations:
assert types == {"solid_floor_insulation"} assert types == {"solid_floor_insulation"}
assert len(recommender.recommendations) == 3
assert recommender.recommendations[2]["total"] == 14604.660000000002
assert recommender.recommendations[2]["new_u_value"] == 0.21
assert recommender.recommendations[2]["parts"][0]["depth"] == 75
assert recommender.recommendations[2]["parts"][0]["depth"] == 75
def test_another_dwelling_below(self, input_properties): def test_another_dwelling_below(self, input_properties):
""" """
This is another description we see when there is a property below This is another description we see when there is a property below
""" """
input_properties[6].floor_area = 100 input_properties[6].insulation_floor_area = 100
input_properties[6].insulation_wall_area = 1
input_properties[6].number_of_floors = 1 input_properties[6].number_of_floors = 1
recommender = FloorRecommendations( recommender = FloorRecommendations(property_instance=input_properties[6], materials=materials)
property_instance=input_properties[6],
materials=parts
)
assert recommender.estimated_u_value is None assert recommender.estimated_u_value is None
recommender.recommend() recommender.recommend()
assert not recommender.property.floor["is_suspended"] assert not recommender.property.floor["is_suspended"]
@ -219,123 +152,123 @@ class TestFloorRecommendations:
assert recommender.estimated_u_value is None assert recommender.estimated_u_value is None
assert not recommender.recommendations assert not recommender.recommendations
def test_exposed_floor_no_insulation(self): # def test_exposed_floor_no_insulation(self):
input_property = Property(id=1, postcode="F4k3 2", address1="223 fake street", epc_client=Mock()) # input_property = Property(id=1, postcode="F4k3 2", address1="223 fake street", epc_client=Mock())
input_property.floor = { # input_property.floor = {
'original_description': 'To unheated space, no insulation (assumed)', # 'original_description': 'To unheated space, no insulation (assumed)',
'clean_description': 'To unheated space, no insulation', 'thermal_transmittance': None, # 'clean_description': 'To unheated space, no insulation', 'thermal_transmittance': None,
'thermal_transmittance_unit': None, 'is_assumed': True, 'is_to_unheated_space': True, # 'thermal_transmittance_unit': None, 'is_assumed': True, 'is_to_unheated_space': True,
'is_to_external_air': False, 'is_suspended': False, 'is_solid': False, 'another_property_below': False, # 'is_to_external_air': False, 'is_suspended': False, 'is_solid': False, 'another_property_below': False,
'insulation_thickness': 'none' # 'insulation_thickness': 'none'
} # }
input_property.age_band = "L" # input_property.age_band = "L"
input_property.set_floor_type() # input_property.set_floor_type()
input_property.data = {"floor-level": 0, "property-type": "House"} # input_property.data = {"floor-level": 0, "property-type": "House"}
input_property.floor_area = 100 # input_property.floor_area = 100
input_property.number_of_floors = 1 # input_property.number_of_floors = 1
#
recommender = FloorRecommendations( # recommender = FloorRecommendations(
property_instance=input_property, # property_instance=input_property,
materials=exposed_floor_insulation_parts # materials=materials
) # )
#
assert not recommender.recommendations # assert not recommender.recommendations
#
recommender.recommend() # recommender.recommend()
#
# Because of age band L, this should have a u-value of 0.22 to begin with and no recommendation # # Because of age band L, this should have a u-value of 0.22 to begin with and no recommendation
assert not len(recommender.recommendations) # assert not len(recommender.recommendations)
assert recommender.estimated_u_value == 0.22 # assert recommender.estimated_u_value == 0.22
#
# Now with an older age band # # Now with an older age band
#
input_property2 = Property(id=1, postcode="F4k3 2", address1="223 fake street", epc_client=Mock()) # input_property2 = Property(id=1, postcode="F4k3 2", address1="223 fake street", epc_client=Mock())
input_property2.floor = { # input_property2.floor = {
'original_description': 'To unheated space, no insulation (assumed)', # 'original_description': 'To unheated space, no insulation (assumed)',
'clean_description': 'To unheated space, no insulation', 'thermal_transmittance': None, # 'clean_description': 'To unheated space, no insulation', 'thermal_transmittance': None,
'thermal_transmittance_unit': None, 'is_assumed': True, 'is_to_unheated_space': True, # 'thermal_transmittance_unit': None, 'is_assumed': True, 'is_to_unheated_space': True,
'is_to_external_air': False, 'is_suspended': False, 'is_solid': False, 'another_property_below': False, # 'is_to_external_air': False, 'is_suspended': False, 'is_solid': False, 'another_property_below': False,
'insulation_thickness': 'none' # 'insulation_thickness': 'none'
} # }
input_property2.age_band = "D" # input_property2.age_band = "D"
input_property2.set_floor_type() # input_property2.set_floor_type()
input_property2.data = {"floor-level": 0, "property-type": "House"} # input_property2.data = {"floor-level": 0, "property-type": "House"}
input_property2.floor_area = 100 # input_property2.floor_area = 100
input_property2.number_of_floors = 1 # input_property2.number_of_floors = 1
#
recommender2 = FloorRecommendations( # recommender2 = FloorRecommendations(
property_instance=input_property2, # property_instance=input_property2,
materials=exposed_floor_insulation_parts # materials=materials
) # )
#
assert not recommender2.recommendations # assert not recommender2.recommendations
#
recommender2.recommend() # recommender2.recommend()
#
assert len(recommender2.recommendations) == 1 # assert len(recommender2.recommendations) == 1
#
assert recommender2.recommendations[0]["new_u_value"] == 0.23 # assert recommender2.recommendations[0]["new_u_value"] == 0.23
assert recommender2.recommendations[0]["starting_u_value"] == 1.2 # assert recommender2.recommendations[0]["starting_u_value"] == 1.2
assert recommender2.recommendations[0]["cost"] == 1500 # assert recommender2.recommendations[0]["cost"] == 1500
#
def test_exposed_floor_below_average_insulated(self): # def test_exposed_floor_below_average_insulated(self):
input_property3 = Property(id=1, postcode="F4k3 2", address1="223 fake street", epc_client=Mock()) # input_property3 = Property(id=1, postcode="F4k3 2", address1="223 fake street", epc_client=Mock())
input_property3.floor = { # input_property3.floor = {
'original_description': 'To unheated space, below average insulation (assumed)', # 'original_description': 'To unheated space, below average insulation (assumed)',
'clean_description': 'To unheated space, below average insulation', 'thermal_transmittance': None, # 'clean_description': 'To unheated space, below average insulation', 'thermal_transmittance': None,
'thermal_transmittance_unit': None, 'is_assumed': True, 'is_to_unheated_space': True, # 'thermal_transmittance_unit': None, 'is_assumed': True, 'is_to_unheated_space': True,
'is_to_external_air': False, 'is_suspended': False, 'is_solid': False, 'another_property_below': False, # 'is_to_external_air': False, 'is_suspended': False, 'is_solid': False, 'another_property_below': False,
'insulation_thickness': 'below average' # 'insulation_thickness': 'below average'
} # }
input_property3.age_band = "C" # input_property3.age_band = "C"
input_property3.set_floor_type() # input_property3.set_floor_type()
input_property3.data = {"floor-level": 0, "property-type": "House"} # input_property3.data = {"floor-level": 0, "property-type": "House"}
input_property3.floor_area = 100 # input_property3.floor_area = 100
input_property3.number_of_floors = 1 # input_property3.number_of_floors = 1
#
recommender3 = FloorRecommendations( # recommender3 = FloorRecommendations(
property_instance=input_property3, # property_instance=input_property3,
materials=exposed_floor_insulation_parts # materials=materials
) # )
#
assert not recommender3.recommendations # assert not recommender3.recommendations
#
recommender3.recommend() # recommender3.recommend()
#
assert recommender3.estimated_u_value == 0.5 # assert recommender3.estimated_u_value == 0.5
#
assert len(recommender3.recommendations) == 1 # assert len(recommender3.recommendations) == 1
#
assert recommender3.recommendations[0]["new_u_value"] == 0.22 # assert recommender3.recommendations[0]["new_u_value"] == 0.22
assert recommender3.recommendations[0]["starting_u_value"] == 0.5 # assert recommender3.recommendations[0]["starting_u_value"] == 0.5
assert recommender3.recommendations[0]["cost"] == 1100 # assert recommender3.recommendations[0]["cost"] == 1100
assert recommender3.recommendations[0]["parts"][0]["depths"] == [100] # assert recommender3.recommendations[0]["parts"][0]["depths"] == [100]
#
# With average insulation, no recommendations # # With average insulation, no recommendations
#
input_property4 = Property(id=1, postcode="F4k3 2", address1="223 fake street", epc_client=Mock()) # input_property4 = Property(id=1, postcode="F4k3 2", address1="223 fake street", epc_client=Mock())
input_property4.floor = { # input_property4.floor = {
'original_description': 'To unheated space, insulated (assumed)', # 'original_description': 'To unheated space, insulated (assumed)',
'clean_description': 'To unheated space, insulated', 'thermal_transmittance': None, # 'clean_description': 'To unheated space, insulated', 'thermal_transmittance': None,
'thermal_transmittance_unit': None, 'is_assumed': True, 'is_to_unheated_space': True, # 'thermal_transmittance_unit': None, 'is_assumed': True, 'is_to_unheated_space': True,
'is_to_external_air': False, 'is_suspended': False, 'is_solid': False, 'another_property_below': False, # 'is_to_external_air': False, 'is_suspended': False, 'is_solid': False, 'another_property_below': False,
'insulation_thickness': 'average' # 'insulation_thickness': 'average'
} # }
input_property4.age_band = "C" # input_property4.age_band = "C"
input_property4.set_floor_type() # input_property4.set_floor_type()
input_property4.data = {"floor-level": 0, "property-type": "House"} # input_property4.data = {"floor-level": 0, "property-type": "House"}
input_property4.floor_area = 100 # input_property4.floor_area = 100
input_property4.number_of_floors = 1 # input_property4.number_of_floors = 1
#
recommender4 = FloorRecommendations( # recommender4 = FloorRecommendations(
property_instance=input_property4, # property_instance=input_property4,
materials=exposed_floor_insulation_parts # materials=materials
) # )
#
assert not recommender4.recommendations # assert not recommender4.recommendations
#
recommender4.recommend() # recommender4.recommend()
#
assert recommender4.estimated_u_value is None # assert recommender4.estimated_u_value is None
#
assert len(recommender4.recommendations) == 0 # assert len(recommender4.recommendations) == 0

View file

@ -1,65 +1,7 @@
from backend.Property import Property from backend.Property import Property
from unittest.mock import Mock from unittest.mock import Mock
from recommendations.RoofRecommendations import RoofRecommendations from recommendations.RoofRecommendations import RoofRecommendations
from recommendations.tests.test_data.materials import materials
loft_insulation_materials = [
{
'id': 18, 'type': 'loft_insulation', 'description': 'Iso Spacesaver Mineral Wool insulation',
'depths': [270, 300], 'depth_unit': 'mm', 'cost': [9, 10], 'cost_unit': 'gbp_sq_meter',
'r_value_per_mm': 0.022727273, 'r_value_unit': 'square_meter_kelvin_per_watt',
'thermal_conductivity': 0.044, 'thermal_conductivity_unit': 'watt_per_meter_kelvin',
'link': 'https://flooringwarehousedirect.co.uk/product/isover-spacesaver-roll-100mm-x-1160mm-x-12-18m-14-13m2/',
'is_active': True
}
]
loft_insulation_materials_50mm_existing = [
{
'id': 18, 'type': 'loft_insulation', 'description': 'Iso Spacesaver Mineral Wool insulation',
'depths': [220, 210], 'depth_unit': 'mm', 'cost': [9, 10], 'cost_unit': 'gbp_sq_meter',
'r_value_per_mm': 0.022727273, 'r_value_unit': 'square_meter_kelvin_per_watt',
'thermal_conductivity': 0.044, 'thermal_conductivity_unit': 'watt_per_meter_kelvin',
'link': 'https://flooringwarehousedirect.co.uk/product/isover-spacesaver-roll-100mm-x-1160mm-x-12-18m-14-13m2/',
'is_active': True
}
]
loft_insulation_materials_150mm_existing = [
{
'id': 18, 'type': 'loft_insulation', 'description': 'Iso Spacesaver Mineral Wool insulation',
'depths': [130, 119], 'depth_unit': 'mm', 'cost': [9, 10], 'cost_unit': 'gbp_sq_meter',
'r_value_per_mm': 0.022727273, 'r_value_unit': 'square_meter_kelvin_per_watt',
'thermal_conductivity': 0.044, 'thermal_conductivity_unit': 'watt_per_meter_kelvin',
'link': 'https://flooringwarehousedirect.co.uk/product/isover-spacesaver-roll-100mm-x-1160mm-x-12-18m-14-13m2/',
'is_active': True
}
]
room_roof_insulation_materials = [
{
'id': 18,
'type': 'room_roof_insulation',
'description': 'Example room roof insulation',
'depths': [50, 150, 220, 270, 300], 'depth_unit': 'mm', 'cost': [9, 10, 11, 12, 13],
'cost_unit': 'gbp_sq_meter',
'r_value_per_mm': 0.022727273, 'r_value_unit': 'square_meter_kelvin_per_watt',
'thermal_conductivity': 0.044, 'thermal_conductivity_unit': 'watt_per_meter_kelvin',
'link': None, 'is_active': True
}
]
flat_roof_insulation_materials = [
{
'id': 18,
'type': 'flat_roof_insulation',
'description': 'Example flat roof insulation',
'depths': [50, 150, 220, 270, 300], 'depth_unit': 'mm', 'cost': [9, 10, 11, 12, 13],
'cost_unit': 'gbp_sq_meter',
'r_value_per_mm': 0.032727273, 'r_value_unit': 'square_meter_kelvin_per_watt',
'thermal_conductivity': 0.044, 'thermal_conductivity_unit': 'watt_per_meter_kelvin',
'link': None, 'is_active': True
}
]
class TestRoofRecommendations: class TestRoofRecommendations:
@ -67,7 +9,7 @@ class TestRoofRecommendations:
def test_loft_insulation_recommendation_no_insulation(self): def test_loft_insulation_recommendation_no_insulation(self):
property_instance = Property(id=0, address1="fake", postcode="fake", epc_client=Mock()) property_instance = Property(id=0, address1="fake", postcode="fake", epc_client=Mock())
property_instance.age_band = "F" property_instance.age_band = "F"
property_instance.floor_area = 100 property_instance.insulation_floor_area = 100
property_instance.roof = { property_instance.roof = {
'original_description': 'Pitched, no insulation (assumed)', 'original_description': 'Pitched, no insulation (assumed)',
'clean_description': 'Pitched, no insulation', 'clean_description': 'Pitched, no insulation',
@ -77,8 +19,11 @@ class TestRoofRecommendations:
'is_at_rafters': False, 'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True, 'is_at_rafters': False, 'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True,
'insulation_thickness': 'none', 'roof_thermal_transmittance': None, 'roof_insulation_thickness': 'none' 'insulation_thickness': 'none', 'roof_thermal_transmittance': None, 'roof_insulation_thickness': 'none'
} }
property_instance.data = {
"county": "Cambridgeshire",
}
roof_recommender = RoofRecommendations(property_instance=property_instance, materials=loft_insulation_materials) roof_recommender = RoofRecommendations(property_instance=property_instance, materials=materials)
assert not roof_recommender.recommendations assert not roof_recommender.recommendations
@ -89,7 +34,7 @@ class TestRoofRecommendations:
def test_loft_insulation_recommendation_50mm_insulation(self): def test_loft_insulation_recommendation_50mm_insulation(self):
property_instance2 = Property(id=0, address1="fake", postcode="fake", epc_client=Mock()) property_instance2 = Property(id=0, address1="fake", postcode="fake", epc_client=Mock())
property_instance2.age_band = "F" property_instance2.age_band = "F"
property_instance2.floor_area = 100 property_instance2.insulation_floor_area = 100
property_instance2.roof = { property_instance2.roof = {
'original_description': 'Pitched, 50mm loft insulation (assumed)', 'original_description': 'Pitched, 50mm loft insulation (assumed)',
'clean_description': 'Pitched, 50mm loft insulation', 'clean_description': 'Pitched, 50mm loft insulation',
@ -99,10 +44,9 @@ class TestRoofRecommendations:
'is_at_rafters': False, 'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True, 'is_at_rafters': False, 'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True,
'insulation_thickness': '50', 'roof_thermal_transmittance': None, 'roof_insulation_thickness': 'none' 'insulation_thickness': '50', 'roof_thermal_transmittance': None, 'roof_insulation_thickness': 'none'
} }
property_instance2.data = {"county": "Kent"}
roof_recommender2 = RoofRecommendations( roof_recommender2 = RoofRecommendations(property_instance=property_instance2, materials=materials)
property_instance=property_instance2, materials=loft_insulation_materials
)
assert not roof_recommender2.recommendations assert not roof_recommender2.recommendations
@ -110,13 +54,13 @@ class TestRoofRecommendations:
assert len(roof_recommender2.recommendations) == 1 assert len(roof_recommender2.recommendations) == 1
assert roof_recommender2.recommendations[0]["cost"] == 900 assert roof_recommender2.recommendations[0]["total"] == 1310.56464
assert roof_recommender2.recommendations[0]["new_u_value"] == 0.14 assert roof_recommender2.recommendations[0]["new_u_value"] == 0.14
assert roof_recommender2.recommendations[0]["starting_u_value"] == 0.68 assert roof_recommender2.recommendations[0]["starting_u_value"] == 0.68
property_instance3 = Property(id=0, address1="fake", postcode="fake", epc_client=Mock()) property_instance3 = Property(id=0, address1="fake", postcode="fake", epc_client=Mock())
property_instance3.age_band = "F" property_instance3.age_band = "F"
property_instance3.floor_area = 100 property_instance3.insulation_floor_area = 100
property_instance3.roof = { property_instance3.roof = {
'original_description': 'Pitched, 50mm loft insulation (assumed)', 'original_description': 'Pitched, 50mm loft insulation (assumed)',
'clean_description': 'Pitched, 50mm loft insulation', 'clean_description': 'Pitched, 50mm loft insulation',
@ -126,24 +70,22 @@ class TestRoofRecommendations:
'is_at_rafters': False, 'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True, 'is_at_rafters': False, 'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True,
'insulation_thickness': '50', 'roof_thermal_transmittance': None, 'roof_insulation_thickness': 'none' 'insulation_thickness': '50', 'roof_thermal_transmittance': None, 'roof_insulation_thickness': 'none'
} }
property_instance3.data = {"county": "Greater London Authority"}
roof_recommender3 = RoofRecommendations( roof_recommender3 = RoofRecommendations(property_instance=property_instance3, materials=materials)
property_instance=property_instance3, materials=loft_insulation_materials_50mm_existing
)
assert not roof_recommender3.recommendations assert not roof_recommender3.recommendations
roof_recommender3.recommend() roof_recommender3.recommend()
# The 220mm insulation should be selected, not the 210
assert roof_recommender3.recommendations assert roof_recommender3.recommendations
assert len(roof_recommender3.recommendations) == 1 assert len(roof_recommender3.recommendations) == 1
assert roof_recommender3.recommendations[0]["parts"][0]["depths"] == [220] assert roof_recommender3.recommendations[0]["parts"][0]["depth"] == 270
def test_loft_insulation_recommendation_150mm_insulation(self): def test_loft_insulation_recommendation_150mm_insulation(self):
property_instance4 = Property(id=0, address1="fake", postcode="fake", epc_client=Mock()) property_instance4 = Property(id=0, address1="fake", postcode="fake", epc_client=Mock())
property_instance4.age_band = "F" property_instance4.age_band = "F"
property_instance4.floor_area = 100 property_instance4.insulation_floor_area = 100
property_instance4.roof = { property_instance4.roof = {
'original_description': 'Pitched, 150mm loft insulation (assumed)', 'original_description': 'Pitched, 150mm loft insulation (assumed)',
'clean_description': 'Pitched, 150mm loft insulation', 'clean_description': 'Pitched, 150mm loft insulation',
@ -153,24 +95,24 @@ class TestRoofRecommendations:
'is_at_rafters': False, 'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True, 'is_at_rafters': False, 'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True,
'insulation_thickness': '150', 'roof_thermal_transmittance': None, 'roof_insulation_thickness': 'none' 'insulation_thickness': '150', 'roof_thermal_transmittance': None, 'roof_insulation_thickness': 'none'
} }
property_instance4.data = {"county": "North East Lincolnshire"}
roof_recommender4 = RoofRecommendations( roof_recommender4 = RoofRecommendations(property_instance=property_instance4, materials=materials)
property_instance=property_instance4, materials=loft_insulation_materials
)
assert not roof_recommender4.recommendations assert not roof_recommender4.recommendations
roof_recommender4.recommend() roof_recommender4.recommend()
assert len(roof_recommender4.recommendations) == 1 assert len(roof_recommender4.recommendations) == 4
assert roof_recommender4.recommendations[0]["cost"] == 900 assert roof_recommender4.recommendations[0]["total"] == 788.0544
assert roof_recommender4.recommendations[0]["new_u_value"] == 0.11 assert roof_recommender4.recommendations[0]["new_u_value"] == 0.15
assert roof_recommender4.recommendations[0]["starting_u_value"] == 0.3 assert roof_recommender4.recommendations[0]["starting_u_value"] == 0.3
assert roof_recommender4.recommendations[0]["parts"][0]["depth"] == 150
property_instance5 = Property(id=0, address1="fake", postcode="fake", epc_client=Mock()) property_instance5 = Property(id=0, address1="fake", postcode="fake", epc_client=Mock())
property_instance5.age_band = "F" property_instance5.age_band = "F"
property_instance5.floor_area = 100 property_instance5.insulation_floor_area = 100
property_instance5.roof = { property_instance5.roof = {
'original_description': 'Pitched, 150mm loft insulation (assumed)', 'original_description': 'Pitched, 150mm loft insulation (assumed)',
'clean_description': 'Pitched, 150mm loft insulation', 'clean_description': 'Pitched, 150mm loft insulation',
@ -180,25 +122,24 @@ class TestRoofRecommendations:
'is_at_rafters': False, 'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True, 'is_at_rafters': False, 'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True,
'insulation_thickness': '150', 'roof_thermal_transmittance': None, 'roof_insulation_thickness': 'none' 'insulation_thickness': '150', 'roof_thermal_transmittance': None, 'roof_insulation_thickness': 'none'
} }
property_instance5.data = {"county": "Somerset"}
roof_recommender5 = RoofRecommendations( roof_recommender5 = RoofRecommendations(property_instance=property_instance5, materials=materials)
property_instance=property_instance5, materials=loft_insulation_materials_150mm_existing
)
assert not roof_recommender5.recommendations assert not roof_recommender5.recommendations
roof_recommender5.recommend() roof_recommender5.recommend()
# The 130mm insulation should be selected, not the 110 # The 150mm insulation should be selected, since there it already 150mm
assert roof_recommender5.recommendations assert roof_recommender5.recommendations
assert len(roof_recommender5.recommendations) == 1 assert len(roof_recommender5.recommendations) == 4
assert roof_recommender5.recommendations[0]["parts"][0]["depths"] == [130] assert roof_recommender5.recommendations[0]["parts"][0]["depth"] == 150
def test_loft_insulation_recommendation_270mm_insulation(self): def test_loft_insulation_recommendation_270mm_insulation(self):
# We shouldn't recommend anything in this case # We shouldn't recommend anything in this case
property_instance6 = Property(id=0, address1="fake", postcode="fake", epc_client=Mock()) property_instance6 = Property(id=0, address1="fake", postcode="fake", epc_client=Mock())
property_instance6.age_band = "F" property_instance6.age_band = "F"
property_instance6.floor_area = 100 property_instance6.insulation_floor_area = 100
property_instance6.roof = { property_instance6.roof = {
'original_description': 'Pitched, 270mm loft insulation (assumed)', 'original_description': 'Pitched, 270mm loft insulation (assumed)',
'clean_description': 'Pitched, 270mm loft insulation', 'clean_description': 'Pitched, 270mm loft insulation',
@ -208,10 +149,9 @@ class TestRoofRecommendations:
'is_at_rafters': False, 'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True, 'is_at_rafters': False, 'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True,
'insulation_thickness': '270', 'roof_thermal_transmittance': None, 'roof_insulation_thickness': 'none' 'insulation_thickness': '270', 'roof_thermal_transmittance': None, 'roof_insulation_thickness': 'none'
} }
property_instance6.data = {"county": "Portsmouth"}
roof_recommender6 = RoofRecommendations( roof_recommender6 = RoofRecommendations(property_instance=property_instance6, materials=materials)
property_instance=property_instance6, materials=loft_insulation_materials
)
assert not roof_recommender6.recommendations assert not roof_recommender6.recommendations
@ -219,219 +159,211 @@ class TestRoofRecommendations:
assert len(roof_recommender6.recommendations) == 0 assert len(roof_recommender6.recommendations) == 0
def test_uninsulated_room_in_roof(self): # def test_uninsulated_room_in_roof(self):
property_instance7 = Property(id=0, address1="fake", postcode="fake", epc_client=Mock()) # property_instance7 = Property(id=0, address1="fake", postcode="fake", epc_client=Mock())
property_instance7.age_band = "F" # property_instance7.age_band = "F"
property_instance7.floor_area = 100 # property_instance7.insulation_floor_area = 100
property_instance7.roof = { # property_instance7.roof = {
'original_description': 'Roof room(s), no insulation (assumed)', # 'original_description': 'Roof room(s), no insulation (assumed)',
'clean_description': 'Roof room(s), no insulation', # 'clean_description': 'Roof room(s), no insulation',
'thermal_transmittance': None, 'thermal_transmittance_unit': None, 'is_pitched': False, # 'thermal_transmittance': None, 'thermal_transmittance_unit': None, 'is_pitched': False,
'is_roof_room': True, 'is_loft': False, 'is_flat': False, 'is_thatched': False, 'is_at_rafters': False, # 'is_roof_room': True, 'is_loft': False, 'is_flat': False, 'is_thatched': False, 'is_at_rafters': False,
'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True, 'insulation_thickness': 'none' # 'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True, 'insulation_thickness': 'none'
} # }
#
property_instance7.pitched_roof_area = 110 # property_instance7.pitched_roof_area = 110
# property_instance7.data = {"county": "Southampton"}
roof_recommender7 = RoofRecommendations( #
property_instance=property_instance7, materials=room_roof_insulation_materials # roof_recommender7 = RoofRecommendations(property_instance=property_instance7, materials=materials)
) #
# assert not roof_recommender7.recommendations
assert not roof_recommender7.recommendations #
# roof_recommender7.recommend()
roof_recommender7.recommend() #
# # Even though we have 3 depths, we only end with 1 due to diminishin returns
# Even though we have 3 depths, we only end with 1 due to diminishin returns # assert len(roof_recommender7.recommendations) == 1
assert len(roof_recommender7.recommendations) == 1 #
# assert roof_recommender7.recommendations[0]["parts"][0]["depths"] == [270]
assert roof_recommender7.recommendations[0]["parts"][0]["depths"] == [270] #
# assert roof_recommender7.recommendations[0]["new_u_value"] == 0.14
assert roof_recommender7.recommendations[0]["new_u_value"] == 0.14 # assert roof_recommender7.recommendations[0]["starting_u_value"] == 0.8
assert roof_recommender7.recommendations[0]["starting_u_value"] == 0.8 # assert roof_recommender7.recommendations[0]["description"] == \
assert roof_recommender7.recommendations[0]["description"] == \ # "Insulate your room roof with 270mm of Example room roof insulation"
"Insulate your room roof with 270mm of Example room roof insulation" #
# def test_ceiling_insulated_room_in_roof(self):
def test_ceiling_insulated_room_in_roof(self): # property_instance8 = Property(id=8, address1="fake", postcode="fake", epc_client=Mock())
property_instance8 = Property(id=8, address1="fake", postcode="fake", epc_client=Mock()) # property_instance8.age_band = "F"
property_instance8.age_band = "F" # property_instance8.insulation_floor_area = 100
property_instance8.floor_area = 100 # property_instance8.roof = {
property_instance8.roof = { # 'original_description': 'Roof room(s), ceiling insulated',
'original_description': 'Roof room(s), ceiling insulated', # 'clean_description': 'Roof room(s), ceiling insulated',
'clean_description': 'Roof room(s), ceiling insulated', # 'thermal_transmittance': None, 'thermal_transmittance_unit': None, 'is_pitched': False,
'thermal_transmittance': None, 'thermal_transmittance_unit': None, 'is_pitched': False, # 'is_roof_room': True, 'is_loft': False, 'is_flat': False, 'is_thatched': False,
'is_roof_room': True, 'is_loft': False, 'is_flat': False, 'is_thatched': False, # 'is_at_rafters': False,
'is_at_rafters': False, # 'is_assumed': False, 'has_dwelling_above': False, 'is_valid': True,
'is_assumed': False, 'has_dwelling_above': False, 'is_valid': True, # 'insulation_thickness': 'average'
'insulation_thickness': 'average' # }
} #
# property_instance8.pitched_roof_area = 110
property_instance8.pitched_roof_area = 110 #
# roof_recommender8 = RoofRecommendations(property_instance=property_instance8, materials=materials)
roof_recommender8 = RoofRecommendations( #
property_instance=property_instance8, materials=room_roof_insulation_materials # assert not roof_recommender8.recommendations
) #
# roof_recommender8.recommend()
assert not roof_recommender8.recommendations #
# # No recommendations in this case
roof_recommender8.recommend() # assert not roof_recommender8.recommendations
#
# No recommendations in this case # def test_insulated_room_in_roof(self):
assert not roof_recommender8.recommendations # property_instance9 = Property(id=9, address1="fake", postcode="fake", epc_client=Mock())
# property_instance9.age_band = "F"
def test_insulated_room_in_roof(self): # property_instance9.insulation_floor_area = 100
property_instance9 = Property(id=9, address1="fake", postcode="fake", epc_client=Mock()) # property_instance9.roof = {
property_instance9.age_band = "F" # 'original_description': 'Roof room(s), insulated (assumed)',
property_instance9.floor_area = 100 # 'clean_description': 'Roof room(s), insulated',
property_instance9.roof = { # 'thermal_transmittance': None, 'thermal_transmittance_unit': None, 'is_pitched': False,
'original_description': 'Roof room(s), insulated (assumed)', # 'is_roof_room': True, 'is_loft': False, 'is_flat': False, 'is_thatched': False, 'is_at_rafters': False,
'clean_description': 'Roof room(s), insulated', # 'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True, 'insulation_thickness': 'average'
'thermal_transmittance': None, 'thermal_transmittance_unit': None, 'is_pitched': False, # }
'is_roof_room': True, 'is_loft': False, 'is_flat': False, 'is_thatched': False, 'is_at_rafters': False, #
'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True, 'insulation_thickness': 'average' # property_instance9.pitched_roof_area = 110
} # property_instance9.data = {"county": "Rutland"}
#
property_instance9.pitched_roof_area = 110 # roof_recommender9 = RoofRecommendations(property_instance=property_instance9, materials=materials)
#
roof_recommender9 = RoofRecommendations( # assert not roof_recommender9.recommendations
property_instance=property_instance9, materials=room_roof_insulation_materials #
) # roof_recommender9.recommend()
#
assert not roof_recommender9.recommendations # # No recommendations in this case
# assert not roof_recommender9.recommendations
roof_recommender9.recommend() #
# def test_limited_insulated_room_in_roof(self):
# No recommendations in this case # property_instance10 = Property(id=10, address1="fake", postcode="fake", epc_client=Mock())
assert not roof_recommender9.recommendations # property_instance10.age_band = "F"
# property_instance10.insulation_floor_area = 100
def test_limited_insulated_room_in_roof(self): # property_instance10.roof = {
property_instance10 = Property(id=10, address1="fake", postcode="fake", epc_client=Mock()) # 'original_description': 'Roof room(s), limited insulation (assumed)',
property_instance10.age_band = "F" # 'clean_description': 'Roof room(s), limited insulation',
property_instance10.floor_area = 100 # 'thermal_transmittance': None, 'thermal_transmittance_unit': None, 'is_pitched': False,
property_instance10.roof = { # 'is_roof_room': True, 'is_loft': False, 'is_flat': False, 'is_thatched': False, 'is_at_rafters': False,
'original_description': 'Roof room(s), limited insulation (assumed)', # 'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True,
'clean_description': 'Roof room(s), limited insulation', # 'insulation_thickness': 'below average'
'thermal_transmittance': None, 'thermal_transmittance_unit': None, 'is_pitched': False, # }
'is_roof_room': True, 'is_loft': False, 'is_flat': False, 'is_thatched': False, 'is_at_rafters': False, #
'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True, # property_instance10.pitched_roof_area = 110
'insulation_thickness': 'below average' # property_instance10.data = {"county": "Westmorland"}
} #
# roof_recommender10 = RoofRecommendations(property_instance=property_instance10, materials=materials)
property_instance10.pitched_roof_area = 110 #
# assert not roof_recommender10.recommendations
roof_recommender10 = RoofRecommendations( #
property_instance=property_instance10, materials=room_roof_insulation_materials # roof_recommender10.recommend()
) #
# assert len(roof_recommender10.recommendations) == 2
assert not roof_recommender10.recommendations #
# assert roof_recommender10.recommendations[0]["parts"][0]["depths"] == [220]
roof_recommender10.recommend() # assert roof_recommender10.recommendations[1]["parts"][0]["depths"] == [270]
#
assert len(roof_recommender10.recommendations) == 2 # assert roof_recommender10.recommendations[0]["new_u_value"] == 0.16
# assert roof_recommender10.recommendations[1]["new_u_value"] == 0.14
assert roof_recommender10.recommendations[0]["parts"][0]["depths"] == [220] #
assert roof_recommender10.recommendations[1]["parts"][0]["depths"] == [270] # assert roof_recommender10.recommendations[0]["starting_u_value"] == 0.8
# assert roof_recommender10.recommendations[1]["starting_u_value"] == 0.8
assert roof_recommender10.recommendations[0]["new_u_value"] == 0.16 #
assert roof_recommender10.recommendations[1]["new_u_value"] == 0.14 # assert roof_recommender10.recommendations[0]["description"] == \
# "Insulate your room roof with 220mm of Example room roof insulation"
assert roof_recommender10.recommendations[0]["starting_u_value"] == 0.8 # assert roof_recommender10.recommendations[1]["description"] == \
assert roof_recommender10.recommendations[1]["starting_u_value"] == 0.8 # "Insulate your room roof with 270mm of Example room roof insulation"
#
assert roof_recommender10.recommendations[0]["description"] == \ # def test_flat_no_insulation(self):
"Insulate your room roof with 220mm of Example room roof insulation" # property_instance11 = Property(id=11, address1="fake", postcode="fake", epc_client=Mock())
assert roof_recommender10.recommendations[1]["description"] == \ # property_instance11.age_band = "D"
"Insulate your room roof with 270mm of Example room roof insulation" # property_instance11.insulation_floor_area = 150
# property_instance11.roof = {
def test_flat_no_insulation(self): # 'original_description': 'Flat, no insulation (assumed)',
property_instance11 = Property(id=11, address1="fake", postcode="fake", epc_client=Mock()) # 'clean_description': 'Flat, no insulation',
property_instance11.age_band = "D" # 'thermal_transmittance': None, 'thermal_transmittance_unit': None, 'is_pitched': False,
property_instance11.floor_area = 150 # 'is_roof_room': False, 'is_loft': False, 'is_flat': True, 'is_thatched': False, 'is_at_rafters': False,
property_instance11.roof = { # 'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True, 'insulation_thickness': 'none'
'original_description': 'Flat, no insulation (assumed)', # }
'clean_description': 'Flat, no insulation', # property_instance11.data = {"county": "Swindon"}
'thermal_transmittance': None, 'thermal_transmittance_unit': None, 'is_pitched': False, #
'is_roof_room': False, 'is_loft': False, 'is_flat': True, 'is_thatched': False, 'is_at_rafters': False, # roof_recommender11 = RoofRecommendations(property_instance=property_instance11, materials=materials)
'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True, 'insulation_thickness': 'none' #
} # assert not roof_recommender11.recommendations
#
roof_recommender11 = RoofRecommendations( # roof_recommender11.recommend()
property_instance=property_instance11, materials=flat_roof_insulation_materials #
) # assert len(roof_recommender11.recommendations) == 1
#
assert not roof_recommender11.recommendations # assert roof_recommender11.recommendations[0]["parts"][0]["depths"] == [270]
#
roof_recommender11.recommend() # assert roof_recommender11.recommendations[0]["new_u_value"] == 0.11
#
assert len(roof_recommender11.recommendations) == 1 # assert roof_recommender11.recommendations[0]["starting_u_value"] == 2.3
#
assert roof_recommender11.recommendations[0]["parts"][0]["depths"] == [270] # assert roof_recommender11.recommendations[0]["description"] == \
# "Insulate the home's flat roof with 270mm of Example flat roof insulation"
assert roof_recommender11.recommendations[0]["new_u_value"] == 0.11 #
# def test_flat_insulated(self):
assert roof_recommender11.recommendations[0]["starting_u_value"] == 2.3 # property_instance12 = Property(id=12, address1="fake", postcode="fake", epc_client=Mock())
# property_instance12.age_band = "D"
assert roof_recommender11.recommendations[0]["description"] == \ # property_instance12.insulation_floor_area = 150
"Insulate the home's flat roof with 270mm of Example flat roof insulation" # property_instance12.roof = {
# 'original_description': 'Flat, insulated (assumed)',
def test_flat_insulated(self): # 'clean_description': 'Flat, insulated',
property_instance12 = Property(id=12, address1="fake", postcode="fake", epc_client=Mock()) # 'thermal_transmittance': None, 'thermal_transmittance_unit': None, 'is_pitched': False,
property_instance12.age_band = "D" # 'is_roof_room': False,
property_instance12.floor_area = 150 # 'is_loft': False, 'is_flat': True, 'is_thatched': False, 'is_at_rafters': False, 'is_assumed': True,
property_instance12.roof = { # 'has_dwelling_above': False, 'is_valid': True, 'insulation_thickness': 'average'
'original_description': 'Flat, insulated (assumed)', # }
'clean_description': 'Flat, insulated', # property_instance12.data = {"county": "Thurrock"}
'thermal_transmittance': None, 'thermal_transmittance_unit': None, 'is_pitched': False, #
'is_roof_room': False, # roof_recommender12 = RoofRecommendations(property_instance=property_instance12, materials=materials)
'is_loft': False, 'is_flat': True, 'is_thatched': False, 'is_at_rafters': False, 'is_assumed': True, #
'has_dwelling_above': False, 'is_valid': True, 'insulation_thickness': 'average' # assert not roof_recommender12.recommendations
} #
# roof_recommender12.recommend()
roof_recommender12 = RoofRecommendations( #
property_instance=property_instance12, materials=flat_roof_insulation_materials # assert not roof_recommender12.recommendations
) #
# def test_flat_limited_insulation(self):
assert not roof_recommender12.recommendations # property_instance13 = Property(id=12, address1="fake", postcode="fake", epc_client=Mock())
# property_instance13.age_band = "D"
roof_recommender12.recommend() # property_instance13.insulation_floor_area = 150
# property_instance13.roof = {
assert not roof_recommender12.recommendations # 'original_description': 'Flat, limited insulation (assumed)',
# 'clean_description': 'Flat, limited insulation',
def test_flat_limited_insulation(self): # 'thermal_transmittance': None, 'thermal_transmittance_unit': None, 'is_pitched': False,
property_instance13 = Property(id=12, address1="fake", postcode="fake", epc_client=Mock()) # 'is_roof_room': False,
property_instance13.age_band = "D" # 'is_loft': False, 'is_flat': True, 'is_thatched': False, 'is_at_rafters': False, 'is_assumed': True,
property_instance13.floor_area = 150 # 'has_dwelling_above': False, 'is_valid': True, 'insulation_thickness': 'below average'
property_instance13.roof = { # }
'original_description': 'Flat, limited insulation (assumed)', # property_instance13.data = {"county": "Tyne and Wear"}
'clean_description': 'Flat, limited insulation', #
'thermal_transmittance': None, 'thermal_transmittance_unit': None, 'is_pitched': False, # roof_recommender13 = RoofRecommendations(property_instance=property_instance13, materials=materials)
'is_roof_room': False, #
'is_loft': False, 'is_flat': True, 'is_thatched': False, 'is_at_rafters': False, 'is_assumed': True, # assert not roof_recommender13.recommendations
'has_dwelling_above': False, 'is_valid': True, 'insulation_thickness': 'below average' #
} # roof_recommender13.recommend()
#
roof_recommender13 = RoofRecommendations( # assert len(roof_recommender13.recommendations) == 1
property_instance=property_instance13, materials=flat_roof_insulation_materials #
) # assert roof_recommender13.recommendations[0]["parts"][0]["depths"] == [220]
#
assert not roof_recommender13.recommendations # assert roof_recommender13.recommendations[0]["new_u_value"] == 0.14
#
roof_recommender13.recommend() # assert roof_recommender13.recommendations[0]["starting_u_value"] == 2.3
#
assert len(roof_recommender13.recommendations) == 1 # assert roof_recommender13.recommendations[0]["description"] == \
# "Insulate the home's flat roof with 220mm of Example flat roof insulation"
assert roof_recommender13.recommendations[0]["parts"][0]["depths"] == [220]
assert roof_recommender13.recommendations[0]["new_u_value"] == 0.14
assert roof_recommender13.recommendations[0]["starting_u_value"] == 2.3
assert roof_recommender13.recommendations[0]["description"] == \
"Insulate the home's flat roof with 220mm of Example flat roof insulation"
def test_property_above(self): def test_property_above(self):
property_instance14 = Property(id=0, address1="fake", postcode="fake", epc_client=Mock()) property_instance14 = Property(id=0, address1="fake", postcode="fake", epc_client=Mock())
property_instance14.age_band = "F" property_instance14.age_band = "F"
property_instance14.floor_area = 100 property_instance14.insulation_floor_area = 100
property_instance14.roof = { property_instance14.roof = {
'original_description': '(other premises above)', 'original_description': '(other premises above)',
'clean_description': '(other premises above)', 'thermal_transmittance': 0, 'clean_description': '(other premises above)', 'thermal_transmittance': 0,
@ -440,10 +372,9 @@ class TestRoofRecommendations:
'is_assumed': False, 'has_dwelling_above': True, 'is_valid': True, 'is_assumed': False, 'has_dwelling_above': True, 'is_valid': True,
'insulation_thickness': None 'insulation_thickness': None
} }
property_instance14.data = {"county": "Suffolk"}
roof_recommender14 = RoofRecommendations( roof_recommender14 = RoofRecommendations(property_instance=property_instance14, materials=materials)
property_instance=property_instance14, materials=loft_insulation_materials
)
assert not roof_recommender14.recommendations assert not roof_recommender14.recommendations