diff --git a/backend/Property.py b/backend/Property.py index 584e1442..6577ba62 100644 --- a/backend/Property.py +++ b/backend/Property.py @@ -111,6 +111,8 @@ class Property: self.measures = ast.literal_eval(measures) if measures else None self.uprn = epc_record.get("uprn") + self.uprn_source = self.data["uprn-source"] + self.full_sap_epc = epc_record.get("full_sap_epc") self.in_conservation_area, self.is_listed, self.is_heritage = None, None, None self.restricted_measures = False diff --git a/backend/SearchEpc.py b/backend/SearchEpc.py index e7e717ac..367d8c85 100644 --- a/backend/SearchEpc.py +++ b/backend/SearchEpc.py @@ -126,6 +126,9 @@ class SearchEpc: combinations about the home to find the property """ + # If we create the uprn based on a hash, we mark it as simulated + UPRN_SOURCE_SIMULATED = "SIMULATED" + MAX_RETRIES = 5 SUCCESS = { @@ -405,8 +408,11 @@ class SearchEpc: else: raise ValueError("Multiple UPRNs found - investigate me") - # If we do not have a UPRN, we create one based on a hash of the address & postcoce - uprn = uprns.pop() if uprns else hash(self.address1 + self.postcode) + if uprns: + uprn = uprns.pop() + else: + newest_epc["uprn-source"] = self.UPRN_SOURCE_SIMULATED + uprn = hash(self.address1 + self.postcode) if self.fast: return newest_epc, [], {}, "", "", None diff --git a/etl/customers/eon/pilot_asset_list.py b/etl/customers/eon/pilot_asset_list.py index 298b34ba..afed61e4 100644 --- a/etl/customers/eon/pilot_asset_list.py +++ b/etl/customers/eon/pilot_asset_list.py @@ -170,39 +170,35 @@ def app(): # For each property, retrieve UPRN with from the Ordnance Survey API. To do this, I have created a free # trial with Ordnance Survey with my personal account as a temporary solution. # Let's just pull the full EPC data for this - # asset_list_with_uprn = [] - # for row, property_meta in tqdm(raw_asset_list_base.iterrows(), total=raw_asset_list_base.shape[0]): - # if row <= 104: - # continue - # time.sleep(1.1) - # searcher = SearchEpc( - # address1=property_meta["address"], - # postcode=property_meta["postcode"], - # auth_token=EPC_AUTH_TOKEN, - # os_api_key=ORDNANCE_SURVEY_API_KEY, - # full_address=", ".join([property_meta["address"], property_meta["postcode"]]) - # ) - # - # # Let's just find the UPRN - # searcher.ordnance_survey_client.get_places_api() - # - # uprn = searcher.ordnance_survey_client.most_relevant_result["UPRN"] - # - # # searcher.find_property(skip_os=False) - # - # asset_list_with_uprn.append( - # { - # **property_meta, - # "uprn": uprn, - # } - # ) + asset_list_with_uprn = [] + for row, property_meta in tqdm(raw_asset_list_base.iterrows(), total=raw_asset_list_base.shape[0]): + searcher = SearchEpc( + address1=property_meta["address"], + postcode=property_meta["postcode"], + auth_token=EPC_AUTH_TOKEN, + os_api_key=ORDNANCE_SURVEY_API_KEY, + full_address=", ".join([property_meta["address"], property_meta["postcode"]]) + ) + + searcher.find_property(skip_os=True) + uprn = searcher.uprn + # searcher.find_property(skip_os=False) + + asset_list_with_uprn.append( + { + **property_meta, + "uprn": uprn, + "matched_address": searcher.address1, + "matched_postcode": searcher.postcode + } + ) # Store this as a backup # import pandas as pd # asset_list_with_uprn_df = pd.DataFrame(asset_list_with_uprn) - # asset_list_with_uprn_df.to_csv("eon_asset_list_with_uprn.csv", index=False) + # asset_list_with_uprn_df.to_csv("eon_asset_list_with_uprn_2.csv", index=False) # Read in - asset_list_with_uprn = pd.read_csv("eon_asset_list_with_uprn.csv").to_dict(orient="records") + # asset_list_with_uprn = pd.read_csv("eon_asset_list_with_uprn.csv").to_dict(orient="records") # Store the asset list and create the portfolio payload asset_list_with_uprn_df = pd.DataFrame(asset_list_with_uprn)