File size: 11,597 Bytes
5309153
 
 
 
941f5e0
5309153
 
 
 
 
 
 
fe59685
5309153
fe59685
 
 
 
 
 
 
 
 
 
 
5309153
 
fe59685
 
 
 
 
5309153
fe59685
 
 
 
 
 
 
 
5309153
fe59685
 
 
5309153
 
fe59685
 
 
 
5309153
fe59685
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5309153
 
fe59685
 
 
 
5309153
fe59685
 
5309153
 
fe59685
 
 
5309153
fe59685
 
 
 
 
 
 
 
 
 
 
5309153
fe59685
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5309153
 
fe59685
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5309153
 
fe59685
 
 
 
 
5309153
fe59685
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5309153
fe59685
5309153
fe59685
 
 
 
 
 
5309153
fe59685
 
 
 
5309153
fe59685
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pandas as pd
import numpy as np
from datetime import datetime
from data import extract_model_data
from utils import COLORS
import gradio as gr
import plotly.express as px
import plotly.graph_objects as go

def get_time_series_summary_dfs(historical_df: pd.DataFrame) -> dict:
    daily_stats = []
    dates = sorted(historical_df['date'].unique())
    
    for date in dates:
        dd = historical_df[historical_df['date'] == date]
        stats = {}
        for platform in ['amd', 'nvidia']:
            p, f, s = (dd[f'success_{platform}'].sum() if f'success_{platform}' in dd.columns else 0,
                      (dd[f'failed_multi_no_{platform}'].sum() + dd[f'failed_single_no_{platform}'].sum()) if f'failed_multi_no_{platform}' in dd.columns else 0,
                      dd[f'skipped_{platform}'].sum() if f'skipped_{platform}' in dd.columns else 0)
            tot = p + f + s
            stats.update({f'{platform}_passed': p, f'{platform}_failed': f, f'{platform}_skipped': s, 
                         f'{platform}_failure_rate': (f / tot * 100) if tot > 0 else 0})
        stats['date'] = date
        daily_stats.append(stats)

    failure_rate_data = []
    for i, s in enumerate(daily_stats):
        for p in ['amd', 'nvidia']:
            chg = s[f'{p}_failure_rate'] - daily_stats[i-1][f'{p}_failure_rate'] if i > 0 else 0
            failure_rate_data.append({'date': s['date'], 'failure_rate': s[f'{p}_failure_rate'], 
                                     'platform': p.upper(), 'change': chg})

    def build_test_data(platform):
        data = []
        for i, s in enumerate(daily_stats):
            for tt in ['passed', 'failed', 'skipped']:
                chg = s[f'{platform}_{tt}'] - daily_stats[i-1][f'{platform}_{tt}'] if i > 0 else 0
                data.append({'date': s['date'], 'count': s[f'{platform}_{tt}'], 
                           'test_type': tt.capitalize(), 'change': chg})
        return pd.DataFrame(data)

    return {'failure_rates_df': pd.DataFrame(failure_rate_data), 
            'amd_tests_df': build_test_data('amd'), 
            'nvidia_tests_df': build_test_data('nvidia')}

def get_model_time_series_dfs(historical_df: pd.DataFrame, model_name: str) -> dict:
    md = historical_df[historical_df.index.str.lower() == model_name.lower()]
    if md.empty:
        empty = pd.DataFrame({'date': [], 'count': [], 'test_type': [], 'change': []})
        return {'amd_df': empty.copy(), 'nvidia_df': empty.copy()}

    dates = sorted(md['date'].unique())
    
    def build_platform_data(platform):
        data = []
        for i, date in enumerate(dates):
            dd = md[md['date'] == date]
            if dd.empty:
                continue
            r = dd.iloc[0]
            p = r.get(f'success_{platform}', 0)
            f = r.get(f'failed_multi_no_{platform}', 0) + r.get(f'failed_single_no_{platform}', 0)
            s = r.get(f'skipped_{platform}', 0)
            
            pr = md[md['date'] == dates[i-1]].iloc[0] if i > 0 and not md[md['date'] == dates[i-1]].empty else None
            pc = pr.get(f'success_{platform}', 0) if pr is not None else 0
            fc = (pr.get(f'failed_multi_no_{platform}', 0) + pr.get(f'failed_single_no_{platform}', 0)) if pr is not None else 0
            sc = pr.get(f'skipped_{platform}', 0) if pr is not None else 0
            
            data.extend([
                {'date': date, 'count': p, 'test_type': 'Passed', 'change': p - pc},
                {'date': date, 'count': f, 'test_type': 'Failed', 'change': f - fc},
                {'date': date, 'count': s, 'test_type': 'Skipped', 'change': s - sc}
            ])
        return pd.DataFrame(data)
    
    return {'amd_df': build_platform_data('amd'), 'nvidia_df': build_platform_data('nvidia')}

def create_time_series_summary_gradio(historical_df: pd.DataFrame) -> dict:
    empty_fig = lambda title: go.Figure().update_layout(title=title, height=500, 
        font=dict(size=16, color='#CCCCCC'), paper_bgcolor='#000000', 
        plot_bgcolor='#1a1a1a', margin=dict(b=130)) or go.Figure()
    
    if historical_df.empty or 'date' not in historical_df.columns:
        ef = empty_fig("No historical data available")
        return {'failure_rates': ef, 'amd_tests': ef, 'nvidia_tests': ef}
    
    daily_stats = []
    for date in sorted(historical_df['date'].unique()):
        dd = historical_df[historical_df['date'] == date]
        counts = {'date': date}
        
        for platform in ['amd', 'nvidia']:
            tot_tests = tot_fails = p = f = s = 0
            for _, row in dd.iterrows():
                stats = extract_model_data(row)[0 if platform == 'amd' else 1]
                tot = stats['passed'] + stats['failed'] + stats['error']
                if tot > 0:
                    tot_tests += tot
                    tot_fails += stats['failed'] + stats['error']
                p += stats['passed']
                f += stats['failed'] + stats['error']
                s += stats['skipped']
            
            counts.update({f'{platform}_failure_rate': (tot_fails / tot_tests * 100) if tot_tests > 0 else 0,
                          f'{platform}_passed': p, f'{platform}_failed': f, f'{platform}_skipped': s})
        daily_stats.append(counts)
    
    fr_data = []
    for i, s in enumerate(daily_stats):
        for p in ['amd', 'nvidia']:
            chg = s[f'{p}_failure_rate'] - daily_stats[i-1][f'{p}_failure_rate'] if i > 0 else 0
            fr_data.append({'date': s['date'], 'failure_rate': s[f'{p}_failure_rate'], 
                           'platform': p.upper(), 'change': chg})
    
    def build_test_data(platform):
        data = []
        for i, s in enumerate(daily_stats):
            for tt in ['passed', 'failed', 'skipped']:
                chg = s[f'{platform}_{tt}'] - daily_stats[i-1][f'{platform}_{tt}'] if i > 0 else 0
                data.append({'date': s['date'], 'count': s[f'{platform}_{tt}'], 
                           'test_type': tt.capitalize(), 'change': chg})
        return pd.DataFrame(data)
    
    fr_df = pd.DataFrame(fr_data)
    
    fig_fr = go.Figure()
    for p, lc, mc in [('NVIDIA', '#76B900', '#FFFFFF'), ('AMD', '#ED1C24', '#404040')]:
        d = fr_df[fr_df['platform'] == p]
        if not d.empty:
            fig_fr.add_trace(go.Scatter(x=d['date'], y=d['failure_rate'], mode='lines+markers',
                name=p, line=dict(color=lc, width=3), 
                marker=dict(size=12, color=mc, line=dict(color=lc, width=2)),
                hovertemplate=f'<b>{p}</b><br>Date: %{{x}}<br>Failure Rate: %{{y:.2f}}%<extra></extra>'))
    
    fig_fr.update_layout(title="Overall Failure Rates Over Time", height=500,
        font=dict(size=16, color='#CCCCCC'), paper_bgcolor='#000000', plot_bgcolor='#1a1a1a',
        title_font_size=20, legend=dict(font=dict(size=16), bgcolor='rgba(0,0,0,0.5)', 
        orientation="h", yanchor="bottom", y=-0.4, xanchor="center", x=0.5),
        xaxis=dict(title='Date', title_font_size=16, tickfont_size=14, gridcolor='#333333', showgrid=True),
        yaxis=dict(title='Failure Rate (%)', title_font_size=16, tickfont_size=14, gridcolor='#333333', showgrid=True),
        hovermode='x unified', margin=dict(b=130))
    
    def create_line_fig(df, title):
        fig = px.line(df, x='date', y='count', color='test_type',
            color_discrete_map={"Passed": COLORS['passed'], "Failed": COLORS['failed'], "Skipped": COLORS['skipped']},
            title=title, labels={'count': 'Number of Tests', 'date': 'Date', 'test_type': 'Test Type'})
        fig.update_traces(mode='lines+markers', marker=dict(size=8), line=dict(width=3))
        fig.update_layout(height=500, font=dict(size=16, color='#CCCCCC'), paper_bgcolor='#000000',
            plot_bgcolor='#1a1a1a', title_font_size=20, legend=dict(font=dict(size=16), 
            bgcolor='rgba(0,0,0,0.5)', orientation="h", yanchor="bottom", y=-0.4, xanchor="center", x=0.5),
            xaxis=dict(title_font_size=16, tickfont_size=14, gridcolor='#333333', showgrid=True),
            yaxis=dict(title_font_size=16, tickfont_size=14, gridcolor='#333333', showgrid=True),
            hovermode='x unified', margin=dict(b=130))
        return fig
    
    return {'failure_rates': fig_fr, 
            'amd_tests': create_line_fig(build_test_data('amd'), "AMD Test Results Over Time"),
            'nvidia_tests': create_line_fig(build_test_data('nvidia'), "NVIDIA Test Results Over Time")}

def create_model_time_series_gradio(historical_df: pd.DataFrame, model_name: str) -> dict:
    def empty_figs():
        ef = lambda plat: go.Figure().update_layout(title=f"{model_name.upper()} - {plat} Results Over Time",
            height=500, font=dict(size=16, color='#CCCCCC'), paper_bgcolor='#000000',
            plot_bgcolor='#1a1a1a', margin=dict(b=130)) or go.Figure()
        return {'amd_plot': ef('AMD'), 'nvidia_plot': ef('NVIDIA')}
    
    if historical_df.empty or 'date' not in historical_df.columns:
        return empty_figs()
    
    md = historical_df[historical_df.index.str.lower() == model_name.lower()]
    if md.empty:
        return empty_figs()
    
    dates = sorted(md['date'].unique())
    
    def build_data(platform):
        data = []
        for i, date in enumerate(dates):
            dd = md[md['date'] == date]
            if dd.empty:
                continue
            r = dd.iloc[0]
            passed = r.get(f'success_{platform}', 0)
            failed = r.get(f'failed_multi_no_{platform}', 0) + r.get(f'failed_single_no_{platform}', 0)
            skipped = r.get(f'skipped_{platform}', 0)
            
            pc = fc = sc = 0
            if i > 0:
                prev_dd = md[md['date'] == dates[i-1]]
                if not prev_dd.empty:
                    pr = prev_dd.iloc[0]
                    pc = pr.get(f'success_{platform}', 0)
                    fc = pr.get(f'failed_multi_no_{platform}', 0) + pr.get(f'failed_single_no_{platform}', 0)
                    sc = pr.get(f'skipped_{platform}', 0)
            
            data.extend([
                {'date': date, 'count': passed, 'test_type': 'Passed', 'change': passed - pc},
                {'date': date, 'count': failed, 'test_type': 'Failed', 'change': failed - fc},
                {'date': date, 'count': skipped, 'test_type': 'Skipped', 'change': skipped - sc}
            ])
        return pd.DataFrame(data)
    
    def create_fig(df, platform):
        fig = px.line(df, x='date', y='count', color='test_type',
            color_discrete_map={"Passed": COLORS['passed'], "Failed": COLORS['failed'], "Skipped": COLORS['skipped']},
            title=f"{model_name.upper()} - {platform} Results Over Time",
            labels={'count': 'Number of Tests', 'date': 'Date', 'test_type': 'Test Type'})
        fig.update_traces(mode='lines+markers', marker=dict(size=8), line=dict(width=3))
        fig.update_layout(height=500, font=dict(size=16, color='#CCCCCC'), paper_bgcolor='#000000',
            plot_bgcolor='#1a1a1a', title_font_size=20, legend=dict(font=dict(size=16),
            bgcolor='rgba(0,0,0,0.5)', orientation="h", yanchor="bottom", y=-0.4, xanchor="center", x=0.5),
            xaxis=dict(title_font_size=16, tickfont_size=14, gridcolor='#333333', showgrid=True),
            yaxis=dict(title_font_size=16, tickfont_size=14, gridcolor='#333333', showgrid=True),
            hovermode='x unified', margin=dict(b=130))
        return fig
    
    return {'amd_plot': create_fig(build_data('amd'), 'AMD'),
            'nvidia_plot': create_fig(build_data('nvidia'), 'NVIDIA')}