Supastrikas-004 commited on
Commit
a693fb8
·
verified ·
1 Parent(s): ebdd779

Update visualizer_module.py

Browse files
Files changed (1) hide show
  1. visualizer_module.py +111 -471
visualizer_module.py CHANGED
@@ -1,504 +1,144 @@
1
- # visualizer_module.py
2
-
3
  import plotly.graph_objects as go
4
- import plotly.express as px
5
  import pandas as pd
6
  import numpy as np
7
- from typing import Dict, List, Optional
8
- import json
9
- from datetime import datetime
10
- import seaborn as sns
11
- import matplotlib.pyplot as plt
12
- from io import BytesIO
13
- import base64
14
 
15
  class EvaluationVisualizer:
16
- """
17
- Visualization component for AetherScore framework
18
- Creates interactive charts and visualizations for evaluation results
19
- """
20
-
21
  def __init__(self):
22
- """Initialize visualizer with color schemes and settings"""
23
-
24
- self.color_scheme = {
25
- 'primary': '#667eea',
26
- 'secondary': '#764ba2',
27
- 'success': '#48bb78',
28
- 'warning': '#f6ad55',
29
- 'danger': '#fc8181',
30
- 'info': '#63b3ed',
31
- 'dark': '#2d3748',
32
- 'light': '#f7fafc'
33
- }
34
-
35
  self.metric_colors = {
36
- 'instruction_following': '#667eea',
37
- 'hallucination_score': '#48bb78',
38
- 'assumption_control': '#f6ad55',
39
- 'coherence': '#63b3ed',
40
- 'accuracy': '#fc8181',
41
- 'overall_score': '#764ba2'
42
  }
43
-
44
- def create_spider_chart(self, scores: Dict, agent_name: str = "Agent") -> str:
45
- """
46
- Create a spider/radar chart for multi-dimensional scores
47
-
48
- Args:
49
- scores: Dictionary of metric scores
50
- agent_name: Name of the agent
51
-
52
- Returns:
53
- HTML string containing the plotly chart
54
- """
55
-
56
- # Prepare data
57
- metrics = ['Instruction\nFollowing', 'Hallucination\nControl',
58
- 'Assumption\nControl', 'Coherence', 'Accuracy']
59
-
60
  values = [
61
- scores.get('instruction_following', 0),
62
- scores.get('hallucination_score', 0),
63
- scores.get('assumption_control', 0),
64
- scores.get('coherence', 0),
65
  scores.get('accuracy', 0)
66
  ]
67
-
68
- # Create radar chart
69
  fig = go.Figure()
70
-
71
- fig.add_trace(go.Scatterpolar(
72
- r=values,
73
- theta=metrics,
74
- fill='toself',
75
- name=agent_name,
76
- line=dict(color=self.color_scheme['primary'], width=2),
77
- fillcolor='rgba(102, 126, 234, 0.3)'
78
- ))
79
-
80
- # Add reference line (perfect score)
81
- fig.add_trace(go.Scatterpolar(
82
- r=[1, 1, 1, 1, 1],
83
- theta=metrics,
84
- name='Perfect Score',
85
- line=dict(color='gray', width=1, dash='dash'),
86
- showlegend=True
87
- ))
88
-
89
- fig.update_layout(
90
- polar=dict(
91
- radialaxis=dict(
92
- visible=True,
93
- range=[0, 1],
94
- tickmode='linear',
95
- tick0=0,
96
- dtick=0.2
97
- )
98
- ),
99
- title=f"{agent_name} - Performance Spider Chart",
100
- showlegend=True,
101
- height=400,
102
- template='plotly_white'
103
- )
104
-
105
- return fig.to_html(include_plotlyjs='cdn', div_id="spider-chart")
106
-
107
- def create_score_bars(self, scores: Dict, agent_name: str = "Agent") -> str:
108
- """
109
- Create horizontal bar chart for score breakdown
110
-
111
- Args:
112
- scores: Dictionary of metric scores
113
- agent_name: Name of the agent
114
-
115
- Returns:
116
- HTML string containing the plotly chart
117
- """
118
-
119
- metrics = []
120
- values = []
121
- colors = []
122
-
123
  metric_map = {
124
- 'instruction_following': 'Instruction Following',
125
- 'hallucination_score': 'Hallucination Control',
126
- 'assumption_control': 'Assumption Control',
127
- 'coherence': 'Coherence',
128
- 'accuracy': 'Accuracy',
129
- 'overall_score': 'Overall Score'
130
  }
 
 
 
131
 
132
- for key, label in metric_map.items():
133
- if key in scores:
134
- metrics.append(label)
135
- values.append(scores[key])
136
- colors.append(self.metric_colors.get(key, '#667eea'))
137
-
138
- fig = go.Figure()
139
-
140
- fig.add_trace(go.Bar(
141
- y=metrics,
142
- x=values,
143
- orientation='h',
144
- marker=dict(color=colors),
145
- text=[f'{v:.2f}' for v in values],
146
- textposition='auto',
147
- ))
148
-
149
- fig.update_layout(
150
- title=f"{agent_name} - Score Breakdown",
151
- xaxis=dict(
152
- title="Score",
153
- range=[0, 1],
154
- tickmode='linear',
155
- tick0=0,
156
- dtick=0.2
157
- ),
158
- yaxis=dict(title="Metric"),
159
- height=400,
160
- template='plotly_white',
161
- showlegend=False
162
- )
163
-
164
- return fig.to_html(include_plotlyjs='cdn', div_id="score-bars")
165
-
166
- def create_evaluation_heatmap(self, results: List[Dict]) -> str:
167
- """
168
- Create a heatmap showing evaluation scores across agents and tasks
169
-
170
- Args:
171
- results: List of evaluation results
172
-
173
- Returns:
174
- HTML string containing the plotly heatmap
175
- """
176
-
177
- # Prepare data for heatmap
178
- agents = sorted(list(set(r['agent_name'] for r in results)))
179
- tasks = sorted(list(set(r['task_id'] for r in results)))
180
-
181
- # Create matrix
182
- matrix = np.full((len(agents), len(tasks)), np.nan)
183
-
184
- for r in results:
185
- agent_idx = agents.index(r['agent_name'])
186
- task_idx = tasks.index(r['task_id'])
187
- matrix[agent_idx][task_idx] = r['scores'].get('overall_score', 0)
188
-
189
- # Create heatmap
190
- fig = go.Figure(data=go.Heatmap(
191
- z=matrix,
192
- x=tasks,
193
- y=agents,
194
- colorscale='Viridis',
195
- colorbar=dict(title="Score"),
196
- text=np.round(matrix, 2),
197
- texttemplate="%{text}",
198
- textfont={"size": 10},
199
- hoverongaps=False
200
- ))
201
-
202
- fig.update_layout(
203
- title="Agent Performance Heatmap",
204
- xaxis=dict(title="Tasks", tickangle=45),
205
- yaxis=dict(title="Agents"),
206
- height=500,
207
- template='plotly_white'
208
- )
209
-
210
- return fig.to_html(include_plotlyjs='cdn', div_id="heatmap")
211
-
212
- def create_score_distribution(self, results: List[Dict]) -> str:
213
- """
214
- Create distribution plots for scores
215
 
216
- Args:
217
- results: List of evaluation results
218
-
219
- Returns:
220
- HTML string containing the distribution plot
221
- """
222
 
223
- # Extract scores for each metric
 
 
 
 
 
 
 
224
  df_data = []
225
  for r in results:
226
- scores = r['scores']
227
- df_data.append({
228
- 'Agent': r.get('agent_name', 'Unknown'),
229
- 'Instruction Following': scores.get('instruction_following', 0),
230
- 'Hallucination Control': scores.get('hallucination_score', 0),
231
- 'Assumption Control': scores.get('assumption_control', 0),
232
- 'Coherence': scores.get('coherence', 0),
233
- 'Accuracy': scores.get('accuracy', 0),
234
- 'Overall Score': scores.get('overall_score', 0)
235
- })
236
-
237
- df = pd.DataFrame(df_data)
238
 
239
- # Create violin plot
 
 
240
  fig = go.Figure()
 
 
241
 
242
- metrics = ['Instruction Following', 'Hallucination Control', 'Assumption Control',
243
- 'Coherence', 'Accuracy', 'Overall Score']
244
-
245
- for metric in metrics:
246
- fig.add_trace(go.Violin(
247
- y=df[metric],
248
- name=metric,
249
- box_visible=True,
250
- meanline_visible=True,
251
- points='all',
252
- jitter=0.1
253
- ))
254
-
255
- fig.update_layout(
256
- title="Score Distribution Analysis",
257
- yaxis=dict(title="Score", range=[0, 1]),
258
- xaxis=dict(title="Metrics"),
259
- height=500,
260
- template='plotly_white',
261
- showlegend=False
262
- )
263
-
264
- return fig.to_html(include_plotlyjs='cdn', div_id="distribution")
265
-
266
- def create_performance_trends(self, results: List[Dict]) -> str:
267
- """
268
- Create performance trend charts over evaluations
269
-
270
- Args:
271
- results: List of evaluation results
272
-
273
- Returns:
274
- HTML string containing trend charts
275
- """
276
-
277
- # Group by agent
278
- agent_trends = {}
279
 
 
280
  for r in results:
281
  agent = r['agent_name']
282
- if agent not in agent_trends:
283
- agent_trends[agent] = []
284
- agent_trends[agent].append(r['scores'].get('overall_score', 0))
285
 
286
- # Create line chart
287
  fig = go.Figure()
 
 
288
 
289
- for agent, scores in agent_trends.items():
290
- fig.add_trace(go.Scatter(
291
- x=list(range(1, len(scores) + 1)),
292
- y=scores,
293
- mode='lines+markers',
294
- name=agent,
295
- line=dict(width=2),
296
- marker=dict(size=8)
297
- ))
298
-
299
- fig.update_layout(
300
- title="Performance Trends Over Evaluations",
301
- xaxis=dict(title="Evaluation Number"),
302
- yaxis=dict(title="Overall Score", range=[0, 1]),
303
- height=400,
304
- template='plotly_white',
305
- hovermode='x unified'
306
- )
307
-
308
- return fig.to_html(include_plotlyjs='cdn', div_id="trends")
309
-
310
- def create_agent_comparison(
311
- self,
312
- agent1_results: List[Dict],
313
- agent2_results: List[Dict],
314
- agent1_name: str = "Agent 1",
315
- agent2_name: str = "Agent 2"
316
- ) -> str:
317
- """
318
- Create comparison chart between two agents
319
-
320
- Args:
321
- agent1_results: Results for first agent
322
- agent2_results: Results for second agent
323
- agent1_name: Name of first agent
324
- agent2_name: Name of second agent
325
-
326
- Returns:
327
- HTML string containing comparison chart
328
- """
329
-
330
- # Calculate average scores
331
- metrics = ['instruction_following', 'hallucination_score',
332
- 'assumption_control', 'coherence', 'accuracy', 'overall_score']
333
-
334
- agent1_avg = {}
335
- agent2_avg = {}
336
-
337
- for metric in metrics:
338
- agent1_scores = [r['scores'].get(metric, 0) for r in agent1_results]
339
- agent2_scores = [r['scores'].get(metric, 0) for r in agent2_results]
340
-
341
- agent1_avg[metric] = np.mean(agent1_scores) if agent1_scores else 0
342
- agent2_avg[metric] = np.mean(agent2_scores) if agent2_scores else 0
343
-
344
- # Create grouped bar chart
345
- fig = go.Figure()
346
-
347
- metric_labels = ['Instruction\nFollowing', 'Hallucination\nControl',
348
- 'Assumption\nControl', 'Coherence', 'Accuracy', 'Overall']
349
-
350
- fig.add_trace(go.Bar(
351
- name=agent1_name,
352
- x=metric_labels,
353
- y=[agent1_avg[m] for m in metrics],
354
- text=[f'{agent1_avg[m]:.2f}' for m in metrics],
355
- textposition='auto',
356
- marker_color=self.color_scheme['primary']
357
- ))
358
-
359
- fig.add_trace(go.Bar(
360
- name=agent2_name,
361
- x=metric_labels,
362
- y=[agent2_avg[m] for m in metrics],
363
- text=[f'{agent2_avg[m]:.2f}' for m in metrics],
364
- textposition='auto',
365
- marker_color=self.color_scheme['secondary']
366
- ))
367
-
368
- fig.update_layout(
369
- title="Agent Performance Comparison",
370
- xaxis=dict(title="Metrics"),
371
- yaxis=dict(title="Average Score", range=[0, 1]),
372
- barmode='group',
373
- height=500,
374
- template='plotly_white'
375
- )
376
-
377
- return fig.to_html(include_plotlyjs='cdn', div_id="comparison")
378
-
379
- def create_radar_comparison(
380
- self,
381
- agent1_results: List[Dict],
382
- agent2_results: List[Dict]
383
- ) -> str:
384
- """
385
- Create radar chart comparing two agents
386
-
387
- Args:
388
- agent1_results: Results for first agent
389
- agent2_results: Results for second agent
390
-
391
- Returns:
392
- HTML string containing radar comparison
393
- """
394
-
395
- # Calculate average scores
396
- metrics = ['Instruction\nFollowing', 'Hallucination\nControl',
397
- 'Assumption\nControl', 'Coherence', 'Accuracy']
398
-
399
- metric_keys = ['instruction_following', 'hallucination_score',
400
- 'assumption_control', 'coherence', 'accuracy']
401
-
402
- agent1_values = []
403
- agent2_values = []
404
-
405
- for key in metric_keys:
406
- scores1 = [r['scores'].get(key, 0) for r in agent1_results]
407
- scores2 = [r['scores'].get(key, 0) for r in agent2_results]
408
 
409
- agent1_values.append(np.mean(scores1) if scores1 else 0)
410
- agent2_values.append(np.mean(scores2) if scores2 else 0)
411
 
412
- # Create radar chart
413
  fig = go.Figure()
414
-
415
- fig.add_trace(go.Scatterpolar(
416
- r=agent1_values,
417
- theta=metrics,
418
- fill='toself',
419
- name='Agent 1',
420
- line=dict(color=self.color_scheme['primary'], width=2),
421
- fillcolor='rgba(102, 126, 234, 0.3)'
422
- ))
423
-
424
- fig.add_trace(go.Scatterpolar(
425
- r=agent2_values,
426
- theta=metrics,
427
- fill='toself',
428
- name='Agent 2',
429
- line=dict(color=self.color_scheme['secondary'], width=2),
430
- fillcolor='rgba(118, 75, 162, 0.3)'
431
- ))
432
-
433
- fig.update_layout(
434
- polar=dict(
435
- radialaxis=dict(
436
- visible=True,
437
- range=[0, 1]
438
- )
439
- ),
440
- title="Agent Comparison - Radar Chart",
441
- showlegend=True,
442
- height=500,
443
- template='plotly_white'
444
- )
445
-
446
- return fig.to_html(include_plotlyjs='cdn', div_id="radar-comparison")
447
-
448
- def create_performance_delta(
449
- self,
450
- agent1_results: List[Dict],
451
- agent2_results: List[Dict]
452
- ) -> str:
453
- """
454
- Create performance delta visualization
455
-
456
- Args:
457
- agent1_results: Results for first agent
458
- agent2_results: Results for second agent
459
-
460
- Returns:
461
- HTML string containing delta visualization
462
- """
463
-
464
- # Calculate deltas
465
- metrics = ['instruction_following', 'hallucination_score',
466
- 'assumption_control', 'coherence', 'accuracy', 'overall_score']
467
-
468
- metric_labels = ['Instruction Following', 'Hallucination Control',
469
- 'Assumption Control', 'Coherence', 'Accuracy', 'Overall']
470
-
471
- deltas = []
472
-
473
- for metric in metrics:
474
- scores1 = [r['scores'].get(metric, 0) for r in agent1_results]
475
- scores2 = [r['scores'].get(metric, 0) for r in agent2_results]
476
-
477
- avg1 = np.mean(scores1) if scores1 else 0
478
- avg2 = np.mean(scores2) if scores2 else 0
479
-
480
- delta = avg2 - avg1
481
- deltas.append(delta)
482
-
483
- colors = [self.color_scheme['success'] if d >= 0 else self.color_scheme['danger'] for d in deltas]
484
 
485
- fig = go.Figure()
486
-
487
- fig.add_trace(go.Bar(
488
- x=metric_labels,
489
- y=deltas,
490
- text=[f'{d:+.2f}' for d in deltas],
491
- textposition='auto',
492
- marker_color=colors
493
- ))
494
 
495
- fig.update_layout(
496
- title="Performance Delta (Agent 2 vs Agent 1)",
497
- xaxis=dict(title="Metrics"),
498
- yaxis=dict(title="Score Difference"),
499
- height=500,
500
- template='plotly_white',
501
- showlegend=False
502
- )
503
-
504
- return fig.to_html(include_plotlyjs='cdn', div_id="delta-chart")
 
 
 
 
 
1
  import plotly.graph_objects as go
 
2
  import pandas as pd
3
  import numpy as np
4
+ from typing import Dict, List
 
 
 
 
 
 
5
 
6
  class EvaluationVisualizer:
 
 
 
 
 
7
  def __init__(self):
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  self.metric_colors = {
9
+ 'instruction_following': '#667eea', 'hallucination_score': '#48bb78',
10
+ 'assumption_control': '#f6ad55', 'coherence': '#63b3ed',
11
+ 'accuracy': '#fc8181', 'overall_score': '#764ba2'
 
 
 
12
  }
13
+
14
+ def create_spider_chart(self, scores: Dict, agent_name: str = "Agent") -> go.Figure:
15
+ """Create a spider/radar chart for multi-dimensional scores."""
16
+ metrics = ['Instruction\nFollowing', 'Hallucination\nControl', 'Assumption\nControl', 'Coherence', 'Accuracy']
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  values = [
18
+ scores.get('instruction_following', 0), scores.get('hallucination_score', 0),
19
+ scores.get('assumption_control', 0), scores.get('coherence', 0),
 
 
20
  scores.get('accuracy', 0)
21
  ]
 
 
22
  fig = go.Figure()
23
+ fig.add_trace(go.Scatterpolar(r=values, theta=metrics, fill='toself', name=agent_name, line=dict(color=self.metric_colors['instruction_following'])))
24
+ fig.update_layout(polar=dict(radialaxis=dict(visible=True, range=[0, 1])), title=f"{agent_name} - Performance Spider Chart", template='plotly_white')
25
+ return fig
26
+
27
+ def create_score_bars(self, scores: Dict, agent_name: str = "Agent") -> go.Figure:
28
+ """Create horizontal bar chart for score breakdown."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  metric_map = {
30
+ 'overall_score': 'Overall Score', 'instruction_following': 'Instruction Following',
31
+ 'hallucination_score': 'Hallucination Control', 'assumption_control': 'Assumption Control',
32
+ 'coherence': 'Coherence', 'accuracy': 'Accuracy'
 
 
 
33
  }
34
+ metrics = [label for key, label in metric_map.items() if key in scores]
35
+ values = [scores[key] for key in metric_map if key in scores]
36
+ colors = [self.metric_colors.get(key, '#667eea') for key in metric_map if key in scores]
37
 
38
+ fig = go.Figure(go.Bar(y=metrics, x=values, orientation='h', marker=dict(color=colors), text=[f'{v:.2f}' for v in values], textposition='auto'))
39
+ fig.update_layout(title=f"{agent_name} - Score Breakdown", xaxis=dict(range=[0, 1]), template='plotly_white', showlegend=False)
40
+ return fig
41
+
42
+ def create_evaluation_heatmap(self, results: List[Dict]) -> go.Figure:
43
+ """Create a heatmap showing evaluation scores across agents and tasks."""
44
+ if not results: return go.Figure().update_layout(title="No data for heatmap")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
+ df_data = [{'agent': r['agent_name'], 'task': r['task_id'], 'score': r['scores'].get('overall_score', 0)} for r in results]
47
+ df = pd.DataFrame(df_data)
48
+ pivot_df = df.pivot(index='agent', columns='task', values='score')
 
 
 
49
 
50
+ fig = go.Figure(data=go.Heatmap(z=pivot_df.values, x=pivot_df.columns, y=pivot_df.index, colorscale='Viridis', colorbar=dict(title="Score")))
51
+ fig.update_layout(title="Agent Performance Heatmap", xaxis_title="Tasks", yaxis_title="Agents", template='plotly_white')
52
+ return fig
53
+
54
+ def create_score_distribution(self, results: List[Dict]) -> go.Figure:
55
+ """Create distribution plots for scores."""
56
+ if not results: return go.Figure().update_layout(title="No data for distribution plot")
57
+
58
  df_data = []
59
  for r in results:
60
+ entry = {'Agent': r.get('agent_name', 'Unknown')}
61
+ entry.update(r['scores'])
62
+ df_data.append(entry)
63
+ df = pd.DataFrame(df_data).melt(id_vars=['Agent'], value_vars=self.metric_colors.keys(), var_name='Metric', value_name='Score')
 
 
 
 
 
 
 
 
64
 
65
+ metric_map = {k: k.replace('_', ' ').title() for k in self.metric_colors.keys()}
66
+ df['Metric'] = df['Metric'].map(metric_map)
67
+
68
  fig = go.Figure()
69
+ for metric in df['Metric'].unique():
70
+ fig.add_trace(go.Violin(y=df[df['Metric'] == metric]['Score'], name=metric, box_visible=True, meanline_visible=True))
71
 
72
+ fig.update_layout(title="Score Distribution Analysis", yaxis_title="Score", template='plotly_white', showlegend=False)
73
+ return fig
74
+
75
+ def create_performance_trends(self, results: List[Dict]) -> go.Figure:
76
+ """Create performance trend charts over evaluations."""
77
+ if not results: return go.Figure().update_layout(title="No data for trend plot")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
+ agent_scores = {}
80
  for r in results:
81
  agent = r['agent_name']
82
+ if agent not in agent_scores: agent_scores[agent] = []
83
+ agent_scores[agent].append(r['scores'].get('overall_score', 0))
 
84
 
 
85
  fig = go.Figure()
86
+ for agent, scores in agent_scores.items():
87
+ fig.add_trace(go.Scatter(x=list(range(1, len(scores) + 1)), y=scores, mode='lines+markers', name=agent))
88
 
89
+ fig.update_layout(title="Performance Trends Over Evaluations", xaxis_title="Evaluation Number", yaxis_title="Overall Score", template='plotly_white')
90
+ return fig
91
+
92
+ def create_agent_comparison(self, agent1_results: List[Dict], agent2_results: List[Dict]) -> go.Figure:
93
+ """Create comparison chart between two agents."""
94
+ metrics = list(self.metric_colors.keys())
95
+ agent1_name = agent1_results[0].get('agent_name', 'Agent 1')
96
+ agent2_name = agent2_results[0].get('agent_name', 'Agent 2')
97
+
98
+ def get_avg_scores(results):
99
+ return {m: np.mean([r['scores'].get(m, 0) for r in results]) for m in metrics}
100
+
101
+ avg1 = get_avg_scores(agent1_results)
102
+ avg2 = get_avg_scores(agent2_results)
103
+ metric_labels = [m.replace('_', ' ').title() for m in metrics]
104
+
105
+ fig = go.Figure(data=[
106
+ go.Bar(name=agent1_name, x=metric_labels, y=[avg1[m] for m in metrics]),
107
+ go.Bar(name=agent2_name, x=metric_labels, y=[avg2[m] for m in metrics])
108
+ ])
109
+ fig.update_layout(barmode='group', title="Agent Performance Comparison", yaxis_title="Average Score", template='plotly_white')
110
+ return fig
111
+
112
+ def create_radar_comparison(self, agent1_results: List[Dict], agent2_results: List[Dict]) -> go.Figure:
113
+ """Create radar chart comparing two agents."""
114
+ metrics = ['instruction_following', 'hallucination_score', 'assumption_control', 'coherence', 'accuracy']
115
+ metric_labels = [m.replace('_', ' ').title() for m in metrics]
116
+
117
+ def get_avg_scores(results):
118
+ return [np.mean([r['scores'].get(m, 0) for r in results]) for m in metrics]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
120
+ agent1_values = get_avg_scores(agent1_results)
121
+ agent2_values = get_avg_scores(agent2_results)
122
 
 
123
  fig = go.Figure()
124
+ fig.add_trace(go.Scatterpolar(r=agent1_values, theta=metric_labels, fill='toself', name=agent1_results[0].get('agent_name', 'Agent 1')))
125
+ fig.add_trace(go.Scatterpolar(r=agent2_values, theta=metric_labels, fill='toself', name=agent2_results[0].get('agent_name', 'Agent 2')))
126
+ fig.update_layout(polar=dict(radialaxis=dict(visible=True, range=[0, 1])), title="Agent Comparison - Radar Chart", template='plotly_white')
127
+ return fig
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
 
129
+ def create_performance_delta(self, agent1_results: List[Dict], agent2_results: List[Dict]) -> go.Figure:
130
+ """Create performance delta visualization."""
131
+ metrics = list(self.metric_colors.keys())
 
 
 
 
 
 
132
 
133
+ def get_avg_scores(results):
134
+ return {m: np.mean([r['scores'].get(m, 0) for r in results]) for m in metrics}
135
+
136
+ avg1 = get_avg_scores(agent1_results)
137
+ avg2 = get_avg_scores(agent2_results)
138
+ deltas = [avg2[m] - avg1[m] for m in metrics]
139
+ colors = ['#48bb78' if d >= 0 else '#fc8181' for d in deltas]
140
+ metric_labels = [m.replace('_', ' ').title() for m in metrics]
141
+
142
+ fig = go.Figure(go.Bar(x=metric_labels, y=deltas, marker_color=colors, text=[f'{d:+.2f}' for d in deltas]))
143
+ fig.update_layout(title="Performance Delta (Agent 2 vs Agent 1)", yaxis_title="Score Difference", template='plotly_white')
144
+ return fig