from datetime import datetime, timezone, date
import itertools
from tqdm import tqdm

import pandas as pd

from etl.epc.Record import EPCRecord
from etl.bill_savings.KwhData import KwhData
from backend.SearchEpc import SearchEpc

from sqlalchemy.orm import sessionmaker

from backend.app.config import get_settings, get_prediction_buckets
from backend.app.db.connection import db_engine
from backend.app.db.functions.materials_functions import get_materials
from backend.ml_models.api import ModelApi

from backend.app.plan.utils import get_cleaned

from backend.Property import Property

from recommendations.Recommendations import Recommendations
from utils.logger import setup_logger
from utils.s3 import read_dataframe_from_s3_parquet, save_dataframe_to_s3_parquet
from sklearn.metrics import mean_absolute_error, mean_absolute_percentage_error

now = datetime.now().strftime("%d-%m-%Y-%H-%M-%S")

logger = setup_logger()

logger.info("Connecting to db")
session = sessionmaker(bind=db_engine)()
created_at = datetime.now().isoformat()

session.begin()
logger.info("Getting the inputs")

cleaning_data = read_dataframe_from_s3_parquet(
    bucket_name=get_settings().DATA_BUCKET,
    file_key="sap_change_model/cleaning_dataset.parquet",
)

materials = get_materials(session)
cleaned = get_cleaned()

uprn_filenames = read_dataframe_from_s3_parquet(
    bucket_name=get_settings().DATA_BUCKET, file_key="spatial/filename_meta.parquet"
)

kwh_client = KwhData(bucket="retrofit-data-dev", read_consumption_data=False)
kwh_client.retail_price_comparison = pd.DataFrame(
    [{"Date": datetime.today().strftime("%Y-%m-%d"),
      'Average standard variable tariff (Large legacy suppliers)': 1}]
)
kwh_client.retail_price_comparison["Date"] = pd.to_datetime(kwh_client.retail_price_comparison["Date"])

scenario_properties = [
    {
        "address": "2 South Terrace",
        "postcode": "NN1 5JY",
        "lmk-key": "1459796789102016070507274146560098",
        "measures": [
            [
                ["internal_wall_insulation"],
                "11",
                {},
                [0],
            ],
            [
                ["external_wall_insulation"],
                "11",
                {},
                [0],
            ],
            [
                ["internal_wall_insulation", "suspended_floor_insulation"],
                "13",
                {},
                [0, 1],
            ],
            [
                ["external_wall_insulation", "suspended_floor_insulation"],
                "13",
                {},
                [0, 1],
            ],
            [["solar", "windows"], "15", {"photo_supply_ending": 50}, [0, 1]],
        ],
    },
    {
        "address": "8 Lindlings",
        "postcode": "HP1 2HA",
        "lmk-key": "c14029235739827d5f627dc8aa9bb567d026b267e851e0db0001db24638667b1",
        "measures": [
            [
                ["cavity_wall_insulation", "loft_insulation"],
                "11",
                {},
                [0, 1],
            ],
            [
                ["loft_insulation"],
                "2",
                {},
                [0],
            ],
            [
                ["cavity_wall_insulation", "loft_insulation", "solid_floor_insulation"],
                "12",
                {},
                [0],
            ],
            [
                ["cavity_wall_insulation", "loft_insulation", "solid_floor_insulation", "low_energy_lighting"],
                "13",
                {},
                [0],
            ],
        ],
    },
    {
        "address": "44 Lindlings",
        "postcode": "HP1 2HE",
        "lmk-key": "99296a6dda21314fef3a61cda59e441e9a2aacf115eb96f4a0fa85696bf7b117",
        "measures": [
            [
                ["cavity_wall_insulation", "loft_insulation"],
                "10",
                {},
                [0, 1],
            ],
        ],
    },
    {
        "address": "46 Chaulden Terrace",
        "postcode": "HP1 2AN",
        "lmk-key": "d1e0534be3a44c33003323b21d0e322e3daddc65b5ee71936f89c59ddab96b50",
        "measures": [
            [
                ["cavity_wall_insulation", "loft_insulation"],
                "11",
                {},
                [0, 1],
            ],
        ],
    },
    {
        "address": "73 Long Chaulden",
        "postcode": "HP1 2HX",
        "lmk-key": "1eae354db522a95188018d9cd0502ed8c609910b6c88f8797d3a25f59b11770a",
        "measures": [
            [
                ["cavity_wall_insulation", "loft_insulation"],
                "10",
                {},
                [0, 1],
            ],
        ],
    },
    # Vectis properties
    {
        "address": "Flat 2, Grove Mansions",
        "postcode": "SW4 9SL",
        "lmk-key": None,
        "epc": {
            'low-energy-fixed-light-count': '18', 'address': 'Flat 2 Grove Mansions, 111, Clapham Common North Side',
            'uprn-source': 'Address Matched', 'floor-height': 3.3, 'heating-cost-potential': '696',
            'unheated-corridor-length': '8.45', 'hot-water-cost-potential': '195',
            'construction-age-band': 'England and Wales: before 1900', 'potential-energy-rating': 'C',
            'mainheat-energy-eff': 'Good', 'windows-env-eff': 'Very Poor', 'lighting-energy-eff': 'Very Good',
            'environment-impact-potential': '72', 'glazed-type': 'Single glazing', 'heating-cost-current': '1219',
            'address3': None, 'mainheatcont-description': 'Programmer, room thermostat and TRVs',
            'sheating-energy-eff': 'N/A', 'property-type': 'Flat', 'local-authority-label': 'Wandsworth',
            'fixed-lighting-outlets-count': '22', 'energy-tariff': 'Dual', 'mechanical-ventilation': 'natural',
            'hot-water-cost-current': '193', 'county': '', 'postcode': 'SW4 9SL', 'solar-water-heating-flag': 'N',
            'constituency': 'E14000549', 'co2-emissions-potential': '2.5', 'number-heated-rooms': '4',
            'floor-description': 'Suspended, no insulation (assumed)', 'energy-consumption-potential': '134',
            'local-authority': 'E09000032', 'built-form': 'Mid-Terrace', 'number-open-fireplaces': '4',
            'windows-description': 'Single glazed', 'glazed-area': 'Much More Than Typical',
            'inspection-date': datetime(2024, 8, 13, 0, 0, tzinfo=timezone.utc),
            'mains-gas-flag': 'Y', 'co2-emiss-curr-per-floor-area': '38', 'address1': 'Flat 2 Grove Mansions, 111',
            'heat-loss-corridor': 'unheated corridor', 'flat-storey-count': None, 'constituency-label': 'Battersea',
            'roof-energy-eff': 'N/A', 'total-floor-area': '105', 'building-reference-number': '',
            'environment-impact-current': '56', 'co2-emissions-current': '4.0',
            'roof-description': '(another dwelling above)', 'floor-energy-eff': 'N/A', 'number-habitable-rooms': '4',
            'address2': 'Clapham Common North Side', 'hot-water-env-eff': 'Good', 'posttown': 'LONDON',
            'mainheatc-energy-eff': 'Good', 'main-fuel': 'mains gas (not community)', 'lighting-env-eff': 'Very Good',
            'windows-energy-eff': 'Very Poor', 'floor-env-eff': 'N/A', 'sheating-env-eff': 'N/A',
            'lighting-description': 'Low energy lighting in 82% of fixed outlets', 'roof-env-eff': 'N/A',
            'walls-energy-eff': 'Poor', 'photo-supply': '0', 'lighting-cost-potential': '164',
            'mainheat-env-eff': 'Good', 'multi-glaze-proportion': '0',
            'main-heating-controls': 'Programmer, room thermostat and TRVs',
            'lodgement-datetime': datetime(2024, 8, 13, 0, 0), 'flat-top-storey': 'N',
            'current-energy-rating': 'D', 'secondheat-description': 'None', 'walls-env-eff': 'Poor',
            'transaction-type': 'ECO assessment', 'uprn': 121016121, 'current-energy-efficiency': '63',
            'energy-consumption-current': '216', 'mainheat-description': 'Boiler and radiators, mains gas',
            'lighting-cost-current': '162', 'lodgement-date': date(2024, 8, 13), 'extension-count': '1',
            'mainheatc-env-eff': 'Good', 'lmk-key': '', 'wind-turbine-count': '0', 'tenure': 'Rented (social)',
            'floor-level': '1', 'potential-energy-efficiency': '74', 'hot-water-energy-eff': 'Good',
            'low-energy-lighting': '82', 'walls-description': 'Solid brick, as built, no insulation (assumed)',
            'hotwater-description': 'From main system'
        },
        "old_epcs": [
            {'low-energy-fixed-light-count': '11', 'address': 'Flat 2 Grove Mansions, Clapham Common North Side',
             'uprn-source': 'Address Matched', 'floor-height': '', 'heating-cost-potential': '495',
             'unheated-corridor-length': '10.16', 'hot-water-cost-potential': '91',
             'construction-age-band': 'England and Wales: 1900-1929', 'potential-energy-rating': 'C',
             'mainheat-energy-eff': 'Good', 'windows-env-eff': 'Very Poor', 'lighting-energy-eff': 'Very Good',
             'environment-impact-potential': '75', 'glazed-type': 'not defined', 'heating-cost-current': '932',
             'address3': '', 'mainheatcont-description': 'Programmer, room thermostat and TRVs',
             'sheating-energy-eff': 'N/A', 'property-type': 'Flat', 'local-authority-label': 'Wandsworth',
             'fixed-lighting-outlets-count': '11', 'energy-tariff': 'Unknown', 'mechanical-ventilation': 'natural',
             'hot-water-cost-current': '90', 'county': 'Greater London Authority', 'postcode': 'SW4 9SL',
             'solar-water-heating-flag': '', 'constituency': 'E14000549', 'co2-emissions-potential': '2.9',
             'number-heated-rooms': '5', 'floor-description': 'Suspended, no insulation (assumed)',
             'energy-consumption-potential': '127', 'local-authority': 'E09000032', 'built-form': 'Mid-Terrace',
             'number-open-fireplaces': '1', 'windows-description': 'Single glazed', 'glazed-area': 'Normal',
             'inspection-date': '2012-11-28', 'mains-gas-flag': 'Y', 'co2-emiss-curr-per-floor-area': '45',
             'address1': 'Flat 2 Grove Mansions', 'heat-loss-corridor': 'unheated corridor', 'flat-storey-count': '',
             'constituency-label': 'Battersea', 'roof-energy-eff': 'N/A', 'total-floor-area': '121.0',
             'building-reference-number': '9347419868', 'environment-impact-current': '53',
             'co2-emissions-current': '5.5', 'roof-description': '(another dwelling above)', 'floor-energy-eff': 'N/A',
             'number-habitable-rooms': '5', 'address2': 'Clapham Common North Side', 'hot-water-env-eff': 'Good',
             'posttown': 'LONDON', 'mainheatc-energy-eff': 'Good', 'main-fuel': 'mains gas (not community)',
             'lighting-env-eff': 'Very Good', 'windows-energy-eff': 'Very Poor', 'floor-env-eff': 'N/A',
             'sheating-env-eff': 'N/A', 'lighting-description': 'Low energy lighting in all fixed outlets',
             'roof-env-eff': 'N/A', 'walls-energy-eff': 'Very Poor', 'photo-supply': '0.0',
             'lighting-cost-potential': '64', 'mainheat-env-eff': 'Good', 'multi-glaze-proportion': '0',
             'main-heating-controls': '2106', 'lodgement-datetime': '2012-11-29 00:17:32', 'flat-top-storey': 'N',
             'current-energy-rating': 'D', 'secondheat-description': 'None', 'walls-env-eff': 'Very Poor',
             'transaction-type': 'rental (private)', 'uprn': '121016121', 'current-energy-efficiency': '59',
             'energy-consumption-current': '234', 'mainheat-description': 'Boiler and radiators, mains gas',
             'lighting-cost-current': '62', 'lodgement-date': '2012-11-29', 'extension-count': '0',
             'mainheatc-env-eff': 'Good', 'lmk-key': '664404619342012112900173280922988', 'wind-turbine-count': '0',
             'tenure': 'rental (private)', 'floor-level': 'Basement', 'potential-energy-efficiency': '76',
             'hot-water-energy-eff': 'Good', 'low-energy-lighting': '100',
             'walls-description': 'Solid brick, as built, no insulation (assumed)',
             'hotwater-description': 'From main system'},
            {'low-energy-fixed-light-count': '5', 'address': 'Flat 2 Grove Mansions, Clapham Common North Side',
             'uprn-source': 'Address Matched', 'floor-height': '3.04', 'heating-cost-potential': '778',
             'unheated-corridor-length': '6.83', 'hot-water-cost-potential': '89',
             'construction-age-band': 'England and Wales: before 1900', 'potential-energy-rating': 'D',
             'mainheat-energy-eff': 'Good', 'windows-env-eff': 'Very Poor', 'lighting-energy-eff': 'Average',
             'environment-impact-potential': '61', 'glazed-type': 'not defined', 'heating-cost-current': '773',
             'address3': '', 'mainheatcont-description': 'Programmer, room thermostat and TRVs',
             'sheating-energy-eff': 'N/A', 'property-type': 'Flat', 'local-authority-label': 'Wandsworth',
             'fixed-lighting-outlets-count': '12', 'energy-tariff': 'Single', 'mechanical-ventilation': 'natural',
             'hot-water-cost-current': '89', 'county': 'Greater London Authority', 'postcode': 'SW4 9SL',
             'solar-water-heating-flag': '', 'constituency': 'E14000549', 'co2-emissions-potential': '4.6',
             'number-heated-rooms': '5', 'floor-description': 'Solid, no insulation (assumed)',
             'energy-consumption-potential': '210', 'local-authority': 'E09000032', 'built-form': 'Semi-Detached',
             'number-open-fireplaces': '0', 'windows-description': 'Single glazed', 'glazed-area': 'Normal',
             'inspection-date': '2011-08-09', 'mains-gas-flag': 'Y', 'co2-emiss-curr-per-floor-area': '41',
             'address1': 'Flat 2 Grove Mansions', 'heat-loss-corridor': 'unheated corridor', 'flat-storey-count': '',
             'constituency-label': 'Battersea', 'roof-energy-eff': 'N/A', 'total-floor-area': '113.52',
             'building-reference-number': '9347419868', 'environment-impact-current': '60',
             'co2-emissions-current': '4.7', 'roof-description': '(another dwelling above)', 'floor-energy-eff': 'N/A',
             'number-habitable-rooms': '5', 'address2': 'Clapham Common North Side', 'hot-water-env-eff': 'Good',
             'posttown': 'LONDON', 'mainheatc-energy-eff': 'Good', 'main-fuel': 'mains gas (not community)',
             'lighting-env-eff': 'Average', 'windows-energy-eff': 'Very Poor', 'floor-env-eff': 'N/A',
             'sheating-env-eff': 'N/A', 'lighting-description': 'Low energy lighting in 42% of fixed outlets',
             'roof-env-eff': 'N/A', 'walls-energy-eff': 'Very Poor', 'photo-supply': '0.0',
             'lighting-cost-potential': '58', 'mainheat-env-eff': 'Good', 'multi-glaze-proportion': '0',
             'main-heating-controls': '2106', 'lodgement-datetime': '2011-08-09 14:08:07', 'flat-top-storey': 'N',
             'current-energy-rating': 'D', 'secondheat-description': 'None', 'walls-env-eff': 'Very Poor',
             'transaction-type': 'rental (private)', 'uprn': '121016121', 'current-energy-efficiency': '64',
             'energy-consumption-current': '216', 'mainheat-description': 'Boiler and radiators, mains gas',
             'lighting-cost-current': '91', 'lodgement-date': '2011-08-09', 'extension-count': '0',
             'mainheatc-env-eff': 'Good', 'lmk-key': '664404649022011080914080739118499', 'wind-turbine-count': '0',
             'tenure': 'rental (private)', 'floor-level': 'Ground', 'potential-energy-efficiency': '65',
             'hot-water-energy-eff': 'Good', 'low-energy-lighting': '42',
             'walls-description': 'Solid brick, as built, no insulation (assumed)',
             'hotwater-description': 'From main system'},
            {'low-energy-fixed-light-count': '', 'address': 'Flat 2, Grove Mansions, 111 Clapham Common North Side',
             'uprn-source': 'Energy Assessor', 'floor-height': '2.24', 'heating-cost-potential': '433',
             'unheated-corridor-length': '13.31', 'hot-water-cost-potential': '99',
             'construction-age-band': 'England and Wales: before 1900', 'potential-energy-rating': 'C',
             'mainheat-energy-eff': 'Good', 'windows-env-eff': 'Very Poor', 'lighting-energy-eff': 'Very Good',
             'environment-impact-potential': '73', 'glazed-type': 'not defined', 'heating-cost-current': '1013',
             'address3': '111 Clapham Common North Side',
             'mainheatcont-description': 'Programmer, room thermostat and TRVs', 'sheating-energy-eff': 'N/A',
             'property-type': 'Flat', 'local-authority-label': 'Wandsworth', 'fixed-lighting-outlets-count': '9',
             'energy-tariff': 'Single', 'mechanical-ventilation': 'natural', 'hot-water-cost-current': '98',
             'county': '', 'postcode': 'SW4 9SL', 'solar-water-heating-flag': 'N', 'constituency': 'E14000549',
             'co2-emissions-potential': '2.7', 'number-heated-rooms': '5',
             'floor-description': 'Solid, no insulation (assumed)', 'energy-consumption-potential': '141',
             'local-authority': 'E09000032', 'built-form': 'Semi-Detached', 'number-open-fireplaces': '0',
             'windows-description': 'Single glazed', 'glazed-area': 'Normal', 'inspection-date': '2022-10-25',
             'mains-gas-flag': 'Y', 'co2-emiss-curr-per-floor-area': '56', 'address1': 'Flat 2',
             'heat-loss-corridor': 'unheated corridor', 'flat-storey-count': '', 'constituency-label': 'Battersea',
             'roof-energy-eff': 'N/A', 'total-floor-area': '106.0', 'building-reference-number': '10003506322',
             'environment-impact-current': '41', 'co2-emissions-current': '6.0',
             'roof-description': '(another dwelling above)', 'floor-energy-eff': 'N/A', 'number-habitable-rooms': '5',
             'address2': 'Grove Mansions', 'hot-water-env-eff': 'Good', 'posttown': 'LONDON',
             'mainheatc-energy-eff': 'Good', 'main-fuel': 'mains gas (not community)', 'lighting-env-eff': 'Very Good',
             'windows-energy-eff': 'Very Poor', 'floor-env-eff': 'N/A', 'sheating-env-eff': 'N/A',
             'lighting-description': 'Low energy lighting in all fixed outlets', 'roof-env-eff': 'N/A',
             'walls-energy-eff': 'Very Poor', 'photo-supply': '0.0', 'lighting-cost-potential': '93',
             'mainheat-env-eff': 'Good', 'multi-glaze-proportion': '0', 'main-heating-controls': '',
             'lodgement-datetime': '2022-10-26 10:18:37', 'flat-top-storey': 'N', 'current-energy-rating': 'E',
             'secondheat-description': 'None', 'walls-env-eff': 'Very Poor', 'transaction-type': 'marketed sale',
             'uprn': '121016121', 'current-energy-efficiency': '50', 'energy-consumption-current': '318',
             'mainheat-description': 'Boiler and radiators, mains gas', 'lighting-cost-current': '91',
             'lodgement-date': '2022-10-26', 'extension-count': '0', 'mainheatc-env-eff': 'Good',
             'lmk-key': '33092029f56530df7c284290fd45a8a3e985f42e3bfb6f6f85785c8accc42445', 'wind-turbine-count': '0',
             'tenure': 'Rented (private)', 'floor-level': '00', 'potential-energy-efficiency': '75',
             'hot-water-energy-eff': 'Good', 'low-energy-lighting': '100',
             'walls-description': 'Solid brick, as built, no insulation (assumed)',
             'hotwater-description': 'From main system'}
        ],
        "measures": [
            [["secondary_glazing"], "2", {}, [0]],
            [
                ["secondary_glazing", "low_energy_lighting", "internal_wall_insulation", "suspended_floor_insulation"],
                "8",
                {},
                [0, 1, 2, 3]
            ],
            [
                ["double_glazing", "internal_wall_insulation", "suspended_floor_insulation"],
                "10",
                {},
                [0, 1, 2]
            ],
            [
                ["internal_wall_insulation"],
                "5",
                {},
                [0]
            ],
            [
                ["internal_wall_insulation", "suspended_floor_insulation"],
                "7",
                {},
                [0, 1, 2]
            ],
        ],
    },

    {
        "address": "Flat 8 Grove Mansions",
        "postcode": "SW4 9SL",
        "lmk-key": None,
        "epc": {
            'low-energy-fixed-light-count': '10',
            'address': 'Flat 8 Grove Mansions, 111, Clapham Common North Side', 'uprn-source': 'Address Matched',
            'floor-height': 2.75, 'heating-cost-potential': '319', 'unheated-corridor-length': '3.9',
            'hot-water-cost-potential': '180', 'construction-age-band': 'England and Wales: before 1900',
            'potential-energy-rating': 'B', 'mainheat-energy-eff': 'Good', 'windows-env-eff': 'Very Poor',
            'lighting-energy-eff': 'Very Good', 'environment-impact-potential': '84',
            'glazed-type': 'Single glazing', 'heating-cost-current': '666', 'address3': None,
            'mainheatcont-description': 'Programmer and room thermostat', 'sheating-energy-eff': 'N/A',
            'property-type': 'Flat', 'local-authority-label': 'Wandsworth', 'fixed-lighting-outlets-count': '14',
            'energy-tariff': 'Single', 'mechanical-ventilation': 'natural', 'hot-water-cost-current': '176',
            'county': '', 'postcode': 'SW4 9SL', 'solar-water-heating-flag': 'N', 'constituency': 'E14000549',
            'co2-emissions-potential': '1.2', 'number-heated-rooms': '3',
            'floor-description': '(another dwelling below)', 'energy-consumption-potential': '96',
            'local-authority': 'E09000032', 'built-form': 'Mid-Terrace', 'number-open-fireplaces': '1',
            'windows-description': 'Single glazed', 'glazed-area': 'Much More Than Typical',
            'inspection-date': datetime(2024, 8, 13, 0, 0, tzinfo=timezone.utc),
            'mains-gas-flag': 'Y', 'co2-emiss-curr-per-floor-area': '30', 'address1': 'Flat 8 Grove Mansions, 111',
            'heat-loss-corridor': 'unheated corridor', 'flat-storey-count': None, 'constituency-label': 'Battersea',
            'roof-energy-eff': 'N/A', 'total-floor-area': '72', 'building-reference-number': '',
            'environment-impact-current': '70', 'co2-emissions-current': '2.2',
            'roof-description': '(another dwelling above)', 'floor-energy-eff': 'N/A',
            'number-habitable-rooms': '3', 'address2': 'Clapham Common North Side', 'hot-water-env-eff': 'Good',
            'posttown': 'LONDON', 'mainheatc-energy-eff': 'Average', 'main-fuel': 'mains gas (not community)',
            'lighting-env-eff': 'Very Good', 'windows-energy-eff': 'Very Poor', 'floor-env-eff': 'N/A',
            'sheating-env-eff': 'N/A', 'lighting-description': 'Low energy lighting in 71% of fixed outlets',
            'roof-env-eff': 'N/A', 'walls-energy-eff': 'Very Poor', 'photo-supply': '0',
            'lighting-cost-potential': '93', 'mainheat-env-eff': 'Good', 'multi-glaze-proportion': '0',
            'main-heating-controls': 'Programmer and room thermostat',
            'lodgement-datetime': datetime(2024, 8, 13, 0, 0), 'flat-top-storey': 'N',
            'current-energy-rating': 'C', 'secondheat-description': 'Room heaters, electric',
            'walls-env-eff': 'Very Poor', 'transaction-type': 'ECO assessment', 'uprn': 10024087855,
            'current-energy-efficiency': '70', 'energy-consumption-current': '170',
            'mainheat-description': 'Boiler and radiators, mains gas', 'lighting-cost-current': '118',
            'lodgement-date': date(2024, 8, 13), 'extension-count': '0', 'mainheatc-env-eff': 'Average',
            'lmk-key': '', 'wind-turbine-count': '0', 'tenure': 'Rented (social)', 'floor-level': '2',
            'potential-energy-efficiency': '81', 'hot-water-energy-eff': 'Good', 'low-energy-lighting': '71',
            'walls-description': 'Solid brick, as built, no insulation (assumed)',
            'hotwater-description': 'From main system'
        },
        "old_epcs": [
            {'low-energy-fixed-light-count': '', 'address': 'Flat 8 Grove Mansions, Clapham Common North Side',
             'uprn-source': 'Address Matched', 'floor-height': '3.07', 'heating-cost-potential': '385',
             'unheated-corridor-length': '4.5', 'hot-water-cost-potential': '100',
             'construction-age-band': 'England and Wales: before 1900', 'potential-energy-rating': 'C',
             'mainheat-energy-eff': 'Very Good', 'windows-env-eff': 'Very Poor', 'lighting-energy-eff': 'Very Good',
             'environment-impact-potential': '75', 'glazed-type': 'not defined', 'heating-cost-current': '405',
             'address3': '', 'mainheatcont-description': 'Programmer, TRVs and bypass', 'sheating-energy-eff': 'N/A',
             'property-type': 'Flat', 'local-authority-label': 'Wandsworth', 'fixed-lighting-outlets-count': '',
             'energy-tariff': 'Single', 'mechanical-ventilation': 'natural', 'hot-water-cost-current': '106',
             'county': 'Greater London Authority', 'postcode': 'SW4 9SL', 'solar-water-heating-flag': 'N',
             'constituency': 'E14000549', 'co2-emissions-potential': '2.4', 'number-heated-rooms': '3',
             'floor-description': '(other premises below)', 'energy-consumption-potential': '169',
             'local-authority': 'E09000032', 'built-form': 'Mid-Terrace', 'number-open-fireplaces': '0',
             'windows-description': 'Single glazed', 'glazed-area': 'Normal', 'inspection-date': '2010-12-07',
             'mains-gas-flag': 'Y', 'co2-emiss-curr-per-floor-area': '30', 'address1': 'Flat 8 Grove Mansions',
             'heat-loss-corridor': 'unheated corridor', 'flat-storey-count': '5.0', 'constituency-label': 'Battersea',
             'roof-energy-eff': 'N/A', 'total-floor-area': '85.53', 'building-reference-number': '5346736568',
             'environment-impact-current': '74', 'co2-emissions-current': '2.6',
             'roof-description': '(another dwelling above)', 'floor-energy-eff': 'N/A', 'number-habitable-rooms': '3',
             'address2': 'Clapham Common North Side', 'hot-water-env-eff': 'Very Good', 'posttown': 'LONDON',
             'mainheatc-energy-eff': 'Average',
             'main-fuel': 'mains gas - this is for backwards compatibility only and should not be used',
             'lighting-env-eff': 'Very Good', 'windows-energy-eff': 'Very Poor', 'floor-env-eff': 'N/A',
             'sheating-env-eff': 'N/A', 'lighting-description': 'Low energy lighting in all fixed outlets',
             'roof-env-eff': 'N/A', 'walls-energy-eff': 'Very Poor', 'photo-supply': '0.0',
             'lighting-cost-potential': '47', 'mainheat-env-eff': 'Very Good', 'multi-glaze-proportion': '0',
             'main-heating-controls': '2107', 'lodgement-datetime': '2010-12-13 09:01:15', 'flat-top-storey': 'N',
             'current-energy-rating': 'C', 'secondheat-description': 'None', 'walls-env-eff': 'Very Poor',
             'transaction-type': 'rental (private)', 'uprn': '10024087855', 'current-energy-efficiency': '77',
             'energy-consumption-current': '179', 'mainheat-description': 'Boiler and radiators, mains gas',
             'lighting-cost-current': '47', 'lodgement-date': '2010-12-13', 'extension-count': '0',
             'mainheatc-env-eff': 'Average', 'lmk-key': '213678952032010121309011556068793', 'wind-turbine-count': '0',
             'tenure': 'rental (private)', 'floor-level': '3rd', 'potential-energy-efficiency': '78',
             'hot-water-energy-eff': 'Very Good', 'low-energy-lighting': '100',
             'walls-description': 'Solid brick, as built, no insulation (assumed)',
             'hotwater-description': 'From main system'},
            {'low-energy-fixed-light-count': '', 'address': 'Flat 8 Grove Mansions, Clapham Common North Side',
             'uprn-source': 'Address Matched', 'floor-height': '2.95', 'heating-cost-potential': '385',
             'unheated-corridor-length': '', 'hot-water-cost-potential': '85', 'construction-age-band': 'NO DATA!',
             'potential-energy-rating': 'C', 'mainheat-energy-eff': 'Very Good', 'windows-env-eff': 'Very Poor',
             'lighting-energy-eff': 'Poor', 'environment-impact-potential': '71', 'glazed-type': 'NO DATA!',
             'heating-cost-current': '380', 'address3': '',
             'mainheatcont-description': 'Programmer, room thermostat and TRVs', 'sheating-energy-eff': 'N/A',
             'property-type': 'Flat', 'local-authority-label': 'Wandsworth', 'fixed-lighting-outlets-count': '',
             'energy-tariff': 'standard tariff', 'mechanical-ventilation': 'NO DATA!', 'hot-water-cost-current': '85',
             'county': 'Greater London Authority', 'postcode': 'SW4 9SL', 'solar-water-heating-flag': '',
             'constituency': 'E14000549', 'co2-emissions-potential': '2.4', 'number-heated-rooms': '',
             'floor-description': '(other premises below)', 'energy-consumption-potential': '211',
             'local-authority': 'E09000032', 'built-form': 'Mid-Terrace', 'number-open-fireplaces': '',
             'windows-description': 'Single glazed', 'glazed-area': 'NO DATA!', 'inspection-date': '2009-10-16',
             'mains-gas-flag': '', 'co2-emiss-curr-per-floor-area': '36', 'address1': 'Flat 8 Grove Mansions',
             'heat-loss-corridor': 'NO DATA!', 'flat-storey-count': '', 'constituency-label': 'Battersea',
             'roof-energy-eff': 'Very Good', 'total-floor-area': '69.03', 'building-reference-number': '5346736568',
             'environment-impact-current': '71', 'co2-emissions-current': '2.5',
             'roof-description': 'Average thermal transmittance 0.06 W/m?K', 'floor-energy-eff': 'N/A',
             'number-habitable-rooms': '', 'address2': 'Clapham Common North Side', 'hot-water-env-eff': 'Very Good',
             'posttown': 'LONDON', 'mainheatc-energy-eff': 'Average',
             'main-fuel': 'mains gas - this is for backwards compatibility only and should not be used',
             'lighting-env-eff': 'Poor', 'windows-energy-eff': 'Very Poor', 'floor-env-eff': 'N/A',
             'sheating-env-eff': 'N/A', 'lighting-description': 'Low energy lighting in 17% of fixed outlets',
             'roof-env-eff': 'Very Good', 'walls-energy-eff': 'Very Poor', 'photo-supply': '',
             'lighting-cost-potential': '36', 'mainheat-env-eff': 'Very Good', 'multi-glaze-proportion': '',
             'main-heating-controls': '', 'lodgement-datetime': '2009-10-16 13:30:30', 'flat-top-storey': '',
             'current-energy-rating': 'C', 'secondheat-description': 'None', 'walls-env-eff': 'Very Poor',
             'transaction-type': 'new dwelling', 'uprn': '10024087855', 'current-energy-efficiency': '73',
             'energy-consumption-current': '219', 'mainheat-description': 'Boiler and radiators, mains gas',
             'lighting-cost-current': '66', 'lodgement-date': '2009-10-16', 'extension-count': '',
             'mainheatc-env-eff': 'Average', 'lmk-key': '213678970922009101613303036468251', 'wind-turbine-count': '0',
             'tenure': '', 'floor-level': 'mid floor', 'potential-energy-efficiency': '75',
             'hot-water-energy-eff': 'Very Good', 'low-energy-lighting': '',
             'walls-description': 'Average thermal transmittance 1.84 W/m?K',
             'hotwater-description': 'From main system'},
            {'low-energy-fixed-light-count': '', 'address': 'Flat 8 Grove Mansions, Clapham Common North Side',
             'uprn-source': 'Address Matched', 'floor-height': '2.95', 'heating-cost-potential': '251',
             'unheated-corridor-length': '', 'hot-water-cost-potential': '85', 'construction-age-band': 'NO DATA!',
             'potential-energy-rating': 'B', 'mainheat-energy-eff': 'Very Good', 'windows-env-eff': 'Good',
             'lighting-energy-eff': 'Poor', 'environment-impact-potential': '82', 'glazed-type': 'NO DATA!',
             'heating-cost-current': '247', 'address3': '',
             'mainheatcont-description': 'Programmer, room thermostat and TRVs', 'sheating-energy-eff': 'N/A',
             'property-type': 'Flat', 'local-authority-label': 'Wandsworth', 'fixed-lighting-outlets-count': '',
             'energy-tariff': 'standard tariff', 'mechanical-ventilation': 'NO DATA!', 'hot-water-cost-current': '85',
             'county': 'Greater London Authority', 'postcode': 'SW4 9SL', 'solar-water-heating-flag': '',
             'constituency': 'E14000549', 'co2-emissions-potential': '1.6', 'number-heated-rooms': '',
             'floor-description': '(other premises below)', 'energy-consumption-potential': '137',
             'local-authority': 'E09000032', 'built-form': 'Mid-Terrace', 'number-open-fireplaces': '',
             'windows-description': 'Fully double glazed', 'glazed-area': 'NO DATA!', 'inspection-date': '2009-10-12',
             'mains-gas-flag': '', 'co2-emiss-curr-per-floor-area': '24', 'address1': 'Flat 8 Grove Mansions',
             'heat-loss-corridor': 'NO DATA!', 'flat-storey-count': '', 'constituency-label': 'Battersea',
             'roof-energy-eff': 'Very Good', 'total-floor-area': '69.03', 'building-reference-number': '5346736568',
             'environment-impact-current': '81', 'co2-emissions-current': '1.7',
             'roof-description': 'Average thermal transmittance 0.06 W/m?K', 'floor-energy-eff': 'N/A',
             'number-habitable-rooms': '', 'address2': 'Clapham Common North Side', 'hot-water-env-eff': 'Very Good',
             'posttown': 'LONDON', 'mainheatc-energy-eff': 'Average',
             'main-fuel': 'mains gas - this is for backwards compatibility only and should not be used',
             'lighting-env-eff': 'Poor', 'windows-energy-eff': 'Good', 'floor-env-eff': 'N/A',
             'sheating-env-eff': 'N/A', 'lighting-description': 'Low energy lighting in 17% of fixed outlets',
             'roof-env-eff': 'Very Good', 'walls-energy-eff': 'Good', 'photo-supply': '',
             'lighting-cost-potential': '37', 'mainheat-env-eff': 'Very Good', 'multi-glaze-proportion': '',
             'main-heating-controls': '', 'lodgement-datetime': '2009-10-12 10:59:43', 'flat-top-storey': '',
             'current-energy-rating': 'B', 'secondheat-description': 'None', 'walls-env-eff': 'Good',
             'transaction-type': 'new dwelling', 'uprn': '10024087855', 'current-energy-efficiency': '81',
             'energy-consumption-current': '145', 'mainheat-description': 'Boiler and radiators, mains gas',
             'lighting-cost-current': '68', 'lodgement-date': '2009-10-12', 'extension-count': '',
             'mainheatc-env-eff': 'Average', 'lmk-key': '213678930302009101210594355619328', 'wind-turbine-count': '0',
             'tenure': '', 'floor-level': 'mid floor', 'potential-energy-efficiency': '83',
             'hot-water-energy-eff': 'Very Good', 'low-energy-lighting': '',
             'walls-description': 'Average thermal transmittance 0.41 W/m?K',
             'hotwater-description': 'From main system'},
            {'low-energy-fixed-light-count': '', 'address': 'Flat 8 Grove Mansions, Clapham Common North Side',
             'uprn-source': 'Address Matched', 'floor-height': '2.75', 'heating-cost-potential': '936',
             'unheated-corridor-length': '15.15', 'hot-water-cost-potential': '97',
             'construction-age-band': 'England and Wales: before 1900', 'potential-energy-rating': 'E',
             'mainheat-energy-eff': 'Good', 'windows-env-eff': 'Very Poor', 'lighting-energy-eff': 'Average',
             'environment-impact-potential': '46', 'glazed-type': 'single glazing', 'heating-cost-current': '927',
             'address3': '', 'mainheatcont-description': 'Programmer and room thermostat', 'sheating-energy-eff': 'N/A',
             'property-type': 'Flat', 'local-authority-label': 'Wandsworth', 'fixed-lighting-outlets-count': '',
             'energy-tariff': 'Single', 'mechanical-ventilation': 'natural', 'hot-water-cost-current': '97',
             'county': 'Greater London Authority', 'postcode': 'SW4 9SL', 'solar-water-heating-flag': 'N',
             'constituency': 'E14000549', 'co2-emissions-potential': '5.9', 'number-heated-rooms': '5',
             'floor-description': '(other premises below)', 'energy-consumption-potential': '374',
             'local-authority': 'E09000032', 'built-form': 'Mid-Terrace', 'number-open-fireplaces': '0',
             'windows-description': 'Single glazed', 'glazed-area': 'More Than Typical',
             'inspection-date': '2009-01-12', 'mains-gas-flag': 'Y', 'co2-emiss-curr-per-floor-area': '63',
             'address1': 'Flat 8 Grove Mansions', 'heat-loss-corridor': 'unheated corridor', 'flat-storey-count': '4.0',
             'constituency-label': 'Battersea', 'roof-energy-eff': 'Very Poor', 'total-floor-area': '96.03',
             'building-reference-number': '5346736568', 'environment-impact-current': '45',
             'co2-emissions-current': '6.0', 'roof-description': 'Pitched, no insulation (assumed)',
             'floor-energy-eff': 'N/A', 'number-habitable-rooms': '5', 'address2': 'Clapham Common North Side',
             'hot-water-env-eff': 'Very Good', 'posttown': 'LONDON', 'mainheatc-energy-eff': 'Poor',
             'main-fuel': 'mains gas - this is for backwards compatibility only and should not be used',
             'lighting-env-eff': 'Average', 'windows-energy-eff': 'Very Poor', 'floor-env-eff': 'N/A',
             'sheating-env-eff': 'N/A', 'lighting-description': 'Low energy lighting in 25% of fixed outlets',
             'roof-env-eff': 'Very Poor', 'walls-energy-eff': 'Very Poor', 'photo-supply': '0.0',
             'lighting-cost-potential': '46', 'mainheat-env-eff': 'Very Good', 'multi-glaze-proportion': '0',
             'main-heating-controls': '2104', 'lodgement-datetime': '2009-01-13 11:24:12', 'flat-top-storey': 'Y',
             'current-energy-rating': 'E', 'secondheat-description': 'Room heaters, electric',
             'walls-env-eff': 'Very Poor', 'transaction-type': 'rental (private)', 'uprn': '10024087855',
             'current-energy-efficiency': '45', 'energy-consumption-current': '380',
             'mainheat-description': 'Boiler and radiators, mains gas', 'lighting-cost-current': '80',
             'lodgement-date': '2009-01-13', 'extension-count': '0', 'mainheatc-env-eff': 'Poor',
             'lmk-key': '213678970922009011311241236228851', 'wind-turbine-count': '0', 'tenure': 'rental (private)',
             'floor-level': '3rd', 'potential-energy-efficiency': '47', 'hot-water-energy-eff': 'Good',
             'low-energy-lighting': '25', 'walls-description': 'Solid brick, as built, no insulation (assumed)',
             'hotwater-description': 'From main system'},
            {'low-energy-fixed-light-count': '', 'address': 'Flat 8 Grove Mansions, Clapham Common North Side',
             'uprn-source': 'Address Matched', 'floor-height': '2.71', 'heating-cost-potential': '220',
             'unheated-corridor-length': '5.17', 'hot-water-cost-potential': '90',
             'construction-age-band': 'England and Wales: before 1900', 'potential-energy-rating': 'B',
             'mainheat-energy-eff': 'Good', 'windows-env-eff': 'Very Poor', 'lighting-energy-eff': 'Very Good',
             'environment-impact-potential': '83', 'glazed-type': 'not defined', 'heating-cost-current': '418',
             'address3': '', 'mainheatcont-description': 'Programmer, room thermostat and TRVs',
             'sheating-energy-eff': 'N/A', 'property-type': 'Flat', 'local-authority-label': 'Wandsworth',
             'fixed-lighting-outlets-count': '6', 'energy-tariff': 'Single', 'mechanical-ventilation': 'natural',
             'hot-water-cost-current': '90', 'county': '', 'postcode': 'SW4 9SL', 'solar-water-heating-flag': 'N',
             'constituency': 'E14000549', 'co2-emissions-potential': '1.3', 'number-heated-rooms': '3',
             'floor-description': '(another dwelling below)', 'energy-consumption-potential': '101',
             'local-authority': 'E09000032', 'built-form': 'Mid-Terrace', 'number-open-fireplaces': '1',
             'windows-description': 'Single glazed', 'glazed-area': 'Normal', 'inspection-date': '2021-04-20',
             'mains-gas-flag': 'Y', 'co2-emiss-curr-per-floor-area': '33', 'address1': 'Flat 8 Grove Mansions',
             'heat-loss-corridor': 'unheated corridor', 'flat-storey-count': '', 'constituency-label': 'Battersea',
             'roof-energy-eff': 'N/A', 'total-floor-area': '74.0', 'building-reference-number': '5346736568',
             'environment-impact-current': '68', 'co2-emissions-current': '2.4',
             'roof-description': '(another dwelling above)', 'floor-energy-eff': 'N/A', 'number-habitable-rooms': '3',
             'address2': 'Clapham Common North Side', 'hot-water-env-eff': 'Good', 'posttown': 'LONDON',
             'mainheatc-energy-eff': 'Good', 'main-fuel': 'mains gas (not community)', 'lighting-env-eff': 'Very Good',
             'windows-energy-eff': 'Very Poor', 'floor-env-eff': 'N/A', 'sheating-env-eff': 'N/A',
             'lighting-description': 'Low energy lighting in all fixed outlets', 'roof-env-eff': 'N/A',
             'walls-energy-eff': 'Very Poor', 'photo-supply': '0.0', 'lighting-cost-potential': '64',
             'mainheat-env-eff': 'Good', 'multi-glaze-proportion': '0', 'main-heating-controls': '',
             'lodgement-datetime': '2021-04-20 17:04:30', 'flat-top-storey': 'N', 'current-energy-rating': 'C',
             'secondheat-description': 'None', 'walls-env-eff': 'Very Poor', 'transaction-type': 'rental',
             'uprn': '10024087855', 'current-energy-efficiency': '70', 'energy-consumption-current': '185',
             'mainheat-description': 'Boiler and radiators, mains gas', 'lighting-cost-current': '63',
             'lodgement-date': '2021-04-20', 'extension-count': '0', 'mainheatc-env-eff': 'Good',
             'lmk-key': '9ad43b42840825a143c7dad8ca36a199f15a72c4df9dd2f07696cc087f04e1e3', 'wind-turbine-count': '0',
             'tenure': 'Rented (private)', 'floor-level': '03', 'potential-energy-efficiency': '81',
             'hot-water-energy-eff': 'Good', 'low-energy-lighting': '100',
             'walls-description': 'Solid brick, as built, no insulation (assumed)',
             'hotwater-description': 'From main system'}
        ],
        "measures": [
            [["secondary_glazing", "low_energy_lighting"], "3", {}, [0, 1]],
            [
                ["secondary_glazing", "low_energy_lighting", "internal_wall_insulation"],
                "8",
                {},
                [0, 1, 2]
            ],
            [
                ["double_glazing", "internal_wall_insulation", "low_energy_lighting"],
                "9",
                {},
                [0, 1, 2]
            ],
            [
                ["internal_wall_insulation"],
                "5",
                {},
                [0]
            ],
            [
                ["internal_wall_insulation", "low_energy_lighting"],
                "5",
                {},
                [0, 1]
            ],
        ],
    },

    {
        "address": "Flat 9 Grove Mansions",
        "postcode": "SW4 9SL",
        "lmk-key": None,
        "epc": {
            'low-energy-fixed-light-count': '10', 'address': 'Flat 9 Grove Mansions, 111, Clapham Common North Side',
            'uprn-source': 'Address Matched', 'floor-height': 3.25, 'heating-cost-potential': '692',
            'unheated-corridor-length': '8.45', 'hot-water-cost-potential': '195',
            'construction-age-band': 'England and Wales: before 1900', 'potential-energy-rating': 'C',
            'mainheat-energy-eff': 'Good', 'windows-env-eff': 'Very Poor', 'lighting-energy-eff': 'Good',
            'environment-impact-potential': '73', 'glazed-type': 'Single glazing', 'heating-cost-current': '1206',
            'address3': None, 'mainheatcont-description': 'Programmer, room thermostat and TRVs',
            'sheating-energy-eff': 'N/A', 'property-type': 'Flat', 'local-authority-label': 'Wandsworth',
            'fixed-lighting-outlets-count': '18', 'energy-tariff': 'Single', 'mechanical-ventilation': 'natural',
            'hot-water-cost-current': '193', 'county': '', 'postcode': 'SW4 9SL', 'solar-water-heating-flag': 'N',
            'constituency': 'E14000549', 'co2-emissions-potential': '2.5', 'number-heated-rooms': '4',
            'floor-description': 'Suspended, no insulation (assumed)', 'energy-consumption-potential': '131',
            'local-authority': 'E09000032', 'built-form': 'Mid-Terrace', 'number-open-fireplaces': '4',
            'windows-description': 'Single glazed', 'glazed-area': 'Much More Than Typical',
            'inspection-date': datetime(2024, 8, 13, 0, 0, tzinfo=timezone.utc),
            'mains-gas-flag': 'Y', 'co2-emiss-curr-per-floor-area': '38', 'address1': 'Flat 9 Grove Mansions, 111',
            'heat-loss-corridor': 'unheated corridor', 'flat-storey-count': None, 'constituency-label': 'Battersea',
            'roof-energy-eff': 'N/A', 'total-floor-area': '106', 'building-reference-number': '',
            'environment-impact-current': '56', 'co2-emissions-current': '4.0',
            'roof-description': '(another dwelling above)', 'floor-energy-eff': 'N/A', 'number-habitable-rooms': '4',
            'address2': 'Clapham Common North Side', 'hot-water-env-eff': 'Good', 'posttown': 'LONDON',
            'mainheatc-energy-eff': 'Good', 'main-fuel': 'mains gas (not community)', 'lighting-env-eff': 'Good',
            'windows-energy-eff': 'Very Poor', 'floor-env-eff': 'N/A', 'sheating-env-eff': 'N/A',
            'lighting-description': 'Low energy lighting in 56% of fixed outlets', 'roof-env-eff': 'N/A',
            'walls-energy-eff': 'Poor', 'photo-supply': '0', 'lighting-cost-potential': '122',
            'mainheat-env-eff': 'Good', 'multi-glaze-proportion': '0',
            'main-heating-controls': 'Programmer, room thermostat and TRVs',
            'lodgement-datetime': datetime(2024, 8, 13, 0, 0), 'flat-top-storey': 'N',
            'current-energy-rating': 'D', 'secondheat-description': 'None', 'walls-env-eff': 'Poor',
            'transaction-type': 'ECO assessment', 'uprn': 121016128, 'current-energy-efficiency': '63',
            'energy-consumption-current': '216', 'mainheat-description': 'Boiler and radiators, mains gas',
            'lighting-cost-current': '174', 'lodgement-date': date(2024, 8, 13), 'extension-count': '1',
            'mainheatc-env-eff': 'Good', 'lmk-key': '', 'wind-turbine-count': '0', 'tenure': 'Rented (social)',
            'floor-level': '1', 'potential-energy-efficiency': '75', 'hot-water-energy-eff': 'Good',
            'low-energy-lighting': '56', 'walls-description': 'Solid brick, as built, no insulation (assumed)',
            'hotwater-description': 'From main system'
        },
        "old_epcs": [
            {'low-energy-fixed-light-count': '10', 'address': 'Flat 9 Grove Mansions, Clapham Common North Side',
             'uprn-source': 'Address Matched', 'floor-height': '', 'heating-cost-potential': '419',
             'unheated-corridor-length': '10.99', 'hot-water-cost-potential': '91',
             'construction-age-band': 'England and Wales: 1900-1929', 'potential-energy-rating': 'C',
             'mainheat-energy-eff': 'Good', 'windows-env-eff': 'Very Poor', 'lighting-energy-eff': 'Very Good',
             'environment-impact-potential': '78', 'glazed-type': 'not defined', 'heating-cost-current': '775',
             'address3': '', 'mainheatcont-description': 'Programmer, room thermostat and TRVs',
             'sheating-energy-eff': 'N/A', 'property-type': 'Flat', 'local-authority-label': 'Wandsworth',
             'fixed-lighting-outlets-count': '10', 'energy-tariff': 'Unknown', 'mechanical-ventilation': 'natural',
             'hot-water-cost-current': '90', 'county': 'Greater London Authority', 'postcode': 'SW4 9SL',
             'solar-water-heating-flag': '', 'constituency': 'E14000549', 'co2-emissions-potential': '2.5',
             'number-heated-rooms': '5', 'floor-description': 'Suspended, no insulation (assumed)',
             'energy-consumption-potential': '113', 'local-authority': 'E09000032', 'built-form': 'Mid-Terrace',
             'number-open-fireplaces': '1', 'windows-description': 'Single glazed', 'glazed-area': 'Normal',
             'inspection-date': '2012-10-23', 'mains-gas-flag': 'Y', 'co2-emiss-curr-per-floor-area': '40',
             'address1': 'Flat 9 Grove Mansions', 'heat-loss-corridor': 'unheated corridor', 'flat-storey-count': '',
             'constituency-label': 'Battersea', 'roof-energy-eff': 'N/A', 'total-floor-area': '115.0',
             'building-reference-number': '3676662078', 'environment-impact-current': '60',
             'co2-emissions-current': '4.5', 'roof-description': '(another dwelling above)', 'floor-energy-eff': 'N/A',
             'number-habitable-rooms': '5', 'address2': 'Clapham Common North Side', 'hot-water-env-eff': 'Good',
             'posttown': 'LONDON', 'mainheatc-energy-eff': 'Good', 'main-fuel': 'mains gas (not community)',
             'lighting-env-eff': 'Very Good', 'windows-energy-eff': 'Very Poor', 'floor-env-eff': 'N/A',
             'sheating-env-eff': 'N/A', 'lighting-description': 'Low energy lighting in all fixed outlets',
             'roof-env-eff': 'N/A', 'walls-energy-eff': 'Very Poor', 'photo-supply': '0.0',
             'lighting-cost-potential': '62', 'mainheat-env-eff': 'Good', 'multi-glaze-proportion': '0',
             'main-heating-controls': '2106', 'lodgement-datetime': '2012-10-23 22:45:57', 'flat-top-storey': 'N',
             'current-energy-rating': 'D', 'secondheat-description': 'None', 'walls-env-eff': 'Very Poor',
             'transaction-type': 'rental (private)', 'uprn': '121016128', 'current-energy-efficiency': '64',
             'energy-consumption-current': '205', 'mainheat-description': 'Boiler and radiators, mains gas',
             'lighting-cost-current': '60', 'lodgement-date': '2012-10-23', 'extension-count': '1',
             'mainheatc-env-eff': 'Good', 'lmk-key': '849060769222012102322455762878332', 'wind-turbine-count': '0',
             'tenure': 'rental (private)', 'floor-level': 'Ground', 'potential-energy-efficiency': '78',
             'hot-water-energy-eff': 'Good', 'low-energy-lighting': '100',
             'walls-description': 'Solid brick, as built, no insulation (assumed)',
             'hotwater-description': 'From main system'},
            {'low-energy-fixed-light-count': '', 'address': 'Flat 9, Grove Mansions, 111 Clapham Common North Side',
             'uprn-source': 'Energy Assessor', 'floor-height': '2.9', 'heating-cost-potential': '269',
             'unheated-corridor-length': '8.05', 'hot-water-cost-potential': '99',
             'construction-age-band': 'England and Wales: before 1900', 'potential-energy-rating': 'B',
             'mainheat-energy-eff': 'Good', 'windows-env-eff': 'Very Poor', 'lighting-energy-eff': 'Very Good',
             'environment-impact-potential': '82', 'glazed-type': 'not defined', 'heating-cost-current': '490',
             'address3': '111 Clapham Common North Side',
             'mainheatcont-description': 'Programmer, room thermostat and TRVs', 'sheating-energy-eff': 'N/A',
             'property-type': 'Flat', 'local-authority-label': 'Wandsworth', 'fixed-lighting-outlets-count': '10',
             'energy-tariff': 'Single', 'mechanical-ventilation': 'natural', 'hot-water-cost-current': '98',
             'county': '', 'postcode': 'SW4 9SL', 'solar-water-heating-flag': 'N', 'constituency': 'E14000549',
             'co2-emissions-potential': '1.7', 'number-heated-rooms': '5',
             'floor-description': '(another dwelling below)', 'energy-consumption-potential': '96',
             'local-authority': 'E09000032', 'built-form': 'Semi-Detached', 'number-open-fireplaces': '0',
             'windows-description': 'Single glazed', 'glazed-area': 'Normal', 'inspection-date': '2022-10-25',
             'mains-gas-flag': 'Y', 'co2-emiss-curr-per-floor-area': '29', 'address1': 'Flat 9',
             'heat-loss-corridor': 'unheated corridor', 'flat-storey-count': '', 'constituency-label': 'Battersea',
             'roof-energy-eff': 'N/A', 'total-floor-area': '101.0', 'building-reference-number': '10003516043',
             'environment-impact-current': '68', 'co2-emissions-current': '3.0',
             'roof-description': '(another dwelling above)', 'floor-energy-eff': 'N/A', 'number-habitable-rooms': '5',
             'address2': 'Grove Mansions', 'hot-water-env-eff': 'Good', 'posttown': 'LONDON',
             'mainheatc-energy-eff': 'Good', 'main-fuel': 'mains gas (not community)', 'lighting-env-eff': 'Very Good',
             'windows-energy-eff': 'Very Poor', 'floor-env-eff': 'N/A', 'sheating-env-eff': 'N/A',
             'lighting-description': 'Low energy lighting in all fixed outlets', 'roof-env-eff': 'N/A',
             'walls-energy-eff': 'Very Poor', 'photo-supply': '0.0', 'lighting-cost-potential': '89',
             'mainheat-env-eff': 'Good', 'multi-glaze-proportion': '0', 'main-heating-controls': '',
             'lodgement-datetime': '2022-10-26 12:39:24', 'flat-top-storey': 'N', 'current-energy-rating': 'C',
             'secondheat-description': 'None', 'walls-env-eff': 'Very Poor', 'transaction-type': 'rental',
             'uprn': '121016128', 'current-energy-efficiency': '71', 'energy-consumption-current': '167',
             'mainheat-description': 'Boiler and radiators, mains gas', 'lighting-cost-current': '87',
             'lodgement-date': '2022-10-26', 'extension-count': '0', 'mainheatc-env-eff': 'Good',
             'lmk-key': '23b377c4b89f9c38549193042ad6d991972db2a43404ba2826ccb9a2bf64540d', 'wind-turbine-count': '0',
             'tenure': 'Rented (private)', 'floor-level': '01', 'potential-energy-efficiency': '81',
             'hot-water-energy-eff': 'Good', 'low-energy-lighting': '100',
             'walls-description': 'Solid brick, as built, no insulation (assumed)',
             'hotwater-description': 'From main system'}],
        "measures": [
            [["secondary_glazing", "low_energy_lighting"], "2", {}, [0, 1]],
            [
                ["secondary_glazing", "low_energy_lighting", "internal_wall_insulation", "suspended_floor_insulation"],
                "9",
                {},
                [0, 1, 2, 3]
            ],
            [
                ["double_glazing", "low_energy_lighting", "internal_wall_insulation", "suspended_floor_insulation"],
                "11",
                {},
                [0, 1, 2, 3]
            ],
            [
                ["internal_wall_insulation"],
                "6",
                {},
                [0]
            ],
            [
                ["internal_wall_insulation", "suspended_floor_insulation"],
                "7",
                {},
                [0, 1]
            ],
            [
                ["internal_wall_insulation", "suspended_floor_insulation", "low_energy_lighting"],
                "8",
                {},
                [0, 1, 2]
            ],
        ],
    },

    {
        "address": "Flat 5 Grove Mansions",
        "postcode": "SW4 9SL",
        "lmk-key": None,
        "epc": {
            'low-energy-fixed-light-count': '1', 'address': 'Flat 5 Grove Mansions, 111, Clapham Common North Side',
            'uprn-source': 'Address Matched', 'floor-height': 2.95, 'heating-cost-potential': '390',
            'unheated-corridor-length': '3.85', 'hot-water-cost-potential': '192',
            'construction-age-band': 'England and Wales: 1900-1929', 'potential-energy-rating': 'B',
            'mainheat-energy-eff': 'Good', 'windows-env-eff': 'Very Poor', 'lighting-energy-eff': 'Poor',
            'environment-impact-potential': '83', 'glazed-type': 'Single glazing', 'heating-cost-current': '945',
            'address3': None, 'mainheatcont-description': 'Programmer and room thermostat',
            'sheating-energy-eff': 'N/A', 'property-type': 'Flat', 'local-authority-label': 'Wandsworth',
            'fixed-lighting-outlets-count': '8', 'energy-tariff': 'Single', 'mechanical-ventilation': 'natural',
            'hot-water-cost-current': '188', 'county': '', 'postcode': 'SW4 9SL', 'solar-water-heating-flag': 'N',
            'constituency': 'E14000549', 'co2-emissions-potential': '1.5', 'number-heated-rooms': '4',
            'floor-description': '(another dwelling below)', 'energy-consumption-potential': '97',
            'local-authority': 'E09000032', 'built-form': 'End-Terrace', 'number-open-fireplaces': '0',
            'windows-description': 'Single glazed', 'glazed-area': 'Much More Than Typical',
            'inspection-date': datetime(2024, 8, 27, 0, 0, tzinfo=timezone.utc),
            'mains-gas-flag': 'Y', 'co2-emiss-curr-per-floor-area': '37', 'address1': 'Flat 5 Grove Mansions, 111',
            'heat-loss-corridor': 'unheated corridor', 'flat-storey-count': None, 'constituency-label': 'Battersea',
            'roof-energy-eff': 'N/A', 'total-floor-area': '90', 'building-reference-number': '',
            'environment-impact-current': '62', 'co2-emissions-current': '3.3',
            'roof-description': '(another dwelling above)', 'floor-energy-eff': 'N/A',
            'number-habitable-rooms': '4', 'address2': 'Clapham Common North Side', 'hot-water-env-eff': 'Good',
            'posttown': 'LONDON', 'mainheatc-energy-eff': 'Average', 'main-fuel': 'mains gas (not community)',
            'lighting-env-eff': 'Poor', 'windows-energy-eff': 'Very Poor', 'floor-env-eff': 'N/A',
            'sheating-env-eff': 'N/A', 'lighting-description': 'Low energy lighting in 13% of fixed outlets',
            'roof-env-eff': 'N/A', 'walls-energy-eff': 'Very Poor', 'photo-supply': '0',
            'lighting-cost-potential': '108', 'mainheat-env-eff': 'Good', 'multi-glaze-proportion': '0',
            'main-heating-controls': 'Programmer and room thermostat',
            'lodgement-datetime': datetime(2024, 8, 27, 0, 0), 'flat-top-storey': 'N',
            'current-energy-rating': 'D', 'secondheat-description': 'None', 'walls-env-eff': 'Very Poor',
            'transaction-type': 'ECO assessment', 'uprn': 121016124, 'current-energy-efficiency': '66',
            'energy-consumption-current': '209', 'mainheat-description': 'Boiler and radiators, mains gas',
            'lighting-cost-current': '202', 'lodgement-date': date(2024, 8, 27), 'extension-count': '1',
            'mainheatc-env-eff': 'Average', 'lmk-key': '', 'wind-turbine-count': '0', 'tenure': 'Rented (private)',
            'floor-level': '2', 'potential-energy-efficiency': '81', 'hot-water-energy-eff': 'Good',
            'low-energy-lighting': '13', 'walls-description': 'Solid brick, as built, no insulation (assumed)',
            'hotwater-description': 'From main system'
        },
        "old_epcs": [
            {'low-energy-fixed-light-count': '10', 'address': 'Flat 9 Grove Mansions, Clapham Common North Side',
             'uprn-source': 'Address Matched', 'floor-height': '', 'heating-cost-potential': '419',
             'unheated-corridor-length': '10.99', 'hot-water-cost-potential': '91',
             'construction-age-band': 'England and Wales: 1900-1929', 'potential-energy-rating': 'C',
             'mainheat-energy-eff': 'Good', 'windows-env-eff': 'Very Poor', 'lighting-energy-eff': 'Very Good',
             'environment-impact-potential': '78', 'glazed-type': 'not defined', 'heating-cost-current': '775',
             'address3': '', 'mainheatcont-description': 'Programmer, room thermostat and TRVs',
             'sheating-energy-eff': 'N/A', 'property-type': 'Flat', 'local-authority-label': 'Wandsworth',
             'fixed-lighting-outlets-count': '10', 'energy-tariff': 'Unknown', 'mechanical-ventilation': 'natural',
             'hot-water-cost-current': '90', 'county': 'Greater London Authority', 'postcode': 'SW4 9SL',
             'solar-water-heating-flag': '', 'constituency': 'E14000549', 'co2-emissions-potential': '2.5',
             'number-heated-rooms': '5', 'floor-description': 'Suspended, no insulation (assumed)',
             'energy-consumption-potential': '113', 'local-authority': 'E09000032', 'built-form': 'Mid-Terrace',
             'number-open-fireplaces': '1', 'windows-description': 'Single glazed', 'glazed-area': 'Normal',
             'inspection-date': '2012-10-23', 'mains-gas-flag': 'Y', 'co2-emiss-curr-per-floor-area': '40',
             'address1': 'Flat 9 Grove Mansions', 'heat-loss-corridor': 'unheated corridor', 'flat-storey-count': '',
             'constituency-label': 'Battersea', 'roof-energy-eff': 'N/A', 'total-floor-area': '115.0',
             'building-reference-number': '3676662078', 'environment-impact-current': '60',
             'co2-emissions-current': '4.5', 'roof-description': '(another dwelling above)', 'floor-energy-eff': 'N/A',
             'number-habitable-rooms': '5', 'address2': 'Clapham Common North Side', 'hot-water-env-eff': 'Good',
             'posttown': 'LONDON', 'mainheatc-energy-eff': 'Good', 'main-fuel': 'mains gas (not community)',
             'lighting-env-eff': 'Very Good', 'windows-energy-eff': 'Very Poor', 'floor-env-eff': 'N/A',
             'sheating-env-eff': 'N/A', 'lighting-description': 'Low energy lighting in all fixed outlets',
             'roof-env-eff': 'N/A', 'walls-energy-eff': 'Very Poor', 'photo-supply': '0.0',
             'lighting-cost-potential': '62', 'mainheat-env-eff': 'Good', 'multi-glaze-proportion': '0',
             'main-heating-controls': '2106', 'lodgement-datetime': '2012-10-23 22:45:57', 'flat-top-storey': 'N',
             'current-energy-rating': 'D', 'secondheat-description': 'None', 'walls-env-eff': 'Very Poor',
             'transaction-type': 'rental (private)', 'uprn': '121016128', 'current-energy-efficiency': '64',
             'energy-consumption-current': '205', 'mainheat-description': 'Boiler and radiators, mains gas',
             'lighting-cost-current': '60', 'lodgement-date': '2012-10-23', 'extension-count': '1',
             'mainheatc-env-eff': 'Good', 'lmk-key': '849060769222012102322455762878332', 'wind-turbine-count': '0',
             'tenure': 'rental (private)', 'floor-level': 'Ground', 'potential-energy-efficiency': '78',
             'hot-water-energy-eff': 'Good', 'low-energy-lighting': '100',
             'walls-description': 'Solid brick, as built, no insulation (assumed)',
             'hotwater-description': 'From main system'},
            {'low-energy-fixed-light-count': '', 'address': 'Flat 9, Grove Mansions, 111 Clapham Common North Side',
             'uprn-source': 'Energy Assessor', 'floor-height': '2.9', 'heating-cost-potential': '269',
             'unheated-corridor-length': '8.05', 'hot-water-cost-potential': '99',
             'construction-age-band': 'England and Wales: before 1900', 'potential-energy-rating': 'B',
             'mainheat-energy-eff': 'Good', 'windows-env-eff': 'Very Poor', 'lighting-energy-eff': 'Very Good',
             'environment-impact-potential': '82', 'glazed-type': 'not defined', 'heating-cost-current': '490',
             'address3': '111 Clapham Common North Side',
             'mainheatcont-description': 'Programmer, room thermostat and TRVs', 'sheating-energy-eff': 'N/A',
             'property-type': 'Flat', 'local-authority-label': 'Wandsworth', 'fixed-lighting-outlets-count': '10',
             'energy-tariff': 'Single', 'mechanical-ventilation': 'natural', 'hot-water-cost-current': '98',
             'county': '', 'postcode': 'SW4 9SL', 'solar-water-heating-flag': 'N', 'constituency': 'E14000549',
             'co2-emissions-potential': '1.7', 'number-heated-rooms': '5',
             'floor-description': '(another dwelling below)', 'energy-consumption-potential': '96',
             'local-authority': 'E09000032', 'built-form': 'Semi-Detached', 'number-open-fireplaces': '0',
             'windows-description': 'Single glazed', 'glazed-area': 'Normal', 'inspection-date': '2022-10-25',
             'mains-gas-flag': 'Y', 'co2-emiss-curr-per-floor-area': '29', 'address1': 'Flat 9',
             'heat-loss-corridor': 'unheated corridor', 'flat-storey-count': '', 'constituency-label': 'Battersea',
             'roof-energy-eff': 'N/A', 'total-floor-area': '101.0', 'building-reference-number': '10003516043',
             'environment-impact-current': '68', 'co2-emissions-current': '3.0',
             'roof-description': '(another dwelling above)', 'floor-energy-eff': 'N/A', 'number-habitable-rooms': '5',
             'address2': 'Grove Mansions', 'hot-water-env-eff': 'Good', 'posttown': 'LONDON',
             'mainheatc-energy-eff': 'Good', 'main-fuel': 'mains gas (not community)', 'lighting-env-eff': 'Very Good',
             'windows-energy-eff': 'Very Poor', 'floor-env-eff': 'N/A', 'sheating-env-eff': 'N/A',
             'lighting-description': 'Low energy lighting in all fixed outlets', 'roof-env-eff': 'N/A',
             'walls-energy-eff': 'Very Poor', 'photo-supply': '0.0', 'lighting-cost-potential': '89',
             'mainheat-env-eff': 'Good', 'multi-glaze-proportion': '0', 'main-heating-controls': '',
             'lodgement-datetime': '2022-10-26 12:39:24', 'flat-top-storey': 'N', 'current-energy-rating': 'C',
             'secondheat-description': 'None', 'walls-env-eff': 'Very Poor', 'transaction-type': 'rental',
             'uprn': '121016128', 'current-energy-efficiency': '71', 'energy-consumption-current': '167',
             'mainheat-description': 'Boiler and radiators, mains gas', 'lighting-cost-current': '87',
             'lodgement-date': '2022-10-26', 'extension-count': '0', 'mainheatc-env-eff': 'Good',
             'lmk-key': '23b377c4b89f9c38549193042ad6d991972db2a43404ba2826ccb9a2bf64540d', 'wind-turbine-count': '0',
             'tenure': 'Rented (private)', 'floor-level': '01', 'potential-energy-efficiency': '81',
             'hot-water-energy-eff': 'Good', 'low-energy-lighting': '100',
             'walls-description': 'Solid brick, as built, no insulation (assumed)',
             'hotwater-description': 'From main system'}],
        "measures": [
            [["secondary_glazing", "low_energy_lighting"], "5", {}, [0, 1]],
            [
                ["secondary_glazing", "low_energy_lighting", "internal_wall_insulation"],
                "13",
                {},
                [0, 1, 2]
            ],
            [
                ["double_glazing", "low_energy_lighting", "internal_wall_insulation"],
                "15",
                {},
                [0, 1, 2]
            ],
            [
                ["internal_wall_insulation"],
                "8",
                {},
                [0]
            ],
            [
                ["low_energy_lighting", "internal_wall_insulation"],
                "10",
                {},
                [0, 1, 2]
            ],
        ],
    },

    {
        "address": "Flat 14 Grove Mansions",
        "postcode": "SW4 9SL",
        "lmk-key": None,
        "epc": {
            'low-energy-fixed-light-count': '9', 'address': 'Flat 14 Grove Mansions, 111, Clapham Common North Side',
            'uprn-source': 'Address Matched', 'floor-height': 3.0, 'heating-cost-potential': '437',
            'unheated-corridor-length': '3.9', 'hot-water-cost-potential': '187',
            'construction-age-band': 'England and Wales: before 1900', 'potential-energy-rating': 'C',
            'mainheat-energy-eff': 'Good', 'windows-env-eff': 'Very Poor', 'lighting-energy-eff': 'Good',
            'environment-impact-potential': '79', 'glazed-type': 'Single glazing', 'heating-cost-current': '841',
            'address3': None, 'mainheatcont-description': 'Programmer, room thermostat and TRVs',
            'sheating-energy-eff': 'N/A', 'property-type': 'Flat', 'local-authority-label': 'Wandsworth',
            'fixed-lighting-outlets-count': '19', 'energy-tariff': 'Dual', 'mechanical-ventilation': 'natural',
            'hot-water-cost-current': '184', 'county': '', 'postcode': 'SW4 9SL', 'solar-water-heating-flag': 'N',
            'constituency': 'E14000549', 'co2-emissions-potential': '1.6', 'number-heated-rooms': '4',
            'floor-description': '(another dwelling below)', 'energy-consumption-potential': '111',
            'local-authority': 'E09000032', 'built-form': 'End-Terrace', 'number-open-fireplaces': '3',
            'windows-description': 'Single glazed', 'glazed-area': 'Much More Than Typical',
            'inspection-date': datetime(2024, 8, 13, 0, 0, tzinfo=timezone.utc),
            'mains-gas-flag': 'Y', 'co2-emiss-curr-per-floor-area': '35', 'address1': 'Flat 14 Grove Mansions, 111',
            'heat-loss-corridor': 'unheated corridor', 'flat-storey-count': None, 'constituency-label': 'Battersea',
            'roof-energy-eff': 'N/A', 'total-floor-area': '83', 'building-reference-number': '',
            'environment-impact-current': '64', 'co2-emissions-current': '2.9',
            'roof-description': '(another dwelling above)', 'floor-energy-eff': 'N/A', 'number-habitable-rooms': '4',
            'address2': 'Clapham Common North Side', 'hot-water-env-eff': 'Good', 'posttown': 'LONDON',
            'mainheatc-energy-eff': 'Good', 'main-fuel': 'mains gas (not community)', 'lighting-env-eff': 'Good',
            'windows-energy-eff': 'Very Poor', 'floor-env-eff': 'N/A', 'sheating-env-eff': 'N/A',
            'lighting-description': 'Low energy lighting in 47% of fixed outlets', 'roof-env-eff': 'N/A',
            'walls-energy-eff': 'Poor', 'photo-supply': '0', 'lighting-cost-potential': '117',
            'mainheat-env-eff': 'Good', 'multi-glaze-proportion': '0',
            'main-heating-controls': 'Programmer, room thermostat and TRVs',
            'lodgement-datetime': datetime(2024, 8, 13, 0, 0), 'flat-top-storey': 'N',
            'current-energy-rating': 'D', 'secondheat-description': 'None', 'walls-env-eff': 'Poor',
            'transaction-type': 'ECO assessment', 'uprn': 121016117, 'current-energy-efficiency': '67',
            'energy-consumption-current': '198', 'mainheat-description': 'Boiler and radiators, mains gas',
            'lighting-cost-current': '179', 'lodgement-date': date(2024, 8, 13), 'extension-count': '1',
            'mainheatc-env-eff': 'Good', 'lmk-key': '', 'wind-turbine-count': '0', 'tenure': 'Rented (social)',
            'floor-level': '2', 'potential-energy-efficiency': '79', 'hot-water-energy-eff': 'Good',
            'low-energy-lighting': '47', 'walls-description': 'Solid brick, as built, no insulation (assumed)',
            'hotwater-description': 'From main system'
        },
        "old_epcs": [
            {'low-energy-fixed-light-count': '12', 'address': 'Flat 14 Grove Mansions, Clapham Common North Side',
             'uprn-source': 'Address Matched', 'floor-height': '', 'heating-cost-potential': '305',
             'unheated-corridor-length': '8.15', 'hot-water-cost-potential': '92',
             'construction-age-band': 'England and Wales: before 1900', 'potential-energy-rating': 'B',
             'mainheat-energy-eff': 'Good', 'windows-env-eff': 'Very Poor', 'lighting-energy-eff': 'Very Good',
             'environment-impact-potential': '84', 'glazed-type': 'not defined', 'heating-cost-current': '639',
             'address3': '', 'mainheatcont-description': 'Programmer, room thermostat and TRVs',
             'sheating-energy-eff': 'N/A', 'property-type': 'Maisonette', 'local-authority-label': 'Wandsworth',
             'fixed-lighting-outlets-count': '12', 'energy-tariff': 'Single', 'mechanical-ventilation': 'natural',
             'hot-water-cost-current': '90', 'county': 'Greater London Authority', 'postcode': 'SW4 9SL',
             'solar-water-heating-flag': '', 'constituency': 'E14000549', 'co2-emissions-potential': '1.8',
             'number-heated-rooms': '4', 'floor-description': '(other premises below)',
             'energy-consumption-potential': '83', 'local-authority': 'E09000032', 'built-form': 'End-Terrace',
             'number-open-fireplaces': '0', 'windows-description': 'Single glazed', 'glazed-area': 'Normal',
             'inspection-date': '2012-07-09', 'mains-gas-flag': 'Y', 'co2-emiss-curr-per-floor-area': '33',
             'address1': 'Flat 14 Grove Mansions', 'heat-loss-corridor': 'unheated corridor', 'flat-storey-count': '',
             'constituency-label': 'Battersea', 'roof-energy-eff': 'N/A', 'total-floor-area': '115.0',
             'building-reference-number': '8277395668', 'environment-impact-current': '67',
             'co2-emissions-current': '3.7', 'roof-description': '(another dwelling above)', 'floor-energy-eff': 'N/A',
             'number-habitable-rooms': '4', 'address2': 'Clapham Common North Side', 'hot-water-env-eff': 'Good',
             'posttown': 'LONDON', 'mainheatc-energy-eff': 'Good', 'main-fuel': 'mains gas (not community)',
             'lighting-env-eff': 'Very Good', 'windows-energy-eff': 'Very Poor', 'floor-env-eff': 'N/A',
             'sheating-env-eff': 'N/A', 'lighting-description': 'Low energy lighting in all fixed outlets',
             'roof-env-eff': 'N/A', 'walls-energy-eff': 'Very Poor', 'photo-supply': '0.0',
             'lighting-cost-potential': '62', 'mainheat-env-eff': 'Good', 'multi-glaze-proportion': '0',
             'main-heating-controls': '2106', 'lodgement-datetime': '2012-07-25 10:03:53', 'flat-top-storey': 'N',
             'current-energy-rating': 'C', 'secondheat-description': 'None', 'walls-env-eff': 'Very Poor',
             'transaction-type': 'rental (private)', 'uprn': '121016117', 'current-energy-efficiency': '69',
             'energy-consumption-current': '169', 'mainheat-description': 'Boiler and radiators, mains gas',
             'lighting-cost-current': '61', 'lodgement-date': '2012-07-25', 'extension-count': '0',
             'mainheatc-env-eff': 'Good', 'lmk-key': '342255683232012072510035337068302', 'wind-turbine-count': '0',
             'tenure': 'rental (private)', 'floor-level': '1st', 'potential-energy-efficiency': '82',
             'hot-water-energy-eff': 'Good', 'low-energy-lighting': '100',
             'walls-description': 'Solid brick, as built, no insulation (assumed)',
             'hotwater-description': 'From main system'},
            {'low-energy-fixed-light-count': '', 'address': 'Flat 14 Grove Mansions, Clapham Common North Side',
             'uprn-source': 'Address Matched', 'floor-height': '3.0', 'heating-cost-potential': '833',
             'unheated-corridor-length': '16.07', 'hot-water-cost-potential': '101',
             'construction-age-band': 'England and Wales: before 1900', 'potential-energy-rating': 'D',
             'mainheat-energy-eff': 'Very Good', 'windows-env-eff': 'Very Poor', 'lighting-energy-eff': 'Good',
             'environment-impact-potential': '53', 'glazed-type': 'single glazing', 'heating-cost-current': '853',
             'address3': '', 'mainheatcont-description': 'Programmer and room thermostat', 'sheating-energy-eff': 'N/A',
             'property-type': 'Flat', 'local-authority-label': 'Wandsworth', 'fixed-lighting-outlets-count': '',
             'energy-tariff': 'Single', 'mechanical-ventilation': 'natural', 'hot-water-cost-current': '101',
             'county': 'Greater London Authority', 'postcode': 'SW4 9SL', 'solar-water-heating-flag': 'N',
             'constituency': 'E14000549', 'co2-emissions-potential': '5.0', 'number-heated-rooms': '4',
             'floor-description': '(other premises below)', 'energy-consumption-potential': '312',
             'local-authority': 'E09000032', 'built-form': 'Semi-Detached', 'number-open-fireplaces': '0',
             'windows-description': 'Single glazed', 'glazed-area': 'Normal', 'inspection-date': '2009-07-31',
             'mains-gas-flag': 'Y', 'co2-emiss-curr-per-floor-area': '54', 'address1': 'Flat 14 Grove Mansions',
             'heat-loss-corridor': 'unheated corridor', 'flat-storey-count': '4.0', 'constituency-label': 'Battersea',
             'roof-energy-eff': 'N/A', 'total-floor-area': '96.6', 'building-reference-number': '8277395668',
             'environment-impact-current': '52', 'co2-emissions-current': '5.2',
             'roof-description': '(another dwelling above)', 'floor-energy-eff': 'N/A', 'number-habitable-rooms': '5',
             'address2': 'Clapham Common North Side', 'hot-water-env-eff': 'Very Good', 'posttown': 'LONDON',
             'mainheatc-energy-eff': 'Poor',
             'main-fuel': 'mains gas - this is for backwards compatibility only and should not be used',
             'lighting-env-eff': 'Good', 'windows-energy-eff': 'Very Poor', 'floor-env-eff': 'N/A',
             'sheating-env-eff': 'N/A', 'lighting-description': 'Low energy lighting in 50% of fixed outlets',
             'roof-env-eff': 'N/A', 'walls-energy-eff': 'Very Poor', 'photo-supply': '0.0',
             'lighting-cost-potential': '50', 'mainheat-env-eff': 'Very Good', 'multi-glaze-proportion': '0',
             'main-heating-controls': '2104', 'lodgement-datetime': '2009-08-10 19:02:03', 'flat-top-storey': 'N',
             'current-energy-rating': 'E', 'secondheat-description': 'Portable electric heaters',
             'walls-env-eff': 'Very Poor', 'transaction-type': 'rental (private)', 'uprn': '121016117',
             'current-energy-efficiency': '53', 'energy-consumption-current': '326',
             'mainheat-description': 'Boiler and radiators, mains gas', 'lighting-cost-current': '76',
             'lodgement-date': '2009-08-10', 'extension-count': '0', 'mainheatc-env-eff': 'Poor',
             'lmk-key': '342255690202009081019020365517398', 'wind-turbine-count': '0', 'tenure': 'rental (private)',
             'floor-level': '1st', 'potential-energy-efficiency': '55', 'hot-water-energy-eff': 'Very Good',
             'low-energy-lighting': '50', 'walls-description': 'Solid brick, as built, no insulation (assumed)',
             'hotwater-description': 'From main system'},
            {'low-energy-fixed-light-count': '', 'address': 'Flat 14, Grove Mansions, 111 Clapham Common North Side',
             'uprn-source': 'Energy Assessor', 'floor-height': '2.76', 'heating-cost-potential': '266',
             'unheated-corridor-length': '14.16', 'hot-water-cost-potential': '95',
             'construction-age-band': 'England and Wales: before 1900', 'potential-energy-rating': 'B',
             'mainheat-energy-eff': 'Good', 'windows-env-eff': 'Very Poor', 'lighting-energy-eff': 'Good',
             'environment-impact-potential': '81', 'glazed-type': 'not defined', 'heating-cost-current': '535',
             'address3': '111 Clapham Common North Side',
             'mainheatcont-description': 'Programmer, room thermostat and TRVs', 'sheating-energy-eff': 'N/A',
             'property-type': 'Flat', 'local-authority-label': 'Wandsworth', 'fixed-lighting-outlets-count': '10',
             'energy-tariff': 'Single', 'mechanical-ventilation': 'natural', 'hot-water-cost-current': '94',
             'county': '', 'postcode': 'SW4 9SL', 'solar-water-heating-flag': 'N', 'constituency': 'E14000549',
             'co2-emissions-potential': '1.7', 'number-heated-rooms': '5',
             'floor-description': '(another dwelling below)', 'energy-consumption-potential': '101',
             'local-authority': 'E09000032', 'built-form': 'Enclosed End-Terrace', 'number-open-fireplaces': '0',
             'windows-description': 'Single glazed', 'glazed-area': 'Normal', 'inspection-date': '2022-07-05',
             'mains-gas-flag': 'Y', 'co2-emiss-curr-per-floor-area': '35', 'address1': 'Flat 14',
             'heat-loss-corridor': 'unheated corridor', 'flat-storey-count': '', 'constituency-label': 'Battersea',
             'roof-energy-eff': 'N/A', 'total-floor-area': '96.0', 'building-reference-number': '10003195613',
             'environment-impact-current': '62', 'co2-emissions-current': '3.4',
             'roof-description': '(another dwelling above)', 'floor-energy-eff': 'N/A', 'number-habitable-rooms': '5',
             'address2': 'Grove Mansions', 'hot-water-env-eff': 'Good', 'posttown': 'LONDON',
             'mainheatc-energy-eff': 'Good', 'main-fuel': 'mains gas (not community)', 'lighting-env-eff': 'Good',
             'windows-energy-eff': 'Very Poor', 'floor-env-eff': 'N/A', 'sheating-env-eff': 'N/A',
             'lighting-description': 'Low energy lighting in 50% of fixed outlets', 'roof-env-eff': 'N/A',
             'walls-energy-eff': 'Very Poor', 'photo-supply': '0.0', 'lighting-cost-potential': '82',
             'mainheat-env-eff': 'Good', 'multi-glaze-proportion': '0', 'main-heating-controls': '',
             'lodgement-datetime': '2022-07-07 12:44:41', 'flat-top-storey': 'N', 'current-energy-rating': 'D',
             'secondheat-description': 'None', 'walls-env-eff': 'Very Poor', 'transaction-type': 'rental',
             'uprn': '121016117', 'current-energy-efficiency': '67', 'energy-consumption-current': '201',
             'mainheat-description': 'Boiler and radiators, mains gas', 'lighting-cost-current': '120',
             'lodgement-date': '2022-07-07', 'extension-count': '0', 'mainheatc-env-eff': 'Good',
             'lmk-key': '17466c218fec8705c20da5b78f1ba528e17d3796d10aa6c4a8c6a8534d098a73', 'wind-turbine-count': '0',
             'tenure': 'Rented (private)', 'floor-level': '02', 'potential-energy-efficiency': '81',
             'hot-water-energy-eff': 'Good', 'low-energy-lighting': '50',
             'walls-description': 'Solid brick, as built, no insulation (assumed)',
             'hotwater-description': 'From main system'}
        ],
        "measures": [
            [["secondary_glazing", "low_energy_lighting"], "3", {}, [0, 1]],
            [
                ["secondary_glazing", "low_energy_lighting", "internal_wall_insulation"],
                "9",
                {},
                [0, 1, 2]
            ],
            [
                ["double_glazing", "low_energy_lighting", "internal_wall_insulation"],
                "11",
                {},
                [0, 1, 2]
            ],
            [
                ["internal_wall_insulation"],
                "6",
                {},
                [0, 1, 2]
            ],
            [
                ["internal_wall_insulation", "low_energy_lighting"],
                "7",
                {},
                [0, 1, 2]
            ],
        ],
    },

    {
        "address": "Flat 19 Grove Mansions",
        "postcode": "SW4 9SL",
        "lmk-key": None,
        "epc": {
            'low-energy-fixed-light-count': '4', 'address': 'Flat 19 Grove Mansions, 111, Clapham Common North Side',
            'uprn-source': 'Address Matched', 'floor-height': 2.46, 'heating-cost-potential': '1010',
            'unheated-corridor-length': '2.4', 'hot-water-cost-potential': '165',
            'construction-age-band': 'England and Wales: before 1900', 'potential-energy-rating': 'D',
            'mainheat-energy-eff': 'Good', 'windows-env-eff': 'Average', 'lighting-energy-eff': 'Good',
            'environment-impact-potential': '58', 'glazed-type': 'double glazing, unknown install date',
            'heating-cost-current': '1598', 'address3': None,
            'mainheatcont-description': 'Programmer, room thermostat and TRVs', 'sheating-energy-eff': 'N/A',
            'property-type': 'Flat', 'local-authority-label': 'Wandsworth', 'fixed-lighting-outlets-count': '7',
            'energy-tariff': 'Single', 'mechanical-ventilation': 'natural', 'hot-water-cost-current': '165',
            'county': '', 'postcode': 'SW4 9SL', 'solar-water-heating-flag': 'N', 'constituency': 'E14000549',
            'co2-emissions-potential': '3.0', 'number-heated-rooms': '3',
            'floor-description': '(another dwelling below)', 'energy-consumption-potential': '259',
            'local-authority': 'E09000032', 'built-form': 'Mid-Terrace', 'number-open-fireplaces': '0',
            'windows-description': 'Fully double glazed', 'glazed-area': 'Much More Than Typical',
            'inspection-date': datetime(2024, 8, 13, 0, 0, tzinfo=timezone.utc),
            'mains-gas-flag': 'Y', 'co2-emiss-curr-per-floor-area': '70', 'address1': 'Flat 19 Grove Mansions, 111',
            'heat-loss-corridor': 'unheated corridor', 'flat-storey-count': None, 'constituency-label': 'Battersea',
            'roof-energy-eff': 'Very Poor', 'total-floor-area': '66', 'building-reference-number': '',
            'environment-impact-current': '40', 'co2-emissions-current': '4.6',
            'roof-description': 'Flat, no insulation (assumed)', 'floor-energy-eff': 'N/A',
            'number-habitable-rooms': '3', 'address2': 'Clapham Common North Side', 'hot-water-env-eff': 'Good',
            'posttown': 'LONDON', 'mainheatc-energy-eff': 'Good', 'main-fuel': 'mains gas (not community)',
            'lighting-env-eff': 'Good', 'windows-energy-eff': 'Average', 'floor-env-eff': 'N/A',
            'sheating-env-eff': 'N/A', 'lighting-description': 'Low energy lighting in 57% of fixed outlets',
            'roof-env-eff': 'Very Poor', 'walls-energy-eff': 'Poor', 'photo-supply': '0',
            'lighting-cost-potential': '91', 'mainheat-env-eff': 'Good', 'multi-glaze-proportion': '100',
            'main-heating-controls': 'Programmer, room thermostat and TRVs',
            'lodgement-datetime': datetime(2024, 8, 13, 0, 0), 'flat-top-storey': 'Y',
            'current-energy-rating': 'E', 'secondheat-description': 'Room heaters, electric', 'walls-env-eff': 'Poor',
            'transaction-type': 'ECO assessment', 'uprn': 10024087902, 'current-energy-efficiency': '42',
            'energy-consumption-current': '399', 'mainheat-description': 'Boiler and radiators, mains gas',
            'lighting-cost-current': '130', 'lodgement-date': date(2024, 8, 13), 'extension-count': '1',
            'mainheatc-env-eff': 'Good', 'lmk-key': '', 'wind-turbine-count': '0', 'tenure': 'Rented (social)',
            'floor-level': '3', 'potential-energy-efficiency': '60', 'hot-water-energy-eff': 'Good',
            'low-energy-lighting': '57', 'walls-description': 'Solid brick, as built, no insulation (assumed)',
            'hotwater-description': 'From main system'
        },
        "old_epcs": [
            {'low-energy-fixed-light-count': '', 'address': 'Flat 19, Grove Mansions, 111 Clapham Common North Side',
             'uprn-source': 'Address Matched', 'floor-height': '2.46', 'heating-cost-potential': '279',
             'unheated-corridor-length': '7.1', 'hot-water-cost-potential': '100',
             'construction-age-band': 'England and Wales: 2007 onwards', 'potential-energy-rating': 'B',
             'mainheat-energy-eff': 'Very Good', 'windows-env-eff': 'Good', 'lighting-energy-eff': 'Very Good',
             'environment-impact-potential': '82', 'glazed-type': 'double glazing installed during or after 2002',
             'heating-cost-current': '293', 'address3': '111 Clapham Common North Side',
             'mainheatcont-description': 'Programmer, TRVs and bypass', 'sheating-energy-eff': 'N/A',
             'property-type': 'Maisonette', 'local-authority-label': 'Wandsworth', 'fixed-lighting-outlets-count': '',
             'energy-tariff': 'Single', 'mechanical-ventilation': 'natural', 'hot-water-cost-current': '106',
             'county': 'Greater London Authority', 'postcode': 'SW4 9SL', 'solar-water-heating-flag': 'N',
             'constituency': 'E14000549', 'co2-emissions-potential': '1.7', 'number-heated-rooms': '3',
             'floor-description': '(other premises below)', 'energy-consumption-potential': '130',
             'local-authority': 'E09000032', 'built-form': 'Mid-Terrace', 'number-open-fireplaces': '0',
             'windows-description': 'Fully double glazed', 'glazed-area': 'Normal', 'inspection-date': '2011-01-28',
             'mains-gas-flag': 'Y', 'co2-emiss-curr-per-floor-area': '23', 'address1': 'Flat 19',
             'heat-loss-corridor': 'unheated corridor', 'flat-storey-count': '5.0', 'constituency-label': 'Battersea',
             'roof-energy-eff': 'Good', 'total-floor-area': '17.99', 'building-reference-number': '0862458668',
             'environment-impact-current': '81', 'co2-emissions-current': '1.8',
             'roof-description': 'Roof room(s), insulated', 'floor-energy-eff': 'N/A', 'number-habitable-rooms': '3',
             'address2': 'Grove Mansions', 'hot-water-env-eff': 'Very Good', 'posttown': 'LONDON',
             'mainheatc-energy-eff': 'Average',
             'main-fuel': 'mains gas - this is for backwards compatibility only and should not be used',
             'lighting-env-eff': 'Very Good', 'windows-energy-eff': 'Good', 'floor-env-eff': 'N/A',
             'sheating-env-eff': 'N/A', 'lighting-description': 'Low energy lighting in all fixed outlets',
             'roof-env-eff': 'Good', 'walls-energy-eff': 'Good', 'photo-supply': '0.0', 'lighting-cost-potential': '46',
             'mainheat-env-eff': 'Very Good', 'multi-glaze-proportion': '100', 'main-heating-controls': '2107',
             'lodgement-datetime': '2011-02-04 10:10:19', 'flat-top-storey': 'Y', 'current-energy-rating': 'B',
             'secondheat-description': 'None', 'walls-env-eff': 'Good', 'transaction-type': 'rental (private)',
             'uprn': '10024087902', 'current-energy-efficiency': '82', 'energy-consumption-current': '138',
             'mainheat-description': 'Boiler and radiators, mains gas', 'lighting-cost-current': '46',
             'lodgement-date': '2011-02-04', 'extension-count': '0', 'mainheatc-env-eff': 'Average',
             'lmk-key': '378427544752011020410101995290068', 'wind-turbine-count': '0', 'tenure': 'rental (private)',
             'floor-level': '4th', 'potential-energy-efficiency': '83', 'hot-water-energy-eff': 'Very Good',
             'low-energy-lighting': '100', 'walls-description': 'Cavity wall, with internal insulation',
             'hotwater-description': 'From main system'},
            {'low-energy-fixed-light-count': '', 'address': 'Flat 19, Grove Mansions, 111 Clapham Common North Side',
             'uprn-source': 'Address Matched', 'floor-height': '2.5', 'heating-cost-potential': '285',
             'unheated-corridor-length': '', 'hot-water-cost-potential': '84', 'construction-age-band': 'NO DATA!',
             'potential-energy-rating': 'B', 'mainheat-energy-eff': 'Very Good', 'windows-env-eff': 'Poor',
             'lighting-energy-eff': 'Average', 'environment-impact-potential': '79', 'glazed-type': 'NO DATA!',
             'heating-cost-current': '282', 'address3': '111 Clapham Common North Side',
             'mainheatcont-description': 'Programmer, room thermostat and TRVs', 'sheating-energy-eff': 'N/A',
             'property-type': 'Flat', 'local-authority-label': 'Wandsworth', 'fixed-lighting-outlets-count': '',
             'energy-tariff': 'standard tariff', 'mechanical-ventilation': 'NO DATA!', 'hot-water-cost-current': '84',
             'county': 'Greater London Authority', 'postcode': 'SW4 9SL', 'solar-water-heating-flag': '',
             'constituency': 'E14000549', 'co2-emissions-potential': '1.8', 'number-heated-rooms': '',
             'floor-description': '(other premises below)', 'energy-consumption-potential': '157',
             'local-authority': 'E09000032', 'built-form': 'End-Terrace', 'number-open-fireplaces': '',
             'windows-description': 'Partial double glazing', 'glazed-area': 'NO DATA!',
             'inspection-date': '2009-10-16', 'mains-gas-flag': '', 'co2-emiss-curr-per-floor-area': '27',
             'address1': 'Flat 19', 'heat-loss-corridor': 'NO DATA!', 'flat-storey-count': '',
             'constituency-label': 'Battersea', 'roof-energy-eff': 'Good', 'total-floor-area': '67.78',
             'building-reference-number': '0862458668', 'environment-impact-current': '78',
             'co2-emissions-current': '1.8', 'roof-description': 'Average thermal transmittance 0.22 W/m?K',
             'floor-energy-eff': 'N/A', 'number-habitable-rooms': '', 'address2': 'Grove Mansions',
             'hot-water-env-eff': 'Very Good', 'posttown': 'LONDON', 'mainheatc-energy-eff': 'Average',
             'main-fuel': 'mains gas - this is for backwards compatibility only and should not be used',
             'lighting-env-eff': 'Average', 'windows-energy-eff': 'Poor', 'floor-env-eff': 'N/A',
             'sheating-env-eff': 'N/A', 'lighting-description': 'Low energy lighting in 43% of fixed outlets',
             'roof-env-eff': 'Good', 'walls-energy-eff': 'Good', 'photo-supply': '', 'lighting-cost-potential': '34',
             'mainheat-env-eff': 'Very Good', 'multi-glaze-proportion': '', 'main-heating-controls': '',
             'lodgement-datetime': '2009-10-16 13:50:54', 'flat-top-storey': '', 'current-energy-rating': 'C',
             'secondheat-description': 'None', 'walls-env-eff': 'Good', 'transaction-type': 'new dwelling',
             'uprn': '10024087902', 'current-energy-efficiency': '80', 'energy-consumption-current': '162',
             'mainheat-description': 'Boiler and radiators, mains gas', 'lighting-cost-current': '54',
             'lodgement-date': '2009-10-16', 'extension-count': '', 'mainheatc-env-eff': 'Average',
             'lmk-key': '378427540962009101613505488368001', 'wind-turbine-count': '0', 'tenure': '',
             'floor-level': 'top floor', 'potential-energy-efficiency': '81', 'hot-water-energy-eff': 'Very Good',
             'low-energy-lighting': '', 'walls-description': 'Average thermal transmittance 0.32 W/m?K',
             'hotwater-description': 'From main system'},
            {'low-energy-fixed-light-count': '', 'address': 'Flat 19, Grove Mansions, 111 Clapham Common North Side',
             'uprn-source': 'Address Matched', 'floor-height': '2.5', 'heating-cost-potential': '272',
             'unheated-corridor-length': '', 'hot-water-cost-potential': '84', 'construction-age-band': 'NO DATA!',
             'potential-energy-rating': 'B', 'mainheat-energy-eff': 'Very Good', 'windows-env-eff': 'Good',
             'lighting-energy-eff': 'Average', 'environment-impact-potential': '80', 'glazed-type': 'NO DATA!',
             'heating-cost-current': '270', 'address3': '111 Clapham Common North Side',
             'mainheatcont-description': 'Programmer, room thermostat and TRVs', 'sheating-energy-eff': 'N/A',
             'property-type': 'Flat', 'local-authority-label': 'Wandsworth', 'fixed-lighting-outlets-count': '',
             'energy-tariff': 'standard tariff', 'mechanical-ventilation': 'NO DATA!', 'hot-water-cost-current': '84',
             'county': 'Greater London Authority', 'postcode': 'SW4 9SL', 'solar-water-heating-flag': '',
             'constituency': 'E14000549', 'co2-emissions-potential': '1.7', 'number-heated-rooms': '',
             'floor-description': '(other premises below)', 'energy-consumption-potential': '150',
             'local-authority': 'E09000032', 'built-form': 'End-Terrace', 'number-open-fireplaces': '',
             'windows-description': 'Fully double glazed', 'glazed-area': 'NO DATA!', 'inspection-date': '2009-10-12',
             'mains-gas-flag': '', 'co2-emiss-curr-per-floor-area': '26', 'address1': 'Flat 19',
             'heat-loss-corridor': 'NO DATA!', 'flat-storey-count': '', 'constituency-label': 'Battersea',
             'roof-energy-eff': 'Good', 'total-floor-area': '67.78', 'building-reference-number': '0862458668',
             'environment-impact-current': '79', 'co2-emissions-current': '1.7',
             'roof-description': 'Average thermal transmittance 0.22 W/m?K', 'floor-energy-eff': 'N/A',
             'number-habitable-rooms': '', 'address2': 'Grove Mansions', 'hot-water-env-eff': 'Very Good',
             'posttown': 'LONDON', 'mainheatc-energy-eff': 'Average',
             'main-fuel': 'mains gas - this is for backwards compatibility only and should not be used',
             'lighting-env-eff': 'Average', 'windows-energy-eff': 'Good', 'floor-env-eff': 'N/A',
             'sheating-env-eff': 'N/A', 'lighting-description': 'Low energy lighting in 43% of fixed outlets',
             'roof-env-eff': 'Good', 'walls-energy-eff': 'Good', 'photo-supply': '', 'lighting-cost-potential': '34',
             'mainheat-env-eff': 'Very Good', 'multi-glaze-proportion': '', 'main-heating-controls': '',
             'lodgement-datetime': '2009-10-12 16:21:11', 'flat-top-storey': '', 'current-energy-rating': 'B',
             'secondheat-description': 'None', 'walls-env-eff': 'Good', 'transaction-type': 'new dwelling',
             'uprn': '10024087902', 'current-energy-efficiency': '81', 'energy-consumption-current': '155',
             'mainheat-description': 'Boiler and radiators, mains gas', 'lighting-cost-current': '54',
             'lodgement-date': '2009-10-12', 'extension-count': '', 'mainheatc-env-eff': 'Average',
             'lmk-key': '378427550802009101216211162819628', 'wind-turbine-count': '0', 'tenure': '',
             'floor-level': 'top floor', 'potential-energy-efficiency': '82', 'hot-water-energy-eff': 'Very Good',
             'low-energy-lighting': '', 'walls-description': 'Average thermal transmittance 0.32 W/m?K',
             'hotwater-description': 'From main system'},
            {'low-energy-fixed-light-count': '', 'address': '19 GROVE MANSIONS, 111 CLAPHAM COMMON NORTH SIDE, LONDON',
             'uprn-source': 'Energy Assessor', 'floor-height': '2.48', 'heating-cost-potential': '258',
             'unheated-corridor-length': '2.46', 'hot-water-cost-potential': '87',
             'construction-age-band': 'England and Wales: 2007-2011', 'potential-energy-rating': 'C',
             'mainheat-energy-eff': 'Good', 'windows-env-eff': 'Average', 'lighting-energy-eff': 'Very Good',
             'environment-impact-potential': '79', 'glazed-type': 'double glazing, unknown install date',
             'heating-cost-current': '264', 'address3': 'LONDON',
             'mainheatcont-description': 'Programmer, room thermostat and TRVs', 'sheating-energy-eff': 'N/A',
             'property-type': 'Flat', 'local-authority-label': 'Wandsworth', 'fixed-lighting-outlets-count': '7',
             'energy-tariff': 'Single', 'mechanical-ventilation': 'natural', 'hot-water-cost-current': '87',
             'county': '', 'postcode': 'SW4 9SL', 'solar-water-heating-flag': 'N', 'constituency': 'E14000549',
             'co2-emissions-potential': '1.5', 'number-heated-rooms': '3',
             'floor-description': '(another dwelling below)', 'energy-consumption-potential': '128',
             'local-authority': 'E09000032', 'built-form': 'End-Terrace', 'number-open-fireplaces': '0',
             'windows-description': 'Fully double glazed', 'glazed-area': 'Normal', 'inspection-date': '2021-03-10',
             'mains-gas-flag': 'Y', 'co2-emiss-curr-per-floor-area': '23', 'address1': '19 GROVE MANSIONS',
             'heat-loss-corridor': 'unheated corridor', 'flat-storey-count': '', 'constituency-label': 'Battersea',
             'roof-energy-eff': 'Good', 'total-floor-area': '66.0', 'building-reference-number': '10000974677',
             'environment-impact-current': '78', 'co2-emissions-current': '1.5',
             'roof-description': 'Roof room(s), insulated (assumed)', 'floor-energy-eff': 'N/A',
             'number-habitable-rooms': '3', 'address2': '111 CLAPHAM COMMON NORTH SIDE', 'hot-water-env-eff': 'Good',
             'posttown': 'LONDON', 'mainheatc-energy-eff': 'Good', '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 all fixed outlets',
             'roof-env-eff': 'Good', 'walls-energy-eff': 'Good', 'photo-supply': '0.0', 'lighting-cost-potential': '62',
             'mainheat-env-eff': 'Good', 'multi-glaze-proportion': '100', 'main-heating-controls': '',
             'lodgement-datetime': '2021-05-16 15:24:17', 'flat-top-storey': 'Y', 'current-energy-rating': 'C',
             'secondheat-description': 'None', 'walls-env-eff': 'Good', 'transaction-type': 'rental',
             'uprn': '10024087902', 'current-energy-efficiency': '77', 'energy-consumption-current': '131',
             'mainheat-description': 'Boiler and radiators, mains gas', 'lighting-cost-current': '62',
             'lodgement-date': '2021-05-16', 'extension-count': '0', 'mainheatc-env-eff': 'Good',
             'lmk-key': '706a5b2d4a92a2f27b7179d6d713dacf81134ff249cad0481f885b13b1b3ffc0', 'wind-turbine-count': '0',
             'tenure': 'Rented (private)', 'floor-level': '03', 'potential-energy-efficiency': '78',
             'hot-water-energy-eff': 'Good', 'low-energy-lighting': '100',
             'walls-description': 'Solid brick, as built, insulated (assumed)',
             'hotwater-description': 'From main system'}
        ],
        "measures": [
            [["low_energy_lighting"], "1", {}, [0, 1]],
            [
                ["low_energy_lighting", "internal_wall_insulation"],
                "13",
                {},
                [0, 1, 2]
            ],
            [
                ["internal_wall_insulation"],
                "12",
                {},
                [0, 1, 2]
            ],
        ],
    },
]
recommendations_scoring_data = []

for scenario_property in tqdm(scenario_properties):
    # We validate each record in the file. If the record is NOT valid, we need to handle this accordingly

    epc_searcher = SearchEpc(
        address1=scenario_property["address"],
        postcode=scenario_property["postcode"],
        auth_token=get_settings().EPC_AUTH_TOKEN,
        os_api_key=get_settings().ORDNANCE_SURVEY_API_KEY,
    )

    if scenario_property["lmk-key"] is None:
        epc_records = {
            "original_epc": scenario_property["epc"],
            "full_sap_epc": {},
            "old_data": scenario_property["old_epcs"],
        }
        address = scenario_property["address"]
        postcode = scenario_property["postcode"]
    else:
        epc_searcher.find_property()

        # Find the epc with the same LMK key
        all_epcs = epc_searcher.older_epcs.copy()
        all_epcs.extend([epc_searcher.newest_epc, epc_searcher.full_sap_epc])
        original_epc = [
            epc
            for epc in all_epcs
            if epc.get("lmk-key", None) == scenario_property.get("lmk-key")
        ][0]

        epc_records = {
            "original_epc": original_epc,
            "full_sap_epc": {},
            "old_data": [],
        }

        address = epc_searcher.address_clean
        postcode = epc_searcher.postcode_clean

    prepared_epc = EPCRecord(
        epc_records=epc_records, run_mode="newdata", cleaning_data=cleaning_data
    )

    p = Property(
        id=prepared_epc.uprn,
        address=address,
        postcode=postcode,
        epc_record=prepared_epc,
    )

    p.get_spatial_data(uprn_filenames)

    kwh_predictions = {
        "heating_kwh_predictions": pd.DataFrame([{"id": p.uprn, "predictions": 12000}]),
        "hotwater_kwh_predictions": pd.DataFrame([{"id": p.uprn, "predictions": 3000}]),
    }
    p.set_features(cleaned, kwh_client, kwh_predictions)
    p.solar_panel_configuration = {
        "panel_performance": pd.DataFrame(
            [{"panneled_roof_area": 34, "n_panels": 10, "array_wattage": 4000, "initial_ac_kwh_per_year": 3800}]
        )
    }

    scoring_list = []
    # Create the record for each of the different measures
    for measure_impact_override in scenario_property["measures"]:

        measure = measure_impact_override[0]
        impact = measure_impact_override[1]
        override = measure_impact_override[2]

        recommender = Recommendations(
            property_instance=p, materials=materials, default_u_values=True, inclusions=measure
        )
        property_recommendations = recommender.recommend()

        wall_recommendations = recommender.wall_recomender.recommendations.copy()
        loft_recommendations = recommender.roof_recommender.recommendations.copy()
        floor_recommendations = recommender.floor_recommender.recommendations.copy()
        solar_recommendations = recommender.solar_recommender.recommendation.copy()
        windows_recommendations = recommender.windows_recommender.recommendation.copy()
        led_recommendations = recommender.lighting_recommender.recommendation.copy()

        p.create_base_difference_epc_record(cleaned_lookup=cleaned)

        wall_recs = []
        loft_recs = []
        floor_recs = []
        solar_recs = []
        windows_recs = []
        lighting_recs = []

        if "internal_wall_insulation" in measure:
            for rec in wall_recommendations:
                if rec["type"] == "internal_wall_insulation":
                    wall_recs.append(rec)

        if "external_wall_insulation" in measure:
            for rec in wall_recommendations:
                if rec["type"] == "external_wall_insulation":
                    wall_recs.append(rec)

        if "cavity_wall_insulation" in measure:
            for rec in wall_recommendations:
                if rec["type"] == "cavity_wall_insulation":
                    wall_recs.append(rec)

        if "loft_insulation" in measure:
            loft_recs = []
            for rec in loft_recommendations:
                if rec["type"] == "loft_insulation":
                    loft_recs.append(rec)

        if "solar" in measure:
            for rec in solar_recommendations:
                if rec["type"] == "solar_pv":
                    solar_recs.append(rec)

        if "windows" in measure or "secondary_glazing" in measure or "double_glazing" in measure:
            for rec in windows_recommendations:
                if rec["type"] == "windows_glazing":
                    windows_recs.append(rec)

        if "low_energy_lighting" in measure:
            for rec in led_recommendations:
                if rec["type"] == "low_energy_lighting":
                    lighting_recs.append(rec)

        if "suspended_floor_insulation" in measure:
            for rec in floor_recommendations:
                if rec["type"] == "suspended_floor_insulation":
                    floor_recs.append(rec)

        if "solid_floor_insulation" in measure:
            for rec in floor_recommendations:
                if rec["type"] == "solid_floor_insulation":
                    floor_recs.append(rec)

        combi_list = [wall_recs, loft_recs, floor_recs, solar_recs, windows_recs, lighting_recs]
        combi_list = [element for element in combi_list if len(element) != 0]

        all_combi_recommendations = list(itertools.product(*combi_list))

        for i, combi in enumerate(all_combi_recommendations):
            recommendation_record = p.base_difference_record.df.to_dict("records")[
                0
            ].copy()
            recommendation_record = p.create_recommendation_scoring_data(
                property_id=i,
                primary_recommendation_id=i,
                recommendation_record=recommendation_record,
                recommendations=list(combi),
            )

            if override is not None:
                for key, value in override.items():
                    recommendation_record[key] = value

            recommendation_record["id"] = "&".join(measure) + "+" + str(i)
            recommendation_record["impact"] = impact
            scoring_list.append(recommendation_record)

    recommendations_scoring_data.extend(scoring_list)

recommendations_scoring_data = pd.DataFrame(recommendations_scoring_data)
recommendations_scoring_data["impact"] = recommendations_scoring_data["impact"].astype(
    int
)
recommendations_scoring_data = recommendations_scoring_data.drop(
    columns=[
        "rdsap_change",
        "heat_demand_change",
        "carbon_change",
        "sap_ending",
        "heat_demand_ending",
        "carbon_ending",
    ]
)

impact_col = recommendations_scoring_data.pop("impact")
recommendations_scoring_data.insert(0, "impact", impact_col)

id_col = recommendations_scoring_data.pop("id")
recommendations_scoring_data.insert(0, "id", id_col)

model_api = ModelApi(
    portfolio_id="generate-scenarios-data", timestamp=created_at, prediction_buckets=get_prediction_buckets()
)

all_predictions = model_api.predict_all(df=recommendations_scoring_data, bucket=get_settings().DATA_BUCKET)

sap_impact = pd.concat(
    [
        all_predictions["sap_change_predictions"],
        recommendations_scoring_data[["uprn", "sap_starting", "impact"]],
    ],
    axis=1
)
sap_impact["predicted_impact"] = sap_impact["predictions"] - sap_impact["sap_starting"]
sap_impact["actual_post_sap"] = sap_impact["impact"] + sap_impact["sap_starting"]
sap_impact = sap_impact[
    [
        'id', 'property_id', 'recommendation_id', 'phase', 'uprn', 'sap_starting', 'predictions', 'actual_post_sap',
        'impact', 'predicted_impact'
    ]
].rename(
    columns={"predictions": "predicted_post_sap", "impact": "actual_impact"}
)

# Get some metrics - MAPE for local testing
mae = mean_absolute_error(sap_impact["actual_post_sap"], sap_impact["predicted_post_sap"])
# 1.4325581395348832
mape = mean_absolute_percentage_error(sap_impact["actual_post_sap"], sap_impact["predicted_post_sap"])
# 0.02260368763204902
mape_impact = mean_absolute_percentage_error(sap_impact["actual_impact"], sap_impact["predicted_impact"])
# 0.38072532764393224

save_dataframe_to_s3_parquet(
    recommendations_scoring_data,
    "retrofit-data-dev",
    f"scenario_data/{now}/recommendations_scoring_data.parquet",
)
