handle the case of not requiring any measures

This commit is contained in:
Khalim Conn-Kowlessar 2024-06-04 13:54:15 +01:00
parent b3f8a9dccc
commit 23b62b0c54

View file

@ -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 = {