petter2025 commited on
Commit
f003859
·
verified ·
1 Parent(s): 18c5d7e

Update core/calculators.py

Browse files
Files changed (1) hide show
  1. core/calculators.py +122 -0
core/calculators.py CHANGED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Enhanced ROI calculators and business logic
3
+ """
4
+
5
+ from typing import Dict
6
+ from core.data_models import IncidentScenario
7
+
8
+ class EnhancedROICalculator:
9
+ """Investor-grade ROI calculator with sensitivity analysis"""
10
+
11
+ def calculate_comprehensive_roi(self, monthly_incidents: int,
12
+ avg_impact: float, team_size: int) -> Dict:
13
+ """Calculate multi-scenario ROI analysis"""
14
+ # Base scenario (realistic)
15
+ base = self._calculate_scenario(monthly_incidents, avg_impact, team_size,
16
+ savings_rate=0.82, efficiency_gain=0.85)
17
+
18
+ # Best case (aggressive adoption)
19
+ best = self._calculate_scenario(monthly_incidents, avg_impact, team_size,
20
+ savings_rate=0.92, efficiency_gain=0.92)
21
+
22
+ # Worst case (conservative)
23
+ worst = self._calculate_scenario(monthly_incidents, avg_impact, team_size,
24
+ savings_rate=0.72, efficiency_gain=0.78)
25
+
26
+ # Generate recommendation
27
+ recommendation = self._get_recommendation(base['roi_multiplier'])
28
+
29
+ return {
30
+ "summary": {
31
+ "your_annual_impact": f"${base['annual_impact']:,.0f}",
32
+ "potential_savings": f"${base['savings']:,.0f}",
33
+ "enterprise_cost": f"${base['enterprise_cost']:,.0f}",
34
+ "roi_multiplier": f"{base['roi_multiplier']:.1f}×",
35
+ "payback_months": f"{base['payback_months']:.1f}",
36
+ "annual_roi_percentage": f"{base['roi_percentage']:.0f}%"
37
+ },
38
+ "scenarios": {
39
+ "base_case": {
40
+ "roi": f"{base['roi_multiplier']:.1f}×",
41
+ "payback": f"{base['payback_months']:.1f} months",
42
+ "confidence": "High"
43
+ },
44
+ "best_case": {
45
+ "roi": f"{best['roi_multiplier']:.1f}×",
46
+ "payback": f"{best['payback_months']:.1f} months",
47
+ "confidence": "Medium"
48
+ },
49
+ "worst_case": {
50
+ "roi": f"{worst['roi_multiplier']:.1f}×",
51
+ "payback": f"{worst['payback_months']:.1f} months",
52
+ "confidence": "Medium"
53
+ }
54
+ },
55
+ "comparison": {
56
+ "industry_average": "5.2× ROI",
57
+ "top_performers": "8.7× ROI",
58
+ "your_position": f"Top {self._get_percentile(base['roi_multiplier'])}%"
59
+ },
60
+ "recommendation": recommendation
61
+ }
62
+
63
+ def _calculate_scenario(self, monthly_incidents: int, avg_impact: float,
64
+ team_size: int, savings_rate: float,
65
+ efficiency_gain: float) -> Dict:
66
+ """Calculate specific scenario"""
67
+ annual_impact = monthly_incidents * 12 * avg_impact
68
+ enterprise_cost = team_size * 125000 # Conservative $125k/engineer
69
+ savings = annual_impact * savings_rate * efficiency_gain
70
+
71
+ roi_multiplier = savings / enterprise_cost if enterprise_cost > 0 else 0
72
+ roi_percentage = (roi_multiplier - 1) * 100
73
+ payback_months = (enterprise_cost / (savings / 12)) if savings > 0 else 0
74
+
75
+ return {
76
+ "annual_impact": annual_impact,
77
+ "enterprise_cost": enterprise_cost,
78
+ "savings": savings,
79
+ "roi_multiplier": roi_multiplier,
80
+ "roi_percentage": roi_percentage,
81
+ "payback_months": payback_months
82
+ }
83
+
84
+ def _get_recommendation(self, roi_multiplier: float) -> Dict:
85
+ """Get recommendation based on ROI"""
86
+ if roi_multiplier >= 5.0:
87
+ return {
88
+ "action": "🚀 Deploy ARF Enterprise",
89
+ "reason": "Exceptional ROI (>5×) with quick payback",
90
+ "timeline": "30-day implementation",
91
+ "expected_value": ">$1M annual savings",
92
+ "priority": "High"
93
+ }
94
+ elif roi_multiplier >= 2.0:
95
+ return {
96
+ "action": "✅ Implement ARF Enterprise",
97
+ "reason": "Strong ROI (2-5×) with operational benefits",
98
+ "timeline": "60-day phased rollout",
99
+ "expected_value": ">$500K annual savings",
100
+ "priority": "Medium"
101
+ }
102
+ else:
103
+ return {
104
+ "action": "🆓 Start with ARF OSS",
105
+ "reason": "Validate value before Enterprise investment",
106
+ "timeline": "14-day evaluation",
107
+ "expected_value": "Operational insights + clear upgrade path",
108
+ "priority": "Low"
109
+ }
110
+
111
+ def _get_percentile(self, roi_multiplier: float) -> str:
112
+ """Calculate percentile vs industry"""
113
+ if roi_multiplier >= 8.0:
114
+ return "10"
115
+ elif roi_multiplier >= 5.0:
116
+ return "25"
117
+ elif roi_multiplier >= 3.0:
118
+ return "50"
119
+ elif roi_multiplier >= 2.0:
120
+ return "75"
121
+ else:
122
+ return "90"