diff --git a/backend/epc_client/client.py b/backend/epc_client/client.py index 33f25ef5..0e3b48fc 100644 --- a/backend/epc_client/client.py +++ b/backend/epc_client/client.py @@ -7,7 +7,11 @@ from typing import Callable, Optional import httpx import pandas as pd -from backend.epc_client.exceptions import EpcApiError, EpcNotFoundError, EpcRateLimitError +from backend.epc_client.exceptions import ( + EpcApiError, + EpcNotFoundError, + EpcRateLimitError, +) from backend.epc_client._retry import call_with_retry from datatypes.epc.domain.epc_property_data import EpcPropertyData from datatypes.epc.domain.mapper import EpcPropertyDataMapper @@ -26,6 +30,7 @@ class EpcSearchResult: current_energy_efficiency_band: str registration_date: str + @property def full_address(self) -> str: parts = [ self.address_line_1, @@ -68,12 +73,16 @@ class EpcClientService: return None # Round 1: score on addressLine1 only - cert_num = self._pick_best_cert(candidates, address, use_full_address=False, fn=get_uprn_candidates) + cert_num = self._pick_best_cert( + candidates, address, use_full_address=False, fn=get_uprn_candidates + ) if cert_num: return self._safe_get(cert_num) # Round 2: score on all address lines joined - cert_num = self._pick_best_cert(candidates, address, use_full_address=True, fn=get_uprn_candidates) + cert_num = self._pick_best_cert( + candidates, address, use_full_address=True, fn=get_uprn_candidates + ) if cert_num: return self._safe_get(cert_num) @@ -145,14 +154,18 @@ class EpcClientService: use_full_address: bool, fn: Callable[..., pd.DataFrame], ) -> Optional[str]: - df = pd.DataFrame([ - { - "address": r.full_address() if use_full_address else r.address_line_1, - "uprn": str(r.uprn) if r.uprn is not None else "", - "certificate_number": r.certificate_number, - } - for r in candidates - ]) + df = pd.DataFrame( + [ + { + "address": ( + r.full_address() if use_full_address else r.address_line_1 + ), + "uprn": str(r.uprn) if r.uprn is not None else "", + "certificate_number": r.certificate_number, + } + for r in candidates + ] + ) scored = fn(df, user_address=user_address) if scored.empty: