Adding unit tests, made floor recommendations code simpler

This commit is contained in:
Khalim Conn-Kowlessar 2023-06-27 12:14:10 +01:00
parent 8b3e8710c9
commit 3f43ef3ee9
3 changed files with 39 additions and 40 deletions

View file

@ -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(

View file

@ -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)

View file

@ -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