mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
60 lines
2.4 KiB
Python
60 lines
2.4 KiB
Python
from datetime import datetime
|
|
|
|
from datatypes.epc.surveys.pashub_rdsap_site_notes import (
|
|
General,
|
|
PasHubRdSapSiteNotes,
|
|
)
|
|
|
|
|
|
class PasHubRdSapSiteNotesExtractor:
|
|
def __init__(self, text_list: list[str]) -> None:
|
|
self.text_list = text_list
|
|
|
|
def _get(self, key: str, offset: int = 1) -> str | None:
|
|
try:
|
|
idx = self.text_list.index(key)
|
|
return self.text_list[idx + offset].strip() or None
|
|
except (ValueError, IndexError):
|
|
return None
|
|
|
|
def _bool(self, key: str, offset: int = 1) -> bool:
|
|
val = self._get(key, offset)
|
|
return val is not None and val.lower() == "yes"
|
|
|
|
def extract(self) -> PasHubRdSapSiteNotes:
|
|
raise NotImplementedError
|
|
|
|
def extract_general(self) -> General:
|
|
inspection_date_raw = self._get("Inspection Date:")
|
|
inspection_date = (
|
|
datetime.strptime(inspection_date_raw, "%d/%m/%Y").strftime("%Y-%m-%d")
|
|
if inspection_date_raw
|
|
else ""
|
|
)
|
|
|
|
storeys_raw = self._get("Number of storeys:") or "0"
|
|
extensions_raw = self._get("Number of Extensions:") or "0"
|
|
|
|
return General(
|
|
epc_checked_before_assessment=self._bool(
|
|
"Confirm you have checked for the existence of an", offset=2
|
|
),
|
|
epc_exists_at_point_of_assessment=self._bool(
|
|
"Does an EPC exist at the point of carrying out this", offset=2
|
|
),
|
|
inspection_date=inspection_date,
|
|
transaction_type=self._get("Transaction Type:") or "",
|
|
tenure=self._get("Tenure:") or "",
|
|
property_type=self._get("Type of Property:") or "",
|
|
detachment_type=self._get("Detachment Type:") or "",
|
|
number_of_storeys=int(storeys_raw.split()[0]),
|
|
terrain_type=self._get("Terrain Type:") or "",
|
|
number_of_extensions=int(extensions_raw.split()[0]),
|
|
electricity_smart_meter=self._bool("Is an electricity smart meter present?"),
|
|
electric_meter_type=self._get("Electric meter type:") or "",
|
|
dwelling_export_capable=self._bool("Is the dwelling export-capable?"),
|
|
mains_gas_available=self._bool("Is mains gas available?"),
|
|
gas_smart_meter=self._bool("Is there a gas smart meter?"),
|
|
gas_meter_accessible=self._bool("Is the gas meter accessible?"),
|
|
measurements_location=self._get("Select Measurements Location:") or "",
|
|
)
|