mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-30 13:10:47 +00:00
Added UvalueEstimations documentation
This commit is contained in:
parent
f5bebd4b78
commit
ea7dd6148e
2 changed files with 54 additions and 9 deletions
|
|
@ -4,15 +4,34 @@ from model_data.EpcClean import EpcClean
|
||||||
|
|
||||||
|
|
||||||
class UvalueEstimations:
|
class UvalueEstimations:
|
||||||
|
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
|
"""
|
||||||
|
Initialize the UvalueEstimations class.
|
||||||
|
|
||||||
|
:param data: The input data as a pandas DataFrame.
|
||||||
|
"""
|
||||||
self.data = pd.DataFrame(data)
|
self.data = pd.DataFrame(data)
|
||||||
self.walls = None
|
self.walls = None
|
||||||
self.walls_decile_data = {}
|
self.walls_decile_data = {}
|
||||||
self.roofs = None
|
self.roofs = None
|
||||||
self.floors = 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):
|
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 = [
|
walls_columns = [
|
||||||
"local-authority", "property-type", "walls-description", "walls-energy-eff", "walls-env-eff",
|
"local-authority", "property-type", "walls-description", "walls-energy-eff", "walls-env-eff",
|
||||||
"total-floor-area", "number-habitable-rooms", "number-heated-rooms"
|
"total-floor-area", "number-habitable-rooms", "number-heated-rooms"
|
||||||
|
|
@ -65,21 +84,35 @@ class UvalueEstimations:
|
||||||
"decile_boundaries": decile_boundaries
|
"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
|
@staticmethod
|
||||||
def classify_into_deciles(df: pd.DataFrame, column: str) -> (pd.DataFrame, list, list):
|
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.
|
Break a column in a Pandas DataFrame into deciles and classify new values into the existing deciles.
|
||||||
|
|
||||||
Args:
|
:param df: The input Pandas DataFrame.
|
||||||
df: The input Pandas DataFrame.
|
:param column: The column name to break into deciles.
|
||||||
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.
|
|
||||||
|
|
||||||
|
:return: A tuple containing:
|
||||||
|
- The DataFrame with the decile group column.
|
||||||
|
- The list of decile labels.
|
||||||
|
- The list of decile boundaries.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Calculate decile boundaries
|
# Calculate decile boundaries
|
||||||
decile_boundaries = np.percentile(df[column], np.arange(0, 101, 10))
|
decile_boundaries = np.percentile(df[column], np.arange(0, 101, 10))
|
||||||
|
|
||||||
|
|
@ -94,6 +127,15 @@ class UvalueEstimations:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def classify_decile_newvalues(decile_boundaries, decile_labels, new_values: list) -> list:
|
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
|
# Classify new values based on decile definitions
|
||||||
classifications = pd.cut(new_values, bins=decile_boundaries, labels=decile_labels, include_lowest=True)
|
classifications = pd.cut(new_values, bins=decile_boundaries, labels=decile_labels, include_lowest=True)
|
||||||
return classifications.tolist()
|
return classifications.tolist()
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ from epc_api.client import EpcClient
|
||||||
from model_data.downloader import pagenated_epc_download
|
from model_data.downloader import pagenated_epc_download
|
||||||
from model_data.EpcClean import EpcClean
|
from model_data.EpcClean import EpcClean
|
||||||
from model_data.OpenUprnClient import OpenUprnClient
|
from model_data.OpenUprnClient import OpenUprnClient
|
||||||
|
from model_data.analysis.UvalueEstimations import UvalueEstimations
|
||||||
|
|
||||||
LAND_REGISTRY_PATHS = [
|
LAND_REGISTRY_PATHS = [
|
||||||
os.path.abspath(os.path.dirname(__file__)) + "/model_data/local_data/pp-monthly-update-new-version.csv",
|
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:
|
for p in input_properties:
|
||||||
p.get_components(cleaner)
|
p.get_components(cleaner)
|
||||||
|
|
||||||
|
uvalue_estimates = UvalueEstimations(data=data)
|
||||||
|
|
||||||
# Now, given the components, we want to idenfity upgrade options
|
# Now, given the components, we want to idenfity upgrade options
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
walls_df = pd.DataFrame(
|
walls_df = pd.DataFrame(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue