commented out epc data reading code

This commit is contained in:
Khalim Conn-Kowlessar 2024-08-22 10:31:03 +01:00
parent 1d82433b06
commit 71d82edb49
2 changed files with 48 additions and 20 deletions

View file

@ -1,18 +1,18 @@
import random # import random
from pathlib import Path # from pathlib import Path
import inspect # import inspect
import pandas as pd # import pandas as pd
#
# this can be used to get example data to build the test cases # # this can be used to get example data to build the test cases
src_file_path = inspect.getfile(lambda: None) # src_file_path = inspect.getfile(lambda: None)
EPC_DIRECTORY = Path(src_file_path).parent / "local_data" / "all-domestic-certificates" # 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()] # epc_directories = [entry for entry in EPC_DIRECTORY.iterdir() if entry.is_dir()]
directory = random.sample(epc_directories, 1)[0] # directory = random.sample(epc_directories, 1)[0]
data = pd.read_csv(directory / "certificates.csv", low_memory=False) # data = pd.read_csv(directory / "certificates.csv", low_memory=False)
# Rename the columns to the same format as the api returns # # Rename the columns to the same format as the api returns
data.columns = [c.replace("_", "-").lower() for c in data.columns] # data.columns = [c.replace("_", "-").lower() for c in data.columns]
#
eg = data.sample(1).to_dict("records")[0] # eg = data.sample(1).to_dict("records")[0]
testing_examples = [ testing_examples = [
{ {
@ -54,7 +54,12 @@ testing_examples = [
'lodgement-datetime': '2014-09-04 09:22:45', 'tenure': 'owner-occupied', '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, 'fixed-lighting-outlets-count': 10.0, 'low-energy-fixed-light-count': 7.0, 'uprn': 100110195416.0,
'uprn-source': 'Address Matched' 'uprn-source': 'Address Matched'
} },
"kwh": {
},
"recommendation_descripptions": [
]
} }
] ]

View file

@ -1,8 +1,10 @@
import pandas as pd 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 import pytest
from backend.Property import Property from backend.Property import Property
from etl.epc.Record import EPCRecord from etl.epc.Record import EPCRecord
from etl.bill_savings.KwhData import KwhData
from recommendations.HeatingRecommender import HeatingRecommender from recommendations.HeatingRecommender import HeatingRecommender
from recommendations.tests.test_data.heating_recommendations_data import testing_examples 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", 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( @pytest.mark.parametrize(
"test_case", "test_case",
testing_examples 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 With this function, we test out multiple heating descriptions and check which recomendations
we retrieve alongside them we retrieve alongside them
:return: :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_record = EPCRecord(
epc_records=epc_records, epc_records=epc_records,
@ -38,8 +54,15 @@ class TestHeatingRecommendations:
id=0, id=0,
postcode=test_case["epc"]["postcode"], postcode=test_case["epc"]["postcode"],
address=test_case["epc"]["address"], 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) recommender = HeatingRecommender(property_instance=p)
# Check they're empty # Check they're empty