mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +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 numpy as np
|
||||
from unittest.mock import Mock, MagicMock
|
||||
|
||||
from recommendations.WallRecommendations import WallRecommendations
|
||||
from backend.Property import Property
|
||||
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
|
||||
|
||||
|
||||
# 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:
|
||||
|
||||
@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
|
||||
def mock_wall_rec_instance(self):
|
||||
# Creating a mock instance of WallRecommendations with the necessary attributes
|
||||
|
|
@ -40,17 +26,30 @@ class TestWallRecommendations:
|
|||
)
|
||||
return mock_wall_rec_instance
|
||||
|
||||
def test_init(self, input_properties):
|
||||
input_properties[0].insulation_wall_area = 100
|
||||
def test_init(self):
|
||||
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(
|
||||
property_instance=input_properties[0],
|
||||
property_instance=p,
|
||||
materials=materials
|
||||
)
|
||||
assert obj
|
||||
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
|
||||
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
|
||||
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
|
||||
input_properties[0].restricted_measures = False
|
||||
input_properties[0].insulation_wall_area = 100
|
||||
|
||||
p = Mock(
|
||||
id=1,
|
||||
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(
|
||||
property_instance=input_properties[0],
|
||||
property_instance=p,
|
||||
materials=materials
|
||||
)
|
||||
assert recommender.property.walls["original_description"] == "Average thermal transmittance 0.16 W/m-¦K"
|
||||
|
|
@ -73,7 +88,7 @@ class TestWallRecommendations:
|
|||
# This should be empty
|
||||
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)
|
||||
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
|
||||
"""
|
||||
input_properties[1].year_built = 1930
|
||||
input_properties[1].insulation_wall_area = 100
|
||||
input_properties[1].walls["clean_description"] = "Solid brick, as built, no insulation"
|
||||
input_properties[1].walls["is_sandstone_or_limestone"] = False
|
||||
input_properties[1].age_band = "A"
|
||||
input_properties[1].restricted_measures = False
|
||||
input_properties[1].already_installed = []
|
||||
input_properties[1].walls["is_park_home"] = False
|
||||
input_properties[1].construction_age_band = "England and Wales: 1930-1949"
|
||||
input_properties[1].non_invasive_recommendations = []
|
||||
|
||||
p = Mock(
|
||||
id=2,
|
||||
year_built=1930,
|
||||
insulation_wall_area=100,
|
||||
age_band="A",
|
||||
restricted_measures=False,
|
||||
already_installed=[],
|
||||
construction_age_band="England and Wales: 1930-1949",
|
||||
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(
|
||||
property_instance=input_properties[1],
|
||||
property_instance=p,
|
||||
materials=materials
|
||||
)
|
||||
assert recommender.property.walls["original_description"] == "Solid brick, as built, no insulation (assumed)"
|
||||
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)
|
||||
# This should result in some recommendations, all of which should be internal insulation
|
||||
|
|
@ -115,7 +140,7 @@ class TestWallRecommendations:
|
|||
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)
|
||||
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
|
||||
"""
|
||||
|
||||
input_properties[6].year_built = 1991
|
||||
input_properties[6].restricted_measures = False
|
||||
input_properties[6].insulation_wall_area = 100
|
||||
p = Mock(
|
||||
id=3,
|
||||
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(
|
||||
property_instance=input_properties[6],
|
||||
property_instance=p,
|
||||
materials=materials
|
||||
)
|
||||
|
||||
assert recommender.property.walls["original_description"] == "Solid brick, as built, insulated (assumed)"
|
||||
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
|
||||
|
||||
recommender.recommend()
|
||||
|
|
@ -507,8 +547,7 @@ class TestCavityWallRecommensations:
|
|||
input_property6.insulation_wall_area = 350
|
||||
input_property6.restricted_measures = False
|
||||
input_property6.construction_age_band = "England and Wales: 1976-1982"
|
||||
|
||||
assert input_property6.walls["is_sandstone_or_limestone"]
|
||||
input_property6.already_installed = []
|
||||
|
||||
recommender6 = WallRecommendations(
|
||||
property_instance=input_property6,
|
||||
|
|
@ -524,6 +563,6 @@ class TestCavityWallRecommensations:
|
|||
assert len(recommender6.recommendations) == 1
|
||||
assert recommender6.estimated_u_value == 1
|
||||
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]["depth"] == 95
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue