From 93a21e5436665a5321730978f563174135b226e7 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Tue, 8 Oct 2024 16:08:50 +0100 Subject: [PATCH] updating recommendation utils tests --- recommendations/recommendation_utils.py | 12 +++++++++--- recommendations/tests/test_recommendation_utils.py | 9 +++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/recommendations/recommendation_utils.py b/recommendations/recommendation_utils.py index 8ddfe1ef..3364f0fa 100644 --- a/recommendations/recommendation_utils.py +++ b/recommendations/recommendation_utils.py @@ -282,11 +282,14 @@ def get_u_value_from_s9( ): """Get the U-value from table S9 based on the insulation thickness.""" - if thickness in ["below average", "average", "above average", "none", None, "0", 0] or ( + if thickness in ["below average", "average", "above average", "none", None] or ( not is_loft and not is_roof_room and not is_at_rafters ): return None + if thickness in [0, "0"] and is_loft: + return None + # Determine the column to refer based on the roof type column = ( "Thatched_roof_U_value_W_m2K" @@ -294,8 +297,11 @@ def get_u_value_from_s9( else "Slates_or_tiles_U_value_W_m2K" ) - # Get the correct U-value based on the insulation thickness - return s9[s9["Insulation_thickness_mm"] >= thickness][column].iloc[0] + if thickness in [0, "0"] and is_roof_room: + return s9[pd.isnull(s9["Insulation_thickness_mm"])][column].iloc[0] + else: + # Get the correct U-value based on the insulation thickness + return s9[s9["Insulation_thickness_mm"] >= thickness][column].iloc[0] def get_roof_u_value( diff --git a/recommendations/tests/test_recommendation_utils.py b/recommendations/tests/test_recommendation_utils.py index 38322c41..b445a798 100644 --- a/recommendations/tests/test_recommendation_utils.py +++ b/recommendations/tests/test_recommendation_utils.py @@ -231,6 +231,15 @@ class TestRecommendationUtils: expected_uvalue = test_case["uvalue"] inputs = test_case.copy() del inputs["uvalue"] + # insulation_thickness = inputs["insulation_thickness"] + # has_dwelling_above = inputs["has_dwelling_above"] + # is_loft = inputs["is_loft"] + # is_roof_room = inputs["is_roof_room"] + # is_thatched = inputs["is_thatched"] + # age_band = inputs["age_band"] + # is_flat = inputs["is_flat"] + # is_pitched = inputs["is_pitched"] + # is_at_rafters = inputs["is_at_rafters"] uvalue = recommendation_utils.get_roof_u_value(**inputs) assert expected_uvalue == uvalue, f"Expected u value {expected_uvalue}, recieved {uvalue}"