mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-30 13:10:47 +00:00
Merge pull request #588 from Hestia-Homes/main
allowing us not to retrieve find my epc data, when we very clearly don't have the right epc
This commit is contained in:
commit
bb0fdf98eb
4 changed files with 34 additions and 37 deletions
|
|
@ -723,7 +723,7 @@ class GoogleSolarApi:
|
||||||
# We set the target rating to EPC C, which is the typical EPC rating we would expect the
|
# We set the target rating to EPC C, which is the typical EPC rating we would expect the
|
||||||
# property to achieve post retrofit of just the fabric
|
# property to achieve post retrofit of just the fabric
|
||||||
"energy_consumption": cls.estimate_new_consumption(
|
"energy_consumption": cls.estimate_new_consumption(
|
||||||
current_energy_efficiency=min(p.data["current-energy-efficiency"], 100),
|
current_energy_efficiency=min(int(p.data["current-energy-efficiency"]), 100),
|
||||||
target_efficiency="69",
|
target_efficiency="69",
|
||||||
current_consumption=p.estimate_electrical_consumption(
|
current_consumption=p.estimate_electrical_consumption(
|
||||||
assumed_ashp_efficiency=assumptions.AVERAGE_ASHP_EFFICIENCY, exclusions=body.exclusions
|
assumed_ashp_efficiency=assumptions.AVERAGE_ASHP_EFFICIENCY, exclusions=body.exclusions
|
||||||
|
|
|
||||||
|
|
@ -175,31 +175,19 @@ def chunked(iterable, size=100):
|
||||||
|
|
||||||
|
|
||||||
def fast_delete_recommendations(session, chunk):
|
def fast_delete_recommendations(session, chunk):
|
||||||
placeholders = ",".join([f"({i})" for i in range(len(chunk))])
|
placeholders = ",".join(["(:p{})".format(i) for i in range(len(chunk))])
|
||||||
|
params = {f"p{i}": chunk[i] for i in range(len(chunk))}
|
||||||
|
|
||||||
sql = text(f"""
|
sql = text(f"""
|
||||||
WITH ids(property_id) AS (
|
WITH ids(property_id) AS (
|
||||||
VALUES {placeholders}
|
VALUES {placeholders}
|
||||||
)
|
)
|
||||||
DELETE FROM recommendation r
|
DELETE FROM recommendation r
|
||||||
USING ids
|
USING ids
|
||||||
WHERE r.property_id = ids.property_id;
|
WHERE r.property_id = ids.property_id;
|
||||||
""")
|
""")
|
||||||
|
|
||||||
session.execute(sql, execution_options={"synchronize_session": False})
|
session.execute(sql, params, execution_options={"synchronize_session": False})
|
||||||
|
|
||||||
# Note; we may be able to go even faster like this:
|
|
||||||
# def delete_with_temp_table(session, chunk):
|
|
||||||
# session.execute(text("CREATE TEMP TABLE tmp_ids (id bigint) ON COMMIT DROP;"))
|
|
||||||
#
|
|
||||||
# insert_sql = "INSERT INTO tmp_ids (id) VALUES " + ",".join(f"({i})" for i in chunk)
|
|
||||||
# session.execute(text(insert_sql))
|
|
||||||
#
|
|
||||||
# session.execute(text("""
|
|
||||||
# DELETE FROM recommendation r
|
|
||||||
# USING tmp_ids t
|
|
||||||
# WHERE r.property_id = t.id;
|
|
||||||
# """))
|
|
||||||
|
|
||||||
|
|
||||||
def clear_portfolio(session: Session, portfolio_id: int, batch_size=100):
|
def clear_portfolio(session: Session, portfolio_id: int, batch_size=100):
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ def patch_epc(patch, epc_records):
|
||||||
if patch_variable in ["address", "postcode"]:
|
if patch_variable in ["address", "postcode"]:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if patch_value == "":
|
if patch_value in ["", None]:
|
||||||
continue
|
continue
|
||||||
if patch_variable in epc_records["original_epc"]:
|
if patch_variable in epc_records["original_epc"]:
|
||||||
epc_records["original_epc"][patch_variable] = patch_value
|
epc_records["original_epc"][patch_variable] = patch_value
|
||||||
|
|
|
||||||
|
|
@ -407,7 +407,10 @@ class RetrieveFindMyEpc:
|
||||||
)
|
)
|
||||||
|
|
||||||
if not extracted_table and not backup_flat:
|
if not extracted_table and not backup_flat:
|
||||||
raise ValueError("No EPC found")
|
# This is a relatively new change, as of November 2025, but we see cases where properties do not
|
||||||
|
# have data appearing on the find my EPC website, particularly for older EPCs. In this case, we allo
|
||||||
|
# for us to not find any information and return nothing
|
||||||
|
return None, None
|
||||||
|
|
||||||
if not extracted_table:
|
if not extracted_table:
|
||||||
extracted_table = deepcopy(backup_flat)
|
extracted_table = deepcopy(backup_flat)
|
||||||
|
|
@ -430,6 +433,11 @@ class RetrieveFindMyEpc:
|
||||||
|
|
||||||
if epc_page_source is None and rrn is None:
|
if epc_page_source is None and rrn is None:
|
||||||
chosen_epc, rrn = self._find_epc_page()
|
chosen_epc, rrn = self._find_epc_page()
|
||||||
|
if chosen_epc is None:
|
||||||
|
# We have no resulting data
|
||||||
|
logger.info("No EPC found for address %s, postcode %s", self.address, self.postcode)
|
||||||
|
return {}
|
||||||
|
|
||||||
address_response = requests.get(chosen_epc, headers=self.HEADERS)
|
address_response = requests.get(chosen_epc, headers=self.HEADERS)
|
||||||
epc_page_source = address_response.text
|
epc_page_source = address_response.text
|
||||||
address_res = BeautifulSoup(address_response.text, features="html.parser")
|
address_res = BeautifulSoup(address_response.text, features="html.parser")
|
||||||
|
|
@ -458,10 +466,11 @@ class RetrieveFindMyEpc:
|
||||||
current_sap = int(current_rating.split(' ')[-1])
|
current_sap = int(current_rating.split(' ')[-1])
|
||||||
|
|
||||||
if current_sap != self.sap_rating:
|
if current_sap != self.sap_rating:
|
||||||
raise ValueError(
|
# This means we likely have the wrong data. If we are in this scenario, we return nothing
|
||||||
f"SAP rating mismatch: expected {self.sap_rating}, got {current_sap} for address {self.address}, "
|
return {
|
||||||
f"postcode {self.postcode}"
|
"epc_certificate": None,
|
||||||
)
|
"page_source": None,
|
||||||
|
}
|
||||||
|
|
||||||
# Retrieve the energy consumption
|
# Retrieve the energy consumption
|
||||||
bills = address_res.find('div', {'id': 'bills-affected'})
|
bills = address_res.find('div', {'id': 'bills-affected'})
|
||||||
|
|
@ -775,21 +784,21 @@ class RetrieveFindMyEpc:
|
||||||
"uprn": epc["uprn"],
|
"uprn": epc["uprn"],
|
||||||
"address": epc["address"],
|
"address": epc["address"],
|
||||||
"postcode": epc["postcode"],
|
"postcode": epc["postcode"],
|
||||||
"recommendations": find_epc_data["recommendations"],
|
"recommendations": find_epc_data.get("recommendations", []),
|
||||||
}
|
}
|
||||||
|
|
||||||
# We need to add the patch information
|
# We need to add the patch information
|
||||||
patch = {
|
patch = {
|
||||||
"current-energy-rating": find_epc_data["current_epc_rating"],
|
"current-energy-rating": find_epc_data.get("current_epc_rating"),
|
||||||
"current-energy-efficiency": find_epc_data["current_epc_efficiency"],
|
"current-energy-efficiency": find_epc_data.get("current_epc_efficiency"),
|
||||||
"potential-energy-rating": find_epc_data["potential_epc_rating"],
|
"potential-energy-rating": find_epc_data.get("potential_epc_rating"),
|
||||||
"potential-energy-efficiency": find_epc_data["potential_epc_efficiency"],
|
"potential-energy-efficiency": find_epc_data.get("potential_epc_efficiency"),
|
||||||
**find_epc_data["epc_data"],
|
**find_epc_data.get("epc_data", {}),
|
||||||
}
|
}
|
||||||
|
|
||||||
page_source = {
|
page_source = {
|
||||||
"rrn": find_epc_data["epc_certificate"],
|
"rrn": find_epc_data.get("epc_certificate"),
|
||||||
"page_source": find_epc_data["page_source"]
|
"page_source": find_epc_data.get("page_source")
|
||||||
}
|
}
|
||||||
|
|
||||||
return non_invasive_recommendations, patch, page_source
|
return non_invasive_recommendations, patch, page_source
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue