fixed generate_scenarios_data

This commit is contained in:
Khalim Conn-Kowlessar 2024-10-07 11:42:03 +01:00
parent 88e4630c25
commit 5078368faf
3 changed files with 33 additions and 43 deletions

View file

@ -566,8 +566,6 @@ class Property:
if not self.data:
raise ValueError("Property does not contain data")
self.set_basic_property_dimensions()
for description, attribute in cleaned.items():
if self.data[description] in self.DATA_ANOMALY_MATCHES:
@ -615,6 +613,7 @@ class Property:
setattr(self, self.ATTRIBUTE_MAP[description], attributes[0])
self.set_basic_property_dimensions()
self.set_wall_type()
self.set_floor_type()
self.set_floor_level()
@ -629,15 +628,6 @@ class Property:
"""
self.solar_panel_configuration = solar_panel_configuration
if not self.roof["is_flat"]:
default_roof_area = estimate_pitched_roof_area(
floor_area=self.insulation_floor_area,
)
else:
default_roof_area = self.insulation_floor_area
self.roof_area = default_roof_area
def set_current_energy(self, kwh_client, kwh_predictions):
"""
Given what we know about the property now, estimates the current energy consumption using the UCL paper
@ -972,6 +962,13 @@ class Property:
self.floor_area / self.number_of_floors
)
if not self.roof["is_flat"]:
self.roof_area = estimate_pitched_roof_area(
floor_area=self.insulation_floor_area,
)
else:
self.roof_area = self.insulation_floor_area
def set_floor_level(self):
self.floor_level = (
FLOOR_LEVEL_MAP[self.data["floor-level"]]

View file

@ -3,25 +3,24 @@ import itertools
import pandas as pd
from etl.epc.Record import EPCRecord
from etl.bill_savings.KwhData import KwhData
from backend.SearchEpc import SearchEpc
from sqlalchemy.orm import sessionmaker
from backend.app.config import get_settings
from backend.app.config import get_settings, get_prediction_buckets
from backend.app.db.connection import db_engine
from backend.app.db.functions.materials_functions import get_materials
from backend.ml_models.api import ModelApi
from backend.app.plan.utils import get_cleaned
from backend.Property import Property
from etl.solar.SolarPhotoSupply import SolarPhotoSupply
from recommendations.Recommendations import Recommendations
from utils.logger import setup_logger
from utils.s3 import read_dataframe_from_s3_parquet, save_dataframe_to_s3_parquet
from datetime import datetime
now = datetime.now().strftime("%d-%m-%Y-%H-%M-%S")
logger = setup_logger()
@ -41,21 +40,16 @@ cleaning_data = read_dataframe_from_s3_parquet(
materials = get_materials(session)
cleaned = get_cleaned()
# TODO: THIS IS A TEMPORARY FIX
new_walls_description_mapping = pd.DataFrame(cleaned["walls-description"])
new_walls_description_mapping.loc[
~new_walls_description_mapping["thermal_transmittance_unit"].isnull(),
"thermal_transmittance_unit",
] = "w/m-¦k"
cleaned["walls-description"] = new_walls_description_mapping.to_dict(orient="records")
uprn_filenames = read_dataframe_from_s3_parquet(
bucket_name=get_settings().DATA_BUCKET, file_key="spatial/filename_meta.parquet"
)
photo_supply_lookup, floor_area_decile_thresholds = SolarPhotoSupply.load(
bucket=get_settings().DATA_BUCKET
kwh_client = KwhData(bucket="retrofit-data-dev", read_consumption_data=False)
kwh_client.retail_price_comparison = pd.DataFrame(
[{"Date": datetime.today().strftime("%Y-%m-%d"),
'Average standard variable tariff (Large legacy suppliers)': 1}]
)
kwh_client.retail_price_comparison["Date"] = pd.to_datetime(kwh_client.retail_price_comparison["Date"])
scenario_properties = [
{
@ -132,7 +126,6 @@ scenario_properties = [
},
]
recommendations_scoring_data = []
for scenario_property in scenario_properties:
@ -173,7 +166,17 @@ for scenario_property in scenario_properties:
)
p.get_spatial_data(uprn_filenames)
p.get_components(cleaned, photo_supply_lookup, floor_area_decile_thresholds)
kwh_predictions = {
"heating_kwh_predictions": pd.DataFrame([{"id": p.uprn, "predictions": 12000}]),
"hotwater_kwh_predictions": pd.DataFrame([{"id": p.uprn, "predictions": 3000}]),
}
p.set_features(cleaned, kwh_client, kwh_predictions)
p.solar_panel_configuration = {
"panel_performance": pd.DataFrame(
[{"panneled_roof_area": 34, "n_panels": 10, "array_wattage": 4000, "initial_ac_kwh_per_year": 3800}]
)
}
recommender = Recommendations(property_instance=p, materials=materials)
property_recommendations = recommender.recommend()
@ -277,20 +280,12 @@ recommendations_scoring_data.insert(0, "impact", impact_col)
id_col = recommendations_scoring_data.pop("id")
recommendations_scoring_data.insert(0, "id", id_col)
from backend.ml_models.api import ModelApi
model_api = ModelApi(portfolio_id="generate-scenarios-data", timestamp=created_at)
all_predictions = model_api.predict_all(
df=recommendations_scoring_data,
bucket=get_settings().DATA_BUCKET,
prediction_buckets={
"sap_change_predictions": get_settings().SAP_PREDICTIONS_BUCKET,
"heat_demand_predictions": get_settings().HEAT_PREDICTIONS_BUCKET,
"carbon_change_predictions": get_settings().CARBON_PREDICTIONS_BUCKET,
},
model_api = ModelApi(
portfolio_id="generate-scenarios-data", timestamp=created_at, prediction_buckets=get_prediction_buckets()
)
all_predictions = model_api.predict_all(df=recommendations_scoring_data, bucket=get_settings().DATA_BUCKET)
save_dataframe_to_s3_parquet(
recommendations_scoring_data,
"retrofit-data-dev",

View file

@ -175,9 +175,7 @@ class SolarPvRecommendations:
if self.property.roof["is_flat"]:
roof_area = self.property.insulation_floor_area
else:
roof_area = estimate_pitched_roof_area(
floor_area=self.property.insulation_floor_area, floor_height=self.property.data["floor-height"]
)
roof_area = estimate_pitched_roof_area(floor_area=self.property.insulation_floor_area, )
solar_configurations = pd.DataFrame(
[
{