From 5becd8d11bee83cc39b6134fdc67786bb7cbbd8a Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Fri, 12 Jan 2024 11:21:13 +0000 Subject: [PATCH] fixed existing unit tests --- backend/tests/test_sap_model_prep.py | 31 +++++++++++++------ etl/solar/SolarPhotoSupply.py | 7 +++++ recommendations/tests/test_costs.py | 6 ++-- .../tests/test_roof_recommendations.py | 4 +-- .../tests/test_window_recommendations.py | 21 ++++++++----- 5 files changed, 48 insertions(+), 21 deletions(-) diff --git a/backend/tests/test_sap_model_prep.py b/backend/tests/test_sap_model_prep.py index c1ff514e..89c436ce 100644 --- a/backend/tests/test_sap_model_prep.py +++ b/backend/tests/test_sap_model_prep.py @@ -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) diff --git a/etl/solar/SolarPhotoSupply.py b/etl/solar/SolarPhotoSupply.py index 1a80c37a..180cd6f5 100644 --- a/etl/solar/SolarPhotoSupply.py +++ b/etl/solar/SolarPhotoSupply.py @@ -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) & diff --git a/recommendations/tests/test_costs.py b/recommendations/tests/test_costs.py index 1d519b91..ab822322 100644 --- a/recommendations/tests/test_costs.py +++ b/recommendations/tests/test_costs.py @@ -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): diff --git a/recommendations/tests/test_roof_recommendations.py b/recommendations/tests/test_roof_recommendations.py index c1a7dfd9..75b7ddb2 100644 --- a/recommendations/tests/test_roof_recommendations.py +++ b/recommendations/tests/test_roof_recommendations.py @@ -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 diff --git a/recommendations/tests/test_window_recommendations.py b/recommendations/tests/test_window_recommendations.py index f103299d..664a1e39 100644 --- a/recommendations/tests/test_window_recommendations.py +++ b/recommendations/tests/test_window_recommendations.py @@ -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,