From 3f43ef3ee9ca2b75e0b1c6fe329e5bc78217d6b8 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Tue, 27 Jun 2023 12:14:10 +0100 Subject: [PATCH] Adding unit tests, made floor recommendations code simpler --- model_data/app.py | 2 + .../recommendations/FloorRecommendations.py | 61 +++++++------------ .../tests/test_floor_recommendations.py | 16 ++++- 3 files changed, 39 insertions(+), 40 deletions(-) diff --git a/model_data/app.py b/model_data/app.py index bad4b303..da37e2ea 100644 --- a/model_data/app.py +++ b/model_data/app.py @@ -70,6 +70,8 @@ def handler(): local_authorities = {p.data['local-authority'] for p in input_properties} + # TODO: Create a more balanced sample where we grab more properties across different properties + # types, as e.g. we're pulling many more flats than houses data = [] for la in tqdm(local_authorities): data.extend( diff --git a/model_data/recommendations/FloorRecommendations.py b/model_data/recommendations/FloorRecommendations.py index d120dba0..983c2274 100644 --- a/model_data/recommendations/FloorRecommendations.py +++ b/model_data/recommendations/FloorRecommendations.py @@ -86,7 +86,8 @@ class FloorRecommendations(BaseUtility): FLOOR_LEVELS = { "Ground": 0, # We don't know what floor level, we just make sure it's not 0 - "mid floor": 1 + "mid floor": 1, + "NODATA!": None } def __init__(self, property_instance: Property, uvalue_estimates: UvalueEstimations): @@ -219,49 +220,31 @@ class FloorRecommendations(BaseUtility): else: raise NotImplementedError("Implement me") + if insulation_thickness == "none": + + region_str, age_band = self.property.data["construction-age-band"].split(":") + region_str = region_str.strip() + age_band = age_band.strip() + region = self.REGION_LOOKUP[region_str] + + u_value = self._estimate_suspended_floor_u_value( + floor_area=total_floor_area / num_floors, + number_of_rooms=number_of_rooms / num_floors, + insulation_thickness=0, + wall_type=wall_type, + region=region, + age_band=age_band, + ) + else: + u_value = self._get_floors_uvalue_estimate() + + self.estimated_u_value = u_value + if is_suspended: - - if insulation_thickness == "none": - - region_str, age_band = self.property.data["construction-age-band"].split(":") - region_str = region_str.strip() - age_band = age_band.strip() - region = self.REGION_LOOKUP[region_str] - - u_value = self._estimate_suspended_floor_u_value( - floor_area=total_floor_area / num_floors, - number_of_rooms=number_of_rooms / num_floors, - insulation_thickness=0, - wall_type=wall_type, - region=region, - age_band=age_band, - ) - else: - u_value = self._get_floors_uvalue_estimate() - # Given the U-value, we recommend underfloor insulation self.recommend_floor_insulation(u_value=u_value, parts=suspended_floor_insulation_parts) if is_solid: - - if insulation_thickness == "none": - - region_str, age_band = self.property.data["construction-age-band"].split(":") - region_str = region_str.strip() - age_band = age_band.strip() - region = self.REGION_LOOKUP[region_str] - - u_value = self._estimate_suspended_floor_u_value( - floor_area=total_floor_area / num_floors, - number_of_rooms=number_of_rooms / num_floors, - insulation_thickness=0, - wall_type=wall_type, - region=region, - age_band=age_band, - ) - else: - u_value = self._get_floors_uvalue_estimate() - # Given the U-value, we recommend solid floor insulation options which are usually solid foam self.recommend_floor_insulation(u_value=u_value, parts=solid_floor_insulation_parts) diff --git a/model_data/tests/test_floor_recommendations.py b/model_data/tests/test_floor_recommendations.py index 95e17ce1..e6d9b907 100644 --- a/model_data/tests/test_floor_recommendations.py +++ b/model_data/tests/test_floor_recommendations.py @@ -50,6 +50,20 @@ class TestWallRecommendations: assert obj.property assert obj.uvalue_estimates - def test_premises_below(self, input_properties, uvalue_estimates): + def test_other_premises_below(self, input_properties, uvalue_estimates): recommender = FloorRecommendations(property_instance=input_properties[0], uvalue_estimates=uvalue_estimates) recommender.recommend() + assert recommender.property.floor["another_property_below"] + + assert not recommender.recommendations + + def test_suspended_no_insulation(self, input_properties, uvalue_estimates): + """ + 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.recommend() + assert recommender.property.floor["is_suspended"] + assert recommended.es + assert recommender.recommendations