Added UvalueEstimations documentation

This commit is contained in:
Khalim Conn-Kowlessar 2023-06-22 10:10:54 +01:00
parent f5bebd4b78
commit ea7dd6148e
2 changed files with 54 additions and 9 deletions

View file

@ -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()

View file

@ -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(