Guarantee every measure column on every scenario sheet 🟩

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Khalim Conn-Kowlessar 2026-07-13 23:10:16 +00:00
parent 04be6b57a2
commit 23ff1e73a8

View file

@ -41,6 +41,9 @@ MEASURE_COLUMNS: tuple[str, ...] = (
"system_tune_up_zoned",
)
# Property identity columns, leading every sheet before the measure columns.
_ID_COLUMNS: tuple[str, ...] = ("property_id", "landlord_property_id")
@dataclass(frozen=True)
class ExportMeasure:
@ -108,14 +111,19 @@ def shape_scenario_sheet(
properties: Sequence[PropertyScenarioData],
) -> ExportSheet:
"""Shape one Scenario's Properties into a wide export sheet (ADR-0065)."""
columns: tuple[str, ...] = ("property_id", "landlord_property_id")
columns: tuple[str, ...] = _ID_COLUMNS + MEASURE_COLUMNS
rows: list[dict[str, Any]] = []
for prop in properties:
row: dict[str, Any] = {
"property_id": prop.property_id,
"landlord_property_id": prop.landlord_property_id,
}
# Every measure column is present, blank unless this Property has it, so
# all scenario sheets share one contract (ADR-0065).
for column in MEASURE_COLUMNS:
row[column] = ""
for measure in prop.measures:
row[measure.measure_type] = measure.estimated_cost
if measure.measure_type in MEASURE_COLUMNS:
row[measure.measure_type] = measure.estimated_cost
rows.append(row)
return ExportSheet(columns=columns, rows=tuple(rows))