From a5a0fa3574499fa7e3c2b040330ff3347a6c65af Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Sat, 31 Aug 2024 15:29:52 +0100 Subject: [PATCH] adding heating recommendation unit tests --- .../test_data/heating_recommendations_data.py | 127 +++++++++++++----- .../tests/test_heating_recommendations.py | 10 ++ 2 files changed, 101 insertions(+), 36 deletions(-) diff --git a/recommendations/tests/test_data/heating_recommendations_data.py b/recommendations/tests/test_data/heating_recommendations_data.py index 7f8c4682..b5e7c42f 100644 --- a/recommendations/tests/test_data/heating_recommendations_data.py +++ b/recommendations/tests/test_data/heating_recommendations_data.py @@ -104,42 +104,95 @@ testing_examples = [ "control recommendation here" }, { - 'lmk-key': '751851300152012022010205497220090', 'address1': '21, Fullers Close', 'address2': 'Kelvedon', - 'address3': None, 'postcode': 'CO5 9JX', 'building-reference-number': 8075968, 'current-energy-rating': 'D', - 'potential-energy-rating': 'D', 'current-energy-efficiency': 55, 'potential-energy-efficiency': 56, - 'property-type_x': 'Bungalow', 'built-form_x': 'Detached', 'inspection-date': '2012-02-20', - 'local-authority': 'E07000067', 'constituency': 'E14001045', 'county': 'Essex', 'lodgement-date': '2012-02-20', - 'transaction-type': 'non marketed sale', 'environment-impact-current': 39, 'environment-impact-potential': 39, - 'energy-consumption-current': 475, 'energy-consumption-potential': 472.0, 'co2-emissions-current': 5.4, - 'co2-emiss-curr-per-floor-area': 84, 'co2-emissions-potential': 5.4, 'lighting-cost-current': 53.0, - 'lighting-cost-potential': 40.0, 'heating-cost-current': 674.0, 'heating-cost-potential': 678.0, - 'hot-water-cost-current': 110.0, 'hot-water-cost-potential': 110.0, 'total-floor-area': 64.45, - 'energy-tariff': 'dual', 'mains-gas-flag': 'N', 'floor-level': 'NODATA!', 'flat-top-storey': None, - 'flat-storey-count': None, 'main-heating-controls': '2402', 'multi-glaze-proportion': 100.0, - 'glazed-type': 'double glazing installed before 2002', 'glazed-area': 'Normal', 'extension-count': 0.0, - 'number-habitable-rooms': 3.0, 'number-heated-rooms': 3.0, 'low-energy-lighting': 67.0, - 'number-open-fireplaces': 0.0, 'hotwater-description': 'Electric immersion, off-peak', - 'hot-water-energy-eff': 'Average', 'hot-water-env-eff': 'Very Poor', - 'floor-description': 'Suspended, no insulation (assumed)', 'floor-energy-eff': None, 'floor-env-eff': None, - 'windows-description': 'Fully double glazed', 'windows-energy-eff': 'Average', 'windows-env-eff': 'Average', - 'walls-description': 'Cavity wall, as built, insulated (assumed)', 'walls-energy-eff': 'Good', - 'walls-env-eff': 'Good', 'secondheat-description': 'Room heaters, electric', 'sheating-energy-eff': None, - 'sheating-env-eff': None, 'roof-description': 'Pitched, 300+ mm loft insulation', - 'roof-energy-eff': 'Very Good', - 'roof-env-eff': 'Very Good', 'mainheat-description': 'Electric storage heaters', 'mainheat-energy-eff': 'Poor', - 'mainheat-env-eff': 'Very Poor', 'mainheatcont-description': 'Automatic charge control', - 'mainheatc-energy-eff': 'Average', 'mainheatc-env-eff': 'Average', - 'lighting-description': 'Low energy lighting in 67% of fixed outlets', 'lighting-energy-eff': 'Good', - 'lighting-env-eff': 'Good', 'main-fuel': 'electricity (not community)', 'wind-turbine-count': 0.0, - 'heat-loss-corridor': 'NO DATA!', 'unheated-corridor-length': None, 'floor-height': 2.38, 'photo-supply': 0.0, - 'solar-water-heating-flag': None, 'mechanical-ventilation': 'natural', 'address': '21, Fullers Close, Kelvedon', - 'local-authority-label': 'Braintree', 'constituency-label': 'Witham', 'posttown': 'COLCHESTER', - 'construction-age-band': 'England and Wales: 1983-1990', 'lodgement-datetime': '2012-02-20 10:20:54', - 'tenure': 'owner-occupied', 'fixed-lighting-outlets-count': 6.0, 'low-energy-fixed-light-count': 4.0, - 'uprn': 100090311351.0, 'uprn-source': 'Address Matched', 'property-type_y': None, 'built-form_y': None, - 'used': None + "epc": { + 'lmk-key': '751851300152012022010205497220090', 'address1': '21, Fullers Close', 'address2': 'Kelvedon', + 'address3': None, 'postcode': 'CO5 9JX', 'building-reference-number': 8075968, 'current-energy-rating': 'D', + 'potential-energy-rating': 'D', 'current-energy-efficiency': 55, 'potential-energy-efficiency': 56, + 'property-type': 'Bungalow', 'built-form': 'Detached', 'inspection-date': '2012-02-20', + 'local-authority': 'E07000067', 'constituency': 'E14001045', 'county': 'Essex', + 'lodgement-date': '2012-02-20', + 'transaction-type': 'non marketed sale', 'environment-impact-current': 39, + 'environment-impact-potential': 39, + 'energy-consumption-current': 475, 'energy-consumption-potential': 472.0, 'co2-emissions-current': 5.4, + 'co2-emiss-curr-per-floor-area': 84, 'co2-emissions-potential': 5.4, 'lighting-cost-current': 53.0, + 'lighting-cost-potential': 40.0, 'heating-cost-current': 674.0, 'heating-cost-potential': 678.0, + 'hot-water-cost-current': 110.0, 'hot-water-cost-potential': 110.0, 'total-floor-area': 64.45, + 'energy-tariff': 'dual', 'mains-gas-flag': 'N', 'floor-level': 'NODATA!', 'flat-top-storey': None, + 'flat-storey-count': None, 'main-heating-controls': '2402', 'multi-glaze-proportion': 100.0, + 'glazed-type': 'double glazing installed before 2002', 'glazed-area': 'Normal', 'extension-count': 0.0, + 'number-habitable-rooms': 3.0, 'number-heated-rooms': 3.0, 'low-energy-lighting': 67.0, + 'number-open-fireplaces': 0.0, 'hotwater-description': 'Electric immersion, off-peak', + 'hot-water-energy-eff': 'Average', 'hot-water-env-eff': 'Very Poor', + 'floor-description': 'Suspended, no insulation (assumed)', 'floor-energy-eff': None, 'floor-env-eff': None, + 'windows-description': 'Fully double glazed', 'windows-energy-eff': 'Average', 'windows-env-eff': 'Average', + 'walls-description': 'Cavity wall, as built, insulated (assumed)', 'walls-energy-eff': 'Good', + 'walls-env-eff': 'Good', 'secondheat-description': 'Room heaters, electric', 'sheating-energy-eff': None, + 'sheating-env-eff': None, 'roof-description': 'Pitched, 300+ mm loft insulation', + 'roof-energy-eff': 'Very Good', + 'roof-env-eff': 'Very Good', 'mainheat-description': 'Electric storage heaters', + 'mainheat-energy-eff': 'Poor', + 'mainheat-env-eff': 'Very Poor', 'mainheatcont-description': 'Automatic charge control', + 'mainheatc-energy-eff': 'Average', 'mainheatc-env-eff': 'Average', + 'lighting-description': 'Low energy lighting in 67% of fixed outlets', 'lighting-energy-eff': 'Good', + 'lighting-env-eff': 'Good', 'main-fuel': 'electricity (not community)', 'wind-turbine-count': 0.0, + 'heat-loss-corridor': 'NO DATA!', 'unheated-corridor-length': None, 'floor-height': 2.38, + 'photo-supply': 0.0, + 'solar-water-heating-flag': None, 'mechanical-ventilation': 'natural', + 'address': '21, Fullers Close, Kelvedon', + 'local-authority-label': 'Braintree', 'constituency-label': 'Witham', 'posttown': 'COLCHESTER', + 'construction-age-band': 'England and Wales: 1983-1990', 'lodgement-datetime': '2012-02-20 10:20:54', + 'tenure': 'owner-occupied', 'fixed-lighting-outlets-count': 6.0, 'low-energy-fixed-light-count': 4.0, + 'uprn': 100090311351.0, 'uprn-source': 'Address Matched', 'property-type_y': None, 'built-form_y': None, + 'used': None + }, + "heating_recommendation_descriptions": [], + "heating_controls_recommendation_descriptions": [], + "notes": "This test has electric storage heaters with automatic charge control - this case should be researched" + "and checked that a high heat retention storage recommendation is actually sensible. If it's not, " + "we should adjust accordingly or perhaps have just a control recommendation" + }, + { + "epc": { + 'lmk-key': '1356416458532015082116515621278108', 'address1': '19a, St. Stephens Road', 'address2': None, + 'address3': None, 'postcode': 'TW3 2BH', 'building-reference-number': 5821158378, + 'current-energy-rating': 'E', 'potential-energy-rating': 'C', 'current-energy-efficiency': 54, + 'potential-energy-efficiency': 76, 'property-type': 'Maisonette', 'built-form': 'Semi-Detached', + 'inspection-date': '2015-08-21', 'local-authority': 'E09000018', 'constituency': 'E14000593', + 'county': 'Greater London Authority', 'lodgement-date': '2015-08-21', 'transaction-type': 'marketed sale', + 'environment-impact-current': 48, 'environment-impact-potential': 78, 'energy-consumption-current': 383, + 'energy-consumption-potential': 155, 'co2-emissions-current': 3.4, 'co2-emiss-curr-per-floor-area': 68, + 'co2-emissions-potential': 1.4, 'lighting-cost-current': 52, 'lighting-cost-potential': 34, + 'heating-cost-current': 560, 'heating-cost-potential': 255, 'hot-water-cost-current': 166, + 'hot-water-cost-potential': 102, 'total-floor-area': 51.0, 'energy-tariff': 'Single', 'mains-gas-flag': 'Y', + 'floor-level': '1st', 'flat-top-storey': 'Y', 'flat-storey-count': None, 'main-heating-controls': '2104', + 'multi-glaze-proportion': 100.0, 'glazed-type': 'double glazing, unknown install date', + 'glazed-area': 'Normal', 'extension-count': 0.0, 'number-habitable-rooms': 3.0, 'number-heated-rooms': 3.0, + 'low-energy-lighting': 50.0, 'number-open-fireplaces': 0.0, 'hotwater-description': 'From main system', + 'hot-water-energy-eff': 'Average', 'hot-water-env-eff': 'Average', + 'floor-description': '(another dwelling below)', 'floor-energy-eff': 'NO DATA!', 'floor-env-eff': None, + 'windows-description': 'Fully double glazed', 'windows-energy-eff': 'Average', 'windows-env-eff': 'Average', + 'walls-description': 'Solid brick, as built, no insulation (assumed)', 'walls-energy-eff': 'Very Poor', + 'walls-env-eff': 'Very Poor', 'secondheat-description': 'Room heaters, mains gas', + 'sheating-energy-eff': None, 'sheating-env-eff': None, + 'roof-description': 'Pitched, 100 mm loft insulation', + 'roof-energy-eff': 'Average', 'roof-env-eff': 'Average', + 'mainheat-description': 'Boiler and radiators, mains gas', 'mainheat-energy-eff': 'Good', + 'mainheat-env-eff': 'Good', 'mainheatcont-description': 'Programmer and room thermostat', + 'mainheatc-energy-eff': 'Average', 'mainheatc-env-eff': 'Average', + 'lighting-description': 'Low energy lighting in 50% of fixed outlets', 'lighting-energy-eff': 'Good', + 'lighting-env-eff': 'Good', 'main-fuel': 'mains gas (not community)', 'wind-turbine-count': 0.0, + 'heat-loss-corridor': 'no corridor', 'unheated-corridor-length': None, 'floor-height': None, + 'photo-supply': None, 'solar-water-heating-flag': 'N', 'mechanical-ventilation': 'natural', + 'address': '19a, St. Stephens Road', 'local-authority-label': 'Hounslow', + 'constituency-label': 'Brentford and Isleworth', 'posttown': 'HOUNSLOW', + 'construction-age-band': 'England and Wales: 1930-1949', 'lodgement-datetime': '2015-08-21 16:51:56', + 'tenure': 'owner-occupied', 'fixed-lighting-outlets-count': None, 'low-energy-fixed-light-count': None, + 'uprn': 100021560521.0, 'uprn-source': 'Address Matched', 'used': None + }, + "heating_recommendation_descriptions": [], + "heating_controls_recommendation_descriptions": [], + "notes": "" } - ] import random @@ -168,7 +221,9 @@ used_examples = pd.DataFrame( ] ) -data = data.merge(used_examples, how="left", on=["mainheat-description", "mainheat-energy-eff"]) +data = data.merge( + used_examples, how="left", on=["mainheat-description", "mainheat-energy-eff", "built-form", "property-type"] +) data = data[pd.isnull(data["used"])] eg = data.sample(1).to_dict("records")[0] diff --git a/recommendations/tests/test_heating_recommendations.py b/recommendations/tests/test_heating_recommendations.py index 35373729..968583e4 100644 --- a/recommendations/tests/test_heating_recommendations.py +++ b/recommendations/tests/test_heating_recommendations.py @@ -54,6 +54,16 @@ class TestHeatingRecommendations: :return: """ + if test_case["epc"]["uprn"] == 100090311351: + raise Exception( + "This test has electric storage heaters with automatic charge control - this case should be researched" + "and checked that a high heat retention storage recommendation is actually sensible. If it's not, " + "we should adjust accordingly or perhaps have just a control recommendation" + ) + + if test_case["epc"]["uprn"] == 100021560521: + raise Exception("Finish this test - could do so while on the train") + epc_records = {"original_epc": test_case["epc"].copy(), "full_sap_epc": {}, "old_data": []} epc_record = EPCRecord(