mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
fixing wall recommendation tests
This commit is contained in:
parent
07a5f3ce44
commit
cc96b13871
1 changed files with 88 additions and 49 deletions
|
|
@ -3,6 +3,7 @@ import pytest
|
||||||
import pickle
|
import pickle
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from unittest.mock import Mock, MagicMock
|
from unittest.mock import Mock, MagicMock
|
||||||
|
|
||||||
from recommendations.WallRecommendations import WallRecommendations
|
from recommendations.WallRecommendations import WallRecommendations
|
||||||
from backend.Property import Property
|
from backend.Property import Property
|
||||||
from recommendations.recommendation_utils import is_diminishing_returns
|
from recommendations.recommendation_utils import is_diminishing_returns
|
||||||
|
|
@ -10,23 +11,8 @@ from recommendations.tests.test_data.materials import materials
|
||||||
from etl.epc.Record import EPCRecord
|
from etl.epc.Record import EPCRecord
|
||||||
|
|
||||||
|
|
||||||
# import inspect
|
|
||||||
# file_path = inspect.getfile(lambda: None)
|
|
||||||
# with open(
|
|
||||||
# os.path.abspath(os.path.dirname(file_path)) + "/recommendations/tests/test_data/input_properties.pkl", "rb"
|
|
||||||
# ) as f:
|
|
||||||
# input_properties = pickle.load(f)
|
|
||||||
|
|
||||||
|
|
||||||
class TestWallRecommendations:
|
class TestWallRecommendations:
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def input_properties(self):
|
|
||||||
with open(
|
|
||||||
os.path.abspath(os.path.dirname(__file__)) + "/test_data/input_properties.pkl", "rb"
|
|
||||||
) as f:
|
|
||||||
return pickle.load(f)
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_wall_rec_instance(self):
|
def mock_wall_rec_instance(self):
|
||||||
# Creating a mock instance of WallRecommendations with the necessary attributes
|
# Creating a mock instance of WallRecommendations with the necessary attributes
|
||||||
|
|
@ -40,17 +26,30 @@ class TestWallRecommendations:
|
||||||
)
|
)
|
||||||
return mock_wall_rec_instance
|
return mock_wall_rec_instance
|
||||||
|
|
||||||
def test_init(self, input_properties):
|
def test_init(self):
|
||||||
input_properties[0].insulation_wall_area = 100
|
p = Mock(
|
||||||
|
id=1,
|
||||||
|
insulation_wall_area=100,
|
||||||
|
walls={
|
||||||
|
'original_description': 'Average thermal transmittance 0.16 W/m-¦K', 'thermal_transmittance': 0.16,
|
||||||
|
'thermal_transmittance_unit': 'w/m-¦k', 'is_cavity_wall': False, 'is_filled_cavity': False,
|
||||||
|
'is_solid_brick': False, 'is_system_built': False, 'is_timber_frame': False,
|
||||||
|
'is_granite_or_whinstone': False, 'is_as_built': False, 'is_cob': False, 'is_assumed': False,
|
||||||
|
'is_sandstone_or_limestone': False, 'insulation_thickness': None, 'external_insulation': False,
|
||||||
|
'internal_insulation': False
|
||||||
|
},
|
||||||
|
already_installed=[],
|
||||||
|
data={"county": "Greater London Authority"}
|
||||||
|
)
|
||||||
|
|
||||||
obj = WallRecommendations(
|
obj = WallRecommendations(
|
||||||
property_instance=input_properties[0],
|
property_instance=p,
|
||||||
materials=materials
|
materials=materials
|
||||||
)
|
)
|
||||||
assert obj
|
assert obj
|
||||||
assert obj.property
|
assert obj.property
|
||||||
|
|
||||||
def test_uvalue_0_16(self, input_properties):
|
def test_uvalue_0_16(self):
|
||||||
"""
|
"""
|
||||||
This tests the wall description Average thermal transmittance 0.16 W/m-¦K
|
This tests the wall description Average thermal transmittance 0.16 W/m-¦K
|
||||||
The important data for this recommendation is:
|
The important data for this recommendation is:
|
||||||
|
|
@ -59,13 +58,29 @@ class TestWallRecommendations:
|
||||||
Since epc built after 1990 are typically built with insulation and this property
|
Since epc built after 1990 are typically built with insulation and this property
|
||||||
already has really good insulation, we do NOT recommend any measures for this property
|
already has really good insulation, we do NOT recommend any measures for this property
|
||||||
"""
|
"""
|
||||||
input_properties[0].year_built = 2014
|
|
||||||
input_properties[0].in_conservation_area = None
|
p = Mock(
|
||||||
input_properties[0].restricted_measures = False
|
id=1,
|
||||||
input_properties[0].insulation_wall_area = 100
|
insulation_wall_area=100,
|
||||||
|
year_built=2014,
|
||||||
|
in_conservation_area=None,
|
||||||
|
restricted_measure=False,
|
||||||
|
walls={
|
||||||
|
'original_description': 'Average thermal transmittance 0.16 W/m-¦K',
|
||||||
|
'clean_description': 'Average thermal transmittance 0.16 W/m-¦K',
|
||||||
|
'thermal_transmittance': 0.16,
|
||||||
|
'thermal_transmittance_unit': 'w/m-¦k', 'is_cavity_wall': False, 'is_filled_cavity': False,
|
||||||
|
'is_solid_brick': False, 'is_system_built': False, 'is_timber_frame': False,
|
||||||
|
'is_granite_or_whinstone': False, 'is_as_built': False, 'is_cob': False, 'is_assumed': False,
|
||||||
|
'is_sandstone_or_limestone': False, 'insulation_thickness': None, 'external_insulation': False,
|
||||||
|
'internal_insulation': False
|
||||||
|
},
|
||||||
|
already_installed=[],
|
||||||
|
data={"county": "Greater London Authority", 'transaction-type': 'new dwelling'}
|
||||||
|
)
|
||||||
|
|
||||||
recommender = WallRecommendations(
|
recommender = WallRecommendations(
|
||||||
property_instance=input_properties[0],
|
property_instance=p,
|
||||||
materials=materials
|
materials=materials
|
||||||
)
|
)
|
||||||
assert recommender.property.walls["original_description"] == "Average thermal transmittance 0.16 W/m-¦K"
|
assert recommender.property.walls["original_description"] == "Average thermal transmittance 0.16 W/m-¦K"
|
||||||
|
|
@ -73,7 +88,7 @@ class TestWallRecommendations:
|
||||||
# This should be empty
|
# This should be empty
|
||||||
assert recommender.recommendations == []
|
assert recommender.recommendations == []
|
||||||
|
|
||||||
def test_solid_brick_no_insulation(self, input_properties):
|
def test_solid_brick_no_insulation(self):
|
||||||
"""
|
"""
|
||||||
This tests a property with a wall description of Solid brick, as built, no insulation (assumed)
|
This tests a property with a wall description of Solid brick, as built, no insulation (assumed)
|
||||||
The property was built in 1930, right on the threshold for when cavity walls were introduced
|
The property was built in 1930, right on the threshold for when cavity walls were introduced
|
||||||
|
|
@ -82,25 +97,35 @@ class TestWallRecommendations:
|
||||||
|
|
||||||
This property is not in a conservation area, however it's a flat so we don't recommend external wall insulation
|
This property is not in a conservation area, however it's a flat so we don't recommend external wall insulation
|
||||||
"""
|
"""
|
||||||
input_properties[1].year_built = 1930
|
|
||||||
input_properties[1].insulation_wall_area = 100
|
p = Mock(
|
||||||
input_properties[1].walls["clean_description"] = "Solid brick, as built, no insulation"
|
id=2,
|
||||||
input_properties[1].walls["is_sandstone_or_limestone"] = False
|
year_built=1930,
|
||||||
input_properties[1].age_band = "A"
|
insulation_wall_area=100,
|
||||||
input_properties[1].restricted_measures = False
|
age_band="A",
|
||||||
input_properties[1].already_installed = []
|
restricted_measures=False,
|
||||||
input_properties[1].walls["is_park_home"] = False
|
already_installed=[],
|
||||||
input_properties[1].construction_age_band = "England and Wales: 1930-1949"
|
construction_age_band="England and Wales: 1930-1949",
|
||||||
input_properties[1].non_invasive_recommendations = []
|
in_conservation_area="not_in_conservation_area",
|
||||||
|
non_invasive_recommendations=[],
|
||||||
|
walls={
|
||||||
|
'original_description': 'Solid brick, as built, no insulation (assumed)',
|
||||||
|
"clean_description": "Solid brick, as built, no insulation",
|
||||||
|
'thermal_transmittance': None,
|
||||||
|
'thermal_transmittance_unit': None, 'is_cavity_wall': False, 'is_filled_cavity': False,
|
||||||
|
'is_solid_brick': True, 'is_system_built': False, 'is_timber_frame': False,
|
||||||
|
'is_granite_or_whinstone': False, 'is_as_built': True, 'is_cob': False, 'is_assumed': True,
|
||||||
|
'is_sandstone_or_limestone': False, 'insulation_thickness': 'none', 'external_insulation': False,
|
||||||
|
'internal_insulation': False, 'is_park_home': False
|
||||||
|
},
|
||||||
|
data={"county": "Greater London Authority", 'property-type': 'Flat', 'walls-energy-eff': 'Very Poor'}
|
||||||
|
)
|
||||||
|
|
||||||
recommender = WallRecommendations(
|
recommender = WallRecommendations(
|
||||||
property_instance=input_properties[1],
|
property_instance=p,
|
||||||
materials=materials
|
materials=materials
|
||||||
)
|
)
|
||||||
assert recommender.property.walls["original_description"] == "Solid brick, as built, no insulation (assumed)"
|
|
||||||
assert not recommender.ewi_valid()
|
assert not recommender.ewi_valid()
|
||||||
assert recommender.property.in_conservation_area == "not_in_conservation_area"
|
|
||||||
assert recommender.property.data["property-type"] == "Flat"
|
|
||||||
|
|
||||||
recommender.recommend(phase=0)
|
recommender.recommend(phase=0)
|
||||||
# This should result in some recommendations, all of which should be internal insulation
|
# This should result in some recommendations, all of which should be internal insulation
|
||||||
|
|
@ -115,7 +140,7 @@ class TestWallRecommendations:
|
||||||
recommender.recommendations
|
recommender.recommendations
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_solid_brick_insulation(self, input_properties):
|
def test_solid_brick_insulation(self):
|
||||||
"""
|
"""
|
||||||
This tests a property with a wall description of Solid brick, as built, insulation (assumed)
|
This tests a property with a wall description of Solid brick, as built, insulation (assumed)
|
||||||
The property was built in 1991, after cavity walls were introduced
|
The property was built in 1991, after cavity walls were introduced
|
||||||
|
|
@ -127,19 +152,34 @@ class TestWallRecommendations:
|
||||||
This property is not in a conservation area, however it's a flat so we don't recommend external wall insulation
|
This property is not in a conservation area, however it's a flat so we don't recommend external wall insulation
|
||||||
"""
|
"""
|
||||||
|
|
||||||
input_properties[6].year_built = 1991
|
p = Mock(
|
||||||
input_properties[6].restricted_measures = False
|
id=3,
|
||||||
input_properties[6].insulation_wall_area = 100
|
year_built=1991,
|
||||||
|
restricted_measures=False,
|
||||||
|
insulation_wall_area=100,
|
||||||
|
already_installed=[],
|
||||||
|
in_conservation_area="not_in_conservation_area",
|
||||||
|
data={'county': 'Greater London Authority', 'property-type': 'Flat'},
|
||||||
|
walls={
|
||||||
|
'original_description': 'Solid brick, as built, insulated (assumed)',
|
||||||
|
'clean_description': 'Solid brick, as built, insulated',
|
||||||
|
'thermal_transmittance': None,
|
||||||
|
'thermal_transmittance_unit': None, 'is_cavity_wall': False, 'is_filled_cavity': False,
|
||||||
|
'is_solid_brick': True, 'is_system_built': False, 'is_timber_frame': False,
|
||||||
|
'is_granite_or_whinstone': False, 'is_as_built': True, 'is_cob': False, 'is_assumed': True,
|
||||||
|
'is_sandstone_or_limestone': False, 'insulation_thickness': 'average', 'external_insulation': False,
|
||||||
|
'internal_insulation': False
|
||||||
|
}
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
recommender = WallRecommendations(
|
recommender = WallRecommendations(
|
||||||
property_instance=input_properties[6],
|
property_instance=p,
|
||||||
materials=materials
|
materials=materials
|
||||||
)
|
)
|
||||||
|
|
||||||
assert recommender.property.walls["original_description"] == "Solid brick, as built, insulated (assumed)"
|
assert recommender.property.walls["original_description"] == "Solid brick, as built, insulated (assumed)"
|
||||||
assert not recommender.ewi_valid()
|
assert not recommender.ewi_valid()
|
||||||
assert recommender.property.in_conservation_area == "not_in_conservation_area"
|
|
||||||
assert recommender.property.data["property-type"] == "Flat"
|
|
||||||
assert recommender.estimated_u_value is None
|
assert recommender.estimated_u_value is None
|
||||||
|
|
||||||
recommender.recommend()
|
recommender.recommend()
|
||||||
|
|
@ -507,8 +547,7 @@ class TestCavityWallRecommensations:
|
||||||
input_property6.insulation_wall_area = 350
|
input_property6.insulation_wall_area = 350
|
||||||
input_property6.restricted_measures = False
|
input_property6.restricted_measures = False
|
||||||
input_property6.construction_age_band = "England and Wales: 1976-1982"
|
input_property6.construction_age_band = "England and Wales: 1976-1982"
|
||||||
|
input_property6.already_installed = []
|
||||||
assert input_property6.walls["is_sandstone_or_limestone"]
|
|
||||||
|
|
||||||
recommender6 = WallRecommendations(
|
recommender6 = WallRecommendations(
|
||||||
property_instance=input_property6,
|
property_instance=input_property6,
|
||||||
|
|
@ -524,6 +563,6 @@ class TestCavityWallRecommensations:
|
||||||
assert len(recommender6.recommendations) == 1
|
assert len(recommender6.recommendations) == 1
|
||||||
assert recommender6.estimated_u_value == 1
|
assert recommender6.estimated_u_value == 1
|
||||||
assert np.isclose(recommender6.recommendations[0]["new_u_value"], 0.26)
|
assert np.isclose(recommender6.recommendations[0]["new_u_value"], 0.26)
|
||||||
assert np.isclose(recommender6.recommendations[0]["total"], 85680.0)
|
assert np.isclose(recommender6.recommendations[0]["total"], 68250.0)
|
||||||
assert recommender6.recommendations[0]["parts"][0]["type"] == "internal_wall_insulation"
|
assert recommender6.recommendations[0]["parts"][0]["type"] == "internal_wall_insulation"
|
||||||
assert recommender6.recommendations[0]["parts"][0]["depth"] == 95
|
assert recommender6.recommendations[0]["parts"][0]["depth"] == 95
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue