mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
removed temp debugging code
This commit is contained in:
parent
33bc38fdc8
commit
97dfa3e572
3 changed files with 14 additions and 173 deletions
|
|
@ -639,15 +639,16 @@ class Property:
|
|||
else:
|
||||
default_roof_area = self.insulation_floor_area
|
||||
|
||||
# Keep a record
|
||||
self.roof_area_comparison = {
|
||||
"api": roof_area,
|
||||
"estimated": default_roof_area
|
||||
}
|
||||
|
||||
# We also set the roof area
|
||||
if roof_area is None:
|
||||
self.roof_area = default_roof_area
|
||||
else:
|
||||
# Perform a comparison between the default_roof_area and roof_area
|
||||
difference = abs(default_roof_area - roof_area)
|
||||
if difference / default_roof_area > 0.1:
|
||||
raise Exception("Investigate difference in roof area")
|
||||
|
||||
self.roof_area = roof_area
|
||||
|
||||
def set_current_energy_bill(self, kwh_client, kwh_predictions):
|
||||
|
|
|
|||
|
|
@ -511,12 +511,12 @@ async def trigger_plan(body: PlanTriggerRequest):
|
|||
input_properties = OpenUprnClient.set_spatial_data(input_properties, bucket_name=get_settings().DATA_BUCKET)
|
||||
|
||||
[p.set_features(cleaned=cleaned, kwh_client=kwh_client, kwh_predictions=kwh_preds) for p in input_properties]
|
||||
logger.info("Performing solar analysis")
|
||||
|
||||
# TODO: If a property is semi-detached, we might get roof surfaces for the main building + the neighbour
|
||||
# TODO: If we can't get high image quality, should we use the solar API? Maybe just for semi-detached units with
|
||||
# extensions, since it doesn't seem to do a great job
|
||||
|
||||
logger.info("Performing solar analysis")
|
||||
building_solar_config, unit_solar_config = GoogleSolarApi.prepare_input_data(
|
||||
input_properties=input_properties,
|
||||
energy_consumption_client=energy_consumption_client,
|
||||
|
|
@ -595,171 +595,6 @@ async def trigger_plan(body: PlanTriggerRequest):
|
|||
scoring_epcs.extend(property_instance.updated_simulation_epcs)
|
||||
recommendations[property_id] = recommendations_with_impact
|
||||
|
||||
# For Debugging
|
||||
# recommendation_impact_df = []
|
||||
# for property_id in recommendations.keys():
|
||||
# for recs_by_type in recommendations[property_id]:
|
||||
# for rec in recs_by_type:
|
||||
# recommendation_impact_df.append(
|
||||
# {
|
||||
# "property_id": property_id,
|
||||
# "uprn": [p.uprn for p in input_properties if p.id == property_id][0],
|
||||
# "address": [p.address for p in input_properties if p.id == property_id][0],
|
||||
# "recommendation_id": rec["recommendation_id"],
|
||||
# "type": rec["type"],
|
||||
# "description": rec["description"],
|
||||
# "sap_points": rec["sap_points"],
|
||||
# "co2_equivalent_savings": rec["co2_equivalent_savings"],
|
||||
# "heat_demand": rec["heat_demand"]
|
||||
# }
|
||||
# )
|
||||
# recommendation_impact_df = pd.DataFrame(recommendation_impact_df)
|
||||
#
|
||||
# surveyed_uprns = [
|
||||
# 10024087855, 121016117, 121016124,
|
||||
# 10024087902, 121016121, 121016128
|
||||
# ]
|
||||
# recommendation_impact_df = recommendation_impact_df[recommendation_impact_df["uprn"].isin(surveyed_uprns)]
|
||||
# # recommendation_impact_df = recommendation_impact_df[recommendation_impact_df["type"].isin(
|
||||
# # ["windows_glazing", "internal_wall_insulation"])
|
||||
# # ]
|
||||
#
|
||||
# actual_impacts_df = pd.DataFrame(
|
||||
# [
|
||||
# # 10024087855
|
||||
# {"uprn": 10024087855, "type": "internal_wall_insulation", "actual_sap_points": 5},
|
||||
# {"uprn": 10024087855, "type": "draught_proofing", "actual_sap_points": 2},
|
||||
# {"uprn": 10024087855, "type": "low_energy_lighting", "actual_sap_points": 0},
|
||||
# {"uprn": 10024087855, "type": "windows_glazing", "actual_sap_points": 4},
|
||||
# # 121016117
|
||||
# {"uprn": 121016117, "type": "internal_wall_insulation", "actual_sap_points": 6},
|
||||
# {"uprn": 121016117, "type": "draught_proofing", "actual_sap_points": 1},
|
||||
# {"uprn": 121016117, "type": "low_energy_lighting", "actual_sap_points": 1},
|
||||
# {"uprn": 121016117, "type": "windows_glazing", "actual_sap_points": 4},
|
||||
# # 121016124
|
||||
# {"uprn": 121016124, "type": "internal_wall_insulation", "actual_sap_points": 8},
|
||||
# {"uprn": 121016124, "type": "low_energy_lighting", "actual_sap_points": 2},
|
||||
# {"uprn": 121016124, "type": "windows_glazing", "actual_sap_points": 5},
|
||||
# # 10024087902
|
||||
# {"uprn": 10024087902, "type": "room_roof_insulation", "actual_sap_points": 16},
|
||||
# {"uprn": 10024087902, "type": "internal_wall_insulation", "actual_sap_points": 2},
|
||||
# {"uprn": 10024087902, "type": "low_energy_lighting", "actual_sap_points": 0},
|
||||
# # 121016121
|
||||
# {"uprn": 121016121, "type": "internal_wall_insulation", "actual_sap_points": 5},
|
||||
# {"uprn": 121016121, "type": "suspended_floor_insulation", "actual_sap_points": 2},
|
||||
# {"uprn": 121016121, "type": "draught_proofing", "actual_sap_points": 1},
|
||||
# {"uprn": 121016121, "type": "windows_glazing", "actual_sap_points": 3},
|
||||
# # 121016128
|
||||
# {"uprn": 121016128, "type": "internal_wall_insulation", "actual_sap_points": 6},
|
||||
# {"uprn": 121016128, "type": "suspended_floor_insulation", "actual_sap_points": 1},
|
||||
# {"uprn": 121016128, "type": "draught_proofing", "actual_sap_points": 1},
|
||||
# {"uprn": 121016128, "type": "low_energy_lighting", "actual_sap_points": 1},
|
||||
# {"uprn": 121016128, "type": "windows_glazing", "actual_sap_points": 3},
|
||||
# ]
|
||||
# )
|
||||
#
|
||||
# comparison = recommendation_impact_df.merge(
|
||||
# actual_impacts_df, how="inner", on=["uprn", "type"]
|
||||
# )
|
||||
#
|
||||
# print(recommendation_impact_df.groupby(["uprn"])["sap_points"].sum())
|
||||
# property_recs = recommendation_impact_df[recommendation_impact_df["uprn"] == 121016128]
|
||||
# property = [p for p in input_properties if p.uprn == 121016128][0]
|
||||
# print(property.data["current-energy-efficiency"])
|
||||
# print(property_recs["sap_points"].sum())
|
||||
# print(property_recs["type"])
|
||||
# print(float(property.data["current-energy-efficiency"]) + property_recs["sap_points"].sum())
|
||||
# recommendations[property.id][2][0]["simulation_config"]
|
||||
|
||||
# from utils.s3 import read_dataframe_from_s3_parquet
|
||||
# training_data = read_dataframe_from_s3_parquet(
|
||||
# bucket_name="retrofit-data-dev",
|
||||
# file_key="sap_change_model/2024-08-06-11-19-49/dataset_rooms.parquet"
|
||||
# )
|
||||
# import pickle
|
||||
# with open("delete_me.pkl", "wb") as f:
|
||||
# pickle.dump(training_data, f)
|
||||
|
||||
# Read in the pickle
|
||||
import pickle
|
||||
with open("delete_me.pkl", "rb") as f:
|
||||
training_data = pickle.load(f)
|
||||
|
||||
# How do we simulate windows:
|
||||
ending_cols = [col for col in training_data.columns if col.endswith("_ending")]
|
||||
starting = {}
|
||||
for c in ending_cols:
|
||||
starting_colname = c.replace("_ending", "_starting")
|
||||
if starting_colname in training_data.columns:
|
||||
starting[c] = starting_colname
|
||||
else:
|
||||
starting[c] = c.replace("_ending", "")
|
||||
|
||||
allowed_to_change = [
|
||||
# Windows
|
||||
"windows_energy_eff_ending",
|
||||
"glazed_type_ending",
|
||||
"glazing_type_ending",
|
||||
"multi_glaze_proportion_ending",
|
||||
|
||||
# Other
|
||||
"sap_ending",
|
||||
"heat_demand_ending",
|
||||
"carbon_ending",
|
||||
"estimated_perimeter_ending",
|
||||
"lodgement_year_ending",
|
||||
"lodgement_month_ending",
|
||||
"days_to_ending",
|
||||
"number_habitable_rooms_ending",
|
||||
"number_heated_rooms_ending",
|
||||
]
|
||||
fixed = [c for c in ending_cols if c not in allowed_to_change + ["uprn"]]
|
||||
training_fixed = training_data.copy()
|
||||
for col in fixed:
|
||||
starting_col = starting[col]
|
||||
training_fixed = training_fixed[training_fixed[col] == training_fixed[starting_col]]
|
||||
|
||||
training_fixed = training_fixed.reset_index(drop=True)
|
||||
|
||||
# Get the recommendation config for this uprn
|
||||
uprn = 121016121
|
||||
property_instance = [p for p in input_properties if p.uprn == uprn][0]
|
||||
property_recs = recommendations[property_instance.id]
|
||||
window_recs = [r for r in property_recs if r[0]["type"] == "windows_glazing"][0]
|
||||
window_recs[0].keys()
|
||||
window_recs[0]["description_simulation"]["multi-glaze-proportion"]
|
||||
# TODO: - In description_simulation for windows, we update glazed-type but in the model training data there
|
||||
# is a column called "glazing-type".
|
||||
# - We don't update glazed-area (should be "Much More Than Typical" most likely? Or Normal??)
|
||||
# TODO: I think we update eveything that we actually need to, when simulating the recommendation impact for the
|
||||
# ML models
|
||||
# TODO: Secondary glazing appears to go to "Good", not "Average". Investigate why
|
||||
# TODO: For the two properties, force recommendations for double glazing and check impact
|
||||
|
||||
z = training_data[training_data["glazed_type_ending"] == "secondary glazing"]
|
||||
z = z[z["multi_glaze_proportion_ending"] == 100]
|
||||
z["windows_energy_eff_ending"].value_counts()
|
||||
|
||||
# Find the things that change
|
||||
example = training_fixed.iloc[3]
|
||||
for _, example in training_fixed.iterrows():
|
||||
things_that_change = []
|
||||
for c in ending_cols:
|
||||
if example[c] != example[starting[c]]:
|
||||
things_that_change.append(c)
|
||||
if len(things_that_change) > 4:
|
||||
print(things_that_change)
|
||||
print(example["uprn"])
|
||||
# blah
|
||||
|
||||
# 100051011370 (doesn't change in actual glazing)
|
||||
# example["glazed_type_ending"]
|
||||
# double glazing installed before 2002
|
||||
# example["glazed_type_starting"]
|
||||
# double glazing, unknown install date
|
||||
|
||||
# 100040925015
|
||||
|
||||
# We call the API with the scoring epcs
|
||||
scoring_epcs = pd.DataFrame(scoring_epcs)
|
||||
scoring_epcs = kwh_client.transform(data=scoring_epcs, cleaned=cleaned)
|
||||
|
|
|
|||
|
|
@ -84,12 +84,17 @@ class RoofRecommendations:
|
|||
|
||||
return (self.insulation_thickness > self.MINIMUM_LOFT_ISULATION_MM) and self.property.roof["is_pitched"]
|
||||
|
||||
def is_room_roof_insulated(self):
|
||||
def is_room_roof_insulated_or_unsuitable(self, measures):
|
||||
|
||||
"""
|
||||
Check if the room roof is already insulated
|
||||
"""
|
||||
|
||||
# If the roof is a room roof room roof is not included in the measures, we deem the recommendation unsuitable
|
||||
unsuitable = "room_roof_insulation" not in measures and self.property.roof["is_roof_room"]
|
||||
if unsuitable:
|
||||
return True
|
||||
|
||||
full_insulated_room_roof = (
|
||||
self.property.roof["is_roof_room"] and
|
||||
self.property.roof["insulation_thickness"] in ["average", "above_average"]
|
||||
|
|
@ -123,7 +128,7 @@ class RoofRecommendations:
|
|||
if (self.insulation_thickness >= self.MINIMUM_FLAT_ROOF_ISULATION_MM) and self.property.roof["is_flat"]:
|
||||
return
|
||||
|
||||
if self.is_room_roof_insulated():
|
||||
if self.is_room_roof_insulated_or_unsuitable(measures):
|
||||
return
|
||||
|
||||
# If we have a u-value already, need to implement this
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue