mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
added gbis pps
This commit is contained in:
parent
0b6bc95881
commit
2595d3a2de
3 changed files with 34 additions and 6 deletions
|
|
@ -874,7 +874,9 @@ async def model_engine(body: PlanTriggerRequest):
|
|||
for group in measures_to_optimise_with_uplift:
|
||||
for r in group:
|
||||
if r["type"] in ["mechanical_ventilation", "low_energy_lighting", "secondary_heating"]:
|
||||
r["innovation_uplift"] = 0
|
||||
r["partial_project_score"], r["partial_project_funding"], r["innovation_uplift"] = (
|
||||
0, 0, 0
|
||||
)
|
||||
continue
|
||||
|
||||
(
|
||||
|
|
@ -906,8 +908,14 @@ async def model_engine(body: PlanTriggerRequest):
|
|||
)
|
||||
|
||||
# Given the solutions we select the optimal one
|
||||
solutions["cost_less_full_project_funding"] = np.where(
|
||||
solutions["scheme"] == "eco4",
|
||||
solutions["total_cost"] - solutions["full_project_funding"] - solutions["total_uplift"],
|
||||
solutions["total_cost"] - solutions["partial_project_funding"] - solutions["total_uplift"]
|
||||
)
|
||||
|
||||
solutions["cost_less_full_project_funding"] = (
|
||||
solutions["total_cost"] - solutions["eco4_full_project_funding"] - solutions["total_uplift"]
|
||||
solutions["total_cost"] - solutions["full_project_funding"] - solutions["total_uplift"]
|
||||
)
|
||||
solutions = solutions.sort_values("cost_less_full_project_funding", ascending=True)
|
||||
|
||||
|
|
|
|||
|
|
@ -272,6 +272,12 @@ def optimise_with_funding_paths(p, input_measures, housing_type, funding: Fundin
|
|||
|
||||
# 3) compute fixed cost/gain, and strip those groups from subproblem
|
||||
fixed_items = [opt for (_, _, opt) in fixed]
|
||||
|
||||
if scheme == "gbis":
|
||||
# Re-set costs as the only funding we get is the PPS
|
||||
for x in fixed_items:
|
||||
x["cost"] = x["raw_cost"]
|
||||
|
||||
fixed_ids = [opt['id'] for opt in fixed_items]
|
||||
fixed_cost, fixed_gain = sum_cost_gain(fixed_items)
|
||||
fixed_groups = {gi for (gi, _, _) in fixed}
|
||||
|
|
@ -285,7 +291,7 @@ def optimise_with_funding_paths(p, input_measures, housing_type, funding: Fundin
|
|||
# do this by adding innovation back onto the cost
|
||||
for grp in sub_measures:
|
||||
for opt in grp:
|
||||
opt["cost"] = opt["cost_minus_uplift"] + opt.get("innovation_uplift", 0.0)
|
||||
opt["cost"] = x["raw_cost"]
|
||||
|
||||
if scheme == "eco4":
|
||||
# Need to strip out any measure types that are not eligible for ECO4 funding (e.g. secondary heating)
|
||||
|
|
@ -391,9 +397,13 @@ def optimise_with_funding_paths(p, input_measures, housing_type, funding: Fundin
|
|||
axis=1
|
||||
)
|
||||
rate = funding.get_abs_rate(is_cavity=p.walls["is_cavity_wall"])
|
||||
solutions["eco4_full_project_funding"] = solutions["project_score"] * rate
|
||||
solutions["full_project_funding"] = solutions["project_score"] * rate
|
||||
# if the scheme is not ECO4, we set the funding to 0 with iloc
|
||||
solutions.loc[solutions["scheme"] != "eco4", "eco4_full_project_funding"] = 0.0
|
||||
solutions.loc[solutions["scheme"] != "eco4", "full_project_funding"] = 0.0
|
||||
solutions["partial_project_funding"] = solutions.apply(
|
||||
lambda x: get_gbis_pps(x),
|
||||
axis=1
|
||||
)
|
||||
|
||||
# We pull out uplifts
|
||||
solutions["total_uplift"] = solutions.apply(lambda x: get_total_uplift(x), axis=1)
|
||||
|
|
@ -404,6 +414,15 @@ def optimise_with_funding_paths(p, input_measures, housing_type, funding: Fundin
|
|||
# ---- helpers -------------------------------------------------------------
|
||||
|
||||
|
||||
def get_gbis_pps(x):
|
||||
if x["scheme"] != "gbis":
|
||||
return 0
|
||||
fixed_ids = row["fixed_ids"]
|
||||
if len(fixed_ids) != 1:
|
||||
raise ValueError("More than one fixed ID for GBIS")
|
||||
return [x for x in row["items"] if x["id"] in fixed_ids][0]["partial_project_funding"]
|
||||
|
||||
|
||||
def get_total_uplift(x):
|
||||
return sum([y["innovation_uplift"] for y in x["items"]])
|
||||
|
||||
|
|
|
|||
|
|
@ -116,7 +116,8 @@ def prepare_input_measures(property_recommendations, goal, needs_ventilation, fu
|
|||
"gain": gain, "type": rec_type,
|
||||
"innovation_uplift": rec["innovation_uplift"] if funding else 0,
|
||||
"cost_minus_uplift": total,
|
||||
"raw_cost": raw_cost
|
||||
"raw_cost": raw_cost,
|
||||
"partial_project_funding": rec["partial_project_funding"]
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue