File size: 12,436 Bytes
be26939
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a12ef5d
 
be26939
 
a12ef5d
be26939
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a12ef5d
be26939
 
 
 
a12ef5d
be26939
a12ef5d
be26939
 
a12ef5d
be26939
a12ef5d
be26939
 
 
 
 
 
 
 
 
 
 
a12ef5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
be26939
a12ef5d
be26939
 
 
a12ef5d
 
 
 
be26939
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a12ef5d
 
 
 
be26939
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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from datetime import datetime
from data import extract_model_data

# Colors matching the existing theme
COLORS = {
    'passed': '#4CAF50',
    'failed': '#E53E3E',
    'skipped': '#FFD54F',
    'error': '#8B0000'
}

# Figure dimensions
FIGURE_WIDTH = 20
FIGURE_HEIGHT = 12

# Styling constants
BLACK = '#000000'
LABEL_COLOR = '#CCCCCC'
TITLE_COLOR = '#FFFFFF'
GRID_COLOR = '#333333'

# Font sizes
TITLE_FONT_SIZE = 24
LABEL_FONT_SIZE = 14
LEGEND_FONT_SIZE = 12


def create_time_series_summary(historical_df: pd.DataFrame) -> plt.Figure:
    """Create time-series visualization for overall failure rates over time."""
    if historical_df.empty or 'date' not in historical_df.columns:
        fig, ax = plt.subplots(figsize=(FIGURE_WIDTH, FIGURE_HEIGHT), facecolor=BLACK)
        ax.set_facecolor(BLACK)
        ax.text(0.5, 0.5, 'No historical data available',
                horizontalalignment='center', verticalalignment='center',
                transform=ax.transAxes, fontsize=20, color='#888888',
                fontfamily='monospace', weight='normal')
        ax.axis('off')
        return fig
    
    # Convert date column to datetime
    historical_df['date_dt'] = pd.to_datetime(historical_df['date'])
    historical_df = historical_df.sort_values('date_dt')
    
    # Group by date and calculate overall statistics
    daily_stats = []
    dates = []
    
    for date in historical_df['date_dt'].unique():
        date_data = historical_df[historical_df['date_dt'] == date]
        
        total_amd_passed = 0
        total_amd_failed = 0
        total_amd_skipped = 0
        total_nvidia_passed = 0
        total_nvidia_failed = 0
        total_nvidia_skipped = 0
        
        for _, row in date_data.iterrows():
            amd_stats, nvidia_stats = extract_model_data(row)[:2]
            
            total_amd_passed += amd_stats['passed']
            total_amd_failed += amd_stats['failed']
            total_amd_skipped += amd_stats['skipped']
            
            total_nvidia_passed += nvidia_stats['passed']
            total_nvidia_failed += nvidia_stats['failed']
            total_nvidia_skipped += nvidia_stats['skipped']
        
        # Calculate failure rates
        amd_total = total_amd_passed + total_amd_failed
        nvidia_total = total_nvidia_passed + total_nvidia_failed
        
        amd_failure_rate = (total_amd_failed / amd_total * 100) if amd_total > 0 else 0
        nvidia_failure_rate = (total_nvidia_failed / nvidia_total * 100) if nvidia_total > 0 else 0
        
        daily_stats.append({
            'amd_failure_rate': amd_failure_rate,
            'nvidia_failure_rate': nvidia_failure_rate,
            'amd_passed': total_amd_passed,
            'amd_failed': total_amd_failed,
            'amd_skipped': total_amd_skipped,
            'nvidia_passed': total_nvidia_passed,
            'nvidia_failed': total_nvidia_failed,
            'nvidia_skipped': total_nvidia_skipped
        })
        dates.append(date)
    
    # Create the plot with 3 subplots: failure rates, AMD stacked, NVIDIA stacked
    fig, (ax1, ax2, ax3) = plt.subplots(3, 1, figsize=(FIGURE_WIDTH, FIGURE_HEIGHT + 4), facecolor=BLACK)
    ax1.set_facecolor(BLACK)
    ax2.set_facecolor(BLACK)
    ax3.set_facecolor(BLACK)
    
    # Plot 1: Failure rates over time
    dates_array = np.array(dates)
    amd_rates = [stat['amd_failure_rate'] for stat in daily_stats]
    nvidia_rates = [stat['nvidia_failure_rate'] for stat in daily_stats]
    
    ax1.plot(dates_array, amd_rates, color='#FF6B6B', linewidth=3, label='AMD', marker='o', markersize=6)
    ax1.plot(dates_array, nvidia_rates, color='#4ECDC4', linewidth=3, label='NVIDIA', marker='s', markersize=6)
    
    ax1.set_title('Overall Failure Rates Over Time', fontsize=TITLE_FONT_SIZE, color=TITLE_COLOR, 
                  fontfamily='monospace', fontweight='bold', pad=20)
    ax1.set_ylabel('Failure Rate (%)', fontsize=LABEL_FONT_SIZE, color=LABEL_COLOR, fontfamily='monospace')
    ax1.grid(True, color=GRID_COLOR, alpha=0.3, linestyle='-', linewidth=0.5)
    ax1.legend(fontsize=LEGEND_FONT_SIZE, loc='upper right', frameon=False, 
               labelcolor=LABEL_COLOR, prop={'family': 'monospace'})
    
    # Format x-axis
    ax1.tick_params(colors=LABEL_COLOR, labelsize=LABEL_FONT_SIZE)
    ax1.xaxis.label.set_color(LABEL_COLOR)
    ax1.yaxis.label.set_color(LABEL_COLOR)
    
    # Plot 2: AMD Test counts over time (stacked area chart)
    amd_passed = [stat['amd_passed'] for stat in daily_stats]
    amd_failed = [stat['amd_failed'] for stat in daily_stats]
    amd_skipped = [stat['amd_skipped'] for stat in daily_stats]
    
    ax2.fill_between(dates_array, 0, amd_passed, color=COLORS['passed'], alpha=0.7, label='Passed')
    ax2.fill_between(dates_array, amd_passed, np.array(amd_passed) + np.array(amd_failed), 
                     color=COLORS['failed'], alpha=0.7, label='Failed')
    ax2.fill_between(dates_array, np.array(amd_passed) + np.array(amd_failed), 
                     np.array(amd_passed) + np.array(amd_failed) + np.array(amd_skipped),
                     color=COLORS['skipped'], alpha=0.7, label='Skipped')
    
    ax2.set_title('AMD Test Results Over Time', fontsize=TITLE_FONT_SIZE, color=TITLE_COLOR, 
                  fontfamily='monospace', fontweight='bold', pad=20)
    ax2.set_ylabel('Number of Tests', fontsize=LABEL_FONT_SIZE, color=LABEL_COLOR, fontfamily='monospace')
    ax2.grid(True, color=GRID_COLOR, alpha=0.3, linestyle='-', linewidth=0.5)
    ax2.legend(fontsize=LEGEND_FONT_SIZE, loc='upper right', frameon=False, 
               labelcolor=LABEL_COLOR, prop={'family': 'monospace'})
    
    # Format x-axis
    ax2.tick_params(colors=LABEL_COLOR, labelsize=LABEL_FONT_SIZE)
    ax2.xaxis.label.set_color(LABEL_COLOR)
    ax2.yaxis.label.set_color(LABEL_COLOR)
    
    # Plot 3: NVIDIA Test counts over time (stacked area chart)
    nvidia_passed = [stat['nvidia_passed'] for stat in daily_stats]
    nvidia_failed = [stat['nvidia_failed'] for stat in daily_stats]
    nvidia_skipped = [stat['nvidia_skipped'] for stat in daily_stats]
    
    ax3.fill_between(dates_array, 0, nvidia_passed, color=COLORS['passed'], alpha=0.7, label='Passed')
    ax3.fill_between(dates_array, nvidia_passed, np.array(nvidia_passed) + np.array(nvidia_failed), 
                     color=COLORS['failed'], alpha=0.7, label='Failed')
    ax3.fill_between(dates_array, np.array(nvidia_passed) + np.array(nvidia_failed), 
                     np.array(nvidia_passed) + np.array(nvidia_failed) + np.array(nvidia_skipped),
                     color=COLORS['skipped'], alpha=0.7, label='Skipped')
    
    ax3.set_title('NVIDIA Test Results Over Time', fontsize=TITLE_FONT_SIZE, color=TITLE_COLOR, 
                  fontfamily='monospace', fontweight='bold', pad=20)
    ax3.set_ylabel('Number of Tests', fontsize=LABEL_FONT_SIZE, color=LABEL_COLOR, fontfamily='monospace')
    ax3.set_xlabel('Date', fontsize=LABEL_FONT_SIZE, color=LABEL_COLOR, fontfamily='monospace')
    ax3.grid(True, color=GRID_COLOR, alpha=0.3, linestyle='-', linewidth=0.5)
    ax3.legend(fontsize=LEGEND_FONT_SIZE, loc='upper right', frameon=False, 
               labelcolor=LABEL_COLOR, prop={'family': 'monospace'})
    
    # Format x-axis
    ax3.tick_params(colors=LABEL_COLOR, labelsize=LABEL_FONT_SIZE)
    ax3.xaxis.label.set_color(LABEL_COLOR)
    ax3.yaxis.label.set_color(LABEL_COLOR)
    
    # Rotate x-axis labels for better readability
    for ax in [ax1, ax2, ax3]:
        ax.tick_params(axis='x', rotation=45)
    
    plt.tight_layout()
    
    # Close any existing figures to prevent memory issues
    plt.close('all')
    
    return fig


def create_model_time_series(historical_df: pd.DataFrame, model_name: str) -> plt.Figure:
    """Create time-series visualization for a specific model."""
    if historical_df.empty or 'date' not in historical_df.columns:
        fig, ax = plt.subplots(figsize=(FIGURE_WIDTH, FIGURE_HEIGHT), facecolor=BLACK)
        ax.set_facecolor(BLACK)
        ax.text(0.5, 0.5, f'No historical data available for {model_name}',
                horizontalalignment='center', verticalalignment='center',
                transform=ax.transAxes, fontsize=20, color='#888888',
                fontfamily='monospace', weight='normal')
        ax.axis('off')
        return fig
    
    # Filter data for the specific model
    model_data = historical_df[historical_df.index.str.lower() == model_name.lower()]
    
    if model_data.empty:
        fig, ax = plt.subplots(figsize=(FIGURE_WIDTH, FIGURE_HEIGHT), facecolor=BLACK)
        ax.set_facecolor(BLACK)
        ax.text(0.5, 0.5, f'No data found for model: {model_name}',
                horizontalalignment='center', verticalalignment='center',
                transform=ax.transAxes, fontsize=20, color='#888888',
                fontfamily='monospace', weight='normal')
        ax.axis('off')
        return fig
    
    # Convert date column to datetime and sort
    model_data = model_data.copy()
    model_data['date_dt'] = pd.to_datetime(model_data['date'])
    model_data = model_data.sort_values('date_dt')
    
    # Extract statistics for each date
    dates = model_data['date_dt'].values
    amd_stats_list = []
    nvidia_stats_list = []
    
    for _, row in model_data.iterrows():
        amd_stats, nvidia_stats = extract_model_data(row)[:2]
        amd_stats_list.append(amd_stats)
        nvidia_stats_list.append(nvidia_stats)
    
    # Create the plot
    fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(FIGURE_WIDTH, FIGURE_HEIGHT), facecolor=BLACK)
    ax1.set_facecolor(BLACK)
    ax2.set_facecolor(BLACK)
    
    # Plot 1: AMD results over time
    amd_passed = [stats['passed'] for stats in amd_stats_list]
    amd_failed = [stats['failed'] for stats in amd_stats_list]
    amd_skipped = [stats['skipped'] for stats in amd_stats_list]
    
    ax1.plot(dates, amd_passed, color=COLORS['passed'], linewidth=3, label='Passed', marker='o', markersize=6)
    ax1.plot(dates, amd_failed, color=COLORS['failed'], linewidth=3, label='Failed', marker='s', markersize=6)
    ax1.plot(dates, amd_skipped, color=COLORS['skipped'], linewidth=3, label='Skipped', marker='^', markersize=6)
    
    ax1.set_title(f'{model_name.upper()} - AMD Results Over Time', fontsize=TITLE_FONT_SIZE, color=TITLE_COLOR, 
                  fontfamily='monospace', fontweight='bold', pad=20)
    ax1.set_ylabel('Number of Tests', fontsize=LABEL_FONT_SIZE, color=LABEL_COLOR, fontfamily='monospace')
    ax1.grid(True, color=GRID_COLOR, alpha=0.3, linestyle='-', linewidth=0.5)
    ax1.legend(fontsize=LEGEND_FONT_SIZE, loc='upper right', frameon=False, 
               labelcolor=LABEL_COLOR, prop={'family': 'monospace'})
    
    # Plot 2: NVIDIA results over time
    nvidia_passed = [stats['passed'] for stats in nvidia_stats_list]
    nvidia_failed = [stats['failed'] for stats in nvidia_stats_list]
    nvidia_skipped = [stats['skipped'] for stats in nvidia_stats_list]
    
    ax2.plot(dates, nvidia_passed, color=COLORS['passed'], linewidth=3, label='Passed', marker='o', markersize=6)
    ax2.plot(dates, nvidia_failed, color=COLORS['failed'], linewidth=3, label='Failed', marker='s', markersize=6)
    ax2.plot(dates, nvidia_skipped, color=COLORS['skipped'], linewidth=3, label='Skipped', marker='^', markersize=6)
    
    ax2.set_title(f'{model_name.upper()} - NVIDIA Results Over Time', fontsize=TITLE_FONT_SIZE, color=TITLE_COLOR, 
                  fontfamily='monospace', fontweight='bold', pad=20)
    ax2.set_ylabel('Number of Tests', fontsize=LABEL_FONT_SIZE, color=LABEL_COLOR, fontfamily='monospace')
    ax2.set_xlabel('Date', fontsize=LABEL_FONT_SIZE, color=LABEL_COLOR, fontfamily='monospace')
    ax2.grid(True, color=GRID_COLOR, alpha=0.3, linestyle='-', linewidth=0.5)
    ax2.legend(fontsize=LEGEND_FONT_SIZE, loc='upper right', frameon=False, 
               labelcolor=LABEL_COLOR, prop={'family': 'monospace'})
    
    # Format axes
    for ax in [ax1, ax2]:
        ax.tick_params(colors=LABEL_COLOR, labelsize=LABEL_FONT_SIZE)
        ax.xaxis.label.set_color(LABEL_COLOR)
        ax.yaxis.label.set_color(LABEL_COLOR)
        ax.tick_params(axis='x', rotation=45)
    
    plt.tight_layout()
    
    # Close any existing figures to prevent memory issues
    plt.close('all')
    
    return fig