diff --git a/backend/onboarders/mappings/parity/as_built_floor_classifiers.py b/backend/onboarders/mappings/parity/as_built_floor_classifiers.py index 9f14fa7d..05894e61 100644 --- a/backend/onboarders/mappings/parity/as_built_floor_classifiers.py +++ b/backend/onboarders/mappings/parity/as_built_floor_classifiers.py @@ -1,4 +1,5 @@ -from backend.onboarders.epc_descriptions import EpcConstructionAgeBand, EpcFloorDescriptions +from datatypes.epc.construction_age_band import EpcConstructionAgeBand +from datatypes.epc.floor import EpcFloorDescriptions def unknown_floor_as_built(age_band: EpcConstructionAgeBand) -> EpcFloorDescriptions: @@ -25,7 +26,7 @@ def unknown_floor_retrofitted(age_band: EpcConstructionAgeBand) -> EpcFloorDescr return EpcFloorDescriptions.suspended_insulated -def solid_floor_as_built(age_band: EpcConstructionAgeBand) -> EpcFloorDescriptions: +def map_solid_floor_as_built(age_band: EpcConstructionAgeBand) -> EpcFloorDescriptions: year = age_band.start_year() if year >= 2003: @@ -35,7 +36,7 @@ def solid_floor_as_built(age_band: EpcConstructionAgeBand) -> EpcFloorDescriptio return EpcFloorDescriptions.solid_no_insulation_assumed -def suspended_floor_as_built(age_band: EpcConstructionAgeBand) -> EpcFloorDescriptions: +def map_suspended_floor_as_built(age_band: EpcConstructionAgeBand) -> EpcFloorDescriptions: year = age_band.start_year() if year >= 2003: @@ -44,3 +45,15 @@ def suspended_floor_as_built(age_band: EpcConstructionAgeBand) -> EpcFloorDescri return EpcFloorDescriptions.suspended_limited_insulation_assumed return EpcFloorDescriptions.suspended_no_insulation_assumed + + +as_built_floor_classifiers = { + "Solid": map_solid_floor_as_built, + "SuspendedTimber": map_suspended_floor_as_built, + "SuspendedNotTimber": map_suspended_floor_as_built, +} + +unknown_as_built_floor_classifiers = { + "RetroFitted": unknown_floor_retrofitted, + "AsBuilt": unknown_floor_as_built, +} diff --git a/backend/onboarders/mappings/parity/as_built_roof_classifiers.py b/backend/onboarders/mappings/parity/as_built_roof_classifiers.py index 7c672ce5..d5c883ba 100644 --- a/backend/onboarders/mappings/parity/as_built_roof_classifiers.py +++ b/backend/onboarders/mappings/parity/as_built_roof_classifiers.py @@ -1,7 +1,7 @@ from backend.onboarders.epc_descriptions import EpcConstructionAgeBand, EpcRoofDescriptions -def classify_flat_roof(age_band: EpcConstructionAgeBand) -> EpcRoofDescriptions: +def map_flat_roof(age_band: EpcConstructionAgeBand) -> EpcRoofDescriptions: """ For a flat, as built roof, these are the breakdowns: @@ -26,7 +26,7 @@ def classify_flat_roof(age_band: EpcConstructionAgeBand) -> EpcRoofDescriptions: return EpcRoofDescriptions.flat_no_insulation -def classify_sloping_ceiling_roof(age_band: EpcConstructionAgeBand) -> EpcRoofDescriptions: +def map_sloping_ceiling_roof(age_band: EpcConstructionAgeBand) -> EpcRoofDescriptions: """ For a sloping ceiling, as built roof, these are the breakdowns: 2023 onwards → Sloping pitched, insulated @@ -48,8 +48,8 @@ def classify_sloping_ceiling_roof(age_band: EpcConstructionAgeBand) -> EpcRoofDe return EpcRoofDescriptions.sloping_pitched_no_insulation -AS_BUILT_ROOF_CLASSIFIERS = { +as_built_roof_classifiers = { # Only need to apply this to flat and sloping ceiling roofs - "Flat": classify_flat_roof, - "PitchedWithSlopingCeiling": classify_sloping_ceiling_roof, + "Flat": map_flat_roof, + "PitchedWithSlopingCeiling": map_sloping_ceiling_roof, } diff --git a/backend/onboarders/mappings/parity/as_built_wall_classifiers.py b/backend/onboarders/mappings/parity/as_built_wall_classifiers.py index f907a533..124270c7 100644 --- a/backend/onboarders/mappings/parity/as_built_wall_classifiers.py +++ b/backend/onboarders/mappings/parity/as_built_wall_classifiers.py @@ -101,7 +101,7 @@ def map_cob_wall_insulation(age_band: EpcConstructionAgeBand): ) -AS_BUILT_WALL_CLASSIFIERS = { +as_built_wall_classifiers = { "Cavity": map_cavity_wall_insulation, "Solid Brick": map_solid_wall_insulation, "Timber Frame": map_timber_frame_wall_insulation, diff --git a/backend/onboarders/parity.py b/backend/onboarders/parity.py index e820f938..c7f982df 100644 --- a/backend/onboarders/parity.py +++ b/backend/onboarders/parity.py @@ -8,11 +8,11 @@ from backend.onboarders.mappings.parity.built_form import parity_map as built_fo from backend.onboarders.mappings.parity.walls import wall_map, wall_unknown_age_fallback from backend.onboarders.epc_descriptions import EpcWallDescriptions, EpcConstructionAgeBand, EpcEfficiency, \ WALL_DESCRIPTION_EFFICIENCIES, resolve_roof_efficiency -from backend.onboarders.mappings.parity.as_built_wall_classifiers import AS_BUILT_WALL_CLASSIFIERS -from backend.onboarders.mappings.parity.as_built_roof_classifiers import AS_BUILT_ROOF_CLASSIFIERS -from backend.onboarders.mappings.parity.as_built_floor_classifiers import unknown_floor_as_built, \ - unknown_floor_retrofitted, \ - solid_floor_as_built, suspended_floor_as_built +from backend.onboarders.mappings.parity.as_built_wall_classifiers import as_built_wall_classifiers +from backend.onboarders.mappings.parity.as_built_roof_classifiers import as_built_roof_classifiers +from backend.onboarders.mappings.parity.as_built_floor_classifiers import ( + as_built_floor_classifiers, unknown_as_built_floor_classifiers +) from datatypes.epc.roof import EpcRoofDescriptions from datatypes.epc.floor import EpcFloorDescriptions from onboarders.mappings.parity.roof import roof_map, roof_unknown_age_fallback @@ -58,7 +58,7 @@ class ParityOnboarder(OnboarderBase): self.assert_no_nulls(self.data, self.landlord_built_form) @staticmethod - def _fill_as_built(row: pd.Series) -> EpcWallDescriptions | None: + def _fill_wall_as_built(row: pd.Series) -> EpcWallDescriptions | None: """ Utility function, used by map_wall_construction in parity transformation module :param row: row of input sustainability data, being transformed @@ -75,7 +75,7 @@ class ParityOnboarder(OnboarderBase): if pd.isnull(row.construction_age_band): return wall_unknown_age_fallback.get(wall_type) - classifier = AS_BUILT_WALL_CLASSIFIERS.get(wall_type) + classifier = as_built_wall_classifiers.get(wall_type) if classifier is None: return None @@ -111,7 +111,7 @@ class ParityOnboarder(OnboarderBase): .map(wall_map) ) - self.data[self.landlord_wall_construction] = self.data.progress_apply(self._fill_as_built, axis=1) + self.data[self.landlord_wall_construction] = self.data.progress_apply(self._fill_wall_as_built, axis=1) # Sanity check self.assert_no_nulls(self.data, self.landlord_wall_construction) @@ -134,7 +134,7 @@ class ParityOnboarder(OnboarderBase): roof_type = row["Roof Construction"] - classifier = AS_BUILT_ROOF_CLASSIFIERS.get(roof_type) + classifier = as_built_roof_classifiers.get(roof_type) if classifier is None: raise NotImplementedError(f"No roof classifier for roof type '{roof_type}'") @@ -214,17 +214,14 @@ class ParityOnboarder(OnboarderBase): return EpcFloorDescriptions.unknown # 3. Known floor types - if floor_type == "Solid": - return solid_floor_as_built(age_band) - - if floor_type in {"SuspendedTimber", "SuspendedNotTimber"}: - return suspended_floor_as_built(age_band) + if floor_type in ["Solid", "SuspendedTimber", "SuspendedNotTimber"]: + classifier = as_built_floor_classifiers[floor_type] + return classifier(age_band) # 4. Unknown floor type if floor_type == "Unknown": - if insulation == "RetroFitted": - return unknown_floor_retrofitted(age_band) - return unknown_floor_as_built(age_band) + classifier = unknown_as_built_floor_classifiers[insulation] + return classifier(age_band) # 5. Truly missing / garbage input return EpcFloorDescriptions.unknown