mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-22 08:48:38 +00:00
build_prediction_target assembles an EPC-less Property's PredictionTarget from its identity (postcode), resolved coordinates, and Landlord-Override attributes (property_type / built_form / wall_construction). The eligibility GATE: a Property whose property_type is unknown returns None — never sized from a mixed-type cohort (ADR-0031). property_type is the hard cohort filter. The override attributes are read through a PredictionTargetAttributesReader port (stub seam) — the real adapter (a read over property_overrides) is being built separately by the team; ingestion wiring depends on the abstraction and tests substitute a fake. 2 tests (assembly + gate); pyright strict clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
51 lines
2 KiB
Python
51 lines
2 KiB
Python
"""Assemble an EPC-less Property's PredictionTarget, with the eligibility gate
|
|
(ADR-0031 slice-5d).
|
|
|
|
A `PredictionTarget` needs the target's own known inputs: its postcode (to find
|
|
the cohort), coordinates (to distance-weight it), and the Landlord-Override
|
|
attributes that condition selection — `property_type` (the HARD cohort filter),
|
|
plus optional `built_form` / `wall_construction`. `property_type` is required: a
|
|
Property whose type is unknown is gated out (never sized from a mixed-type
|
|
cohort), so the builder returns None and the caller skips prediction.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from typing import Optional, Union
|
|
|
|
from domain.epc_prediction.comparable_properties import PredictionTarget
|
|
from domain.geospatial.coordinates import Coordinates
|
|
from domain.property.property import PropertyIdentity
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class PredictionTargetAttributes:
|
|
"""The target Property's own attributes resolved from Landlord Overrides,
|
|
needed to find and condition its cohort. `property_type` is the code-space
|
|
value the cohort EPCs carry (e.g. "2"); None means it could not be resolved,
|
|
which gates the Property out of prediction."""
|
|
|
|
property_type: Optional[str]
|
|
built_form: Optional[str] = None
|
|
wall_construction: Optional[Union[int, str]] = None
|
|
|
|
|
|
def build_prediction_target(
|
|
identity: PropertyIdentity,
|
|
coordinates: Optional[Coordinates],
|
|
attributes: PredictionTargetAttributes,
|
|
) -> Optional[PredictionTarget]:
|
|
"""The PredictionTarget for an EPC-less Property, or None when ineligible —
|
|
`property_type` is the hard cohort filter, so a Property whose type is unknown
|
|
is gated out of prediction (ADR-0031) rather than sized from a mixed-type
|
|
cohort."""
|
|
if attributes.property_type is None:
|
|
return None
|
|
return PredictionTarget(
|
|
postcode=identity.postcode,
|
|
property_type=attributes.property_type,
|
|
built_form=attributes.built_form,
|
|
wall_construction=attributes.wall_construction,
|
|
coordinates=coordinates,
|
|
)
|