making full_address property

This commit is contained in:
Khalim Conn-Kowlessar 2026-04-28 12:04:46 +00:00
parent 001e9ce882
commit cadf8836d1

View file

@ -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: