unit tests for unheated space floor insulation

This commit is contained in:
Khalim Conn-Kowlessar 2023-10-24 16:27:38 +08:00
parent 448c6a3772
commit 0c5ff1153c
3 changed files with 155 additions and 7 deletions

View file

@ -58,6 +58,7 @@ class FloorRecommendations(Definitions):
)
property_type = self.property.data["property-type"]
floor_area = self.property.floor_area / self.property.number_of_storeys
year_built = self.property.year_built
if self.property.floor["another_property_below"] | (self.property.floor["insulation_thickness"] in [
@ -84,7 +85,7 @@ class FloorRecommendations(Definitions):
u_value = get_floor_u_value(
floor_type=self.property.floor_type,
area=float(self.property.data["total-floor-area"]),
area=floor_area,
perimeter=self.property.perimeter,
age_band=self.property.age_band,
insulation_thickness=self.property.floor["insulation_thickness"],
@ -92,16 +93,22 @@ class FloorRecommendations(Definitions):
)
self.estimated_u_value = u_value
if u_value < self.BUILDING_REGULATIONS_PART_L_MAX_U_VALUE:
return
if self.property.floor["is_suspended"]:
# Given the U-value, we recommend underfloor insulation
self.recommend_floor_insulation(u_value=u_value, parts=self.suspended_floor_insulation_parts)
return
if self.property.floor["is_solid"]:
# Given the U-value, we recommend solid floor insulation options which are usually solid foam
self.recommend_floor_insulation(u_value=u_value, parts=self.solid_floor_insulation_parts)
return
if self.property.floor["is_to_unheated_space"] or self.property.floor["is_to_external_air"]:
self.recommend_floor_insulation(u_value=u_value, parts=self.exposed_floor_insulation_parts)
return
raise NotImplementedError("Implement me!")
@ -130,8 +137,9 @@ class FloorRecommendations(Definitions):
if new_u_value <= self.BUILDING_REGULATIONS_PART_L_MAX_U_VALUE:
lowest_selected_u_value = update_lowest_selected_u_value(lowest_selected_u_value, new_u_value)
quantity = self.property.floor_area / self.property.number_of_storeys
estimated_cost = cost_per_unit * self.property.floor_area
estimated_cost = cost_per_unit * quantity
self.recommendations.append(
{
@ -139,7 +147,7 @@ class FloorRecommendations(Definitions):
get_recommended_part(
part=part,
selected_depth=depth,
quantity=self.property.floor_area,
quantity=quantity,
quantity_unit=QuantityUnits.m2.value,
selected_total_cost=estimated_cost
),

View file

@ -350,17 +350,17 @@ def get_exposed_floor_uvalue(insulation_thickness_str, age_band):
unknown_insulation_age_bands = ["A", "B", "C", "D", "E", "F", "G", "H", "I"]
# As directed by the documentation, if the insulation thickness is not known, we assume it's
# 50mm for these age bands
if insulation_thickness_str in ["below_average", "average", "above_average"] and (
if insulation_thickness_str in ["below average", "average", "above average"] and (
age_band in unknown_insulation_age_bands
):
insulation_thickness = 50
elif insulation_thickness_str in ["none", None]:
insulation_thickness = 0
elif insulation_thickness_str in ["below_average"]:
elif insulation_thickness_str == "below average":
insulation_thickness = 50
elif insulation_thickness_str == "average":
insulation_thickness = 100
elif insulation_thickness_str == "above_average":
elif insulation_thickness_str == "above average":
insulation_thickness = 150
else:
insulation_thickness = int(insulation_thickness_str.replace("mm", ""))

View file

@ -3,6 +3,7 @@ import pytest
import os
from unittest.mock import Mock
from recommendations.FloorRecommendations import FloorRecommendations
from backend.Property import Property
# with open(
# os.path.abspath(os.path.dirname(__file__)) + "/recommendations/tests/test_data/input_properties.pkl", "rb"
@ -67,7 +68,23 @@ solid_floor_insulation_parts = [
]
parts = suspended_floor_insulation_parts + solid_floor_insulation_parts
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:
@ -119,6 +136,7 @@ class TestFloorRecommendations:
input_properties[2].perimeter = 20
input_properties[2].wall_type = "solid brick"
input_properties[2].floor_type = "suspended"
input_properties[2].number_of_storeys = 1
recommender = FloorRecommendations(
property_instance=input_properties[2],
@ -162,6 +180,7 @@ class TestFloorRecommendations:
input_properties[4].perimeter = 50
input_properties[4].wall_type = "solid brick"
input_properties[4].floor_type = "solid"
input_properties[4].number_of_storeys = 1
recommender = FloorRecommendations(
property_instance=input_properties[4],
@ -193,3 +212,124 @@ class TestFloorRecommendations:
assert not recommender.property.floor["is_solid"]
assert recommender.estimated_u_value is None
assert not recommender.recommendations
def test_exposed_floor_no_insulation(self):
input_property = Property(id=1, postcode="F4k3 2", address1="223 fake street", epc_client=Mock())
input_property.floor = {
'original_description': 'To unheated space, no insulation (assumed)',
'clean_description': 'To unheated space, no insulation', 'thermal_transmittance': None,
'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,
'insulation_thickness': 'none'
}
input_property.age_band = "L"
input_property.set_floor_type()
input_property.data = {"floor-level": 0, "property-type": "House"}
input_property.floor_area = 100
input_property.number_of_storeys = 1
recommender = FloorRecommendations(
property_instance=input_property,
materials=exposed_floor_insulation_parts
)
assert not recommender.recommendations
recommender.recommend()
# 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 recommender.estimated_u_value == 0.22
# Now with an older age band
input_property2 = Property(id=1, postcode="F4k3 2", address1="223 fake street", epc_client=Mock())
input_property2.floor = {
'original_description': 'To unheated space, no insulation (assumed)',
'clean_description': 'To unheated space, no insulation', 'thermal_transmittance': None,
'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,
'insulation_thickness': 'none'
}
input_property2.age_band = "D"
input_property2.set_floor_type()
input_property2.data = {"floor-level": 0, "property-type": "House"}
input_property2.floor_area = 100
input_property2.number_of_storeys = 1
recommender2 = FloorRecommendations(
property_instance=input_property2,
materials=exposed_floor_insulation_parts
)
assert not recommender2.recommendations
recommender2.recommend()
assert len(recommender2.recommendations) == 1
assert recommender2.recommendations[0]["new_u_value"] == 0.23
assert recommender2.recommendations[0]["starting_u_value"] == 1.2
assert recommender2.recommendations[0]["cost"] == 1500
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.floor = {
'original_description': 'To unheated space, below average insulation (assumed)',
'clean_description': 'To unheated space, below average insulation', 'thermal_transmittance': None,
'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,
'insulation_thickness': 'below average'
}
input_property3.age_band = "C"
input_property3.set_floor_type()
input_property3.data = {"floor-level": 0, "property-type": "House"}
input_property3.floor_area = 100
input_property3.number_of_storeys = 1
recommender3 = FloorRecommendations(
property_instance=input_property3,
materials=exposed_floor_insulation_parts
)
assert not recommender3.recommendations
recommender3.recommend()
assert recommender3.estimated_u_value == 0.5
assert len(recommender3.recommendations) == 1
assert recommender3.recommendations[0]["new_u_value"] == 0.22
assert recommender3.recommendations[0]["starting_u_value"] == 0.5
assert recommender3.recommendations[0]["cost"] == 1100
assert recommender3.recommendations[0]["parts"][0]["depths"] == [100]
# With average insulation, no recommendations
input_property4 = Property(id=1, postcode="F4k3 2", address1="223 fake street", epc_client=Mock())
input_property4.floor = {
'original_description': 'To unheated space, insulated (assumed)',
'clean_description': 'To unheated space, insulated', 'thermal_transmittance': None,
'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,
'insulation_thickness': 'average'
}
input_property4.age_band = "C"
input_property4.set_floor_type()
input_property4.data = {"floor-level": 0, "property-type": "House"}
input_property4.floor_area = 100
input_property4.number_of_storeys = 1
recommender4 = FloorRecommendations(
property_instance=input_property4,
materials=exposed_floor_insulation_parts
)
assert not recommender4.recommendations
recommender4.recommend()
assert recommender4.estimated_u_value is None
assert len(recommender4.recommendations) == 0