mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
fixed automated assignment
This commit is contained in:
parent
548672cc10
commit
b3f8a9dccc
1 changed files with 33 additions and 10 deletions
|
|
@ -830,8 +830,14 @@ async def build_mds(body: MdsRequest):
|
|||
results = []
|
||||
for p in input_properties:
|
||||
|
||||
sap_before = int(p.data["current-energy-efficiency"])
|
||||
epc_before = p.data["current-energy-rating"]
|
||||
heat_demand_before = p.data["energy-consumption-current"]
|
||||
carbon_before = p.data["co2-emissions-current"]
|
||||
|
||||
package_comparison = []
|
||||
for _id in recommendations[p.id].keys():
|
||||
|
||||
sap_prediction = all_predictions["sap_change_predictions"][
|
||||
(all_predictions["sap_change_predictions"]["property_id"] == str(p.id)) &
|
||||
(all_predictions["sap_change_predictions"]["recommendation_id"].str.contains(re.escape(_id)))
|
||||
|
|
@ -854,8 +860,10 @@ async def build_mds(body: MdsRequest):
|
|||
sap_target = epc_to_sap_lower_bound(epc_target)
|
||||
# Define the measures
|
||||
sap_threshold_barrier = sap_prediction[sap_prediction["predictions"] >= sap_target]
|
||||
meets_threshold = True
|
||||
if sap_threshold_barrier.empty:
|
||||
raise NotImplementedError("FIX ME")
|
||||
sap_threshold_barrier = sap_prediction.tail(1)
|
||||
meets_threshold = False
|
||||
sap_threshold_barrier = sap_threshold_barrier.head(1)
|
||||
|
||||
sap_prediction = sap_prediction[
|
||||
|
|
@ -881,16 +889,9 @@ async def build_mds(body: MdsRequest):
|
|||
]
|
||||
costs = sum(costs)
|
||||
|
||||
sap_before = int(p.data["current-energy-efficiency"])
|
||||
sap_after = sap_prediction["predictions"].values[-1]
|
||||
|
||||
epc_before = p.data["current-energy-rating"]
|
||||
epc_after = sap_to_epc(sap_after)
|
||||
|
||||
heat_demand_before = p.data["energy-consumption-current"]
|
||||
heat_demand_after = heat_demand_prediction["predictions"].values[-1]
|
||||
|
||||
carbon_before = p.data["co2-emissions-current"]
|
||||
carbon_after = carbon_prediction["predictions"].values[-1]
|
||||
|
||||
current_adjusted_energy = AnnualBillSavings.adjust_energy_to_metered(
|
||||
|
|
@ -924,13 +925,35 @@ async def build_mds(body: MdsRequest):
|
|||
"carbon_after": carbon_after,
|
||||
"bill_savings": bill_savings,
|
||||
"energy_savings": energy_savings,
|
||||
"meets_threshold": meets_threshold
|
||||
}
|
||||
)
|
||||
|
||||
package_comparison = pd.DataFrame(package_comparison)
|
||||
# Find the smallest cost package
|
||||
package_comparison = package_comparison.sort_values("cost")
|
||||
package_comparison = package_comparison.head(1).to_dict("records")[0]
|
||||
if not package_comparison.empty:
|
||||
|
||||
# We check if any of the packages meet the threshold
|
||||
if package_comparison["meets_threshold"].any():
|
||||
package_comparison = package_comparison[package_comparison["meets_threshold"]]
|
||||
|
||||
package_comparison = package_comparison.sort_values("cost")
|
||||
package_comparison = package_comparison.head(1).to_dict("records")[0]
|
||||
else:
|
||||
package_comparison = {
|
||||
"measures": [],
|
||||
"sap_before": sap_before,
|
||||
"sap_after": sap_before,
|
||||
"epc_before": epc_before,
|
||||
"epc_after": epc_before,
|
||||
"heat_demand_before": heat_demand_before,
|
||||
"heat_demand_after": heat_demand_before,
|
||||
"carbon_before": carbon_before,
|
||||
"carbon_after": carbon_before,
|
||||
"bill_savings": 0,
|
||||
"energy_savings": 0,
|
||||
"meets_threshold": False
|
||||
}
|
||||
|
||||
config = [c for c in plan_input if c["uprn"] == str(p.uprn)]
|
||||
if not config:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue