mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
make choose cheapest relevant plan method public as it's called from outside the module
This commit is contained in:
parent
9a177065b6
commit
508f3f2859
2 changed files with 20 additions and 20 deletions
|
|
@ -26,12 +26,29 @@ def process_portfolio(
|
|||
if not property_plans:
|
||||
raise ValueError(f"No plans for property {uprn}")
|
||||
|
||||
cheapest_plan = _choose_cheapest_relevant_plan(
|
||||
cheapest_plan = choose_cheapest_relevant_plan(
|
||||
property_plans, plan_priority_order
|
||||
)
|
||||
_update_default_flags(property_plans, cheapest_plan)
|
||||
|
||||
|
||||
def choose_cheapest_relevant_plan(
|
||||
plans: List[Plan], plan_priority_order: Optional[List[int]] = []
|
||||
) -> Plan:
|
||||
plans_to_consider: List[Plan] = [p for p in plans if p.is_compliant] or plans
|
||||
|
||||
def plan_cost(plan: Plan) -> float:
|
||||
return (
|
||||
plan.record.cost_of_works
|
||||
if plan.record.cost_of_works is not None
|
||||
else float("inf")
|
||||
)
|
||||
|
||||
cheapest_plan = min(plans_to_consider, key=plan_cost)
|
||||
|
||||
return cheapest_plan
|
||||
|
||||
|
||||
def _load_plans_for_portfolio(portfolio_id: int) -> List[Plan]:
|
||||
plans: List[Plan] = []
|
||||
|
||||
|
|
@ -68,23 +85,6 @@ def _group_plans_by_property(plans: List[Plan]) -> Dict[int, List[Plan]]:
|
|||
return grouped
|
||||
|
||||
|
||||
def _choose_cheapest_relevant_plan(
|
||||
plans: List[Plan], plan_priority_order: Optional[List[int]] = []
|
||||
) -> Plan:
|
||||
plans_to_consider: List[Plan] = [p for p in plans if p.is_compliant] or plans
|
||||
|
||||
def plan_cost(plan: Plan) -> float:
|
||||
return (
|
||||
plan.record.cost_of_works
|
||||
if plan.record.cost_of_works is not None
|
||||
else float("inf")
|
||||
)
|
||||
|
||||
cheapest_plan = min(plans_to_consider, key=plan_cost)
|
||||
|
||||
return cheapest_plan
|
||||
|
||||
|
||||
def _update_default_flags(plans: List[Plan], cheapest_plan: Plan) -> None:
|
||||
plans_to_update: List[Plan] = []
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from backend.app.domain.classes.scenario import Scenario
|
|||
from backend.app.domain.records.plan_record import PlanRecord
|
||||
from backend.app.domain.records.scenario_record import ScenarioRecord
|
||||
from backend.app.db.models.portfolio import Epc, PortfolioGoal
|
||||
from backend.categorisation.processor import _choose_cheapest_relevant_plan
|
||||
from backend.categorisation.processor import choose_cheapest_relevant_plan
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
@ -79,7 +79,7 @@ def test_prioritised_plan_selected(created_at_datetime: datetime) -> None:
|
|||
expected_default_plan_id = 2
|
||||
|
||||
# act
|
||||
actual_default_plan = _choose_cheapest_relevant_plan(
|
||||
actual_default_plan = choose_cheapest_relevant_plan(
|
||||
plans=[epc_c_plan, minor_works_plan],
|
||||
plan_priority_order=plan_priority_order,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue