mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-19 17:03:02 +00:00
55 lines
2.1 KiB
Python
55 lines
2.1 KiB
Python
"""The real ``PredictionTargetAttributesReader`` — landlord-overrides-backed.
|
|
|
|
Composes the faithful ``PropertyOverridesReader`` with the value→code mapping:
|
|
reads the Property's main-building (building_part 0) ``property_type`` /
|
|
``built_form_type`` overrides and translates them into the gov-EPC code space the
|
|
cohort filter compares against (ADR-0031). An unresolvable ``property_type``
|
|
becomes None, which gates the Property out of prediction downstream
|
|
(``build_prediction_target``). Wall/roof overrides are left to the later
|
|
``epc_with_overlay`` slice — this reader conditions cohort selection only.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Optional
|
|
|
|
from domain.epc.property_overrides.override_code_mapping import (
|
|
built_form_to_code,
|
|
property_type_to_code,
|
|
)
|
|
from domain.epc_prediction.prediction_target import PredictionTargetAttributes
|
|
from repositories.property.prediction_target_attributes_reader import (
|
|
PredictionTargetAttributesReader,
|
|
)
|
|
from repositories.property.property_overrides_reader import PropertyOverridesReader
|
|
|
|
_MAIN_BUILDING = 0
|
|
_PROPERTY_TYPE_COMPONENT = "property_type"
|
|
_BUILT_FORM_COMPONENT = "built_form_type"
|
|
|
|
|
|
class OverrideBackedPredictionAttributesReader(PredictionTargetAttributesReader):
|
|
def __init__(self, overrides_reader: PropertyOverridesReader) -> None:
|
|
self._overrides_reader = overrides_reader
|
|
|
|
def attributes_for(self, property_id: int) -> PredictionTargetAttributes:
|
|
overrides = self._overrides_reader.overrides_for(property_id)
|
|
|
|
property_type_value = overrides.value(_PROPERTY_TYPE_COMPONENT, _MAIN_BUILDING)
|
|
built_form_value = overrides.value(_BUILT_FORM_COMPONENT, _MAIN_BUILDING)
|
|
|
|
property_type: Optional[str] = (
|
|
property_type_to_code(property_type_value)
|
|
if property_type_value is not None
|
|
else None
|
|
)
|
|
built_form: Optional[str] = (
|
|
built_form_to_code(built_form_value)
|
|
if built_form_value is not None
|
|
else None
|
|
)
|
|
|
|
return PredictionTargetAttributes(
|
|
property_type=property_type,
|
|
built_form=built_form,
|
|
)
|