From 23b62b0c54c51f375cc842f30f96acfcf3f021f8 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Tue, 4 Jun 2024 13:54:15 +0100 Subject: [PATCH] handle the case of not requiring any measures --- backend/app/plan/router.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/app/plan/router.py b/backend/app/plan/router.py index 0e7753e2..f86b1759 100644 --- a/backend/app/plan/router.py +++ b/backend/app/plan/router.py @@ -857,6 +857,9 @@ async def build_mds(body: MdsRequest): carbon_prediction["row_id"] = carbon_prediction.index epc_target = body.goal_value + if epc_before == epc_target: + continue + sap_target = epc_to_sap_lower_bound(epc_target) # Define the measures sap_threshold_barrier = sap_prediction[sap_prediction["predictions"] >= sap_target] @@ -934,10 +937,13 @@ async def build_mds(body: MdsRequest): if not package_comparison.empty: # We check if any of the packages meet the threshold + # If none of them do, take the one that gets closest to the target if package_comparison["meets_threshold"].any(): package_comparison = package_comparison[package_comparison["meets_threshold"]] + package_comparison = package_comparison.sort_values("cost") + else: + package_comparison = package_comparison.sort_values("sap_after", ascending=False) - package_comparison = package_comparison.sort_values("cost") package_comparison = package_comparison.head(1).to_dict("records")[0] else: package_comparison = {