Pulling out rebaseling predictions

This commit is contained in:
Khalim Conn-Kowlessar 2026-03-23 19:45:19 +00:00
parent 70b99f8359
commit 8b2af1556a
3 changed files with 36 additions and 22 deletions

View file

@ -91,7 +91,7 @@ def get_prediction_buckets():
"hotwater_kwh_predictions": get_settings().HOTWATER_KWH_PREDICTIONS_BUCKET,
# Score model - SAP re-baselining model
"retrofit-sap-baseline-predictions": get_settings().SAP_BASELINE_PREDICTIONS_BUCKET,
"retrofit-carbon-baseline-predictions": get_settings().CARBON_BASELINE_PREDICTIONS_BUCKET,
"retrofit-heat-baseline-predictions": get_settings().HEAT_BASELINE_PREDICTIONS_BUCKET,
"retrofit_sap_baseline_predictions": get_settings().SAP_BASELINE_PREDICTIONS_BUCKET,
"retrofit_carbon_baseline_predictions": get_settings().CARBON_BASELINE_PREDICTIONS_BUCKET,
"retrofit_heat_baseline_predictions": get_settings().HEAT_BASELINE_PREDICTIONS_BUCKET,
}

View file

@ -2,6 +2,7 @@ import time
import json
from copy import deepcopy
from datetime import datetime
from typing import Dict
from tqdm import tqdm
import pandas as pd
@ -796,9 +797,7 @@ async def model_engine(body: PlanTriggerRequest):
prediction_buckets=get_prediction_buckets(),
max_retries=1
)
await model_api.async_warm_up_lambdas(
model_prefies=model_api.KWH_MODEL_PREFIXES + model_api.MODEL_PREFIXES
)
await model_api.async_warm_up_lambdas(model_prefies=model_api.models_for_warm_up)
logger.info("Reading in materials and cleaned datasets")
cleaned = get_cleaned()
@ -822,15 +821,17 @@ async def model_engine(body: PlanTriggerRequest):
# Trigger re-scoring
rebaselining_scoring_data["is_post_sap10_starting"] = True
rebaselining_response = model_api.predict_all(
df=rebaselining_scoring_data,
bucket=get_settings().DATA_BUCKET,
model_prefixes=["retrofit-sap-baseline-predictions"],
model_prefixes=model_api.BASELINE_MODEL_PREFIXES,
extract_ids=False,
extract_uprn=True
)
# TODO - Pull out predictions!!!
# TODO: TEMP: Compare values
compare_scores = []
for x in rebaselining_scoring_data["uprn"].unique():
@ -850,21 +851,24 @@ async def model_engine(body: PlanTriggerRequest):
for uprn in rebaselining_scoring_data["uprn"].unique():
# Get the predictions
sap_prediction = rebaselining_response["retrofit-sap-baseline-predictions"][
rebaselining_response["retrofit-sap-baseline-predictions"]["uprn"] == uprn
]["predictions"].values[0]
models = [
"retrofit-sap-baseline-predictions",
"retrofit-carbon-baseline-predictions",
"retrofit-heat-baseline-predictions",
]
property_prediction: Dict[str, float] = {
model: rebaselining_response[model][
rebaselining_response[model]["uprn"] == uprn
]["predictions"].values[0] for model in models
}
carbon_prediction = 1337
heat_demand_prediction = 1337
epc_prediction = sap_to_epc(sap_prediction)
# We now need to insert the new values into the epc_record
property_instance = next(p for p in input_properties if p.uprn == int(uprn))
property_instance.epc_record.insert_new_performance_values(
new_sap=sap_prediction,
new_epc=epc_prediction,
new_carbon=carbon_prediction,
new_heat_demand=heat_demand_prediction,
new_sap=property_prediction["retrofit-sap-baseline-predictions"],
new_epc=sap_to_epc(property_prediction["retrofit-sap-baseline-predictions"]),
new_carbon=property_prediction["retrofit-carbon-baseline-predictions"],
new_heat_demand=property_prediction["retrofit-heat-baseline-predictions"],
)
kwh_client = KwhData(bucket=get_settings().DATA_BUCKET, read_consumption_data=True)

View file

@ -22,6 +22,12 @@ class ModelApi:
KWH_MODEL_PREFIXES = ["heating_kwh_predictions", "hotwater_kwh_predictions"]
BASELINE_MODEL_PREFIXES = [
"retrofit_sap_baseline_predictions",
"retrofit_heat_baseline_predictions",
"retrofit_carbon_baseline_predictions",
]
MODEL_URLS: Dict[str, str] = {
"sap_change_predictions": "sapmodel",
"heat_demand_predictions": "heatmodel",
@ -29,9 +35,9 @@ class ModelApi:
"hotwater_kwh_predictions": "hotwaterkwhmodel",
"heating_kwh_predictions": "heatingkwhmodel",
# Baseline prediction models
"retrofit-sap-baseline-predictions": "sapbaselinemodel",
"retrofit-heat-baseline-predictions": "heatbaselinemodel",
"retrofit-carbon-baseline-predictions": "carbonbaselinemodel",
"retrofit_sap_baseline_predictions": "sapbaselinemodel",
"retrofit_heat_baseline_predictions": "heatbaselinemodel",
"retrofit_carbon_baseline_predictions": "carbonbaselinemodel",
}
def __init__(
@ -339,3 +345,7 @@ class ModelApi:
)
return all_predictions
@property
def models_for_warm_up(self):
return self.KWH_MODEL_PREFIXES + self.MODEL_PREFIXES + self.BASELINE_MODEL_PREFIXES