mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
Thread the UPRN the PashubService has already resolved for a job into the PasHub site-notes mapper so the EpcPropertyData aggregate is born with its uprn set, and the existing save_epc_property_data path persists it. - EpcPropertyDataMapper.from_site_notes gains uprn: Optional[int] = None and sets it unconditionally (site notes never carry a UPRN natively). - parse_site_notes_pdf / _parse_pashub forward the uprn; the Elmhurst branch is untouched. - PashubService coerces uprn str -> int in one place, carries it on the internal upload record, and passes it into parse_site_notes_pdf. - No new lookups; jobs with no known UPRN still persist null, unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
32 lines
1.2 KiB
Python
32 lines
1.2 KiB
Python
from typing import List, Optional
|
|
|
|
from datatypes.epc.domain.epc_property_data import EpcPropertyData
|
|
from datatypes.epc.domain.mapper import EpcPropertyDataMapper
|
|
|
|
from backend.documents_parser.elmhurst_extractor import ElmhurstSiteNotesExtractor
|
|
from backend.documents_parser.extractor import PasHubRdSapSiteNotesExtractor
|
|
from backend.documents_parser.pdf import pdf_to_pages, pdf_to_text_list
|
|
|
|
|
|
def parse_site_notes_pdf(
|
|
file_path: str, uprn: Optional[int] = None
|
|
) -> EpcPropertyData:
|
|
with open(file_path, "rb") as f:
|
|
pdf_bytes = f.read()
|
|
pages = pdf_to_pages(pdf_bytes)
|
|
if "Elmhurst Energy Systems" in "\n".join(pages):
|
|
return _parse_elmhurst(pages)
|
|
return _parse_pashub(pdf_bytes, uprn=uprn)
|
|
|
|
|
|
def _parse_elmhurst(pages: List[str]) -> EpcPropertyData:
|
|
site_notes = ElmhurstSiteNotesExtractor(pages).extract()
|
|
return EpcPropertyDataMapper.from_elmhurst_site_notes(site_notes)
|
|
|
|
|
|
def _parse_pashub(
|
|
pdf_bytes: bytes, uprn: Optional[int] = None
|
|
) -> EpcPropertyData:
|
|
tokens = pdf_to_text_list(pdf_bytes)
|
|
site_notes = PasHubRdSapSiteNotesExtractor(tokens).extract()
|
|
return EpcPropertyDataMapper.from_site_notes(site_notes, uprn=uprn)
|