diff --git a/backend/SearchEpc.py b/backend/SearchEpc.py index db9ec4ff..4c329448 100644 --- a/backend/SearchEpc.py +++ b/backend/SearchEpc.py @@ -11,6 +11,7 @@ from BaseUtility import Definitions from utils.logger import setup_logger from typing import List from fuzzywuzzy import process +from backend.app.utils import sap_to_epc logger = setup_logger() @@ -554,7 +555,7 @@ class SearchEpc: # If loop finishes without a valid response, raise an exception raise Exception("Unable to find postcode data after trimming - investigate me") - def estimate_epc(self, property_type, built_form, lmks_to_drop=None): + def estimate_epc(self, property_type, built_form, lmks_to_drop=None, exclude_old=False): """ For a property that does not have an EPC, we retrieve the EPC data for the closest properties and estimate the EPC for the property in question. @@ -567,6 +568,7 @@ class SearchEpc: the ordnance survey api :param lmks_to_drop: This is a list of LMK keys that should be dropped from the estimation process. This is used as an override for testing, to drop EPCs for the property we are testing + :param exclude_old: Used to drop any expired EPCs (more than 10 years old) :return: """ @@ -584,6 +586,9 @@ class SearchEpc: # If we still have missing dates, we set it to the mean of the non NA dates epc_data["lodgement-datetime"] = epc_data["lodgement-datetime"].fillna(epc_data["lodgement-datetime"].mean()) + if exclude_old: + epc_data = epc_data[epc_data["lodgement-datetime"] > pd.Timestamp.now() - pd.DateOffset(years=10)] + # For each attribute, we need to determine the datatype and use an appropriate method # to estimate. estimated_epc = {} @@ -624,6 +629,8 @@ class SearchEpc: else: estimated_epc["lodgement-date"] = estimated_epc["lodgement-datetime"].strftime("%Y-%m-%d") + estimated_epc["current-energy-rating"] = sap_to_epc(estimated_epc["current-energy-efficiency"]) + estimated_epc["postcode"] = self.postcode estimated_epc["uprn"] = self.uprn estimated_epc["address"] = self.full_address diff --git a/etl/customers/eon/deck_examples.py b/etl/customers/eon/deck_examples.py new file mode 100644 index 00000000..8773ce09 --- /dev/null +++ b/etl/customers/eon/deck_examples.py @@ -0,0 +1,30 @@ +""" +This script contains bits of codes for examples to be included in the Deck +""" + +from backend.SearchEpc import SearchEpc +from dotenv import load_dotenv +import os + +load_dotenv(dotenv_path="backend/.env") + +EPC_AUTH_TOKEN = os.getenv("EPC_AUTH_TOKEN") + +searcher = SearchEpc( + address1="Flat above 7 Malling Road", + postcode="ME6 5AA", + auth_token=EPC_AUTH_TOKEN, + os_api_key="", + property_type=None, + fast=False, +) + +res = searcher.estimate_epc( + property_type="Flat", + built_form="Mid-Terrace", + lmks_to_drop=[ + "4c3714a59744ab2c6e60441f0fa0eb903f283c6c62d0691e108cadbc7b5a8caa", + "363197839762013013017062127708717", + "363197811132009091518041845968302" + ] +)