From 505fe0736becf7ad649d24ff68bf902825239b02 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Wed, 10 Apr 2024 18:46:51 +0100 Subject: [PATCH] Updating optimiser to only optimise solar recommendations that include the battery --- backend/app/plan/router.py | 7 ++----- recommendations/SolarPvRecommendations.py | 3 ++- recommendations/optimiser/optimiser_functions.py | 12 +++++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/backend/app/plan/router.py b/backend/app/plan/router.py index 4b4d45e7..6f179c79 100644 --- a/backend/app/plan/router.py +++ b/backend/app/plan/router.py @@ -75,7 +75,7 @@ async def trigger_plan(body: PlanTriggerRequest): logger.info("Connecting to db") session = sessionmaker(bind=db_engine)() created_at = datetime.now().isoformat() - + # TODO: We should store the trigger file path in the database with the plan so we can track the file that # triggered the plan @@ -242,7 +242,7 @@ async def trigger_plan(body: PlanTriggerRequest): expected_adjusted_energy=expected_adjusted_energy ) - input_measures = prepare_input_measures(recommendations_with_impact, body.goal, body.housing_type) + input_measures = prepare_input_measures(recommendations_with_impact, body.goal) current_sap_points = int(property_instance.data["current-energy-efficiency"]) target_sap_points = epc_to_sap_lower_bound(body.goal_value) @@ -279,9 +279,6 @@ async def trigger_plan(body: PlanTriggerRequest): if ventilation_rec: selected_recommendations.add(ventilation_rec["recommendation_id"]) - # We check if the selected recommendation is wall ventilation and if so, we make sure - # mechanical ventilation is selected - # We'll use the set of selected recommendations to filter the recommendations to upload final_recommendations = [ [ diff --git a/recommendations/SolarPvRecommendations.py b/recommendations/SolarPvRecommendations.py index 4cf1c1fc..f75003ce 100644 --- a/recommendations/SolarPvRecommendations.py +++ b/recommendations/SolarPvRecommendations.py @@ -122,6 +122,7 @@ class SolarPvRecommendations: **cost_result, # This is required for simulating the SAP impact. solar_pv_percentage is between 0 & 1 so we scale # back up here - "photo_supply": 100 * roof_coverage + "photo_supply": 100 * roof_coverage, + "has_battery": has_battery } ) diff --git a/recommendations/optimiser/optimiser_functions.py b/recommendations/optimiser/optimiser_functions.py index 9860c5ea..6159b930 100644 --- a/recommendations/optimiser/optimiser_functions.py +++ b/recommendations/optimiser/optimiser_functions.py @@ -1,17 +1,13 @@ -def prepare_input_measures(property_recommendations, goal, housing_type): +def prepare_input_measures(property_recommendations, goal): """ Basic function to convert recommendations_to_upload to a format that is suitable for the optimiser - large :param property_recommendations: object containing the recommendations, created in the plan trigger api :param goal: goal to be optimised for, should be one of the keys in gain_map. E.g. if the gain is SAP points, the goal should reflect that desired gain - :param housing_type: type of housing the recommendations are for - should be one of "Social" or "Private" :return: Nested list of input measures """ - if housing_type not in ["Social", "Private"]: - raise ValueError("Invalid housing type - investigate me") - goal_map = { "Increase EPC": "sap_points" } @@ -22,6 +18,12 @@ def prepare_input_measures(property_recommendations, goal, housing_type): input_measures = [] for recs in property_recommendations: + if recs[0]["type"] == "solar_pv": + # if the recommendation is a solar recommendation without a battery, we exclude it from the optimisation. + # That will ensure that the optimiser only considers solar recommendations with batteries, so we don't + # under-report the potential cost + recs = [r for r in recs if recs["has_battery"]] + input_measures.append( [ {