mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
input is list of scenarios to consider not list of plans
This commit is contained in:
parent
490c8946d7
commit
475b3d0e13
5 changed files with 21 additions and 11 deletions
|
|
@ -632,6 +632,13 @@ def get_plans_by_ids(ids: List[int]) -> List[PlanModel]:
|
|||
return session_any.exec(stmt).scalars().all()
|
||||
|
||||
|
||||
def get_plans_by_scenario_ids(ids: List[int]) -> List[PlanModel]:
|
||||
stmt = select(PlanModel).where(PlanModel.scenario_id.in_(ids))
|
||||
with db_read_session() as session:
|
||||
session_any: Any = session # Typehint as Any to satisfy Pylance...
|
||||
return session_any.exec(stmt).scalars().all()
|
||||
|
||||
|
||||
def get_scenarios_by_portfolio_id(portfolio_id: int) -> List[ScenarioModel]:
|
||||
stmt = select(ScenarioModel).where(ScenarioModel.portfolio_id == portfolio_id)
|
||||
with db_read_session() as session:
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from pydantic import BaseModel
|
|||
class CategorisationTriggerRequest(BaseModel):
|
||||
portfolio_id: int
|
||||
|
||||
plans_to_consider: Optional[List[int]] = None
|
||||
scenarios_to_consider: Optional[List[int]] = None
|
||||
plan_priority_order: Optional[List[int]] = None
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ def handler(event: Mapping[str, Any], context: Any) -> None:
|
|||
|
||||
process_portfolio(
|
||||
payload.portfolio_id,
|
||||
payload.plans_to_consider,
|
||||
payload.scenarios_to_consider,
|
||||
payload.plan_priority_order,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ payload = {
|
|||
"body": json.dumps(
|
||||
{
|
||||
"portfolio_id": 556,
|
||||
"plans_to_consider": [1589319, 1589320],
|
||||
"scenarios_to_consider": [1040, 1041],
|
||||
"plan_priority_order": [],
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ from backend.app.db.functions.recommendations_functions import (
|
|||
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,
|
||||
set_plan_and_scenario_default,
|
||||
)
|
||||
|
|
@ -19,12 +20,12 @@ logger = setup_logger()
|
|||
|
||||
def process_portfolio(
|
||||
portfolio_id: int,
|
||||
plans_to_consider: Optional[List[int]] = None,
|
||||
scenarios_to_consider: Optional[List[int]] = None,
|
||||
plan_priority_order: Optional[List[int]] = None,
|
||||
) -> None:
|
||||
logger.info(f"Processing portfolio {portfolio_id}")
|
||||
|
||||
plans: List[Plan] = _load_plans_for_portfolio(portfolio_id, plans_to_consider)
|
||||
plans: List[Plan] = _load_plans_for_portfolio(portfolio_id, scenarios_to_consider)
|
||||
|
||||
plans_by_property: Dict[int, List[Plan]] = _group_plans_by_property(plans)
|
||||
|
||||
|
|
@ -88,15 +89,17 @@ def choose_cheapest_relevant_plan(
|
|||
|
||||
|
||||
def _load_plans_for_portfolio(
|
||||
portfolio_id: int, plans_to_consider: Optional[List[int]] = None
|
||||
portfolio_id: int, scenarios_to_consider: Optional[List[int]] = None
|
||||
) -> List[Plan]:
|
||||
|
||||
if plans_to_consider:
|
||||
if len(plans_to_consider) < 2:
|
||||
raise ValueError("Cannot run auto categorisation for fewer than 2 plans")
|
||||
if scenarios_to_consider:
|
||||
if len(scenarios_to_consider) < 2:
|
||||
raise ValueError(
|
||||
"Cannot run auto categorisation for fewer than 2 scenarios"
|
||||
)
|
||||
|
||||
logger.info(f"Getting {len(plans_to_consider)} Plans")
|
||||
plan_models: List[PlanModel] = get_plans_by_ids(plans_to_consider)
|
||||
logger.info(f"Getting {len(scenarios_to_consider)} plans")
|
||||
plan_models: List[PlanModel] = get_plans_by_scenario_ids(scenarios_to_consider)
|
||||
|
||||
else:
|
||||
logger.info(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue