mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
renamed files and classes to be more reflective
This commit is contained in:
parent
bb5241b695
commit
31c8d0b5b2
10 changed files with 31 additions and 31 deletions
|
|
@ -1,13 +1,13 @@
|
|||
from typing import List, Dict, Any
|
||||
from collections import Counter
|
||||
|
||||
from epc_data.cleaning.Roof import CleanRoof
|
||||
from epc_data.cleaning.Floor import CleanFloor
|
||||
from epc_data.attributes.RoofAttributes import RoofAttributes
|
||||
from epc_data.attributes.FloorAttributes import FloorAttributes
|
||||
|
||||
|
||||
class EpcClean:
|
||||
"""
|
||||
Container for methods which we utilise for cleaning EPC data
|
||||
Container for methods which we utilise for attributes EPC data
|
||||
"""
|
||||
|
||||
CLEANING_FIELDS: List[str] = [
|
||||
|
|
@ -36,9 +36,9 @@ class EpcClean:
|
|||
for field in self.CLEANING_FIELDS:
|
||||
self.unique_vals[field] = Counter([v[field] for v in self.data])
|
||||
|
||||
self.clean_wrapper(field="roof-description", cleaning_cls=CleanRoof)
|
||||
self.clean_wrapper(field="roof-description", cleaning_cls=RoofAttributes)
|
||||
|
||||
# self.clean_wrapper(field="floor-description", cleaning_cls=CleanFloor)
|
||||
self.clean_wrapper(field="floor-description", cleaning_cls=FloorAttributes)
|
||||
|
||||
def _init_empty_cleaned_obj(self) -> None:
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -40,11 +40,11 @@ def handler():
|
|||
cleaner.clean()
|
||||
|
||||
# For testing:
|
||||
from epc_data.cleaning.Floor import CleanFloor
|
||||
from epc_data.attributes.FloorAttributes import FloorAttributes
|
||||
descriptions = {x["floor-description"] for x in data}
|
||||
out = []
|
||||
for description in descriptions:
|
||||
res = CleanFloor(description).clean()
|
||||
res = FloorAttributes(description).clean()
|
||||
out.append(
|
||||
{
|
||||
"original_description": description,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
from typing import Dict, Union, Optional
|
||||
from epc_data.cleaning.cleaning_utils import extract_thermal_transmittence, search_split_description
|
||||
from epc_data.attributes.attribute_utils import extract_thermal_transmittence, search_split_description
|
||||
|
||||
|
||||
class CleanFloor:
|
||||
class FloorAttributes:
|
||||
|
||||
def __init__(self, description: str):
|
||||
"""
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
from typing import Dict, Union, Optional
|
||||
from epc_data.cleaning.cleaning_utils import extract_thermal_transmittence, search_split_description
|
||||
from epc_data.attributes.attribute_utils import extract_thermal_transmittence, search_split_description
|
||||
|
||||
|
||||
class CleanRoof:
|
||||
class RoofAttributes:
|
||||
|
||||
def __init__(self, description):
|
||||
"""
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import pytest
|
||||
from epc_data.cleaning.cleaning_utils import extract_thermal_transmittence, search_split_description
|
||||
from epc_data.attributes.attribute_utils import extract_thermal_transmittence, search_split_description
|
||||
|
||||
|
||||
def test__extract_thermal_transmittence():
|
||||
|
|
@ -12,6 +12,6 @@ def test__search_split_roof_description():
|
|||
assert search_split_description("limited") == "below average"
|
||||
assert search_split_description("no insulation") == "none"
|
||||
assert search_split_description("limited insulation") == "below average"
|
||||
|
||||
|
||||
with pytest.raises(NotImplementedError):
|
||||
search_split_description("unknown")
|
||||
|
|
@ -1,62 +1,62 @@
|
|||
import pytest
|
||||
from epc_data.tests.test_data.EpcClean_test_floor_cases import clean_floor_cases
|
||||
from epc_data.cleaning.Floor import CleanFloor
|
||||
from epc_data.tests.test_data.test_floor_attributes_cases import clean_floor_cases
|
||||
from epc_data.attributes.FloorAttributes import FloorAttributes
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
class TestEpcClean:
|
||||
class TestCleanFloor:
|
||||
|
||||
@patch('epc_data.cleaning.cleaning_utils.search_split_description')
|
||||
@patch('epc_data.attributes.attribute_utils.search_split_description')
|
||||
def test_find_insulation_thickness_to_unheated_space(self, mock_search_split_description):
|
||||
# Set up the mock to return a specific value
|
||||
mock_search_split_description.return_value = 'average'
|
||||
|
||||
# clean_floor = CleanFloor('description to unheated space')
|
||||
insulation_thickness = CleanFloor._find_insulation_thickness(
|
||||
insulation_thickness = FloorAttributes._find_insulation_thickness(
|
||||
'to unheated space, insulated', True, False, False, False
|
||||
)
|
||||
|
||||
assert insulation_thickness == 'average'
|
||||
|
||||
@patch('epc_data.cleaning.cleaning_utils.search_split_description')
|
||||
@patch('epc_data.attributes.attribute_utils.search_split_description')
|
||||
def test_find_insulation_thickness_to_external_air(self, mock_search_split_description):
|
||||
# Set up the mock to return a specific value
|
||||
mock_search_split_description.return_value = 'below average'
|
||||
|
||||
# clean_floor = CleanFloor('To external air, limited insulation')
|
||||
insulation_thickness = CleanFloor._find_insulation_thickness(
|
||||
insulation_thickness = FloorAttributes._find_insulation_thickness(
|
||||
'to external air, limited insulation', False, True, False, False
|
||||
)
|
||||
|
||||
assert insulation_thickness == 'below average'
|
||||
|
||||
@patch('epc_data.cleaning.cleaning_utils.search_split_description')
|
||||
@patch('epc_data.attributes.attribute_utils.search_split_description')
|
||||
def test_find_insulation_thickness_is_suspended(self, mock_search_split_description):
|
||||
# Set up the mock to return a specific value
|
||||
mock_search_split_description.return_value = 'none'
|
||||
|
||||
# clean_floor = CleanFloor('description suspended')
|
||||
insulation_thickness = CleanFloor._find_insulation_thickness(
|
||||
insulation_thickness = FloorAttributes._find_insulation_thickness(
|
||||
'suspended, no insulation', False, False, True, False
|
||||
)
|
||||
|
||||
assert insulation_thickness == 'none'
|
||||
|
||||
@patch('epc_data.cleaning.cleaning_utils.search_split_description')
|
||||
@patch('epc_data.attributes.attribute_utils.search_split_description')
|
||||
def test_find_insulation_thickness_is_solid(self, mock_search_split_description):
|
||||
# Set up the mock to return a specific value
|
||||
mock_search_split_description.return_value = 'none'
|
||||
|
||||
# clean_floor = CleanFloor('description solid')
|
||||
insulation_thickness = CleanFloor._find_insulation_thickness(
|
||||
insulation_thickness = FloorAttributes._find_insulation_thickness(
|
||||
'solid, no insulation (assumed)', False, False, False, True
|
||||
)
|
||||
|
||||
assert insulation_thickness == 'none'
|
||||
|
||||
def test_find_insulation_thickness_not_handled(self):
|
||||
clean_floor = CleanFloor('description not handled')
|
||||
clean_floor = FloorAttributes('description not handled')
|
||||
with pytest.raises(NotImplementedError):
|
||||
clean_floor._find_insulation_thickness(
|
||||
'description not handled', False, False, False, False
|
||||
|
|
@ -64,7 +64,7 @@ class TestEpcClean:
|
|||
|
||||
def test_clean_floor(self):
|
||||
for test_case in clean_floor_cases:
|
||||
result = CleanFloor(test_case['original_description']).clean()
|
||||
result = FloorAttributes(test_case['original_description']).clean()
|
||||
# Ensure the output ordering is correct
|
||||
expected_result = {key: test_case[key] for key in result.keys()}
|
||||
expected_result["desc"] = test_case["original_description"]
|
||||
|
|
@ -2,8 +2,8 @@ import pytest
|
|||
import pickle
|
||||
from epc_data.EpcClean import EpcClean
|
||||
from pathlib import Path
|
||||
from epc_data.tests.test_data.EpcClean_test_roof_cases import clean_roof_test_cases
|
||||
from epc_data.cleaning.Roof import CleanRoof
|
||||
from epc_data.tests.test_data.test_roof_attributes_cases import clean_roof_test_cases
|
||||
from epc_data.attributes.RoofAttributes import RoofAttributes
|
||||
|
||||
# For local testing
|
||||
if __file__ == "<input>":
|
||||
|
|
@ -33,10 +33,10 @@ class TestEpcClean:
|
|||
assert all([len(values) == 0 for values in self.cleaner.cleaned.values()])
|
||||
|
||||
def test__find_insulation_thickness(self):
|
||||
assert CleanRoof._find_insulation_thickness("no insulation", False, False, False) == 0
|
||||
assert RoofAttributes._find_insulation_thickness("no insulation", False, False, False) == 0
|
||||
|
||||
def test_clean_roof(self):
|
||||
result = CleanRoof('Pitched, 270 mm loft insulation').clean()
|
||||
result = RoofAttributes('Pitched, 270 mm loft insulation').clean()
|
||||
|
||||
# change the expected output based on your requirement
|
||||
expected_output = {
|
||||
|
|
@ -57,7 +57,7 @@ class TestEpcClean:
|
|||
assert result == expected_output
|
||||
|
||||
for test_case in clean_roof_test_cases:
|
||||
result = CleanRoof(test_case['original_description']).clean()
|
||||
result = RoofAttributes(test_case['original_description']).clean()
|
||||
# Ensure the output ordering is correct
|
||||
expected_result = {key: test_case[key] for key in result.keys()}
|
||||
expected_result["desc"] = test_case["original_description"]
|
||||
|
|
@ -65,7 +65,7 @@ class TestEpcClean:
|
|||
assert result == expected_result
|
||||
|
||||
def test_clean_roof_with_dwelling_above(self):
|
||||
result = CleanRoof('(another dwelling above)').clean()
|
||||
result = RoofAttributes('(another dwelling above)').clean()
|
||||
|
||||
expected_output = {
|
||||
"is_valid": True,
|
||||
Loading…
Add table
Reference in a new issue