mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Added wall test cases
This commit is contained in:
parent
5146e6e0b4
commit
7385719b37
6 changed files with 106 additions and 77 deletions
|
|
@ -1,6 +1,4 @@
|
|||
import pytest
|
||||
import pickle
|
||||
from model_data.EpcClean import EpcClean
|
||||
from pathlib import Path
|
||||
from model_data.tests.test_data.test_roof_attributes_cases import clean_roof_test_cases
|
||||
from model_data.epc_attributes.RoofAttributes import RoofAttributes
|
||||
|
|
|
|||
|
|
@ -93,12 +93,6 @@ class FloorRecommendations(Definitions):
|
|||
# The floor is already compliant
|
||||
return
|
||||
|
||||
# For these methods, we need to know the additional details about the property
|
||||
if self.property.walls["is_solid_brick"]:
|
||||
wall_type = "solid brick"
|
||||
else:
|
||||
raise NotImplementedError("Implement me")
|
||||
|
||||
total_floor_area = float(self.property.data["total-floor-area"])
|
||||
number_of_rooms = float(self.property.data["number-habitable-rooms"])
|
||||
|
||||
|
|
@ -118,7 +112,7 @@ class FloorRecommendations(Definitions):
|
|||
|
||||
wall_type = get_wall_type(**self.property.walls)
|
||||
|
||||
self.estimated_u_value = get_floor_u_value(
|
||||
u_value = get_floor_u_value(
|
||||
floor_type="suspended" if is_suspended else "solid",
|
||||
area=total_floor_area,
|
||||
perimeter=estimated_perimeter,
|
||||
|
|
@ -126,6 +120,7 @@ class FloorRecommendations(Definitions):
|
|||
insulation_thickness=insulation_thickness,
|
||||
wall_type=wall_type
|
||||
)
|
||||
self.estimated_u_value = u_value
|
||||
|
||||
if is_suspended:
|
||||
# Given the U-value, we recommend underfloor insulation
|
||||
|
|
|
|||
80
recommendations/tests/test_data/wall_uvalue_test_cases.py
Normal file
80
recommendations/tests/test_data/wall_uvalue_test_cases.py
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
wall_uvalue_test_cases = [
|
||||
{
|
||||
"clean_description": "Cavity wall, as built, partial insulation",
|
||||
"age_band": "A",
|
||||
"is_granite_or_whinstone": False,
|
||||
"is_sandstone_or_limestone": False,
|
||||
"uvalue": 0.7
|
||||
},
|
||||
{
|
||||
"clean_description": "Cavity wall, as built, partial insulation",
|
||||
"age_band": "F",
|
||||
"is_granite_or_whinstone": False,
|
||||
"is_sandstone_or_limestone": False,
|
||||
"uvalue": 0.4
|
||||
},
|
||||
{
|
||||
"clean_description": "Cavity wall, as built, partial insulation",
|
||||
"age_band": "F",
|
||||
"is_granite_or_whinstone": False,
|
||||
"is_sandstone_or_limestone": False,
|
||||
"uvalue": 0.4
|
||||
},
|
||||
{
|
||||
|
||||
"clean_description": "Solid brick, with internal insulation",
|
||||
"age_band": "C",
|
||||
"is_granite_or_whinstone": False,
|
||||
"is_sandstone_or_limestone": False,
|
||||
"uvalue": 0.32
|
||||
},
|
||||
{
|
||||
"clean_description": "Solid brick, as built, no insulation",
|
||||
"age_band": "C",
|
||||
"is_granite_or_whinstone": False,
|
||||
"is_sandstone_or_limestone": False,
|
||||
"uvalue": 1.7
|
||||
},
|
||||
{
|
||||
"clean_description": "Timber frame, as built, no insulation",
|
||||
"age_band": "E",
|
||||
"is_granite_or_whinstone": False,
|
||||
"is_sandstone_or_limestone": False,
|
||||
"uvalue": 0.8
|
||||
},
|
||||
{
|
||||
"clean_description": "Sandstone or limestone, with external insulation",
|
||||
"age_band": "E",
|
||||
"is_granite_or_whinstone": False,
|
||||
"is_sandstone_or_limestone": False,
|
||||
"uvalue": 0.32
|
||||
},
|
||||
{
|
||||
"clean_description": "Granite or whinstone, as built, partial insulation",
|
||||
"age_band": "E",
|
||||
"is_granite_or_whinstone": False,
|
||||
"is_sandstone_or_limestone": False,
|
||||
"uvalue": 0.55
|
||||
},
|
||||
{
|
||||
"clean_description": "System built, as built, no insulation",
|
||||
"age_band": "E",
|
||||
"is_granite_or_whinstone": False,
|
||||
"is_sandstone_or_limestone": False,
|
||||
"uvalue": 1.7
|
||||
},
|
||||
{
|
||||
"clean_description": "Cob, with internal insulation",
|
||||
"age_band": "E",
|
||||
"is_granite_or_whinstone": False,
|
||||
"is_sandstone_or_limestone": False,
|
||||
"uvalue": 0.26
|
||||
},
|
||||
{
|
||||
"clean_description": "Park home wall, with internal insulation",
|
||||
"age_band": "E",
|
||||
"is_granite_or_whinstone": False,
|
||||
"is_sandstone_or_limestone": False,
|
||||
"uvalue": 0
|
||||
}
|
||||
]
|
||||
|
|
@ -8,12 +8,6 @@ from recommendations.FloorRecommendations import FloorRecommendations
|
|||
# os.path.abspath(os.path.dirname(__file__)) + "/recommendations/tests/test_data/input_properties.pkl", "rb"
|
||||
# ) as f:
|
||||
# input_properties = pickle.load(f)
|
||||
#
|
||||
# with open(
|
||||
# os.path.abspath(os.path.dirname(__file__)) + "/recommendations/tests/test_data/uvalue_estimates.pkl", "rb"
|
||||
# ) as f:
|
||||
# uvalue_estimates = pickle.load(f)
|
||||
|
||||
|
||||
suspended_floor_insulation_parts = [
|
||||
{
|
||||
|
|
@ -85,13 +79,6 @@ class TestWallRecommendations:
|
|||
) as f:
|
||||
return pickle.load(f)
|
||||
|
||||
@pytest.fixture
|
||||
def uvalue_estimates(self):
|
||||
with open(
|
||||
os.path.abspath(os.path.dirname(__file__)) + "/test_data/uvalue_estimates.pkl", "rb"
|
||||
) as f:
|
||||
return pickle.load(f)
|
||||
|
||||
@pytest.fixture
|
||||
def mock_floor_rec_instance(self):
|
||||
# Creating a mock instance of WallRecommendations with the necessary attributes
|
||||
|
|
@ -99,27 +86,22 @@ class TestWallRecommendations:
|
|||
property_mock.full_sap_epc = {"lodgement-date": "2000-01-01"} # or any date you want
|
||||
property_mock.data = {"construction-age-band": "1950"} # or any other data that fits your tests
|
||||
|
||||
uvalue_estimates_mock = Mock()
|
||||
|
||||
mock_wall_rec_instance = FloorRecommendations(property_mock, uvalue_estimates_mock, "Decile 1", parts)
|
||||
mock_wall_rec_instance = FloorRecommendations(property_mock, "Decile 1", parts)
|
||||
return mock_wall_rec_instance
|
||||
|
||||
def test_init(self, input_properties, uvalue_estimates):
|
||||
def test_init(self, input_properties):
|
||||
obj = FloorRecommendations(
|
||||
property_instance=input_properties[0],
|
||||
uvalue_estimates=uvalue_estimates,
|
||||
total_floor_area_group_decile="Decile 1",
|
||||
materials=parts
|
||||
)
|
||||
assert obj
|
||||
assert obj.property
|
||||
assert obj.uvalue_estimates
|
||||
assert obj.total_floor_area_group_decile == "Decile 1"
|
||||
|
||||
def test_other_premises_below(self, input_properties, uvalue_estimates):
|
||||
def test_other_premises_below(self, input_properties):
|
||||
recommender = FloorRecommendations(
|
||||
property_instance=input_properties[0],
|
||||
uvalue_estimates=uvalue_estimates,
|
||||
total_floor_area_group_decile="Decile 1",
|
||||
materials=parts
|
||||
)
|
||||
|
|
@ -128,7 +110,7 @@ class TestWallRecommendations:
|
|||
|
||||
assert not recommender.recommendations
|
||||
|
||||
def test_suspended_no_insulation(self, input_properties, uvalue_estimates):
|
||||
def test_suspended_no_insulation(self, input_properties):
|
||||
"""
|
||||
For a suspended floor without insulation, we use the rdsap methogology to estimate a U-value for the floor
|
||||
:return:
|
||||
|
|
@ -136,24 +118,24 @@ class TestWallRecommendations:
|
|||
|
||||
input_properties[2].floor_area = 50
|
||||
input_properties[2].walls["is_park_home"] = False
|
||||
input_properties[2].age_band = "A"
|
||||
|
||||
recommender = FloorRecommendations(
|
||||
property_instance=input_properties[2],
|
||||
uvalue_estimates=uvalue_estimates,
|
||||
total_floor_area_group_decile="Decile 1",
|
||||
materials=parts
|
||||
)
|
||||
assert recommender.estimated_u_value is None
|
||||
recommender.recommend()
|
||||
assert recommender.property.floor["is_suspended"]
|
||||
assert recommender.estimated_u_value == 0.8766389420265843
|
||||
assert recommender.estimated_u_value == 0.51
|
||||
assert recommender.recommendations
|
||||
|
||||
types = {part["type"] for x in recommender.recommendations for part in x["parts"]}
|
||||
|
||||
assert types == {"suspended_floor_insulation"}
|
||||
|
||||
def test_uvalue_0_12(self, input_properties, uvalue_estimates):
|
||||
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
|
||||
does not need floor insulation
|
||||
|
|
@ -161,7 +143,6 @@ class TestWallRecommendations:
|
|||
"""
|
||||
recommender = FloorRecommendations(
|
||||
property_instance=input_properties[3],
|
||||
uvalue_estimates=uvalue_estimates,
|
||||
total_floor_area_group_decile="Decile 1",
|
||||
materials=parts
|
||||
)
|
||||
|
|
@ -172,16 +153,17 @@ class TestWallRecommendations:
|
|||
assert recommender.estimated_u_value is None
|
||||
assert not recommender.recommendations
|
||||
|
||||
def test_solid_no_insulation(self, input_properties, uvalue_estimates):
|
||||
def test_solid_no_insulation(self, input_properties):
|
||||
"""
|
||||
:return:
|
||||
"""
|
||||
|
||||
input_properties[4].floor_area = 100
|
||||
input_properties[4].walls["is_park_home"] = False
|
||||
input_properties[4].age_band = "B"
|
||||
|
||||
recommender = FloorRecommendations(
|
||||
property_instance=input_properties[4],
|
||||
uvalue_estimates=uvalue_estimates,
|
||||
total_floor_area_group_decile="Decile 1",
|
||||
materials=parts
|
||||
)
|
||||
|
|
@ -189,21 +171,20 @@ class TestWallRecommendations:
|
|||
recommender.recommend()
|
||||
assert not recommender.property.floor["is_suspended"]
|
||||
assert recommender.property.floor["is_solid"]
|
||||
assert recommender.estimated_u_value == 0.7528014214215474
|
||||
assert recommender.estimated_u_value == 0.63
|
||||
assert recommender.recommendations
|
||||
|
||||
types = {part["type"] for x in recommender.recommendations for part in x["parts"]}
|
||||
|
||||
assert types == {"solid_floor_insulation"}
|
||||
|
||||
def test_another_dwelling_below(self, input_properties, uvalue_estimates):
|
||||
def test_another_dwelling_below(self, input_properties):
|
||||
"""
|
||||
This is another description we see when there is a property below
|
||||
"""
|
||||
|
||||
recommender = FloorRecommendations(
|
||||
property_instance=input_properties[6],
|
||||
uvalue_estimates=uvalue_estimates,
|
||||
total_floor_area_group_decile="Decile 1",
|
||||
materials=parts
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import pytest
|
|||
from unittest.mock import MagicMock
|
||||
from recommendations import recommendation_utils
|
||||
from datatypes.enums import QuantityUnits
|
||||
from recommendations.tests.test_data.wall_uvalue_test_cases import wall_uvalue_test_cases
|
||||
|
||||
|
||||
class TestRecommendationUtils:
|
||||
|
|
@ -43,39 +44,6 @@ class TestRecommendationUtils:
|
|||
part=part, selected_depth=1, selected_total_cost=50, quantity=99, quantity_unit="m2"
|
||||
) == {'depths': [1], 'estimated_cost': 50, 'quantity': 99, 'quantity_unit': QuantityUnits.m2.value}
|
||||
|
||||
def test_get_uvalue_estimate(self, property_mock):
|
||||
uvalue_estimates = [
|
||||
{
|
||||
'total-floor-area_group': 'Decile 1',
|
||||
'number-habitable-rooms': 3,
|
||||
'number-heated-rooms': 2,
|
||||
'median_thermal_transmittance': 1
|
||||
},
|
||||
{
|
||||
'total-floor-area_group': 'Decile 1',
|
||||
'number-habitable-rooms': 3,
|
||||
'number-heated-rooms': 2,
|
||||
'median_thermal_transmittance': 2
|
||||
}
|
||||
]
|
||||
|
||||
assert recommendation_utils.get_uvalue_estimate(uvalue_estimates, property_mock, "Decile 1") == 1.5
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
recommendation_utils.get_uvalue_estimate([], property_mock, "Decile 1")
|
||||
|
||||
# Test with missing 'median_thermal_transmittance' key
|
||||
uvalue_estimates_missing_key = [
|
||||
{
|
||||
'total-floor-area_group': 'Decile 1',
|
||||
'number-habitable-rooms': 3,
|
||||
'number-heated-rooms': 2
|
||||
}
|
||||
]
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
recommendation_utils.get_uvalue_estimate(uvalue_estimates_missing_key, property_mock, "Decile 1")
|
||||
|
||||
def test_get_roof_u_value(self):
|
||||
# Test case 1: Insulation thickness is known and is_loft is True
|
||||
inputs = {
|
||||
|
|
@ -248,3 +216,14 @@ class TestRecommendationUtils:
|
|||
|
||||
u_value = recommendation_utils.get_roof_u_value(**inputs)
|
||||
assert u_value == 0.0, f"Expected 0.0, but got {u_value}"
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"test_case",
|
||||
wall_uvalue_test_cases
|
||||
)
|
||||
def test_get_wall_uvalue(self, test_case):
|
||||
expected_uvalue = test_case["uvalue"]
|
||||
inputs = test_case.copy()
|
||||
del inputs["uvalue"]
|
||||
uvalue = recommendation_utils.get_wall_u_value(**inputs)
|
||||
assert expected_uvalue == uvalue, f"Expected u value {expected_uvalue}, recieved {uvalue}"
|
||||
|
|
|
|||
|
|
@ -1,12 +1,8 @@
|
|||
import os
|
||||
|
||||
import pandas as pd
|
||||
import pytest
|
||||
import pickle
|
||||
import numpy as np
|
||||
from unittest.mock import Mock, MagicMock
|
||||
from recommendations.WallRecommendations import WallRecommendations
|
||||
from model_data.analysis.UvalueEstimations import UvalueEstimations
|
||||
from backend.Property import Property
|
||||
from recommendations.recommendation_utils import is_diminishing_returns
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue