Update core/visualizations.py
Browse files- core/visualizations.py +812 -403
core/visualizations.py
CHANGED
|
@@ -1,18 +1,29 @@
|
|
| 1 |
"""
|
| 2 |
-
Enhanced visualization engine for ARF Demo
|
|
|
|
| 3 |
"""
|
| 4 |
-
|
| 5 |
-
import plotly.express as px
|
| 6 |
-
import numpy as np
|
| 7 |
-
import pandas as pd
|
| 8 |
-
from typing import Dict, List, Any, Optional
|
| 9 |
import logging
|
|
|
|
|
|
|
| 10 |
|
| 11 |
logger = logging.getLogger(__name__)
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
class EnhancedVisualizationEngine:
|
| 15 |
-
"""Enhanced visualization engine with
|
| 16 |
|
| 17 |
def __init__(self):
|
| 18 |
self.color_palette = {
|
|
@@ -22,440 +33,719 @@ class EnhancedVisualizationEngine:
|
|
| 22 |
"danger": "#ef4444",
|
| 23 |
"info": "#8b5cf6",
|
| 24 |
"dark": "#1e293b",
|
| 25 |
-
"light": "#f8fafc"
|
|
|
|
|
|
|
|
|
|
| 26 |
}
|
| 27 |
-
|
| 28 |
-
def create_executive_dashboard(self, data: Optional[Dict] = None) ->
|
| 29 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
if data is None:
|
| 31 |
data = {"roi_multiplier": 5.2}
|
| 32 |
|
| 33 |
roi_multiplier = data.get("roi_multiplier", 5.2)
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
}
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
-
def
|
| 89 |
-
"""Create
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
-
# Different patterns for different scenarios
|
| 94 |
if "Cache" in scenario_name:
|
| 95 |
-
|
| 96 |
-
noise = np.random.normal(0, 8, 100)
|
| 97 |
-
metric_name = "Cache Hit Rate (%)"
|
| 98 |
normal_range = (70, 95)
|
|
|
|
| 99 |
elif "Database" in scenario_name:
|
| 100 |
-
base_data = 70 + 30 * np.sin(time_points * 0.15)
|
| 101 |
-
noise = np.random.normal(0, 6, 100)
|
| 102 |
metric_name = "Connection Pool Usage"
|
| 103 |
normal_range = (20, 60)
|
| 104 |
-
|
| 105 |
-
base_data = 50 + 40 * np.sin(time_points * 0.1)
|
| 106 |
-
noise = np.random.normal(0, 10, 100)
|
| 107 |
-
metric_name = "Memory Usage (%)"
|
| 108 |
-
normal_range = (40, 80)
|
| 109 |
else:
|
| 110 |
-
base_data = 80 + 20 * np.sin(time_points * 0.25)
|
| 111 |
-
noise = np.random.normal(0, 5, 100)
|
| 112 |
metric_name = "System Load"
|
| 113 |
normal_range = (50, 90)
|
|
|
|
| 114 |
|
| 115 |
-
|
|
|
|
|
|
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
# Normal operation
|
| 121 |
-
fig.add_trace(go.Scatter(
|
| 122 |
-
x=time_points[:70],
|
| 123 |
-
y=data[:70],
|
| 124 |
-
mode='lines',
|
| 125 |
-
name='Normal Operation',
|
| 126 |
-
line=dict(color=self.color_palette["primary"], width=3),
|
| 127 |
-
fill='tozeroy',
|
| 128 |
-
fillcolor='rgba(59, 130, 246, 0.1)'
|
| 129 |
-
))
|
| 130 |
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
line=dict(color=self.color_palette["danger"], width=3, dash='dash'),
|
| 138 |
-
fill='tozeroy',
|
| 139 |
-
fillcolor='rgba(239, 68, 68, 0.1)'
|
| 140 |
-
))
|
| 141 |
|
| 142 |
-
#
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
|
| 192 |
-
def create_impact_gauge(self, scenario_name: str) ->
|
| 193 |
-
"""Create business impact gauge"""
|
| 194 |
impact_map = {
|
| 195 |
-
"Cache Miss Storm": {"revenue": 8500, "severity": "critical"},
|
| 196 |
-
"Database Connection Pool Exhaustion": {"revenue": 4200, "severity": "high"},
|
| 197 |
-
"Kubernetes Memory Leak": {"revenue": 5500, "severity": "high"},
|
| 198 |
-
"API Rate Limit Storm": {"revenue": 3800, "severity": "medium"},
|
| 199 |
-
"Network Partition": {"revenue": 12000, "severity": "critical"},
|
| 200 |
-
"Storage I/O Saturation": {"revenue": 6800, "severity": "high"}
|
| 201 |
}
|
| 202 |
|
| 203 |
-
impact = impact_map.get(scenario_name, {"revenue": 5000, "severity": "medium"})
|
| 204 |
-
|
| 205 |
-
fig = go.Figure(go.Indicator(
|
| 206 |
-
mode="gauge+number",
|
| 207 |
-
value=impact["revenue"],
|
| 208 |
-
title={'text': "π° Hourly Revenue Risk", 'font': {'size': 16}},
|
| 209 |
-
number={'prefix': "$", 'font': {'size': 28}},
|
| 210 |
-
gauge={
|
| 211 |
-
'axis': {'range': [0, 15000], 'tickwidth': 1},
|
| 212 |
-
'bar': {'color': self._get_severity_color(impact["severity"])},
|
| 213 |
-
'steps': [
|
| 214 |
-
{'range': [0, 3000], 'color': '#10b981'},
|
| 215 |
-
{'range': [3000, 7000], 'color': '#f59e0b'},
|
| 216 |
-
{'range': [7000, 15000], 'color': '#ef4444'}
|
| 217 |
-
],
|
| 218 |
-
'threshold': {
|
| 219 |
-
'line': {'color': "black", 'width': 4},
|
| 220 |
-
'thickness': 0.75,
|
| 221 |
-
'value': impact["revenue"]
|
| 222 |
-
}
|
| 223 |
-
}
|
| 224 |
-
))
|
| 225 |
-
|
| 226 |
-
fig.update_layout(
|
| 227 |
-
height=300,
|
| 228 |
-
margin=dict(l=20, r=20, t=50, b=20),
|
| 229 |
-
paper_bgcolor='rgba(0,0,0,0)'
|
| 230 |
-
)
|
| 231 |
-
|
| 232 |
-
return fig
|
| 233 |
-
|
| 234 |
-
def create_agent_performance_chart(self) -> go.Figure:
|
| 235 |
-
"""Create agent performance comparison chart"""
|
| 236 |
-
agents = ["Detection", "Recall", "Decision"]
|
| 237 |
-
accuracy = [98.7, 92.0, 94.0]
|
| 238 |
-
speed = [45, 30, 60] # seconds
|
| 239 |
-
confidence = [99.8, 92.0, 94.0]
|
| 240 |
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
marker_color=self.color_palette["primary"]),
|
| 244 |
-
go.Bar(name='Speed (seconds)', x=agents, y=speed,
|
| 245 |
-
marker_color=self.color_palette["success"]),
|
| 246 |
-
go.Bar(name='Confidence (%)', x=agents, y=confidence,
|
| 247 |
-
marker_color=self.color_palette["info"])
|
| 248 |
-
])
|
| 249 |
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
)
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
fig = go.Figure()
|
| 278 |
-
|
| 279 |
-
fig.add_trace(go.Bar(
|
| 280 |
-
name='Manual Process',
|
| 281 |
-
x=phases,
|
| 282 |
-
y=manual_times_min,
|
| 283 |
-
marker_color=self.color_palette["danger"],
|
| 284 |
-
text=[f"{t:.0f}m" for t in manual_times_min],
|
| 285 |
-
textposition='auto'
|
| 286 |
-
))
|
| 287 |
-
|
| 288 |
-
fig.add_trace(go.Bar(
|
| 289 |
-
name='ARF Autonomous',
|
| 290 |
-
x=phases,
|
| 291 |
-
y=arf_times_min,
|
| 292 |
-
marker_color=self.color_palette["success"],
|
| 293 |
-
text=[f"{t:.0f}m" for t in arf_times_min],
|
| 294 |
-
textposition='auto'
|
| 295 |
-
))
|
| 296 |
-
|
| 297 |
-
total_manual = sum(manual_times_min)
|
| 298 |
-
total_arf = sum(arf_times_min)
|
| 299 |
-
|
| 300 |
-
fig.update_layout(
|
| 301 |
-
title=f"β° Incident Timeline Comparison<br>"
|
| 302 |
-
f"<span style='font-size: 14px; color: #6b7280'>"
|
| 303 |
-
f"Total: {total_manual:.0f}m manual vs {total_arf:.0f}m ARF "
|
| 304 |
-
f"({((total_manual - total_arf) / total_manual * 100):.0f}% faster)</span>",
|
| 305 |
-
barmode='group',
|
| 306 |
-
height=400,
|
| 307 |
-
plot_bgcolor='rgba(0,0,0,0)',
|
| 308 |
-
paper_bgcolor='rgba(0,0,0,0)',
|
| 309 |
-
legend=dict(
|
| 310 |
-
orientation="h",
|
| 311 |
-
yanchor="bottom",
|
| 312 |
-
y=1.02,
|
| 313 |
-
xanchor="right",
|
| 314 |
-
x=1
|
| 315 |
-
),
|
| 316 |
-
yaxis_title="Time (minutes)"
|
| 317 |
-
)
|
| 318 |
-
|
| 319 |
-
return fig
|
| 320 |
-
|
| 321 |
-
def create_roi_simulation_chart(self, roi_data: Dict) -> go.Figure:
|
| 322 |
-
"""Create ROI simulation chart"""
|
| 323 |
-
scenarios = ["Worst Case", "Base Case", "Best Case"]
|
| 324 |
-
roi_values = [
|
| 325 |
-
roi_data.get("worst_case", 4.0),
|
| 326 |
-
roi_data.get("base_case", 5.2),
|
| 327 |
-
roi_data.get("best_case", 6.5)
|
| 328 |
-
]
|
| 329 |
-
|
| 330 |
-
fig = go.Figure(go.Bar(
|
| 331 |
-
x=scenarios,
|
| 332 |
-
y=roi_values,
|
| 333 |
-
marker_color=[
|
| 334 |
-
self.color_palette["warning"],
|
| 335 |
-
self.color_palette["success"],
|
| 336 |
-
self.color_palette["primary"]
|
| 337 |
-
],
|
| 338 |
-
text=[f"{v:.1f}Γ" for v in roi_values],
|
| 339 |
-
textposition='auto'
|
| 340 |
-
))
|
| 341 |
-
|
| 342 |
-
fig.update_layout(
|
| 343 |
-
title="π ROI Simulation Scenarios",
|
| 344 |
-
yaxis_title="ROI Multiplier",
|
| 345 |
-
height=400,
|
| 346 |
-
plot_bgcolor='rgba(0,0,0,0)',
|
| 347 |
-
paper_bgcolor='rgba(0,0,0,0)',
|
| 348 |
-
yaxis=dict(range=[0, max(roi_values) * 1.2])
|
| 349 |
-
)
|
| 350 |
-
|
| 351 |
-
# Add industry average line
|
| 352 |
-
fig.add_hline(
|
| 353 |
-
y=5.2,
|
| 354 |
-
line_dash="dash",
|
| 355 |
-
line_color="gray",
|
| 356 |
-
annotation_text="Industry Average",
|
| 357 |
-
annotation_position="top right"
|
| 358 |
-
)
|
| 359 |
-
|
| 360 |
-
return fig
|
| 361 |
|
| 362 |
-
def
|
| 363 |
-
"""
|
| 364 |
-
if
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
|
| 371 |
-
def
|
| 372 |
-
"""Create
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
("Cache Miss", "DB Pool", 0.85),
|
| 376 |
-
("DB Pool", "Memory Leak", 0.72),
|
| 377 |
-
("Memory Leak", "API Limit", 0.65),
|
| 378 |
-
("API Limit", "Network", 0.58),
|
| 379 |
-
("Cache Miss", "Network", 0.45)
|
| 380 |
-
]
|
| 381 |
-
|
| 382 |
-
fig = go.Figure()
|
| 383 |
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 394 |
))
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
showlegend=False
|
| 404 |
))
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 417 |
|
| 418 |
-
def
|
| 419 |
-
"""
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
parents=["", "System", "System", "System", "API", "API"],
|
| 423 |
-
values=[100, 30, 40, 30, 15, 15],
|
| 424 |
-
marker=dict(colors=px.colors.sequential.Blues)
|
| 425 |
-
))
|
| 426 |
-
|
| 427 |
-
fig.update_layout(
|
| 428 |
-
title="π System Dependency Map",
|
| 429 |
-
height=500,
|
| 430 |
-
plot_bgcolor='rgba(0,0,0,0)',
|
| 431 |
-
paper_bgcolor='rgba(0,0,0,0)'
|
| 432 |
-
)
|
| 433 |
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
"""Create action-outcome graph"""
|
| 438 |
-
actions = ["Scale Cache", "Restart DB", "Limit API", "Monitor Memory"]
|
| 439 |
-
success_rates = [87, 92, 78, 85]
|
| 440 |
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
text=[f"{rate}%" for rate in success_rates],
|
| 446 |
-
textposition='auto'
|
| 447 |
-
))
|
| 448 |
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
|
| 458 |
-
return
|
| 459 |
|
| 460 |
def _get_severity_color(self, severity: str) -> str:
|
| 461 |
"""Get color for severity level"""
|
|
@@ -465,4 +755,123 @@ class EnhancedVisualizationEngine:
|
|
| 465 |
"medium": self.color_palette["info"],
|
| 466 |
"low": self.color_palette["success"]
|
| 467 |
}
|
| 468 |
-
return color_map.get(severity.lower(), self.color_palette["info"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
"""
|
| 2 |
+
Enhanced visualization engine for ARF Demo with clear boundary indicators
|
| 3 |
+
FIXED VERSION: Works even when Plotly fails, shows clear real/simulated boundaries
|
| 4 |
"""
|
| 5 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
import logging
|
| 7 |
+
from typing import Dict, List, Any, Optional, Tuple
|
| 8 |
+
import random
|
| 9 |
|
| 10 |
logger = logging.getLogger(__name__)
|
| 11 |
|
| 12 |
+
# Try to import Plotly, but have fallbacks
|
| 13 |
+
try:
|
| 14 |
+
import plotly.graph_objects as go
|
| 15 |
+
import plotly.express as px
|
| 16 |
+
import numpy as np
|
| 17 |
+
import pandas as pd
|
| 18 |
+
PLOTLY_AVAILABLE = True
|
| 19 |
+
logger.info("β
Plotly available for advanced visualizations")
|
| 20 |
+
except ImportError as e:
|
| 21 |
+
PLOTLY_AVAILABLE = False
|
| 22 |
+
logger.warning(f"β οΈ Plotly not available: {e}. Using HTML fallback visualizations.")
|
| 23 |
+
|
| 24 |
|
| 25 |
class EnhancedVisualizationEngine:
|
| 26 |
+
"""Enhanced visualization engine with boundary awareness and fallbacks"""
|
| 27 |
|
| 28 |
def __init__(self):
|
| 29 |
self.color_palette = {
|
|
|
|
| 33 |
"danger": "#ef4444",
|
| 34 |
"info": "#8b5cf6",
|
| 35 |
"dark": "#1e293b",
|
| 36 |
+
"light": "#f8fafc",
|
| 37 |
+
"real_arf": "#10b981", # Green for real ARF
|
| 38 |
+
"simulated": "#f59e0b", # Amber for simulated
|
| 39 |
+
"mock": "#64748b", # Gray for mock
|
| 40 |
}
|
| 41 |
+
|
| 42 |
+
def create_executive_dashboard(self, data: Optional[Dict] = None, is_real_arf: bool = True) -> Any:
|
| 43 |
+
"""
|
| 44 |
+
Create executive dashboard with clear boundary indicators
|
| 45 |
+
|
| 46 |
+
Args:
|
| 47 |
+
data: Dashboard data
|
| 48 |
+
is_real_arf: Whether this is real ARF or simulated/mock
|
| 49 |
+
|
| 50 |
+
Returns:
|
| 51 |
+
Plotly figure or HTML fallback
|
| 52 |
+
"""
|
| 53 |
if data is None:
|
| 54 |
data = {"roi_multiplier": 5.2}
|
| 55 |
|
| 56 |
roi_multiplier = data.get("roi_multiplier", 5.2)
|
| 57 |
|
| 58 |
+
if not PLOTLY_AVAILABLE:
|
| 59 |
+
# HTML fallback
|
| 60 |
+
return self._create_html_dashboard(roi_multiplier, is_real_arf)
|
| 61 |
|
| 62 |
+
try:
|
| 63 |
+
# Create a multi-panel executive dashboard with boundary indicators
|
| 64 |
+
fig = go.Figure()
|
| 65 |
+
|
| 66 |
+
# Main ROI gauge with boundary indicator
|
| 67 |
+
boundary_color = self.color_palette["real_arf"] if is_real_arf else self.color_palette["simulated"]
|
| 68 |
+
boundary_text = "REAL ARF OSS" if is_real_arf else "SIMULATED"
|
| 69 |
+
|
| 70 |
+
fig.add_trace(go.Indicator(
|
| 71 |
+
mode="number+gauge",
|
| 72 |
+
value=roi_multiplier,
|
| 73 |
+
title={
|
| 74 |
+
"text": f"<b>ROI Multiplier</b><br>"
|
| 75 |
+
f"<span style='font-size: 12px; color: {boundary_color}'>"
|
| 76 |
+
f"π {boundary_text}</span>"
|
| 77 |
+
},
|
| 78 |
+
domain={'x': [0.25, 0.75], 'y': [0.6, 1]},
|
| 79 |
+
gauge={
|
| 80 |
+
'axis': {'range': [0, 10], 'tickwidth': 1},
|
| 81 |
+
'bar': {'color': boundary_color},
|
| 82 |
+
'steps': [
|
| 83 |
+
{'range': [0, 2], 'color': '#e5e7eb'},
|
| 84 |
+
{'range': [2, 4], 'color': '#d1d5db'},
|
| 85 |
+
{'range': [4, 6], 'color': '#10b981'},
|
| 86 |
+
{'range': [6, 10], 'color': '#059669'}
|
| 87 |
+
],
|
| 88 |
+
'threshold': {
|
| 89 |
+
'line': {'color': "black", 'width': 4},
|
| 90 |
+
'thickness': 0.75,
|
| 91 |
+
'value': roi_multiplier
|
| 92 |
+
}
|
| 93 |
}
|
| 94 |
+
))
|
| 95 |
+
|
| 96 |
+
# Add boundary indicator in top right
|
| 97 |
+
fig.add_annotation(
|
| 98 |
+
x=0.98, y=0.98,
|
| 99 |
+
xref="paper", yref="paper",
|
| 100 |
+
text=f"π {boundary_text}",
|
| 101 |
+
showarrow=False,
|
| 102 |
+
font=dict(size=14, color=boundary_color, family="Arial, sans-serif"),
|
| 103 |
+
bgcolor="white",
|
| 104 |
+
bordercolor=boundary_color,
|
| 105 |
+
borderwidth=2,
|
| 106 |
+
borderpad=4,
|
| 107 |
+
opacity=0.9
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
# Add secondary metrics with clear sourcing
|
| 111 |
+
source_text = "Real ARF OSS" if is_real_arf else "Demo Simulation"
|
| 112 |
+
|
| 113 |
+
fig.add_trace(go.Indicator(
|
| 114 |
+
mode="number",
|
| 115 |
+
value=85,
|
| 116 |
+
title={
|
| 117 |
+
"text": f"MTTR Reduction<br>"
|
| 118 |
+
f"<span style='font-size: 10px; color: #64748b'>{source_text}</span>"
|
| 119 |
+
},
|
| 120 |
+
number={'suffix': "%", 'font': {'size': 24}},
|
| 121 |
+
domain={'x': [0.1, 0.4], 'y': [0.2, 0.5]}
|
| 122 |
+
))
|
| 123 |
+
|
| 124 |
+
fig.add_trace(go.Indicator(
|
| 125 |
+
mode="number",
|
| 126 |
+
value=94,
|
| 127 |
+
title={
|
| 128 |
+
"text": f"Detection Accuracy<br>"
|
| 129 |
+
f"<span style='font-size: 10px; color: #64748b'>{source_text}</span>"
|
| 130 |
+
},
|
| 131 |
+
number={'suffix': "%", 'font': {'size': 24}},
|
| 132 |
+
domain={'x': [0.6, 0.9], 'y': [0.2, 0.5]}
|
| 133 |
+
))
|
| 134 |
+
|
| 135 |
+
fig.update_layout(
|
| 136 |
+
height=700,
|
| 137 |
+
paper_bgcolor="rgba(0,0,0,0)",
|
| 138 |
+
plot_bgcolor="rgba(0,0,0,0)",
|
| 139 |
+
font={'family': "Arial, sans-serif"},
|
| 140 |
+
margin=dict(t=50, b=50, l=50, r=50),
|
| 141 |
+
title=f"π Executive Dashboard - ARF v3.3.7<br>"
|
| 142 |
+
f"<span style='font-size: 14px; color: {boundary_color}'>"
|
| 143 |
+
f"Mode: {boundary_text}</span>"
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
+
return fig
|
| 147 |
+
|
| 148 |
+
except Exception as e:
|
| 149 |
+
logger.error(f"Plotly dashboard creation failed: {e}")
|
| 150 |
+
return self._create_html_dashboard(roi_multiplier, is_real_arf)
|
| 151 |
|
| 152 |
+
def _create_html_dashboard(self, roi_multiplier: float, is_real_arf: bool) -> str:
|
| 153 |
+
"""Create HTML fallback dashboard"""
|
| 154 |
+
boundary_color = self.color_palette["real_arf"] if is_real_arf else self.color_palette["simulated"]
|
| 155 |
+
boundary_text = "REAL ARF OSS" if is_real_arf else "SIMULATED"
|
| 156 |
+
|
| 157 |
+
return f"""
|
| 158 |
+
<div style="border: 2px solid {boundary_color}; border-radius: 16px; padding: 25px;
|
| 159 |
+
background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
|
| 160 |
+
box-shadow: 0 8px 32px rgba(0,0,0,0.1);">
|
| 161 |
+
|
| 162 |
+
<!-- Boundary indicator -->
|
| 163 |
+
<div style="position: absolute; top: 15px; right: 15px; padding: 6px 12px;
|
| 164 |
+
background: {boundary_color}; color: white; border-radius: 20px;
|
| 165 |
+
font-size: 12px; font-weight: bold; display: flex; align-items: center; gap: 6px;">
|
| 166 |
+
π {boundary_text}
|
| 167 |
+
</div>
|
| 168 |
+
|
| 169 |
+
<h3 style="margin: 0 0 20px 0; color: #1e293b; font-size: 20px; font-weight: 700;">
|
| 170 |
+
π Executive Dashboard - ARF v3.3.7
|
| 171 |
+
</h3>
|
| 172 |
+
|
| 173 |
+
<!-- Main ROI Gauge -->
|
| 174 |
+
<div style="text-align: center; margin: 30px 0;">
|
| 175 |
+
<div style="font-size: 14px; color: #64748b; margin-bottom: 10px; font-weight: 500;">
|
| 176 |
+
ROI Multiplier
|
| 177 |
+
</div>
|
| 178 |
+
<div style="position: relative; width: 160px; height: 160px; margin: 0 auto;">
|
| 179 |
+
<!-- Background circle -->
|
| 180 |
+
<div style="position: absolute; width: 160px; height: 160px;
|
| 181 |
+
border-radius: 50%; background: #f1f5f9; border: 10px solid #e2e8f0;"></div>
|
| 182 |
+
<!-- ROI arc -->
|
| 183 |
+
<div style="position: absolute; width: 160px; height: 160px;
|
| 184 |
+
border-radius: 50%;
|
| 185 |
+
background: conic-gradient({boundary_color} 0% {roi_multiplier*10}%, #e2e8f0 {roi_multiplier*10}% 100%);
|
| 186 |
+
border: 10px solid transparent; clip-path: polygon(50% 50%, 100% 0, 100% 100%);"></div>
|
| 187 |
+
<!-- Center value -->
|
| 188 |
+
<div style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
|
| 189 |
+
font-size: 32px; font-weight: 800; color: {boundary_color};">
|
| 190 |
+
{roi_multiplier:.1f}Γ
|
| 191 |
+
</div>
|
| 192 |
+
</div>
|
| 193 |
+
<div style="margin-top: 15px; font-size: 12px; color: {boundary_color}; font-weight: 600;">
|
| 194 |
+
{boundary_text} Analysis
|
| 195 |
+
</div>
|
| 196 |
+
</div>
|
| 197 |
+
|
| 198 |
+
<!-- Secondary metrics -->
|
| 199 |
+
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 30px;">
|
| 200 |
+
<div style="text-align: center; padding: 15px; background: #f8fafc; border-radius: 12px;">
|
| 201 |
+
<div style="font-size: 12px; color: #64748b; margin-bottom: 8px;">MTTR Reduction</div>
|
| 202 |
+
<div style="font-size: 28px; font-weight: 700; color: #10b981;">85%</div>
|
| 203 |
+
<div style="font-size: 10px; color: #94a3b8; margin-top: 4px;">{boundary_text}</div>
|
| 204 |
+
</div>
|
| 205 |
+
|
| 206 |
+
<div style="text-align: center; padding: 15px; background: #f8fafc; border-radius: 12px;">
|
| 207 |
+
<div style="font-size: 12px; color: #64748b; margin-bottom: 8px;">Detection Accuracy</div>
|
| 208 |
+
<div style="font-size: 28px; font-weight: 700; color: #10b981;">94%</div>
|
| 209 |
+
<div style="font-size: 10px; color: #94a3b8; margin-top: 4px;">{boundary_text}</div>
|
| 210 |
+
</div>
|
| 211 |
+
</div>
|
| 212 |
+
|
| 213 |
+
<!-- Data source note -->
|
| 214 |
+
<div style="margin-top: 25px; padding: 12px; background: #f1f5f9; border-radius: 8px; border-left: 4px solid {boundary_color};">
|
| 215 |
+
<div style="font-size: 12px; color: #475569; line-height: 1.5;">
|
| 216 |
+
<strong>π Data Source:</strong> {boundary_text} v3.3.7 β’
|
| 217 |
+
<strong>β‘ Processing:</strong> Real-time analysis β’
|
| 218 |
+
<strong>π― Confidence:</strong> Deterministic scoring
|
| 219 |
+
</div>
|
| 220 |
+
</div>
|
| 221 |
+
</div>
|
| 222 |
+
"""
|
| 223 |
+
|
| 224 |
+
def create_telemetry_plot(self, scenario_name: str, anomaly_detected: bool = True,
|
| 225 |
+
is_real_arf: bool = True) -> Any:
|
| 226 |
+
"""Create telemetry plot with boundary indicators"""
|
| 227 |
+
if not PLOTLY_AVAILABLE:
|
| 228 |
+
return self._create_html_telemetry(scenario_name, anomaly_detected, is_real_arf)
|
| 229 |
+
|
| 230 |
+
try:
|
| 231 |
+
import numpy as np
|
| 232 |
+
|
| 233 |
+
# Generate realistic telemetry data
|
| 234 |
+
time_points = np.arange(0, 100, 1)
|
| 235 |
+
|
| 236 |
+
# Different patterns for different scenarios
|
| 237 |
+
if "Cache" in scenario_name:
|
| 238 |
+
base_data = 100 + 50 * np.sin(time_points * 0.2)
|
| 239 |
+
noise = np.random.normal(0, 8, 100)
|
| 240 |
+
metric_name = "Cache Hit Rate (%)"
|
| 241 |
+
normal_range = (70, 95)
|
| 242 |
+
elif "Database" in scenario_name:
|
| 243 |
+
base_data = 70 + 30 * np.sin(time_points * 0.15)
|
| 244 |
+
noise = np.random.normal(0, 6, 100)
|
| 245 |
+
metric_name = "Connection Pool Usage"
|
| 246 |
+
normal_range = (20, 60)
|
| 247 |
+
elif "Memory" in scenario_name:
|
| 248 |
+
base_data = 50 + 40 * np.sin(time_points * 0.1)
|
| 249 |
+
noise = np.random.normal(0, 10, 100)
|
| 250 |
+
metric_name = "Memory Usage (%)"
|
| 251 |
+
normal_range = (40, 80)
|
| 252 |
+
else:
|
| 253 |
+
base_data = 80 + 20 * np.sin(time_points * 0.25)
|
| 254 |
+
noise = np.random.normal(0, 5, 100)
|
| 255 |
+
metric_name = "System Load"
|
| 256 |
+
normal_range = (50, 90)
|
| 257 |
+
|
| 258 |
+
data = base_data + noise
|
| 259 |
+
|
| 260 |
+
fig = go.Figure()
|
| 261 |
+
|
| 262 |
+
boundary_color = self.color_palette["real_arf"] if is_real_arf else self.color_palette["simulated"]
|
| 263 |
+
boundary_text = "REAL ARF" if is_real_arf else "SIMULATED"
|
| 264 |
+
|
| 265 |
+
if anomaly_detected:
|
| 266 |
+
# Normal operation
|
| 267 |
+
fig.add_trace(go.Scatter(
|
| 268 |
+
x=time_points[:70],
|
| 269 |
+
y=data[:70],
|
| 270 |
+
mode='lines',
|
| 271 |
+
name='Normal Operation',
|
| 272 |
+
line=dict(color=self.color_palette["primary"], width=3),
|
| 273 |
+
fill='tozeroy',
|
| 274 |
+
fillcolor='rgba(59, 130, 246, 0.1)'
|
| 275 |
+
))
|
| 276 |
+
|
| 277 |
+
# Anomaly period
|
| 278 |
+
fig.add_trace(go.Scatter(
|
| 279 |
+
x=time_points[70:],
|
| 280 |
+
y=data[70:],
|
| 281 |
+
mode='lines',
|
| 282 |
+
name='π¨ Anomaly Detected',
|
| 283 |
+
line=dict(color=self.color_palette["danger"], width=3, dash='dash'),
|
| 284 |
+
fill='tozeroy',
|
| 285 |
+
fillcolor='rgba(239, 68, 68, 0.1)'
|
| 286 |
+
))
|
| 287 |
+
|
| 288 |
+
# Add detection point
|
| 289 |
+
fig.add_vline(
|
| 290 |
+
x=70,
|
| 291 |
+
line_dash="dash",
|
| 292 |
+
line_color=self.color_palette["success"],
|
| 293 |
+
annotation_text=f"ARF Detection ({boundary_text})",
|
| 294 |
+
annotation_position="top",
|
| 295 |
+
annotation_font_color=boundary_color
|
| 296 |
+
)
|
| 297 |
+
else:
|
| 298 |
+
# All normal
|
| 299 |
+
fig.add_trace(go.Scatter(
|
| 300 |
+
x=time_points,
|
| 301 |
+
y=data,
|
| 302 |
+
mode='lines',
|
| 303 |
+
name=metric_name,
|
| 304 |
+
line=dict(color=self.color_palette["primary"], width=3),
|
| 305 |
+
fill='tozeroy',
|
| 306 |
+
fillcolor='rgba(59, 130, 246, 0.1)'
|
| 307 |
+
))
|
| 308 |
+
|
| 309 |
+
# Add normal range
|
| 310 |
+
fig.add_hrect(
|
| 311 |
+
y0=normal_range[0],
|
| 312 |
+
y1=normal_range[1],
|
| 313 |
+
fillcolor="rgba(16, 185, 129, 0.1)",
|
| 314 |
+
opacity=0.2,
|
| 315 |
+
line_width=0,
|
| 316 |
+
annotation_text="Normal Range",
|
| 317 |
+
annotation_position="top left"
|
| 318 |
+
)
|
| 319 |
+
|
| 320 |
+
# Add boundary indicator
|
| 321 |
+
fig.add_annotation(
|
| 322 |
+
x=0.02, y=0.98,
|
| 323 |
+
xref="paper", yref="paper",
|
| 324 |
+
text=f"π {boundary_text}",
|
| 325 |
+
showarrow=False,
|
| 326 |
+
font=dict(size=12, color=boundary_color),
|
| 327 |
+
bgcolor="white",
|
| 328 |
+
bordercolor=boundary_color,
|
| 329 |
+
borderwidth=2,
|
| 330 |
+
borderpad=4
|
| 331 |
+
)
|
| 332 |
+
|
| 333 |
+
fig.update_layout(
|
| 334 |
+
title=f"π {metric_name} - Live Telemetry<br>"
|
| 335 |
+
f"<span style='font-size: 12px; color: #64748b'>"
|
| 336 |
+
f"ARF v3.3.7 β’ {boundary_text} Analysis</span>",
|
| 337 |
+
xaxis_title="Time (minutes)",
|
| 338 |
+
yaxis_title=metric_name,
|
| 339 |
+
height=350,
|
| 340 |
+
margin=dict(l=20, r=20, t=70, b=20),
|
| 341 |
+
plot_bgcolor='rgba(0,0,0,0)',
|
| 342 |
+
paper_bgcolor='rgba(0,0,0,0)',
|
| 343 |
+
legend=dict(
|
| 344 |
+
orientation="h",
|
| 345 |
+
yanchor="bottom",
|
| 346 |
+
y=1.02,
|
| 347 |
+
xanchor="right",
|
| 348 |
+
x=1
|
| 349 |
+
)
|
| 350 |
+
)
|
| 351 |
+
|
| 352 |
+
return fig
|
| 353 |
+
|
| 354 |
+
except Exception as e:
|
| 355 |
+
logger.error(f"Telemetry plot creation failed: {e}")
|
| 356 |
+
return self._create_html_telemetry(scenario_name, anomaly_detected, is_real_arf)
|
| 357 |
+
|
| 358 |
+
def _create_html_telemetry(self, scenario_name: str, anomaly_detected: bool, is_real_arf: bool) -> str:
|
| 359 |
+
"""HTML fallback for telemetry visualization"""
|
| 360 |
+
boundary_color = self.color_palette["real_arf"] if is_real_arf else self.color_palette["simulated"]
|
| 361 |
+
boundary_text = "REAL ARF" if is_real_arf else "SIMULATED"
|
| 362 |
|
|
|
|
| 363 |
if "Cache" in scenario_name:
|
| 364 |
+
metric_name = "Cache Hit Rate"
|
|
|
|
|
|
|
| 365 |
normal_range = (70, 95)
|
| 366 |
+
current_value = 18 if anomaly_detected else 85
|
| 367 |
elif "Database" in scenario_name:
|
|
|
|
|
|
|
| 368 |
metric_name = "Connection Pool Usage"
|
| 369 |
normal_range = (20, 60)
|
| 370 |
+
current_value = 92 if anomaly_detected else 45
|
|
|
|
|
|
|
|
|
|
|
|
|
| 371 |
else:
|
|
|
|
|
|
|
| 372 |
metric_name = "System Load"
|
| 373 |
normal_range = (50, 90)
|
| 374 |
+
current_value = 185 if anomaly_detected else 65
|
| 375 |
|
| 376 |
+
# Calculate position in range
|
| 377 |
+
percentage = ((current_value - normal_range[0]) / (normal_range[1] - normal_range[0])) * 100
|
| 378 |
+
percentage = max(0, min(100, percentage))
|
| 379 |
|
| 380 |
+
return f"""
|
| 381 |
+
<div style="border: 2px solid {boundary_color}; border-radius: 16px; padding: 20px;
|
| 382 |
+
background: white; box-shadow: 0 4px 12px rgba(0,0,0,0.05);">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 383 |
|
| 384 |
+
<!-- Boundary indicator -->
|
| 385 |
+
<div style="position: absolute; top: 15px; right: 15px; padding: 4px 10px;
|
| 386 |
+
background: {boundary_color}; color: white; border-radius: 15px;
|
| 387 |
+
font-size: 11px; font-weight: bold; display: flex; align-items: center; gap: 5px;">
|
| 388 |
+
π {boundary_text}
|
| 389 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 390 |
|
| 391 |
+
<h4 style="margin: 0 0 15px 0; color: #1e293b; font-size: 16px; font-weight: 600;">
|
| 392 |
+
π {metric_name} - Live Telemetry
|
| 393 |
+
</h4>
|
| 394 |
+
|
| 395 |
+
<!-- Simplified timeline -->
|
| 396 |
+
<div style="position: relative; height: 100px; margin: 20px 0;">
|
| 397 |
+
<!-- Background line -->
|
| 398 |
+
<div style="position: absolute; left: 0; right: 0; top: 50%;
|
| 399 |
+
height: 2px; background: #e2e8f0; transform: translateY(-50%);"></div>
|
| 400 |
+
|
| 401 |
+
<!-- Normal range -->
|
| 402 |
+
<div style="position: absolute; left: 10%; right: 40%; top: 50%;
|
| 403 |
+
height: 6px; background: #10b981; transform: translateY(-50%);
|
| 404 |
+
border-radius: 3px; opacity: 0.3;"></div>
|
| 405 |
+
|
| 406 |
+
<!-- Anomaly point -->
|
| 407 |
+
<div style="position: absolute; left: 70%; top: 50%;
|
| 408 |
+
transform: translate(-50%, -50%);">
|
| 409 |
+
<div style="width: 20px; height: 20px; border-radius: 50%;
|
| 410 |
+
background: {'#ef4444' if anomaly_detected else '#10b981'};
|
| 411 |
+
border: 3px solid white; box-shadow: 0 0 0 2px {'#ef4444' if anomaly_detected else '#10b981'};">
|
| 412 |
+
</div>
|
| 413 |
+
<div style="position: absolute; top: 25px; left: 50%; transform: translateX(-50%);
|
| 414 |
+
white-space: nowrap; font-size: 11px; color: #64748b;">
|
| 415 |
+
{current_value}
|
| 416 |
+
</div>
|
| 417 |
+
</div>
|
| 418 |
+
|
| 419 |
+
<!-- Labels -->
|
| 420 |
+
<div style="position: absolute; left: 10%; top: 70px; font-size: 11px; color: #64748b;">
|
| 421 |
+
Normal: {normal_range[0]}
|
| 422 |
+
</div>
|
| 423 |
+
<div style="position: absolute; left: 40%; top: 70px; font-size: 11px; color: #64748b;">
|
| 424 |
+
Warning: {normal_range[1]}
|
| 425 |
+
</div>
|
| 426 |
+
<div style="position: absolute; left: 70%; top: 70px; font-size: 11px;
|
| 427 |
+
color: {'#ef4444' if anomaly_detected else '#10b981'}; font-weight: 500;">
|
| 428 |
+
Current: {current_value}
|
| 429 |
+
</div>
|
| 430 |
+
</div>
|
| 431 |
+
|
| 432 |
+
<!-- Status indicator -->
|
| 433 |
+
<div style="display: flex; justify-content: space-between; align-items: center;
|
| 434 |
+
margin-top: 15px; padding: 10px; background: #f8fafc; border-radius: 8px;">
|
| 435 |
+
<div>
|
| 436 |
+
<div style="font-size: 12px; color: #64748b;">Status</div>
|
| 437 |
+
<div style="font-size: 14px; color: {'#ef4444' if anomaly_detected else '#10b981'};
|
| 438 |
+
font-weight: 600;">
|
| 439 |
+
{'π¨ Anomaly Detected' if anomaly_detected else 'β
Normal'}
|
| 440 |
+
</div>
|
| 441 |
+
</div>
|
| 442 |
+
<div style="text-align: right;">
|
| 443 |
+
<div style="font-size: 12px; color: #64748b;">ARF Mode</div>
|
| 444 |
+
<div style="font-size: 14px; color: {boundary_color}; font-weight: 600;">
|
| 445 |
+
{boundary_text}
|
| 446 |
+
</div>
|
| 447 |
+
</div>
|
| 448 |
+
</div>
|
| 449 |
+
</div>
|
| 450 |
+
"""
|
| 451 |
|
| 452 |
+
def create_impact_gauge(self, scenario_name: str, is_real_arf: bool = True) -> Any:
|
| 453 |
+
"""Create business impact gauge with boundary indicators"""
|
| 454 |
impact_map = {
|
| 455 |
+
"Cache Miss Storm": {"revenue": 8500, "severity": "critical", "users": 45000},
|
| 456 |
+
"Database Connection Pool Exhaustion": {"revenue": 4200, "severity": "high", "users": 25000},
|
| 457 |
+
"Kubernetes Memory Leak": {"revenue": 5500, "severity": "high", "users": 35000},
|
| 458 |
+
"API Rate Limit Storm": {"revenue": 3800, "severity": "medium", "users": 20000},
|
| 459 |
+
"Network Partition": {"revenue": 12000, "severity": "critical", "users": 75000},
|
| 460 |
+
"Storage I/O Saturation": {"revenue": 6800, "severity": "high", "users": 30000}
|
| 461 |
}
|
| 462 |
|
| 463 |
+
impact = impact_map.get(scenario_name, {"revenue": 5000, "severity": "medium", "users": 30000})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 464 |
|
| 465 |
+
if not PLOTLY_AVAILABLE:
|
| 466 |
+
return self._create_html_impact_gauge(impact, is_real_arf)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 467 |
|
| 468 |
+
try:
|
| 469 |
+
boundary_color = self.color_palette["real_arf"] if is_real_arf else self.color_palette["simulated"]
|
| 470 |
+
boundary_text = "REAL ARF" if is_real_arf else "SIMULATED"
|
| 471 |
+
severity_color = self._get_severity_color(impact["severity"])
|
| 472 |
+
|
| 473 |
+
fig = go.Figure(go.Indicator(
|
| 474 |
+
mode="gauge+number",
|
| 475 |
+
value=impact["revenue"],
|
| 476 |
+
title={
|
| 477 |
+
"text": f"π° Hourly Revenue Risk<br>"
|
| 478 |
+
f"<span style='font-size: 12px; color: {boundary_color}'>"
|
| 479 |
+
f"{boundary_text} Analysis</span>"
|
| 480 |
+
},
|
| 481 |
+
number={'prefix': "$", 'font': {'size': 28}},
|
| 482 |
+
gauge={
|
| 483 |
+
'axis': {'range': [0, 15000], 'tickwidth': 1},
|
| 484 |
+
'bar': {'color': severity_color},
|
| 485 |
+
'steps': [
|
| 486 |
+
{'range': [0, 3000], 'color': '#10b981'},
|
| 487 |
+
{'range': [3000, 7000], 'color': '#f59e0b'},
|
| 488 |
+
{'range': [7000, 15000], 'color': '#ef4444'}
|
| 489 |
+
],
|
| 490 |
+
'threshold': {
|
| 491 |
+
'line': {'color': "black", 'width': 4},
|
| 492 |
+
'thickness': 0.75,
|
| 493 |
+
'value': impact["revenue"]
|
| 494 |
+
}
|
| 495 |
+
}
|
| 496 |
+
))
|
| 497 |
+
|
| 498 |
+
# Add users affected annotation
|
| 499 |
+
fig.add_annotation(
|
| 500 |
+
x=0.5, y=0.3,
|
| 501 |
+
xref="paper", yref="paper",
|
| 502 |
+
text=f"π₯ {impact['users']:,} users affected",
|
| 503 |
+
showarrow=False,
|
| 504 |
+
font=dict(size=14, color="#64748b")
|
| 505 |
)
|
| 506 |
+
|
| 507 |
+
fig.update_layout(
|
| 508 |
+
height=350,
|
| 509 |
+
margin=dict(l=20, r=20, t=80, b=20),
|
| 510 |
+
paper_bgcolor='rgba(0,0,0,0)',
|
| 511 |
+
plot_bgcolor='rgba(0,0,0,0)'
|
| 512 |
+
)
|
| 513 |
+
|
| 514 |
+
return fig
|
| 515 |
+
|
| 516 |
+
except Exception as e:
|
| 517 |
+
logger.error(f"Impact gauge creation failed: {e}")
|
| 518 |
+
return self._create_html_impact_gauge(impact, is_real_arf)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 519 |
|
| 520 |
+
def _create_html_impact_gauge(self, impact: Dict, is_real_arf: bool) -> str:
|
| 521 |
+
"""HTML fallback for impact gauge"""
|
| 522 |
+
boundary_color = self.color_palette["real_arf"] if is_real_arf else self.color_palette["simulated"]
|
| 523 |
+
boundary_text = "REAL ARF" if is_real_arf else "SIMULATED"
|
| 524 |
+
severity_color = self._get_severity_color(impact["severity"])
|
| 525 |
+
|
| 526 |
+
# Calculate percentage for gauge
|
| 527 |
+
revenue = impact["revenue"]
|
| 528 |
+
percentage = min(100, (revenue / 15000) * 100)
|
| 529 |
+
|
| 530 |
+
return f"""
|
| 531 |
+
<div style="border: 2px solid {boundary_color}; border-radius: 16px; padding: 20px;
|
| 532 |
+
background: white; box-shadow: 0 4px 12px rgba(0,0,0,0.05); text-align: center;">
|
| 533 |
+
|
| 534 |
+
<!-- Boundary indicator -->
|
| 535 |
+
<div style="position: absolute; top: 15px; right: 15px; padding: 4px 10px;
|
| 536 |
+
background: {boundary_color}; color: white; border-radius: 15px;
|
| 537 |
+
font-size: 11px; font-weight: bold; display: flex; align-items: center; gap: 5px;">
|
| 538 |
+
π {boundary_text}
|
| 539 |
+
</div>
|
| 540 |
+
|
| 541 |
+
<h4 style="margin: 0 0 15px 0; color: #1e293b; font-size: 16px; font-weight: 600;">
|
| 542 |
+
π° Business Impact
|
| 543 |
+
</h4>
|
| 544 |
+
|
| 545 |
+
<!-- Revenue gauge -->
|
| 546 |
+
<div style="position: relative; width: 200px; height: 200px; margin: 0 auto;">
|
| 547 |
+
<!-- Background circle -->
|
| 548 |
+
<div style="position: absolute; width: 200px; height: 200px;
|
| 549 |
+
border-radius: 50%; background: #f1f5f9; border: 12px solid #e2e8f0;"></div>
|
| 550 |
+
|
| 551 |
+
<!-- Severity arc -->
|
| 552 |
+
<div style="position: absolute; width: 200px; height: 200px;
|
| 553 |
+
border-radius: 50%;
|
| 554 |
+
background: conic-gradient({severity_color} 0% {percentage}%, #e2e8f0 {percentage}% 100%);
|
| 555 |
+
border: 12px solid transparent; clip-path: polygon(50% 50%, 100% 0, 100% 100%);"></div>
|
| 556 |
+
|
| 557 |
+
<!-- Center value -->
|
| 558 |
+
<div style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
|
| 559 |
+
font-size: 28px; font-weight: 800; color: {severity_color}; line-height: 1;">
|
| 560 |
+
${revenue:,}<br>
|
| 561 |
+
<span style="font-size: 14px; color: #64748b;">per hour</span>
|
| 562 |
+
</div>
|
| 563 |
+
</div>
|
| 564 |
+
|
| 565 |
+
<!-- Severity indicator -->
|
| 566 |
+
<div style="display: inline-block; padding: 6px 16px; background: {severity_color};
|
| 567 |
+
color: white; border-radius: 20px; font-size: 13px; font-weight: bold;
|
| 568 |
+
margin: 15px 0; text-transform: uppercase;">
|
| 569 |
+
{impact['severity']} SEVERITY
|
| 570 |
+
</div>
|
| 571 |
+
|
| 572 |
+
<!-- User impact -->
|
| 573 |
+
<div style="margin-top: 15px; padding: 12px; background: #f8fafc; border-radius: 10px;">
|
| 574 |
+
<div style="display: flex; justify-content: space-between; align-items: center;">
|
| 575 |
+
<div style="font-size: 13px; color: #64748b;">π₯ Users Affected</div>
|
| 576 |
+
<div style="font-size: 18px; font-weight: 700; color: #1e293b;">
|
| 577 |
+
{impact['users']:,}
|
| 578 |
+
</div>
|
| 579 |
+
</div>
|
| 580 |
+
<div style="font-size: 11px; color: #94a3b8; margin-top: 5px; text-align: center;">
|
| 581 |
+
Analysis: {boundary_text} v3.3.7
|
| 582 |
+
</div>
|
| 583 |
+
</div>
|
| 584 |
+
</div>
|
| 585 |
+
"""
|
| 586 |
|
| 587 |
+
def create_timeline_comparison(self, is_real_arf: bool = True) -> Any:
|
| 588 |
+
"""Create timeline comparison chart"""
|
| 589 |
+
if not PLOTLY_AVAILABLE:
|
| 590 |
+
return self._create_html_timeline(is_real_arf)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 591 |
|
| 592 |
+
try:
|
| 593 |
+
import numpy as np
|
| 594 |
+
|
| 595 |
+
phases = ["Detection", "Analysis", "Decision", "Execution", "Recovery"]
|
| 596 |
+
manual_times = [300, 1800, 1200, 1800, 3600] # seconds
|
| 597 |
+
arf_times = [45, 30, 60, 720, 0]
|
| 598 |
+
|
| 599 |
+
# Convert to minutes for readability
|
| 600 |
+
manual_times_min = [t/60 for t in manual_times]
|
| 601 |
+
arf_times_min = [t/60 for t in arf_times]
|
| 602 |
+
|
| 603 |
+
fig = go.Figure()
|
| 604 |
+
|
| 605 |
+
boundary_color = self.color_palette["real_arf"] if is_real_arf else self.color_palette["simulated"]
|
| 606 |
+
boundary_text = "REAL ARF" if is_real_arf else "SIMULATED"
|
| 607 |
+
|
| 608 |
+
fig.add_trace(go.Bar(
|
| 609 |
+
name='Manual Process',
|
| 610 |
+
x=phases,
|
| 611 |
+
y=manual_times_min,
|
| 612 |
+
marker_color=self.color_palette["danger"],
|
| 613 |
+
text=[f"{t:.0f}m" for t in manual_times_min],
|
| 614 |
+
textposition='auto'
|
| 615 |
))
|
| 616 |
+
|
| 617 |
+
fig.add_trace(go.Bar(
|
| 618 |
+
name=f'ARF Autonomous ({boundary_text})',
|
| 619 |
+
x=phases,
|
| 620 |
+
y=arf_times_min,
|
| 621 |
+
marker_color=boundary_color,
|
| 622 |
+
text=[f"{t:.0f}m" for t in arf_times_min],
|
| 623 |
+
textposition='auto'
|
|
|
|
| 624 |
))
|
| 625 |
+
|
| 626 |
+
total_manual = sum(manual_times_min)
|
| 627 |
+
total_arf = sum(arf_times_min)
|
| 628 |
+
|
| 629 |
+
fig.update_layout(
|
| 630 |
+
title=f"β° Incident Timeline Comparison<br>"
|
| 631 |
+
f"<span style='font-size: 14px; color: #6b7280'>"
|
| 632 |
+
f"Total: {total_manual:.0f}m manual vs {total_arf:.0f}m ARF "
|
| 633 |
+
f"({((total_manual - total_arf) / total_manual * 100):.0f}% faster)</span>",
|
| 634 |
+
barmode='group',
|
| 635 |
+
height=400,
|
| 636 |
+
plot_bgcolor='rgba(0,0,0,0)',
|
| 637 |
+
paper_bgcolor='rgba(0,0,0,0)',
|
| 638 |
+
legend=dict(
|
| 639 |
+
orientation="h",
|
| 640 |
+
yanchor="bottom",
|
| 641 |
+
y=1.02,
|
| 642 |
+
xanchor="right",
|
| 643 |
+
x=1
|
| 644 |
+
),
|
| 645 |
+
yaxis_title="Time (minutes)"
|
| 646 |
+
)
|
| 647 |
+
|
| 648 |
+
return fig
|
| 649 |
+
|
| 650 |
+
except Exception as e:
|
| 651 |
+
logger.error(f"Timeline comparison creation failed: {e}")
|
| 652 |
+
return self._create_html_timeline(is_real_arf)
|
| 653 |
|
| 654 |
+
def _create_html_timeline(self, is_real_arf: bool) -> str:
|
| 655 |
+
"""HTML fallback for timeline comparison"""
|
| 656 |
+
boundary_color = self.color_palette["real_arf"] if is_real_arf else self.color_palette["simulated"]
|
| 657 |
+
boundary_text = "REAL ARF" if is_real_arf else "SIMULATED"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 658 |
|
| 659 |
+
phases = ["Detection", "Analysis", "Decision", "Execution", "Recovery"]
|
| 660 |
+
manual_times = [5, 30, 20, 30, 60] # minutes
|
| 661 |
+
arf_times = [0.75, 0.5, 1, 12, 0] # minutes
|
|
|
|
|
|
|
|
|
|
| 662 |
|
| 663 |
+
# Calculate totals
|
| 664 |
+
total_manual = sum(manual_times)
|
| 665 |
+
total_arf = sum(arf_times)
|
| 666 |
+
percent_faster = ((total_manual - total_arf) / total_manual) * 100
|
|
|
|
|
|
|
|
|
|
| 667 |
|
| 668 |
+
return f"""
|
| 669 |
+
<div style="border: 2px solid {boundary_color}; border-radius: 16px; padding: 20px;
|
| 670 |
+
background: white; box-shadow: 0 4px 12px rgba(0,0,0,0.05);">
|
| 671 |
+
|
| 672 |
+
<!-- Boundary indicator -->
|
| 673 |
+
<div style="position: absolute; top: 15px; right: 15px; padding: 4px 10px;
|
| 674 |
+
background: {boundary_color}; color: white; border-radius: 15px;
|
| 675 |
+
font-size: 11px; font-weight: bold; display: flex; align-items: center; gap: 5px;">
|
| 676 |
+
β° {boundary_text}
|
| 677 |
+
</div>
|
| 678 |
+
|
| 679 |
+
<h4 style="margin: 0 0 15px 0; color: #1e293b; font-size: 16px; font-weight: 600;">
|
| 680 |
+
β° Timeline Comparison
|
| 681 |
+
</h4>
|
| 682 |
+
|
| 683 |
+
<div style="font-size: 13px; color: #64748b; margin-bottom: 20px; line-height: 1.5;">
|
| 684 |
+
<strong>Manual:</strong> {total_manual:.0f} minutes β’
|
| 685 |
+
<strong>ARF ({boundary_text}):</strong> {total_arf:.0f} minutes β’
|
| 686 |
+
<strong>Faster:</strong> {percent_faster:.0f}%
|
| 687 |
+
</div>
|
| 688 |
+
|
| 689 |
+
<!-- Timeline visualization -->
|
| 690 |
+
<div style="position: relative; margin: 20px 0;">
|
| 691 |
+
<!-- Timeline line -->
|
| 692 |
+
<div style="position: absolute; left: 0; right: 0; top: 20px;
|
| 693 |
+
height: 2px; background: #e2e8f0;"></div>
|
| 694 |
+
|
| 695 |
+
{self._create_timeline_segments(phases, manual_times, arf_times, boundary_color)}
|
| 696 |
+
|
| 697 |
+
<!-- Legend -->
|
| 698 |
+
<div style="display: flex; gap: 15px; margin-top: 50px; justify-content: center;">
|
| 699 |
+
<div style="display: flex; align-items: center; gap: 6px;">
|
| 700 |
+
<div style="width: 12px; height: 12px; background: #ef4444; border-radius: 2px;"></div>
|
| 701 |
+
<div style="font-size: 12px; color: #64748b;">Manual Process</div>
|
| 702 |
+
</div>
|
| 703 |
+
<div style="display: flex; align-items: center; gap: 6px;">
|
| 704 |
+
<div style="width: 12px; height: 12px; background: {boundary_color}; border-radius: 2px;"></div>
|
| 705 |
+
<div style="font-size: 12px; color: #64748b;">ARF ({boundary_text})</div>
|
| 706 |
+
</div>
|
| 707 |
+
</div>
|
| 708 |
+
</div>
|
| 709 |
+
|
| 710 |
+
<!-- Summary -->
|
| 711 |
+
<div style="margin-top: 20px; padding: 15px; background: #f8fafc; border-radius: 10px;">
|
| 712 |
+
<div style="font-size: 14px; color: #475569; line-height: 1.6;">
|
| 713 |
+
<strong>π― ARF Value:</strong> Reduces MTTR from {total_manual:.0f} to {total_arf:.0f} minutes<br>
|
| 714 |
+
<strong>π Mode:</strong> {boundary_text} autonomous execution<br>
|
| 715 |
+
<strong>π Impact:</strong> {percent_faster:.0f}% faster resolution
|
| 716 |
+
</div>
|
| 717 |
+
</div>
|
| 718 |
+
</div>
|
| 719 |
+
"""
|
| 720 |
+
|
| 721 |
+
def _create_timeline_segments(self, phases: List[str], manual_times: List[float],
|
| 722 |
+
arf_times: List[float], boundary_color: str) -> str:
|
| 723 |
+
"""Create timeline segments HTML"""
|
| 724 |
+
segments_html = ""
|
| 725 |
+
total_width = 0
|
| 726 |
+
|
| 727 |
+
for i, (phase, manual_time, arf_time) in enumerate(zip(phases, manual_times, arf_times)):
|
| 728 |
+
# Calculate widths as percentages
|
| 729 |
+
manual_width = (manual_time / 125) * 100 # 125 = sum of all times
|
| 730 |
+
arf_width = (arf_time / 125) * 100
|
| 731 |
+
|
| 732 |
+
segments_html += f"""
|
| 733 |
+
<div style="position: absolute; left: {total_width}%; width: {manual_width}%;
|
| 734 |
+
top: 10px; text-align: center;">
|
| 735 |
+
<div style="height: 20px; background: #ef4444; border-radius: 4px; margin-bottom: 5px;"></div>
|
| 736 |
+
<div style="font-size: 11px; color: #64748b;">{phase}<br>{manual_time:.0f}m</div>
|
| 737 |
+
</div>
|
| 738 |
+
|
| 739 |
+
<div style="position: absolute; left: {total_width}%; width: {arf_width}%;
|
| 740 |
+
top: 35px; text-align: center;">
|
| 741 |
+
<div style="height: 20px; background: {boundary_color}; border-radius: 4px; margin-bottom: 5px;"></div>
|
| 742 |
+
<div style="font-size: 11px; color: #475569; font-weight: 500;">{arf_time:.0f}m</div>
|
| 743 |
+
</div>
|
| 744 |
+
"""
|
| 745 |
+
|
| 746 |
+
total_width += manual_width
|
| 747 |
|
| 748 |
+
return segments_html
|
| 749 |
|
| 750 |
def _get_severity_color(self, severity: str) -> str:
|
| 751 |
"""Get color for severity level"""
|
|
|
|
| 755 |
"medium": self.color_palette["info"],
|
| 756 |
"low": self.color_palette["success"]
|
| 757 |
}
|
| 758 |
+
return color_map.get(severity.lower(), self.color_palette["info"])
|
| 759 |
+
|
| 760 |
+
# Keep other methods from original file but add boundary parameters
|
| 761 |
+
def create_agent_performance_chart(self, is_real_arf: bool = True) -> Any:
|
| 762 |
+
"""Create agent performance comparison chart"""
|
| 763 |
+
if not PLOTLY_AVAILABLE:
|
| 764 |
+
# HTML fallback
|
| 765 |
+
boundary_color = self.color_palette["real_arf"] if is_real_arf else self.color_palette["simulated"]
|
| 766 |
+
boundary_text = "REAL ARF" if is_real_arf else "SIMULATED"
|
| 767 |
+
|
| 768 |
+
agents = ["Detection", "Recall", "Decision"]
|
| 769 |
+
accuracy = [98.7, 92.0, 94.0]
|
| 770 |
+
speed = [45, 30, 60]
|
| 771 |
+
|
| 772 |
+
rows = ""
|
| 773 |
+
for agent, acc, spd in zip(agents, accuracy, speed):
|
| 774 |
+
rows += f"""
|
| 775 |
+
<tr>
|
| 776 |
+
<td style="padding: 8px; border-bottom: 1px solid #e2e8f0;">
|
| 777 |
+
<div style="font-weight: 600; color: #1e293b;">{agent}</div>
|
| 778 |
+
</td>
|
| 779 |
+
<td style="padding: 8px; border-bottom: 1px solid #e2e8f0; text-align: center;">
|
| 780 |
+
<div style="font-weight: 700; color: #10b981;">{acc}%</div>
|
| 781 |
+
</td>
|
| 782 |
+
<td style="padding: 8px; border-bottom: 1px solid #e2e8f0; text-align: center;">
|
| 783 |
+
<div style="font-weight: 700; color: {boundary_color};">{spd}s</div>
|
| 784 |
+
</td>
|
| 785 |
+
</tr>
|
| 786 |
+
"""
|
| 787 |
+
|
| 788 |
+
return f"""
|
| 789 |
+
<div style="border: 2px solid {boundary_color}; border-radius: 16px; padding: 20px;
|
| 790 |
+
background: white; box-shadow: 0 4px 12px rgba(0,0,0,0.05);">
|
| 791 |
+
<div style="position: absolute; top: 15px; right: 15px; padding: 4px 10px;
|
| 792 |
+
background: {boundary_color}; color: white; border-radius: 15px;
|
| 793 |
+
font-size: 11px; font-weight: bold; display: flex; align-items: center; gap: 5px;">
|
| 794 |
+
π€ {boundary_text}
|
| 795 |
+
</div>
|
| 796 |
+
|
| 797 |
+
<h4 style="margin: 0 0 15px 0; color: #1e293b; font-size: 16px; font-weight: 600;">
|
| 798 |
+
π€ Agent Performance
|
| 799 |
+
</h4>
|
| 800 |
+
|
| 801 |
+
<table style="width: 100%; border-collapse: collapse;">
|
| 802 |
+
<thead>
|
| 803 |
+
<tr>
|
| 804 |
+
<th style="padding: 8px; text-align: left; color: #64748b; font-size: 13px; border-bottom: 2px solid #e2e8f0;">Agent</th>
|
| 805 |
+
<th style="padding: 8px; text-align: center; color: #64748b; font-size: 13px; border-bottom: 2px solid #e2e8f0;">Accuracy</th>
|
| 806 |
+
<th style="padding: 8px; text-align: center; color: #64748b; font-size: 13px; border-bottom: 2px solid #e2e8f0;">Speed</th>
|
| 807 |
+
</tr>
|
| 808 |
+
</thead>
|
| 809 |
+
<tbody>
|
| 810 |
+
{rows}
|
| 811 |
+
</tbody>
|
| 812 |
+
</table>
|
| 813 |
+
|
| 814 |
+
<div style="margin-top: 15px; padding: 10px; background: #f8fafc; border-radius: 8px;">
|
| 815 |
+
<div style="font-size: 12px; color: #64748b; line-height: 1.5;">
|
| 816 |
+
<strong>Mode:</strong> {boundary_text} v3.3.7 β’
|
| 817 |
+
<strong>Avg Accuracy:</strong> {(sum(accuracy)/len(accuracy)):.1f}% β’
|
| 818 |
+
<strong>Avg Speed:</strong> {(sum(speed)/len(speed)):.0f}s
|
| 819 |
+
</div>
|
| 820 |
+
</div>
|
| 821 |
+
</div>
|
| 822 |
+
"""
|
| 823 |
+
|
| 824 |
+
# Original Plotly implementation with boundary additions
|
| 825 |
+
try:
|
| 826 |
+
agents = ["Detection", "Recall", "Decision"]
|
| 827 |
+
accuracy = [98.7, 92.0, 94.0]
|
| 828 |
+
speed = [45, 30, 60] # seconds
|
| 829 |
+
confidence = [99.8, 92.0, 94.0]
|
| 830 |
+
|
| 831 |
+
boundary_color = self.color_palette["real_arf"] if is_real_arf else self.color_palette["simulated"]
|
| 832 |
+
boundary_text = "REAL ARF" if is_real_arf else "SIMULATED"
|
| 833 |
+
|
| 834 |
+
fig = go.Figure(data=[
|
| 835 |
+
go.Bar(name='Accuracy (%)', x=agents, y=accuracy,
|
| 836 |
+
marker_color=self.color_palette["primary"]),
|
| 837 |
+
go.Bar(name='Speed (seconds)', x=agents, y=speed,
|
| 838 |
+
marker_color=boundary_color),
|
| 839 |
+
go.Bar(name='Confidence (%)', x=agents, y=confidence,
|
| 840 |
+
marker_color=self.color_palette["info"])
|
| 841 |
+
])
|
| 842 |
+
|
| 843 |
+
# Add boundary annotation
|
| 844 |
+
fig.add_annotation(
|
| 845 |
+
x=0.98, y=0.98,
|
| 846 |
+
xref="paper", yref="paper",
|
| 847 |
+
text=f"π€ {boundary_text}",
|
| 848 |
+
showarrow=False,
|
| 849 |
+
font=dict(size=12, color=boundary_color),
|
| 850 |
+
bgcolor="white",
|
| 851 |
+
bordercolor=boundary_color,
|
| 852 |
+
borderwidth=2,
|
| 853 |
+
borderpad=4
|
| 854 |
+
)
|
| 855 |
+
|
| 856 |
+
fig.update_layout(
|
| 857 |
+
title=f"π€ Agent Performance Metrics<br>"
|
| 858 |
+
f"<span style='font-size: 12px; color: #64748b'>{boundary_text} v3.3.7</span>",
|
| 859 |
+
barmode='group',
|
| 860 |
+
height=400,
|
| 861 |
+
plot_bgcolor='rgba(0,0,0,0)',
|
| 862 |
+
paper_bgcolor='rgba(0,0,0,0)',
|
| 863 |
+
legend=dict(
|
| 864 |
+
orientation="h",
|
| 865 |
+
yanchor="bottom",
|
| 866 |
+
y=1.02,
|
| 867 |
+
xanchor="right",
|
| 868 |
+
x=1
|
| 869 |
+
)
|
| 870 |
+
)
|
| 871 |
+
|
| 872 |
+
return fig
|
| 873 |
+
|
| 874 |
+
except Exception as e:
|
| 875 |
+
logger.error(f"Agent performance chart creation failed: {e}")
|
| 876 |
+
# Return HTML fallback
|
| 877 |
+
return self.create_agent_performance_chart.__wrapped__(self, is_real_arf)
|