Building rooms: single heating leaf per room¶
Context¶
Issue #1575: the building-rooms results graph showed the same quantity for centralized (thermal) and electric heating. Uploading only an electric factor should give 0 thermal / 100% electric; instead both appeared equal.
PR #1661 first split heating into heating_elec / heating_thermal leaves,
but emitted a room's kwh/m² against both leaves and zeroed the mismatched
one with an overloaded conversion_factor = 0. That approach was wrong on four
counts:
- It emitted a spurious
0.0row for the non-applicable heating leaf. - It overloaded
conversion_factoras a kill-switch — and a legitimate0.0(e.g. a carbon-free thermal network) was coerced to1.0by a falsyor. - It silently dropped all heating at ZZ level (missing/invalid
room_type), because the gate keyed onemission_type.parent. energy_typewas declared a value field yet read from a place inconsistent with the classification-based ingestion.
Approach¶
Decide the correct heating leaf once, up front, from the matched factor's
energy_type, so a room emits electric OR thermal — never both. Selection
moves out of the per-leaf formula and into emission-type resolution.
Changes¶
energy_type→ classification. Moved back tobuildings_classification_fields; alias-normalization dropped (stored values are alreadyelectric/thermal).- Resolve the factor's energy type in the service.
DataEntryEmissionService._get_building_energy_typereads the matched factor'sclassification.energy_type— cache-aware for bulk recalc, single DBgetotherwise. It fails loudly on a missing factor or an invalidenergy_typerather than silently dropping heating.Nonemeans "no matched factor → no heating". - Explicit dispatch, no smuggling.
resolve_emission_typestakes an explicit keywordbuilding_energy_typeand routes building rooms through_resolve_building_rooms(data, energy_type), which appends only the matchingheating_electric/heating_thermalleaf (WW leaf whenroom_typeis set, ZZ parent otherwise).data_entry.datais never mutated. - Enum rename.
EmissionType.buildings__rooms__heating_elec→heating_electric; frontend chart constants updated to match. - Formula simplified.
_compute_kwh_emissionno longer inspectsenergy_type.conversion_factorapplies to heating only, defaults to1.0, and an explicitis Nonecheck preserves a legitimate0.0.
Result¶
- A room with only an electric factor emits
0thermal /100%electric (and vice-versa). - Rollup no longer double-counts: 65.0, not 95.0.
- Corrupt/missing building factors fail loudly instead of vanishing heating.
Tests¶
- Unit —
test_buildings_schemas.py(formula +resolve_computationsselection),test_building_rooms_resolver.py(leaf selection per energy type and room-type presence),test_data_entry_emission_service.py(energy-type resolution, cache path, loud failure on corrupt factor). - Integration —
test_buildings_csv_pg.py: an electric factor emits only the electric leaf, a thermal factor only the thermal leaf, no double-count;test_strategy_b_rematch_pg.pyupdated for the enum rename.
Delivery¶
- Branch
fix/1661-refactor→ commit9f2d6bb8(fix) +206fdc8f(int()-cast cleanup onprimary_factor_id). - PR #1714 →
dev, closes #1575.
Follow-up¶
Frontend graph differentiation (issue #1465) is tracked separately.