mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-30 13:10:47 +00:00
reducing cleaning code
This commit is contained in:
parent
ec146cba77
commit
034a5de104
1 changed files with 19 additions and 30 deletions
|
|
@ -102,11 +102,26 @@ CLEANING_RULES: dict[str, CleaningRule] = {
|
||||||
"anomaly_to": None,
|
"anomaly_to": None,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"number-open-fireplaces": {
|
||||||
|
"cast": int,
|
||||||
|
"default": 0
|
||||||
|
},
|
||||||
|
|
||||||
"extension-count": {
|
"extension-count": {
|
||||||
"cast": int,
|
"cast": int,
|
||||||
"default": 0
|
"default": 0
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"flat-storey-count": {
|
||||||
|
"cast": int,
|
||||||
|
"anomaly_to": None
|
||||||
|
},
|
||||||
|
|
||||||
|
"number-habitable-rooms": {
|
||||||
|
"cast": int,
|
||||||
|
"anomaly_to": None
|
||||||
|
},
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
# TO NONE
|
# TO NONE
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
|
|
@ -410,7 +425,10 @@ class EPCRecord:
|
||||||
|
|
||||||
if "cast" in rule and value is not None:
|
if "cast" in rule and value is not None:
|
||||||
try:
|
try:
|
||||||
self._prepared_epc[field] = rule["cast"](value)
|
if rule["cast"] is int:
|
||||||
|
self._prepared_epc[field] = int(float(value))
|
||||||
|
else:
|
||||||
|
self._prepared_epc[field] = rule["cast"](value)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"Failed casting field '{field}' value '{value}': {e}"
|
f"Failed casting field '{field}' value '{value}': {e}"
|
||||||
|
|
@ -581,7 +599,6 @@ class EPCRecord:
|
||||||
|
|
||||||
self._clean_built_form()
|
self._clean_built_form()
|
||||||
self._clean_solar_hot_water()
|
self._clean_solar_hot_water()
|
||||||
self._clean_count_variables()
|
|
||||||
self._clean_heat_loss_corridor()
|
self._clean_heat_loss_corridor()
|
||||||
self._clean_age_band()
|
self._clean_age_band()
|
||||||
self._clean_year_built()
|
self._clean_year_built()
|
||||||
|
|
@ -867,34 +884,6 @@ class EPCRecord:
|
||||||
self._prepared_epc["heat-loss-corridor"]
|
self._prepared_epc["heat-loss-corridor"]
|
||||||
]
|
]
|
||||||
|
|
||||||
def _clean_count_variables(self) -> None:
|
|
||||||
"""
|
|
||||||
This method will clean the count variables, if empty or invalid
|
|
||||||
"""
|
|
||||||
if not self._prepared_epc:
|
|
||||||
raise ValueError("EPC Recrod doesn not contain epc data")
|
|
||||||
|
|
||||||
_fields = [
|
|
||||||
"number-open-fireplaces",
|
|
||||||
"extension-count",
|
|
||||||
"flat-storey-count",
|
|
||||||
"number-habitable-rooms",
|
|
||||||
]
|
|
||||||
|
|
||||||
null_attributes = ["flat-storey-count", "number-habitable-rooms"]
|
|
||||||
|
|
||||||
for attribute in _fields:
|
|
||||||
value = self._prepared_epc[attribute]
|
|
||||||
if value in DATA_ANOMALY_MATCHES or pd.isnull(value):
|
|
||||||
if attribute in null_attributes:
|
|
||||||
value = None
|
|
||||||
else:
|
|
||||||
value = 0
|
|
||||||
else:
|
|
||||||
value = int(float(value))
|
|
||||||
|
|
||||||
self._prepared_epc[attribute] = value
|
|
||||||
|
|
||||||
def _clean_solar_hot_water(self) -> None:
|
def _clean_solar_hot_water(self) -> None:
|
||||||
"""
|
"""
|
||||||
This method will clean the solar hot water, if empty or invalid
|
This method will clean the solar hot water, if empty or invalid
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue