mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
Coerce banded flat_location string to its floor integer 🟩
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
862a7ccc61
commit
48760971a7
1 changed files with 14 additions and 1 deletions
|
|
@ -2549,7 +2549,9 @@ class EpcPropertyDataMapper:
|
||||||
SapFlatDetails(
|
SapFlatDetails(
|
||||||
level=schema.sap_flat_details.level,
|
level=schema.sap_flat_details.level,
|
||||||
top_storey=schema.sap_flat_details.top_storey,
|
top_storey=schema.sap_flat_details.top_storey,
|
||||||
flat_location=schema.sap_flat_details.flat_location,
|
flat_location=_flat_location_int(
|
||||||
|
schema.sap_flat_details.flat_location
|
||||||
|
),
|
||||||
heat_loss_corridor=schema.sap_flat_details.heat_loss_corridor,
|
heat_loss_corridor=schema.sap_flat_details.heat_loss_corridor,
|
||||||
storey_count=schema.sap_flat_details.storey_count,
|
storey_count=schema.sap_flat_details.storey_count,
|
||||||
unheated_corridor_length_m=(
|
unheated_corridor_length_m=(
|
||||||
|
|
@ -3111,6 +3113,17 @@ def _clear_basement_flag_when_system_built(
|
||||||
return replace(epc, sap_building_parts=new_parts)
|
return replace(epc, sap_building_parts=new_parts)
|
||||||
|
|
||||||
|
|
||||||
|
def _flat_location_int(value: Any) -> int:
|
||||||
|
"""`sap_flat_details.flat_location` is the flat's floor number, lodged by the
|
||||||
|
gov API as a plain int on most certs but as a banded string `"20+"` (floor 20
|
||||||
|
or above) on high floors. The `epc_flat_details.flat_location` column is a
|
||||||
|
NOT-NULL integer, so the raw band crashed the modelling_e2e insert. Coerce the
|
||||||
|
band to its floor (`"20+"` → 20); Elmhurst caps the floor number at 30."""
|
||||||
|
if isinstance(value, int):
|
||||||
|
return value
|
||||||
|
return int(str(value).strip().rstrip("+"))
|
||||||
|
|
||||||
|
|
||||||
def _measurement_value(field: Any) -> float:
|
def _measurement_value(field: Any) -> float:
|
||||||
"""SAP measurements arrive as a `Measurement` (with `.value`), a raw dict
|
"""SAP measurements arrive as a `Measurement` (with `.value`), a raw dict
|
||||||
{'value': N, 'quantity': '...'} when `from_dict` didn't coerce, or a plain
|
{'value': N, 'quantity': '...'} when `from_dict` didn't coerce, or a plain
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue