From ea7dd6148e135bba00b5abc57b6e1ce5ce5df896 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Thu, 22 Jun 2023 10:10:54 +0100 Subject: [PATCH] Added UvalueEstimations documentation --- model_data/analysis/UvalueEstimations.py | 60 ++++++++++++++++++++---- model_data/app.py | 3 ++ 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/model_data/analysis/UvalueEstimations.py b/model_data/analysis/UvalueEstimations.py index 06049c63..2f19f9ad 100644 --- a/model_data/analysis/UvalueEstimations.py +++ b/model_data/analysis/UvalueEstimations.py @@ -4,15 +4,34 @@ from model_data.EpcClean import EpcClean class UvalueEstimations: - def __init__(self, data): + """ + Initialize the UvalueEstimations class. + + :param data: The input data as a pandas DataFrame. + """ self.data = pd.DataFrame(data) self.walls = None self.walls_decile_data = {} self.roofs = None self.floors = None + def get_estimates(self, cleaner: EpcClean): + """ + Calculate U-value estimates for walls, roofs, and floors. + + :param cleaner: An instance of the EpcClean class used for cleaning data. + """ + self.set_walls(cleaner) + self.set_roofs(cleaner) + self.set_floors(cleaner) + def set_walls(self, cleaner: EpcClean): + """ + Set U-value estimates for walls. + + :param cleaner: An instance of the EpcClean class used for cleaning data. + """ walls_columns = [ "local-authority", "property-type", "walls-description", "walls-energy-eff", "walls-env-eff", "total-floor-area", "number-habitable-rooms", "number-heated-rooms" @@ -65,21 +84,35 @@ class UvalueEstimations: "decile_boundaries": decile_boundaries } + def set_roofs(self, cleaner: EpcClean): + """ + Set U-value estimates for roofs. + + :param cleaner: An instance of the EpcClean class used for cleaning data. + """ + pass + + def set_floors(self, cleaner: EpcClean): + """ + Set U-value estimates for floors. + + :param cleaner: An instance of the EpcClean class used for cleaning data. + """ + pass + @staticmethod def classify_into_deciles(df: pd.DataFrame, column: str) -> (pd.DataFrame, list, list): """ Break a column in a Pandas DataFrame into deciles and classify new values into the existing deciles. - Args: - df: The input Pandas DataFrame. - column: The column name to break into deciles. - new_values: A list of new values to classify. - - Returns: - A list of classifications for the new values. + :param df: The input Pandas DataFrame. + :param column: The column name to break into deciles. + :return: A tuple containing: + - The DataFrame with the decile group column. + - The list of decile labels. + - The list of decile boundaries. """ - # Calculate decile boundaries decile_boundaries = np.percentile(df[column], np.arange(0, 101, 10)) @@ -94,6 +127,15 @@ class UvalueEstimations: @staticmethod def classify_decile_newvalues(decile_boundaries, decile_labels, new_values: list) -> list: + """ + Classify new values into existing deciles based on decile definitions. + + :param decile_boundaries: The list of decile boundaries. + :param decile_labels: The list of decile labels. + :param new_values: A list of new values to classify. + + :return: The classifications for the new values as a list. + """ # Classify new values based on decile definitions classifications = pd.cut(new_values, bins=decile_boundaries, labels=decile_labels, include_lowest=True) return classifications.tolist() diff --git a/model_data/app.py b/model_data/app.py index 5ff71816..d9add8d9 100644 --- a/model_data/app.py +++ b/model_data/app.py @@ -11,6 +11,7 @@ from epc_api.client import EpcClient from model_data.downloader import pagenated_epc_download from model_data.EpcClean import EpcClean from model_data.OpenUprnClient import OpenUprnClient +from model_data.analysis.UvalueEstimations import UvalueEstimations LAND_REGISTRY_PATHS = [ os.path.abspath(os.path.dirname(__file__)) + "/model_data/local_data/pp-monthly-update-new-version.csv", @@ -112,6 +113,8 @@ def handler(): for p in input_properties: p.get_components(cleaner) + uvalue_estimates = UvalueEstimations(data=data) + # Now, given the components, we want to idenfity upgrade options import pandas as pd walls_df = pd.DataFrame(