diff --git a/backend/app/plan/router.py b/backend/app/plan/router.py index b3d1c623..d869bcb5 100644 --- a/backend/app/plan/router.py +++ b/backend/app/plan/router.py @@ -164,6 +164,32 @@ async def trigger_plan(body: PlanTriggerRequest): model_api = ModelApi(portfolio_id=body.portfolio_id, timestamp=created_at) + recommendations_scoring_data.head() + z = recommendations_scoring_data[recommendations_scoring_data["uprn"] == 100070505235].copy() + z = z[z["roof_thermal_transmittance"] != z["roof_thermal_transmittance_ending"]] + z["roof_thermal_transmittance_ending"] = 0.4 + z["roof_energy_eff_ending"] = "Average" + + now = model_api.predict_all( + df=z, + bucket=get_settings().DATA_BUCKET, + prediction_buckets={ + "sap_change_predictions": get_settings().SAP_PREDICTIONS_BUCKET, + "heat_demand_predictions": get_settings().HEAT_PREDICTIONS_BUCKET, + "carbon_change_predictions": get_settings().CARBON_PREDICTIONS_BUCKET + } + ) + + now["sap_change_predictions"] + input_properties[1].data["mechanical-ventilation"] + # id predictions property_id recommendation_id + # 0 3696+9 56.3 3696 9 + # 1 3696+10 56.8 3696 10 + # 2 3696+11 56.3 3696 11 + # 3 3696+12 56.8 3696 12 + # With good rather than very good + now["sap_change_predictions"] + all_predictions = model_api.predict_all( df=recommendations_scoring_data, bucket=get_settings().DATA_BUCKET, diff --git a/etl/epc/Record.py b/etl/epc/Record.py index 70586749..f1dde43e 100644 --- a/etl/epc/Record.py +++ b/etl/epc/Record.py @@ -635,8 +635,11 @@ class EPCRecord: This method will clean the ventilation, if empty or invalid """ self.prepared_epc['mechanical-ventilation'] = None if ( - self.mechanical_ventilation == "" or self.mechanical_ventilation in DATA_ANOMALY_MATCHES) else ( - self.mechanical_ventilation) + (self.prepared_epc['mechanical-ventilation'] == "") or + (self.prepared_epc['mechanical-ventilation'] in DATA_ANOMALY_MATCHES) + ) else ( + self.prepared_epc['mechanical-ventilation'] + ) def _field_validation(self): """ diff --git a/etl/epc/tests/test_epcrecord.py b/etl/epc/tests/test_epcrecord.py new file mode 100644 index 00000000..f55bd30a --- /dev/null +++ b/etl/epc/tests/test_epcrecord.py @@ -0,0 +1,98 @@ +import pytest +from utils.s3 import read_dataframe_from_s3_parquet +from etl.epc.Record import EPCRecord +from unittest.mock import Mock + + +class TestEpcRecord: + + @pytest.fixture() + def cleaning_data(self): + cleaning_data = read_dataframe_from_s3_parquet( + bucket_name="retrofit-data-dev", file_key="sap_change_model/cleaning_dataset.parquet", + ) + + return cleaning_data + + @pytest.fixture() + def epc_records_1(self): + epc_records_1 = { + 'original_epc': { + 'low-energy-fixed-light-count': '', 'address': '139 School Road, Hall Green', + 'uprn-source': 'Energy Assessor', 'floor-height': '2.6', 'heating-cost-potential': '1138', + 'unheated-corridor-length': '', 'hot-water-cost-potential': '175', + 'construction-age-band': 'England and Wales: 1900-1929', 'potential-energy-rating': 'B', + 'mainheat-energy-eff': 'Good', 'windows-env-eff': 'Average', 'lighting-energy-eff': 'Very Good', + 'environment-impact-potential': '82', 'glazed-type': 'double glazing, unknown install date', + 'heating-cost-current': '2711', 'address3': '', + 'mainheatcont-description': 'Programmer, TRVs and bypass', + 'sheating-energy-eff': 'N/A', 'property-type': 'House', 'local-authority-label': 'Birmingham', + 'fixed-lighting-outlets-count': '11', 'energy-tariff': 'Single', 'mechanical-ventilation': 'natural', + 'hot-water-cost-current': '310', 'county': '', 'postcode': 'B28 8JF', 'solar-water-heating-flag': 'N', + 'constituency': 'E14000562', 'co2-emissions-potential': '2.0', 'number-heated-rooms': '4', + 'floor-description': 'Suspended, no insulation (assumed)', 'energy-consumption-potential': '107', + 'local-authority': 'E08000025', 'built-form': 'Semi-Detached', 'number-open-fireplaces': '0', + 'windows-description': 'Fully double glazed', 'glazed-area': 'Normal', 'inspection-date': '2023-07-05', + 'mains-gas-flag': 'Y', 'co2-emiss-curr-per-floor-area': '65', 'address1': '139 School Road', + 'heat-loss-corridor': '', 'flat-storey-count': '', 'constituency-label': 'Birmingham, Hall Green', + 'roof-energy-eff': 'Average', 'total-floor-area': '103.0', 'building-reference-number': '10004697322', + 'environment-impact-current': '43', 'co2-emissions-current': '6.7', + 'roof-description': 'Pitched, 100 mm loft insulation', 'floor-energy-eff': 'N/A', + 'number-habitable-rooms': '4', 'address2': 'Hall Green', 'hot-water-env-eff': 'Good', + 'posttown': 'BIRMINGHAM', 'mainheatc-energy-eff': 'Average', 'main-fuel': 'mains gas (not community)', + 'lighting-env-eff': 'Very Good', 'windows-energy-eff': 'Average', 'floor-env-eff': 'N/A', + 'sheating-env-eff': 'N/A', 'lighting-description': 'Low energy lighting in 82% of fixed outlets', + 'roof-env-eff': 'Average', 'walls-energy-eff': 'Very Poor', 'photo-supply': '0.0', + 'lighting-cost-potential': '182', 'mainheat-env-eff': 'Good', 'multi-glaze-proportion': '100', + 'main-heating-controls': '', 'lodgement-datetime': '2023-07-13 08:23:07', 'flat-top-storey': '', + 'current-energy-rating': 'E', 'secondheat-description': 'None', 'walls-env-eff': 'Very Poor', + 'transaction-type': 'rental', 'uprn': '100070505235', 'current-energy-efficiency': '51', + 'energy-consumption-current': '366', 'mainheat-description': 'Boiler and radiators, mains gas', + 'lighting-cost-current': '182', 'lodgement-date': '2023-07-13', 'extension-count': '0', + 'mainheatc-env-eff': 'Average', + 'lmk-key': 'c1d137711da433fb3cced74b1a6848da8bbc1159d076455d26d7b4668982601e', + 'wind-turbine-count': '0', + 'tenure': 'Rented (social)', 'floor-level': '', 'potential-energy-efficiency': '84', + 'hot-water-energy-eff': 'Good', 'low-energy-lighting': '82', + 'walls-description': 'Solid brick, as built, no insulation (assumed)', + 'hotwater-description': 'From main system'}, 'full_sap_epc': {}, 'old_data': [] + } + return epc_records_1 + + def test_clean_mechanical_ventilation(self, cleaning_data, epc_records_1): + # We have an epc with Natural ventilation - the resulting epc should also have natural ventulation + + record = EPCRecord(cleaning_data=cleaning_data) + record.prepared_epc = { + "mechanical-ventilation": "natural" + } + record._clean_ventilation() + + assert record.prepared_epc["mechanical-ventilation"] == "natural" + + record2 = EPCRecord(cleaning_data=cleaning_data) + record2.prepared_epc = { + "mechanical-ventilation": "" + } + + record2._clean_ventilation() + + assert record2.prepared_epc["mechanical-ventilation"] is None + + record3 = EPCRecord(cleaning_data=cleaning_data) + record3.prepared_epc = { + "mechanical-ventilation": None + } + + record3._clean_ventilation() + + assert record3.prepared_epc["mechanical-ventilation"] is None + + record4 = EPCRecord(cleaning_data=cleaning_data) + record4.prepared_epc = { + "mechanical-ventilation": "INVALID" + } + + record4._clean_ventilation() + + assert record4.prepared_epc["mechanical-ventilation"] is None