Moved out search_split_description

This commit is contained in:
Khalim Conn-Kowlessar 2023-06-08 17:30:33 +01:00
parent 77c20d981a
commit 3d6ed88634
5 changed files with 62 additions and 28 deletions

View file

@ -1,4 +1,5 @@
from typing import Dict, Union
from epc_data.cleaning.cleaning_utils import extract_thermal_transmittence, search_split_description
class CleanFloor:
@ -13,16 +14,47 @@ class CleanFloor:
"""
description_lower = self.description.lower().strip()
assumed = "assumed" in description_lower
to_unheated_space = "to unheated space" in description_lower
if "another dwelling below" in description_lower:
return self._make_clean_output(
has_dwelling_below=True,
thermal_transmittence=None,
thermal_transmittence_unit=None,
to_unheated_space=to_unheated_space,
assumed=assumed
)
raise Exception("EKJH")
thermal_transmittence, thermal_transmittence_unit = None, None
if "insulated" in description_lower:
bh
elif "thermal transmittance" in description_lower:
thermal_transmittence, thermal_transmittence_unit = extract_thermal_transmittence(description_lower)
return self._make_clean_output(
has_dwelling_below=False,
thermal_transmittence=thermal_transmittence,
thermal_transmittence_unit=thermal_transmittence_unit,
to_unheated_space=to_unheated_space,
assumed=assumed
)
@classmethod
def _find_insulation_thickness(cls, description_lower, to_unheated_space):
if to_unheated_space:
desc_split = description_lower.split("to unheated space,")[-1].strip().split("(assumed)")[0].strip()
return search_split_description(desc_split)
@staticmethod
def _make_clean_output(has_dwelling_below):
def _make_clean_output(
has_dwelling_below, thermal_transmittence, thermal_transmittence_unit, to_unheated_space, assumed
) -> Dict[str, Union[str, bool, int, None]]:
return {
"has_dwelling_below": has_dwelling_below,
"thermal_transmittence": thermal_transmittence,
"thermal_transmittence_unit": thermal_transmittence_unit,
"to_unheated_space": to_unheated_space,
"assumed": assumed
}

View file

@ -1,5 +1,5 @@
from typing import Dict, Union, Optional
from epc_data.cleaning.cleaning_utils import extract_thermal_transmittence
from epc_data.cleaning.cleaning_utils import extract_thermal_transmittence, search_split_description
class CleanRoof:
@ -126,22 +126,8 @@ class CleanRoof:
}
@staticmethod
def _search_split_description(desc: str) -> str:
"""
Searches roof descriptions and looks for key words, determining a description about the roof's insulation.
:param desc: Description to be searched.
:return: Result of the search.
"""
if desc == "insulated":
return "average"
if desc == "limited":
return "below average"
raise NotImplementedError("Handle me")
@classmethod
def _find_insulation_thickness(
cls, description_lower: str, is_pitched: bool, is_roof_room: bool, is_flat: bool
description_lower: str, is_pitched: bool, is_roof_room: bool, is_flat: bool
) -> Union[int, str, None]:
"""
Finds insulation thickness in the description.
@ -168,7 +154,7 @@ class CleanRoof:
if "invalid input" in description_lower:
return None
desc = description_lower.split("pitched,")[-1].strip().split(" ")[0]
return cls._search_split_description(desc)
return search_split_description(desc)
if is_roof_room:
desc_split_lookup = {
@ -182,11 +168,11 @@ class CleanRoof:
return res
desc = desc_split.split(" ")[0]
return cls._search_split_description(desc)
return search_split_description(desc)
if is_flat:
# Just search for specific phrases
desc = description_lower.split("flat,")[-1].lstrip().split(" ")[0]
return cls._search_split_description(desc)
return search_split_description(desc)
return None

View file

@ -27,3 +27,17 @@ def extract_thermal_transmittence(description_lower: str) -> Tuple[Union[float,
unit = None
return u_value, unit
def search_split_description(desc: str) -> str:
"""
Searches split descriptions and looks for key words, determining a description about the roof's/floor's insulation.
:param desc: Description to be searched.
:return: Result of the search.
"""
if desc == "insulated":
return "average"
if desc == "limited":
return "below average"
raise NotImplementedError("Handle me")

View file

@ -32,12 +32,6 @@ class TestEpcClean:
self.cleaner._init_empty_cleaned_obj()
assert all([len(values) == 0 for values in self.cleaner.cleaned.values()])
def test__search_split_roof_description(self):
assert CleanRoof._search_split_description("insulated") == "average"
assert CleanRoof._search_split_description("limited") == "below average"
with pytest.raises(NotImplementedError):
CleanRoof._search_split_description("unknown")
def test__find_insulation_thickness(self):
assert CleanRoof._find_insulation_thickness("no insulation", False, False, False) == 0

View file

@ -1,6 +1,14 @@
from epc_data.cleaning.cleaning_utils import extract_thermal_transmittence
import pytest
from epc_data.cleaning.cleaning_utils import extract_thermal_transmittence, search_split_description
def test__extract_thermal_transmittence():
description = "U-value of 2.3 w/m-¦k"
assert extract_thermal_transmittence(description) == (2.3, "w/m-¦k")
def test__search_split_roof_description():
assert search_split_description("insulated") == "average"
assert search_split_description("limited") == "below average"
with pytest.raises(NotImplementedError):
search_split_description("unknown")