mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
fixed existing unit tests
This commit is contained in:
parent
7969f51733
commit
5becd8d11b
5 changed files with 48 additions and 21 deletions
|
|
@ -7,7 +7,6 @@ import pytest
|
|||
import msgpack
|
||||
|
||||
from utils.s3 import read_dataframe_from_s3_parquet, read_from_s3
|
||||
from tqdm import tqdm
|
||||
|
||||
|
||||
# Handy code for selecting testing data
|
||||
|
|
@ -121,7 +120,21 @@ class TestSapModelPrep:
|
|||
cleaned = msgpack.unpackb(cleaned, raw=False)
|
||||
return cleaned
|
||||
|
||||
def test_fill_cavity_wall(self, cleaned, cleaning_data):
|
||||
@pytest.fixture
|
||||
def photo_supply_lookup(self):
|
||||
photo_supply_lookup = read_dataframe_from_s3_parquet(
|
||||
bucket_name="retrofit-data-dev", file_key="solar_pv_supply/photo_supply_lookup.parquet",
|
||||
)
|
||||
return photo_supply_lookup
|
||||
|
||||
@pytest.fixture
|
||||
def floor_area_decile_thresholds(self):
|
||||
floor_area_decile_thresholds = read_dataframe_from_s3_parquet(
|
||||
bucket_name="retrofit-data-dev", file_key="solar_pv_supply/floor_area_decile_thresholds.parquet",
|
||||
)
|
||||
return floor_area_decile_thresholds
|
||||
|
||||
def test_fill_cavity_wall(self, cleaned, cleaning_data, photo_supply_lookup, floor_area_decile_thresholds):
|
||||
"""
|
||||
We ensure that the process that prepares the data in the engine code results in the same data as
|
||||
the model is trained on
|
||||
|
|
@ -290,7 +303,7 @@ class TestSapModelPrep:
|
|||
address=starting_epc["address1"],
|
||||
data=starting_epc
|
||||
)
|
||||
home.get_components(cleaned)
|
||||
home.get_components(cleaned, photo_supply_lookup, floor_area_decile_thresholds)
|
||||
|
||||
data_processor = DataProcessor(None, newdata=True)
|
||||
data_processor.insert_data(pd.DataFrame([home.get_model_data()]))
|
||||
|
|
@ -354,7 +367,7 @@ class TestSapModelPrep:
|
|||
|
||||
assert test_record[c].values[0] == row[c]
|
||||
|
||||
def test_internal_wall_insulation(self, cleaned, cleaning_data):
|
||||
def test_internal_wall_insulation(self, cleaned, cleaning_data, photo_supply_lookup, floor_area_decile_thresholds):
|
||||
|
||||
starting_epc2 = {
|
||||
'low-energy-fixed-light-count': '2', 'address': 'FLAT 12, WAREHOUSE W, 3 WESTERN GATEWAY',
|
||||
|
|
@ -509,7 +522,7 @@ class TestSapModelPrep:
|
|||
address=starting_epc2["address1"],
|
||||
data=starting_epc2
|
||||
)
|
||||
home2.get_components(cleaned)
|
||||
home2.get_components(cleaned, photo_supply_lookup, floor_area_decile_thresholds)
|
||||
home2.set_number_lighting_outlets(None)
|
||||
|
||||
data_processor2 = DataProcessor(None, newdata=True)
|
||||
|
|
@ -575,7 +588,7 @@ class TestSapModelPrep:
|
|||
|
||||
assert test_record2[c].values[0] == row2[c]
|
||||
|
||||
def test_ventilation(self, cleaned, cleaning_data):
|
||||
def test_ventilation(self, cleaned, cleaning_data, photo_supply_lookup, floor_area_decile_thresholds):
|
||||
|
||||
starting_epc3 = {
|
||||
'low-energy-fixed-light-count': '', 'address': '45 Shepperson Road', 'uprn-source': 'Energy Assessor',
|
||||
|
|
@ -728,7 +741,7 @@ class TestSapModelPrep:
|
|||
address=starting_epc3["address1"],
|
||||
data=starting_epc3
|
||||
)
|
||||
home3.get_components(cleaned)
|
||||
home3.get_components(cleaned, photo_supply_lookup, floor_area_decile_thresholds)
|
||||
home3.set_number_lighting_outlets(None)
|
||||
|
||||
data_processor3 = DataProcessor(None, newdata=True)
|
||||
|
|
@ -778,7 +791,7 @@ class TestSapModelPrep:
|
|||
|
||||
assert test_record3[c].values[0] == row3[c]
|
||||
|
||||
def test_fireplaces(self, cleaned, cleaning_data):
|
||||
def test_fireplaces(self, cleaned, cleaning_data, photo_supply_lookup, floor_area_decile_thresholds):
|
||||
|
||||
starting_epc4 = {
|
||||
'low-energy-fixed-light-count': '', 'address': '9 Glebe Road, Asfordby Hill',
|
||||
|
|
@ -936,7 +949,7 @@ class TestSapModelPrep:
|
|||
address=starting_epc4["address1"],
|
||||
data=starting_epc4
|
||||
)
|
||||
home4.get_components(cleaned)
|
||||
home4.get_components(cleaned, photo_supply_lookup, floor_area_decile_thresholds)
|
||||
home4.set_number_lighting_outlets(None)
|
||||
|
||||
data_processor4 = DataProcessor(None, newdata=True)
|
||||
|
|
|
|||
|
|
@ -199,6 +199,13 @@ class SolarPhotoSupply:
|
|||
|
||||
# Convert the tenure to lower case, as is done in the creation of the dataset
|
||||
tenure = tenure.lower()
|
||||
# We remap the "not defined"
|
||||
tenure = {
|
||||
"not defined - use in the case of a new dwelling for which the intended tenure in not known. it is not to "
|
||||
"be used for an existing dwelling":
|
||||
"not defined - use in the case of a new dwelling for which the intended tenure in not known. it is no"
|
||||
}.get(tenure, tenure)
|
||||
|
||||
photo_supply_matched = photo_supply_lookup[
|
||||
(photo_supply_lookup["tenure"] == tenure) &
|
||||
(photo_supply_lookup["built_form"] == built_form) &
|
||||
|
|
|
|||
|
|
@ -58,9 +58,9 @@ class TestCosts:
|
|||
)
|
||||
|
||||
assert loft_results == {
|
||||
'total': 430.21445040000003, 'subtotal': 358.512042, 'vat': 71.70240840000001,
|
||||
'contingency': 25.608003000000004, 'preliminaries': 25.608003000000004, 'material': 198.29923000000002,
|
||||
'profit': 51.21600600000001, 'labour_hours': 3.685, 'labour_cost': 57.7808, 'labour_days': 0.460625
|
||||
'total': 639.4133610000001, 'subtotal': 532.8444675000001, 'vat': 106.56889350000002,
|
||||
'contingency': 71.045929, 'preliminaries': 35.5229645, 'material': 297.448845, 'profit': 71.045929,
|
||||
'labour_hours': 3.685, 'labour_cost': 57.7808, 'labour_days': 0.460625
|
||||
}
|
||||
|
||||
def test_internal_wall_insulation(self):
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ class TestRoofRecommendations:
|
|||
|
||||
assert len(roof_recommender2.recommendations) == 1
|
||||
|
||||
assert roof_recommender2.recommendations[0]["total"] == 1310.56464
|
||||
assert roof_recommender2.recommendations[0]["total"] == 1936.9206000000004
|
||||
assert roof_recommender2.recommendations[0]["new_u_value"] == 0.14
|
||||
assert roof_recommender2.recommendations[0]["starting_u_value"] == 0.68
|
||||
|
||||
|
|
@ -104,7 +104,7 @@ class TestRoofRecommendations:
|
|||
|
||||
assert len(roof_recommender4.recommendations) == 4
|
||||
|
||||
assert roof_recommender4.recommendations[0]["total"] == 788.0544
|
||||
assert roof_recommender4.recommendations[0]["total"] == 1128.744
|
||||
assert roof_recommender4.recommendations[0]["new_u_value"] == 0.15
|
||||
assert roof_recommender4.recommendations[0]["starting_u_value"] == 0.3
|
||||
assert roof_recommender4.recommendations[0]["parts"][0]["depth"] == 150
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@ class TestWindowRecommendations:
|
|||
address='1',
|
||||
data={
|
||||
"county": "Wychavon",
|
||||
"multi-glaze-proportion": 0
|
||||
"multi-glaze-proportion": 0,
|
||||
"uprn": 0
|
||||
}
|
||||
)
|
||||
property_1.windows = {
|
||||
|
|
@ -53,7 +54,8 @@ class TestWindowRecommendations:
|
|||
address='1',
|
||||
data={
|
||||
"county": "Wychavon",
|
||||
"multi-glaze-proportion": 33
|
||||
"multi-glaze-proportion": 33,
|
||||
"uprn": 0
|
||||
}
|
||||
)
|
||||
property_2.windows = {'original_description': 'Mostly double glazing', 'has_glazing': True,
|
||||
|
|
@ -86,7 +88,8 @@ class TestWindowRecommendations:
|
|||
address='1',
|
||||
data={
|
||||
"county": "Wychavon",
|
||||
"multi-glaze-proportion": 80
|
||||
"multi-glaze-proportion": 80,
|
||||
"uprn": 0
|
||||
}
|
||||
)
|
||||
property_3.windows = {'original_description': 'Fully double glazed', 'has_glazing': True,
|
||||
|
|
@ -109,7 +112,8 @@ class TestWindowRecommendations:
|
|||
address='1',
|
||||
data={
|
||||
"county": "Wychavon",
|
||||
"multi-glaze-proportion": 100
|
||||
"multi-glaze-proportion": 100,
|
||||
"uprn": 0
|
||||
}
|
||||
)
|
||||
property_4.windows = {'original_description': 'Full secondary glazing', 'has_glazing': True,
|
||||
|
|
@ -132,7 +136,8 @@ class TestWindowRecommendations:
|
|||
address='1',
|
||||
data={
|
||||
"county": "Wychavon",
|
||||
"multi-glaze-proportion": 50
|
||||
"multi-glaze-proportion": 50,
|
||||
"uprn": 0
|
||||
}
|
||||
)
|
||||
property_5.windows = {'original_description': 'Partial secondary glazing', 'has_glazing': True,
|
||||
|
|
@ -161,7 +166,8 @@ class TestWindowRecommendations:
|
|||
address='1',
|
||||
data={
|
||||
"county": "Wychavon",
|
||||
"multi-glaze-proportion": 0
|
||||
"multi-glaze-proportion": 0,
|
||||
"uprn": 0
|
||||
}
|
||||
)
|
||||
property_6.windows = {'original_description': 'Single glazed', 'has_glazing': False, 'glazing_coverage': None,
|
||||
|
|
@ -195,7 +201,8 @@ class TestWindowRecommendations:
|
|||
address='1',
|
||||
data={
|
||||
"county": "Wychavon",
|
||||
"multi-glaze-proportion": 100
|
||||
"multi-glaze-proportion": 100,
|
||||
"uprn": 0
|
||||
}
|
||||
)
|
||||
property_7.windows = {'original_description': 'Fully triple glazed', 'has_glazing': True,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue