File size: 1,797 Bytes
f84a02d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import json
import logging
from typing import Any, Dict
from intelligence.models import BusinessScenario, ResourceRole
from sqlalchemy.orm import Session

logger = logging.getLogger(__name__)

class ScenarioEngine:
    def __init__(self, db: Session):
        self.db = db

    def simulate_hiring_scenario(self, workspace_id: str, hiring_plan: Dict[str, int]) -> BusinessScenario:
        """
        Simulate impact of hiring X people in Role Y.
        Input: {"Senior Engineer": 2}
        """
        # 1. Calculate Cost Impact
        monthly_cost_increase = 0.0
        capacity_increase_hours = 0.0
        
        for role_name, count in hiring_plan.items():
            role = self.db.query(ResourceRole).filter(
                ResourceRole.workspace_id == workspace_id,
                ResourceRole.name == role_name
            ).first()
            
            if role:
                # Assume 160 hrs/mo
                cost = role.hourly_cost * 160 * count
                monthly_cost_increase += cost
                capacity_increase_hours += (160 * count)
            else:
                 logger.warning(f"Role {role_name} not found, skipping cost calc.")

        impact = {
            "monthly_cash_burn_increase": monthly_cost_increase,
            "monthly_capacity_increase_hours": capacity_increase_hours,
            "can_support_additional_revenue": capacity_increase_hours * 200 # Assume $200 billable rate
        }
        
        # Save Scenario
        scenario = BusinessScenario(
            workspace_id=workspace_id,
            name=f"Hiring Simulation: {json.dumps(hiring_plan)}",
            parameters_json=hiring_plan,
            impact_json=impact
        )
        self.db.add(scenario)
        self.db.commit()
        
        return scenario