From 71d82edb49ac3df51ba013ca335ee7b9f99fb0d8 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Thu, 22 Aug 2024 10:31:03 +0100 Subject: [PATCH] commented out epc data reading code --- .../test_data/heating_recommendations_data.py | 37 +++++++++++-------- .../tests/test_heating_recommendations.py | 31 ++++++++++++++-- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/recommendations/tests/test_data/heating_recommendations_data.py b/recommendations/tests/test_data/heating_recommendations_data.py index 3cb80876..0656e917 100644 --- a/recommendations/tests/test_data/heating_recommendations_data.py +++ b/recommendations/tests/test_data/heating_recommendations_data.py @@ -1,18 +1,18 @@ -import random -from pathlib import Path -import inspect -import pandas as pd - -# this can be used to get example data to build the test cases -src_file_path = inspect.getfile(lambda: None) -EPC_DIRECTORY = Path(src_file_path).parent / "local_data" / "all-domestic-certificates" -epc_directories = [entry for entry in EPC_DIRECTORY.iterdir() if entry.is_dir()] -directory = random.sample(epc_directories, 1)[0] -data = pd.read_csv(directory / "certificates.csv", low_memory=False) -# Rename the columns to the same format as the api returns -data.columns = [c.replace("_", "-").lower() for c in data.columns] - -eg = data.sample(1).to_dict("records")[0] +# import random +# from pathlib import Path +# import inspect +# import pandas as pd +# +# # this can be used to get example data to build the test cases +# src_file_path = inspect.getfile(lambda: None) +# EPC_DIRECTORY = Path(src_file_path).parent / "local_data" / "all-domestic-certificates" +# epc_directories = [entry for entry in EPC_DIRECTORY.iterdir() if entry.is_dir()] +# directory = random.sample(epc_directories, 1)[0] +# data = pd.read_csv(directory / "certificates.csv", low_memory=False) +# # Rename the columns to the same format as the api returns +# data.columns = [c.replace("_", "-").lower() for c in data.columns] +# +# eg = data.sample(1).to_dict("records")[0] testing_examples = [ { @@ -54,7 +54,12 @@ testing_examples = [ 'lodgement-datetime': '2014-09-04 09:22:45', 'tenure': 'owner-occupied', 'fixed-lighting-outlets-count': 10.0, 'low-energy-fixed-light-count': 7.0, 'uprn': 100110195416.0, 'uprn-source': 'Address Matched' - } + }, + "kwh": { + }, + "recommendation_descripptions": [ + + ] } ] diff --git a/recommendations/tests/test_heating_recommendations.py b/recommendations/tests/test_heating_recommendations.py index 8857c343..76927702 100644 --- a/recommendations/tests/test_heating_recommendations.py +++ b/recommendations/tests/test_heating_recommendations.py @@ -1,8 +1,10 @@ import pandas as pd -from utils.s3 import read_dataframe_from_s3_parquet +import msgpack +from utils.s3 import read_dataframe_from_s3_parquet, read_from_s3 import pytest from backend.Property import Property from etl.epc.Record import EPCRecord +from etl.bill_savings.KwhData import KwhData from recommendations.HeatingRecommender import HeatingRecommender from recommendations.tests.test_data.heating_recommendations_data import testing_examples @@ -15,18 +17,32 @@ class TestHeatingRecommendations: bucket_name="retrofit-data-dev", file_key="sap_change_model/cleaning_dataset.parquet", ) + @pytest.fixture + def cleaned(self): + df = read_from_s3( + s3_file_name="cleaned_epc_data/cleaned.bson", + bucket_name="retrofit-data-dev" + ) + + df = msgpack.unpackb(df, raw=False) + return df + + @pytest.fixture + def kwh_client(self): + return KwhData(bucket="retrofit-data-dev", read_consumption_data=True) + @pytest.mark.parametrize( "test_case", testing_examples ) - def test_recommend(self, test_case, cleaning_data): + def test_recommend(self, test_case, cleaning_data, cleaned, kwh_client): """ With this function, we test out multiple heating descriptions and check which recomendations we retrieve alongside them :return: """ - epc_records = {"original_epc": test_case["epc"], "full_sap_epc": {}, "old_data": []} + epc_records = {"original_epc": test_case["epc"].copy(), "full_sap_epc": {}, "old_data": []} epc_record = EPCRecord( epc_records=epc_records, @@ -38,8 +54,15 @@ class TestHeatingRecommendations: id=0, postcode=test_case["epc"]["postcode"], address=test_case["epc"]["address"], - epc_record=epc_record + epc_record=epc_record, + energy_assessment={ + "condition": {}, + "energy_assessment_is_newer": False + } ) + # TODO: Implement me + kwh_predictions = test_case["kwhs"] + p.set_features(cleaned=cleaned, kwh_client=kwh_client, kwh_predictions=kwh_predictions) recommender = HeatingRecommender(property_instance=p) # Check they're empty