diff --git a/backend/Property.py b/backend/Property.py index 106931d8..c1568de0 100644 --- a/backend/Property.py +++ b/backend/Property.py @@ -357,8 +357,8 @@ class Property: simulation_epc = self.epc_record.prepared_epc.copy() # Replace the understores with hyphens simulation_epc = {k.replace("_", "-"): v for k, v in simulation_epc.items()} - simulation_epc.update(simulation_epc) - self.simulation_epcs = simulation_epc + simulation_epc.update(phase_epc_transformation) + self.simulation_epcs[phase] = simulation_epc @staticmethod def create_recommendation_scoring_data( diff --git a/backend/app/config.py b/backend/app/config.py index 6f2e405b..ef48c317 100644 --- a/backend/app/config.py +++ b/backend/app/config.py @@ -8,9 +8,6 @@ class Settings(BaseSettings): SECRET_KEY: str ENVIRONMENT: str DATA_BUCKET: str - SAP_PREDICTIONS_BUCKET: str - CARBON_PREDICTIONS_BUCKET: str - HEAT_PREDICTIONS_BUCKET: str PLAN_TRIGGER_BUCKET: str EPC_AUTH_TOKEN: str ORDNANCE_SURVEY_API_KEY: str @@ -21,6 +18,14 @@ class Settings(BaseSettings): DB_PORT: str DB_NAME: str + # Prediction buckets + SAP_PREDICTIONS_BUCKET: str + CARBON_PREDICTIONS_BUCKET: str + HEAT_PREDICTIONS_BUCKET: str + LIGHTING_COST_PREDICTIONS_BUCKET: str + HEATING_COST_PREDICTIONS_BUCKET: str + HOT_WATER_COST_PREDICTIONS_BUCKET: str + class Config: env_file = "backend/.env" @@ -28,3 +33,15 @@ class Settings(BaseSettings): @lru_cache() def get_settings(): return Settings() + + +@lru_cache() +def get_prediction_buckets(): + return { + "sap_change_predictions": get_settings().SAP_PREDICTIONS_BUCKET, + "heat_demand_predictions": get_settings().HEAT_PREDICTIONS_BUCKET, + "carbon_change_predictions": get_settings().CARBON_PREDICTIONS_BUCKET, + "lighting_cost_predictions": get_settings().LIGHTING_COST_PREDICTIONS_BUCKET, + "heating_cost_predictions": get_settings().HEATING_COST_PREDICTIONS_BUCKET, + "hot_water_cost_predictions": get_settings().HOT_WATER_COST_PREDICTIONS_BUCKET + } diff --git a/backend/app/plan/router.py b/backend/app/plan/router.py index e2adbed1..609d737f 100644 --- a/backend/app/plan/router.py +++ b/backend/app/plan/router.py @@ -10,7 +10,7 @@ from sqlalchemy.exc import IntegrityError, OperationalError from sqlalchemy.orm import sessionmaker from starlette.responses import Response -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.app.db.functions.portfolio_functions import aggregate_portfolio_recommendations @@ -462,21 +462,13 @@ async def trigger_plan(body: PlanTriggerRequest): model_api = ModelApi(portfolio_id=body.portfolio_id, timestamp=created_at) - all_predictions = { - "sap_change_predictions": pd.DataFrame(), - "heat_demand_predictions": pd.DataFrame(), - "carbon_change_predictions": pd.DataFrame() - } + all_predictions = model_api.predictions_template() to_loop_over = range(0, recommendations_scoring_data.shape[0], SCORING_BATCH_SIZE) for chunk in tqdm(to_loop_over, total=len(to_loop_over)): predictions_dict = model_api.predict_all( df=recommendations_scoring_data.iloc[chunk:chunk + SCORING_BATCH_SIZE], 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 - } + prediction_buckets=get_prediction_buckets() ) # Append the predictions to the predictions dictionary diff --git a/backend/ml_models/api.py b/backend/ml_models/api.py index a2024dd7..4844d7fd 100644 --- a/backend/ml_models/api.py +++ b/backend/ml_models/api.py @@ -11,13 +11,19 @@ class ModelApi: MODEL_PREFIXES = [ "sap_change_predictions", "heat_demand_predictions", - "carbon_change_predictions" + "carbon_change_predictions", + "lighting_cost_predictions", + "heating_cost_predictions", + "hot_water_cost_predictions", ] MODEL_URLS = { "sap_change_predictions": "sapmodel", "heat_demand_predictions": "heatmodel", - "carbon_change_predictions": "carbonmodel" + "carbon_change_predictions": "carbonmodel", + "lighting_cost_predictions": "lightingmodel", + "heating_cost_predictions": "heatingmodel", + "hot_water_cost_predictions": "hotwatermodel", } def __init__( @@ -39,6 +45,17 @@ class ModelApi: self.portfolio_id = portfolio_id self.timestamp = timestamp + @staticmethod + def predictions_template(): + return { + "sap_change_predictions": pd.DataFrame(), + "heat_demand_predictions": pd.DataFrame(), + "carbon_change_predictions": pd.DataFrame(), + "lighting_cost_predictions": pd.DataFrame(), + "heating_cost_predictions": pd.DataFrame(), + "hot_water_cost_predictions": pd.DataFrame(), + } + def upload_scoring_data(self, df: pd.DataFrame, bucket: str, model_prefix: str) -> str: """ The sap model api needs a scoring data that is sitting in s3 to use as a dataset to score on diff --git a/etl/bill_savings/data_collection.py b/etl/bill_savings/data_collection.py index c51bf59e..be141c01 100644 --- a/etl/bill_savings/data_collection.py +++ b/etl/bill_savings/data_collection.py @@ -133,7 +133,7 @@ def app(): energy_consumption_data = [] for i, directory in tqdm(enumerate(epc_directories), total=len(epc_directories)): # Skip the first 50 - if i < 26: + if i < 110: continue data = pd.read_csv(directory / "certificates.csv", low_memory=False)