mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
priority list is scenarios not plans 🟥
This commit is contained in:
parent
475b3d0e13
commit
ce8c1d23e6
4 changed files with 13 additions and 14 deletions
|
|
@ -6,7 +6,7 @@ class CategorisationTriggerRequest(BaseModel):
|
|||
portfolio_id: int
|
||||
|
||||
scenarios_to_consider: Optional[List[int]] = None
|
||||
plan_priority_order: Optional[List[int]] = None
|
||||
scenario_priority_order: Optional[List[int]] = None
|
||||
|
||||
|
||||
# {"portfolio_id": 556, "plans_to_consider": [1589319,1589320], "plan_priority_order": [1589319,1589320]}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ def handler(event: Mapping[str, Any], context: Any) -> None:
|
|||
process_portfolio(
|
||||
payload.portfolio_id,
|
||||
payload.scenarios_to_consider,
|
||||
payload.plan_priority_order,
|
||||
payload.scenario_priority_order,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ from typing import Dict, List, Optional
|
|||
from backend.app.db.functions.recommendations_functions import (
|
||||
bulk_update_plans,
|
||||
get_default_plan_ids_for_property,
|
||||
get_plans_by_ids,
|
||||
get_plans_by_portfolio_id,
|
||||
get_plans_by_scenario_ids,
|
||||
get_scenarios_by_portfolio_id,
|
||||
|
|
@ -21,7 +20,7 @@ logger = setup_logger()
|
|||
def process_portfolio(
|
||||
portfolio_id: int,
|
||||
scenarios_to_consider: Optional[List[int]] = None,
|
||||
plan_priority_order: Optional[List[int]] = None,
|
||||
scenario_priority_order: Optional[List[int]] = None,
|
||||
) -> None:
|
||||
logger.info(f"Processing portfolio {portfolio_id}")
|
||||
|
||||
|
|
@ -35,7 +34,7 @@ def process_portfolio(
|
|||
raise ValueError(f"No plans for property {property_id}")
|
||||
|
||||
cheapest_plan = choose_cheapest_relevant_plan(
|
||||
property_plans, plan_priority_order
|
||||
property_plans, scenario_priority_order
|
||||
)
|
||||
|
||||
# Unset existing default(s) in case they are outside the plans to consider
|
||||
|
|
@ -49,9 +48,9 @@ def process_portfolio(
|
|||
|
||||
|
||||
def choose_cheapest_relevant_plan(
|
||||
plans: List[Plan], plan_priority_order: Optional[List[int]] = None
|
||||
plans: List[Plan], scenario_priority_order: Optional[List[int]] = None
|
||||
) -> Plan:
|
||||
plan_priority_order = plan_priority_order or []
|
||||
scenario_priority_order = scenario_priority_order or []
|
||||
|
||||
eligible_plans: List[Plan] = [plan for plan in plans if plan.is_compliant] or plans
|
||||
if not eligible_plans:
|
||||
|
|
@ -80,7 +79,7 @@ def choose_cheapest_relevant_plan(
|
|||
if (plan.record.cost_of_works or float("inf")) == min_cost
|
||||
]
|
||||
|
||||
for priority_plan_id in plan_priority_order:
|
||||
for priority_plan_id in scenario_priority_order:
|
||||
for plan in cheapest_plans:
|
||||
if plan.id == priority_plan_id:
|
||||
return plan
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ def make_scenario(name: str, created_at: datetime, is_default: bool) -> Scenario
|
|||
multi_plan=False,
|
||||
is_default=is_default,
|
||||
)
|
||||
return Scenario(record=record, id=1 if is_default else 2)
|
||||
return Scenario(record=record, id=3 if is_default else 4)
|
||||
|
||||
|
||||
def make_plan(
|
||||
|
|
@ -54,17 +54,17 @@ def make_plan(
|
|||
)
|
||||
|
||||
|
||||
def test_prioritised_plan_selected(created_at_datetime: datetime) -> None:
|
||||
def test_prioritised_scenario_selected(created_at_datetime: datetime) -> None:
|
||||
# arrange
|
||||
epc_c_plan = make_plan(created_at_datetime, True, name="EPC C")
|
||||
minor_works_plan = make_plan(created_at_datetime, False, name="EPC C - Minor Works")
|
||||
plan_priority_order: List[int] = [2, 1]
|
||||
scenario_priority_order: List[int] = [4, 3]
|
||||
expected_default_plan_id = 2
|
||||
|
||||
# act
|
||||
actual_default_plan = choose_cheapest_relevant_plan(
|
||||
plans=[epc_c_plan, minor_works_plan],
|
||||
plan_priority_order=plan_priority_order,
|
||||
scenario_priority_order=scenario_priority_order,
|
||||
)
|
||||
|
||||
# assert
|
||||
|
|
@ -81,13 +81,13 @@ def test_cheapest_plan_returned_if_not_in_priority_list(
|
|||
minor_works_plan = make_plan(
|
||||
created_at_datetime, False, cost_of_works=100.0, name="EPC C - Minor Works"
|
||||
)
|
||||
plan_priority_order: List[int] = [1, 3]
|
||||
scenario_priority_order: List[int] = [3, 5]
|
||||
expected_default_plan_id = 2
|
||||
|
||||
# act
|
||||
actual_default_plan = choose_cheapest_relevant_plan(
|
||||
plans=[epc_c_plan, minor_works_plan],
|
||||
plan_priority_order=plan_priority_order,
|
||||
scenario_priority_order=scenario_priority_order,
|
||||
)
|
||||
|
||||
# assert
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue