mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-30 13:10:47 +00:00
114 lines
4.3 KiB
Python
114 lines
4.3 KiB
Python
import pandas as pd
|
|
from tqdm import tqdm
|
|
from utils.s3 import save_dataframe_to_s3_parquet, read_dataframe_from_s3_parquet
|
|
from utils.logger import setup_logger
|
|
from etl.epc.settings import EARLIEST_EPC_DATE
|
|
|
|
logger = setup_logger()
|
|
|
|
|
|
class AirSourceHeatPumpEfficiency:
|
|
|
|
def __init__(self, file_directories, cleaned_lookup):
|
|
"""
|
|
:param file_directories: A list of directories where files are stored.
|
|
:param cleaned_lookup: A dictionary containing cleaned lookup data.
|
|
"""
|
|
self.file_directories = file_directories
|
|
self.cleaned_lookup = cleaned_lookup
|
|
|
|
self.results = []
|
|
|
|
def create_dataset(self):
|
|
logger.info("Creating solar photo supply dataset")
|
|
|
|
all_counts = []
|
|
for dir in tqdm(self.file_directories):
|
|
filepath = dir / "certificates.csv"
|
|
df = pd.read_csv(filepath, low_memory=False)
|
|
df = df[~pd.isnull(df["UPRN"])]
|
|
df["UPRN"] = df["UPRN"].astype(int).astype(str)
|
|
# Take entries after SAP12
|
|
df["LODGEMENT_DATE"] = pd.to_datetime(df["LODGEMENT_DATE"])
|
|
df = df[df["LODGEMENT_DATE"] > EARLIEST_EPC_DATE]
|
|
|
|
df = df[
|
|
~df["TENURE"].isin(
|
|
[
|
|
"unknown",
|
|
"Not defined - use in the case of a new dwelling for which the intended tenure in not known. "
|
|
"It is not to be used for an existing dwelling"
|
|
]
|
|
)
|
|
]
|
|
|
|
# Take entries that contain an air source heat pump
|
|
df = df[
|
|
df["MAINHEAT_DESCRIPTION"].str.contains("air source heat pump", case=False, na=False)
|
|
]
|
|
|
|
# Drop rows that have a missing PROPERTY_TYPE, BUILT_FORM, CONSTRUCTION_AGE_BAND, TOTAL_FLOOR_AREA
|
|
for col in ["PROPERTY_TYPE", "BUILT_FORM", "CONSTRUCTION_AGE_BAND", "TOTAL_FLOOR_AREA"]:
|
|
df = df[~pd.isnull(df[col])]
|
|
# Get the columns we're interested in
|
|
df = df[
|
|
[
|
|
"PROPERTY_TYPE",
|
|
"BUILT_FORM",
|
|
"MAINHEAT_DESCRIPTION",
|
|
"MAINHEAT_ENERGY_EFF",
|
|
"MAINHEATCONT_DESCRIPTION",
|
|
"MAINHEATC_ENERGY_EFF",
|
|
"MAIN_FUEL",
|
|
"HOTWATER_DESCRIPTION",
|
|
"HOT_WATER_ENERGY_EFF",
|
|
"MAINS_GAS_FLAG"
|
|
]
|
|
]
|
|
|
|
counts = df.groupby(
|
|
[
|
|
"PROPERTY_TYPE",
|
|
"BUILT_FORM",
|
|
"MAINHEAT_DESCRIPTION",
|
|
"MAINHEAT_ENERGY_EFF",
|
|
"MAINHEATCONT_DESCRIPTION",
|
|
"MAINHEATC_ENERGY_EFF",
|
|
"MAIN_FUEL",
|
|
"HOTWATER_DESCRIPTION",
|
|
"HOT_WATER_ENERGY_EFF",
|
|
"MAINS_GAS_FLAG"
|
|
]
|
|
).size().reset_index(name="count")
|
|
|
|
all_counts.append(counts)
|
|
|
|
all_counts = pd.concat(all_counts)
|
|
|
|
all_counts_agg = all_counts.groupby(
|
|
[
|
|
"PROPERTY_TYPE",
|
|
"BUILT_FORM",
|
|
"MAINHEAT_DESCRIPTION",
|
|
"MAINHEAT_ENERGY_EFF",
|
|
"MAINHEATCONT_DESCRIPTION",
|
|
"MAINHEATC_ENERGY_EFF",
|
|
"MAIN_FUEL",
|
|
"HOTWATER_DESCRIPTION",
|
|
"HOT_WATER_ENERGY_EFF",
|
|
"MAINS_GAS_FLAG"
|
|
]
|
|
)["count"].sum().reset_index()
|
|
|
|
all_counts_agg.groupby("PROPERTY_TYPE")["count"].sum()
|
|
# In houses, 68% of the cases where we see air source heat pumps are in detached and semi-detached houses
|
|
all_counts_agg[all_counts_agg["PROPERTY_TYPE"] == "House"]["BUILT_FORM"].value_counts(normalize=True)
|
|
|
|
all_counts_agg[all_counts_agg["PROPERTY_TYPE"] == "Flat"]["BUILT_FORM"].value_counts()
|
|
|
|
# In Bungalows, 74% of cases where we see air source heat pumps are in detached and semi-detached houses
|
|
all_counts_agg[all_counts_agg["PROPERTY_TYPE"] == "Bungalow"]["BUILT_FORM"].value_counts(normalize=True)
|
|
|
|
# TODO: Research options for mid and end-terrace houses
|
|
# TODO: Research the options for flats - we see them appear in flats, but practically speaking, how does the
|
|
# install process work?
|