mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
fixed recommendation tests
This commit is contained in:
parent
2f88f2a0af
commit
e3d94b9307
6 changed files with 62 additions and 34 deletions
|
|
@ -285,7 +285,8 @@ class WallRecommendations(BaseUtility):
|
|||
u_value = self.DEFAULT_U_VALUES["solid_brick"]
|
||||
else:
|
||||
u_value = get_uvalue_estimate(
|
||||
uvalue_estimates=self.uvalue_estimates, property=self.property,
|
||||
uvalue_estimates=self.uvalue_estimates,
|
||||
property=self.property,
|
||||
total_floor_area_group_decile=self.total_floor_area_group_decile
|
||||
)
|
||||
self.estimated_u_value = u_value
|
||||
|
|
|
|||
|
|
@ -30,17 +30,26 @@ class TestWallRecommendations:
|
|||
|
||||
uvalue_estimates_mock = Mock()
|
||||
|
||||
mock_wall_rec_instance = FloorRecommendations(property_mock, uvalue_estimates_mock)
|
||||
mock_wall_rec_instance = FloorRecommendations(property_mock, uvalue_estimates_mock, "Decile 1")
|
||||
return mock_wall_rec_instance
|
||||
|
||||
def test_init(self, input_properties, uvalue_estimates):
|
||||
obj = FloorRecommendations(property_instance=input_properties[0], uvalue_estimates=uvalue_estimates)
|
||||
obj = FloorRecommendations(
|
||||
property_instance=input_properties[0],
|
||||
uvalue_estimates=uvalue_estimates,
|
||||
total_floor_area_group_decile="Decile 1"
|
||||
)
|
||||
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):
|
||||
recommender = FloorRecommendations(property_instance=input_properties[0], uvalue_estimates=uvalue_estimates)
|
||||
recommender = FloorRecommendations(
|
||||
property_instance=input_properties[0],
|
||||
uvalue_estimates=uvalue_estimates,
|
||||
total_floor_area_group_decile="Decile 1"
|
||||
)
|
||||
recommender.recommend()
|
||||
assert recommender.property.floor["another_property_below"]
|
||||
|
||||
|
|
@ -51,7 +60,11 @@ class TestWallRecommendations:
|
|||
For a suspended floor without insulation, we use the rdsap methogology to estimate a U-value for the floor
|
||||
:return:
|
||||
"""
|
||||
recommender = FloorRecommendations(property_instance=input_properties[2], uvalue_estimates=uvalue_estimates)
|
||||
recommender = FloorRecommendations(
|
||||
property_instance=input_properties[2],
|
||||
uvalue_estimates=uvalue_estimates,
|
||||
total_floor_area_group_decile="Decile 1"
|
||||
)
|
||||
assert recommender.estimated_u_value is None
|
||||
recommender.recommend()
|
||||
assert recommender.property.floor["is_suspended"]
|
||||
|
|
@ -68,7 +81,11 @@ class TestWallRecommendations:
|
|||
does not need floor insulation
|
||||
:return:
|
||||
"""
|
||||
recommender = FloorRecommendations(property_instance=input_properties[3], uvalue_estimates=uvalue_estimates)
|
||||
recommender = FloorRecommendations(
|
||||
property_instance=input_properties[3],
|
||||
uvalue_estimates=uvalue_estimates,
|
||||
total_floor_area_group_decile="Decile 1"
|
||||
)
|
||||
assert recommender.estimated_u_value is None
|
||||
recommender.recommend()
|
||||
assert not recommender.property.floor["is_suspended"]
|
||||
|
|
@ -80,7 +97,11 @@ class TestWallRecommendations:
|
|||
"""
|
||||
:return:
|
||||
"""
|
||||
recommender = FloorRecommendations(property_instance=input_properties[4], uvalue_estimates=uvalue_estimates)
|
||||
recommender = FloorRecommendations(
|
||||
property_instance=input_properties[4],
|
||||
uvalue_estimates=uvalue_estimates,
|
||||
total_floor_area_group_decile="Decile 1"
|
||||
)
|
||||
assert recommender.estimated_u_value is None
|
||||
recommender.recommend()
|
||||
assert not recommender.property.floor["is_suspended"]
|
||||
|
|
@ -96,8 +117,12 @@ class TestWallRecommendations:
|
|||
"""
|
||||
This is another description we see when there is a property below
|
||||
"""
|
||||
input_properties[6].floor
|
||||
recommender = FloorRecommendations(property_instance=input_properties[6], uvalue_estimates=uvalue_estimates)
|
||||
|
||||
recommender = FloorRecommendations(
|
||||
property_instance=input_properties[6],
|
||||
uvalue_estimates=uvalue_estimates,
|
||||
total_floor_area_group_decile="Decile 1"
|
||||
)
|
||||
assert recommender.estimated_u_value is None
|
||||
recommender.recommend()
|
||||
assert not recommender.property.floor["is_suspended"]
|
||||
|
|
|
|||
|
|
@ -56,10 +56,10 @@ class TestRecommendationUtils:
|
|||
}
|
||||
]
|
||||
|
||||
assert recommendation_utils.get_uvalue_estimate(uvalue_estimates, property_mock) == 1.5
|
||||
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)
|
||||
recommendation_utils.get_uvalue_estimate([], property_mock, "Decile 1")
|
||||
|
||||
# Test with missing 'median_thermal_transmittance' key
|
||||
uvalue_estimates_missing_key = [
|
||||
|
|
@ -71,4 +71,4 @@ class TestRecommendationUtils:
|
|||
]
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
recommendation_utils.get_uvalue_estimate(uvalue_estimates_missing_key, property_mock)
|
||||
recommendation_utils.get_uvalue_estimate(uvalue_estimates_missing_key, property_mock, "Decile 1")
|
||||
|
|
|
|||
|
|
@ -36,14 +36,19 @@ class TestWallRecommendations:
|
|||
|
||||
uvalue_estimates_mock = Mock()
|
||||
|
||||
mock_wall_rec_instance = WallRecommendations(property_mock, uvalue_estimates_mock)
|
||||
mock_wall_rec_instance = WallRecommendations(property_mock, uvalue_estimates_mock, "Decile 1")
|
||||
return mock_wall_rec_instance
|
||||
|
||||
def test_init(self, input_properties, uvalue_estimates):
|
||||
obj = WallRecommendations(property_instance=input_properties[0], uvalue_estimates=uvalue_estimates)
|
||||
obj = WallRecommendations(
|
||||
property_instance=input_properties[0],
|
||||
uvalue_estimates=uvalue_estimates,
|
||||
total_floor_area_group_decile="Decile 1"
|
||||
)
|
||||
assert obj
|
||||
assert obj.property
|
||||
assert obj.uvalue_estimates
|
||||
assert obj.total_floor_area_group_decile == "Decile 1"
|
||||
|
||||
def test_uvalue_0_16(self, input_properties, uvalue_estimates):
|
||||
"""
|
||||
|
|
@ -55,7 +60,11 @@ class TestWallRecommendations:
|
|||
already has really good insulation, we do NOT recommend any measures for this property
|
||||
"""
|
||||
input_properties[0].year_built = 2014
|
||||
recommender = WallRecommendations(property_instance=input_properties[0], uvalue_estimates=uvalue_estimates)
|
||||
recommender = WallRecommendations(
|
||||
property_instance=input_properties[0],
|
||||
uvalue_estimates=uvalue_estimates,
|
||||
total_floor_area_group_decile="Decile 1"
|
||||
)
|
||||
assert recommender.property.walls["original_description"] == "Average thermal transmittance 0.16 W/m-¦K"
|
||||
recommender.recommend()
|
||||
# This should be empty
|
||||
|
|
@ -71,7 +80,11 @@ 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
|
||||
recommender = WallRecommendations(property_instance=input_properties[1], uvalue_estimates=uvalue_estimates)
|
||||
recommender = WallRecommendations(
|
||||
property_instance=input_properties[1],
|
||||
uvalue_estimates=uvalue_estimates,
|
||||
total_floor_area_group_decile="Decile 1"
|
||||
)
|
||||
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"
|
||||
|
|
@ -106,7 +119,11 @@ class TestWallRecommendations:
|
|||
"""
|
||||
|
||||
input_properties[6].year_built = 1991
|
||||
recommender = WallRecommendations(property_instance=input_properties[6], uvalue_estimates=uvalue_estimates)
|
||||
recommender = WallRecommendations(
|
||||
property_instance=input_properties[6],
|
||||
uvalue_estimates=uvalue_estimates.walls.to_dict("records"),
|
||||
total_floor_area_group_decile="Decile 1"
|
||||
)
|
||||
|
||||
assert recommender.property.walls["original_description"] == "Solid brick, as built, insulated (assumed)"
|
||||
assert not recommender.ewi_valid
|
||||
|
|
@ -118,7 +135,7 @@ class TestWallRecommendations:
|
|||
|
||||
# We should result in some recommendations, all of which should be internal wall insulation
|
||||
assert recommender.recommendations
|
||||
assert recommender.estimated_u_value == 0.45
|
||||
assert recommender.estimated_u_value == 0.4115686274509804
|
||||
|
||||
rec_types = {part["type"] for rec in recommender.recommendations for part in rec["parts"]}
|
||||
assert rec_types == {"internal_wall_insulation"}
|
||||
|
|
@ -221,7 +238,7 @@ class TestWallRecommendationsBase:
|
|||
|
||||
@pytest.fixture
|
||||
def wall_recommendations_instance(self, property_mock, uvalue_estimations_mock):
|
||||
wall_recommendations_instance = WallRecommendations(property_mock, uvalue_estimations_mock)
|
||||
wall_recommendations_instance = WallRecommendations(property_mock, uvalue_estimations_mock, "Decile 1")
|
||||
wall_recommendations_instance.uvalue_estimates.walls_decile_data = {
|
||||
"decile_labels": MagicMock(),
|
||||
"decile_boundaries": MagicMock()
|
||||
|
|
@ -241,21 +258,6 @@ class TestWallRecommendationsBase:
|
|||
wall_recommendations_instance.property.data = {"property-type": "house"}
|
||||
assert wall_recommendations_instance.ewi_valid is True
|
||||
|
||||
def test_get_walls_uvalue_estimate(self, wall_recommendations_instance, uvalue_estimations_mock):
|
||||
wall_recommendations_instance.uvalue_estimates = uvalue_estimations_mock
|
||||
wall_recommendations_instance.property.data = {
|
||||
"local-authority": "E09000012",
|
||||
"property-type": "Bungalow",
|
||||
"built-form": "End-Terrace",
|
||||
"walls-energy-eff": "Very Good",
|
||||
"walls-env-eff": "Very Good",
|
||||
"total-floor-area": 10,
|
||||
"number-habitable-rooms": "",
|
||||
"number-heated-rooms": ""
|
||||
}
|
||||
|
||||
assert wall_recommendations_instance._get_walls_uvalue_estimate() == 0.15
|
||||
|
||||
def test_recommend_without_u_value(self, wall_recommendations_instance):
|
||||
wall_recommendations_instance.property.walls = {
|
||||
"thermal_transmittance": None,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue