mbligh | bcb2a86 | 2008-06-06 14:22:41 +0000 | [diff] [blame] | 1 | import os, re, string, sys |
| 2 | import frontend, reason_qualifier |
mbligh | bfec522 | 2007-09-14 16:58:57 +0000 | [diff] [blame] | 3 | |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 4 | color_map = { |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame] | 5 | 'header' : '#e5e5c0', # greyish yellow |
| 6 | 'blank' : '#ffffff', # white |
| 7 | 'plain_text' : '#e5e5c0', # greyish yellow |
| 8 | 'borders' : '#bbbbbb', # grey |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 9 | 'white' : '#ffffff', # white |
| 10 | 'green' : '#66ff66', # green |
| 11 | 'yellow' : '#fffc00', # yellow |
| 12 | 'red' : '#ff6666', # red |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 13 | |
| 14 | #### additional keys for shaded color of a box |
| 15 | #### depending on stats of GOOD/FAIL |
mbligh | 310b59e | 2008-03-25 23:53:55 +0000 | [diff] [blame] | 16 | '100pct' : '#80ff80', # green, 94% to 100% of success |
| 17 | '95pct' : '#c0ff80', # step twrds yellow, 88% to 94% of success |
| 18 | '90pct' : '#ffff80', # yellow, 82% to 88% |
| 19 | '85pct' : '#ffc040', # 76% to 82% |
| 20 | '75pct' : '#ff4040', # red, 1% to 76% |
| 21 | '0pct' : '#d080d0', # violet, <1% of success |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 22 | |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 23 | } |
mbligh | bfec522 | 2007-09-14 16:58:57 +0000 | [diff] [blame] | 24 | |
mbligh | 5684b03 | 2008-06-06 14:25:35 +0000 | [diff] [blame^] | 25 | _brief_mode = False |
| 26 | |
| 27 | |
| 28 | def set_brief_mode(): |
| 29 | global _brief_mode |
| 30 | _brief_mode = True |
| 31 | |
| 32 | |
| 33 | def is_brief_mode(): |
| 34 | return _brief_mode |
| 35 | |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 36 | |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 37 | def color_keys_row(): |
| 38 | """ Returns one row table with samples of 'NNpct' colors |
| 39 | defined in the color_map |
| 40 | and numbers of corresponding %% |
| 41 | """ |
mbligh | 5684b03 | 2008-06-06 14:25:35 +0000 | [diff] [blame^] | 42 | ### This function does not require maintenance in case of |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 43 | ### color_map augmenting - as long as |
| 44 | ### color keys for box shading have names that end with 'pct' |
| 45 | keys = filter(lambda key: key.endswith('pct'), color_map.keys()) |
| 46 | def num_pct(key): |
| 47 | return int(key.replace('pct','')) |
| 48 | keys.sort(key=num_pct) |
| 49 | html = '' |
| 50 | for key in keys: |
| 51 | html+= "\t\t\t<td bgcolor =%s> </td>\n"\ |
| 52 | % color_map[key] |
| 53 | hint = key.replace('pct',' %') |
| 54 | if hint[0]<>'0': ## anything but 0 % |
| 55 | hint = 'to ' + hint |
| 56 | html+= "\t\t\t<td> %s </td>\n" % hint |
| 57 | |
| 58 | html = """ |
| 59 | <table width = "500" border="0" cellpadding="2" cellspacing="2">\n |
| 60 | <tbody>\n |
| 61 | <tr>\n |
| 62 | %s |
| 63 | </tr>\n |
| 64 | </tbody> |
| 65 | </table><br> |
| 66 | """ % html |
| 67 | return html |
| 68 | |
mbligh | 5684b03 | 2008-06-06 14:25:35 +0000 | [diff] [blame^] | 69 | |
| 70 | def calculate_html(link, data, tooltip=None, row_label=None, column_label=None): |
| 71 | if not is_brief_mode(): |
| 72 | hover_text = '%s:%s' % (row_label, column_label) |
| 73 | if data: ## cell is not empty |
| 74 | hover_text += '<br>%s' % tooltip |
| 75 | else: |
| 76 | ## avoid "None" printed in empty cells |
| 77 | data = ' ' |
| 78 | html = ('<center><a class="info" href="%s">' |
| 79 | '%s<span>%s</span></a></center>' % |
| 80 | (link, data, hover_text)) |
| 81 | return html |
| 82 | # no hover if embedded into AFE but links shall redirect to new window |
| 83 | if data: ## cell is non empty |
| 84 | html = '<a href="%s" target=NEW>%s</a>' % (link, data) |
| 85 | return html |
| 86 | else: ## cell is empty |
| 87 | return ' ' |
| 88 | |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 89 | |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 90 | class box: |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 91 | def __init__(self, data, color_key = None, header = False, link = None, |
jadmanski | f9fa427 | 2008-05-02 15:43:33 +0000 | [diff] [blame] | 92 | tooltip = None, row_label = None, column_label = None): |
mbligh | 5684b03 | 2008-06-06 14:25:35 +0000 | [diff] [blame^] | 93 | |
| 94 | ## in brief mode we display grid table only and nothing more |
| 95 | ## - mouse hovering feature is stubbed in brief mode |
| 96 | ## - any link opens new window or tab |
| 97 | |
| 98 | redirect = "" |
| 99 | if is_brief_mode(): |
| 100 | ## we are acting under AFE |
| 101 | ## any link shall open new window |
| 102 | redirect = " target=NEW" |
| 103 | |
mbligh | 835c0e4 | 2008-03-11 21:39:54 +0000 | [diff] [blame] | 104 | if data: |
| 105 | data = "<tt>%s</tt>" % data |
mbligh | 5684b03 | 2008-06-06 14:25:35 +0000 | [diff] [blame^] | 106 | |
| 107 | if link and not tooltip: |
| 108 | ## FlipAxis corner, column and row headers |
| 109 | self.data = ('<a href="%s"%s>%s</a>' % |
| 110 | (link, redirect, data)) |
mbligh | f91b3f5 | 2007-10-07 00:47:04 +0000 | [diff] [blame] | 111 | else: |
mbligh | 5684b03 | 2008-06-06 14:25:35 +0000 | [diff] [blame^] | 112 | self.data = calculate_html(link, data, tooltip, |
| 113 | row_label, column_label) |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 114 | |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 115 | if color_map.has_key(color_key): |
| 116 | self.color = color_map[color_key] |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame] | 117 | elif header: |
| 118 | self.color = color_map['header'] |
| 119 | elif data: |
| 120 | self.color = color_map['plain_text'] |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 121 | else: |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame] | 122 | self.color = color_map['blank'] |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 123 | self.header = header |
| 124 | |
| 125 | |
mbligh | 38757e7 | 2007-09-30 22:32:13 +0000 | [diff] [blame] | 126 | def html(self): |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 127 | if self.data: |
| 128 | data = self.data |
| 129 | else: |
| 130 | data = ' ' |
| 131 | |
| 132 | if self.header: |
| 133 | box_html = 'th' |
| 134 | else: |
| 135 | box_html = 'td' |
| 136 | |
mbligh | 38757e7 | 2007-09-30 22:32:13 +0000 | [diff] [blame] | 137 | return "<%s bgcolor=%s>%s</%s>" % \ |
| 138 | (box_html, self.color, data, box_html) |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 139 | |
| 140 | |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 141 | def grade_from_status(status): |
| 142 | # % of goodness |
| 143 | # GOOD (6) -> 1 |
mbligh | 302482e | 2008-05-01 20:06:16 +0000 | [diff] [blame] | 144 | # TEST_NA (8) is not counted |
mbligh | 1b4780e | 2008-02-21 16:27:52 +0000 | [diff] [blame] | 145 | # ## If the test doesn't PASS, it FAILS |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 146 | # else -> 0 |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 147 | |
| 148 | if status == 6: |
| 149 | return 1.0 |
mbligh | 1b4780e | 2008-02-21 16:27:52 +0000 | [diff] [blame] | 150 | else: |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 151 | return 0.0 |
| 152 | |
| 153 | |
| 154 | def average_grade_from_status_count(status_count): |
| 155 | average_grade = 0 |
| 156 | total_count = 0 |
| 157 | for key in status_count.keys(): |
mbligh | 302482e | 2008-05-01 20:06:16 +0000 | [diff] [blame] | 158 | if key != 8: # TEST_NA status |
| 159 | average_grade += (grade_from_status(key) |
| 160 | * status_count[key]) |
| 161 | total_count += status_count[key] |
| 162 | if total_count != 0: |
| 163 | average_grade = average_grade / total_count |
| 164 | else: |
| 165 | average_grade = 0.0 |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 166 | return average_grade |
| 167 | |
| 168 | |
| 169 | def shade_from_status_count(status_count): |
| 170 | if not status_count: |
| 171 | return None |
| 172 | |
| 173 | ## average_grade defines a shade of the box |
| 174 | ## 0 -> violet |
| 175 | ## 0.76 -> red |
| 176 | ## 0.88-> yellow |
| 177 | ## 1.0 -> green |
| 178 | average_grade = average_grade_from_status_count(status_count) |
| 179 | |
| 180 | ## find appropiate keyword from color_map |
| 181 | if average_grade<0.01: |
| 182 | shade = '0pct' |
mbligh | 8e7c78e | 2008-02-20 21:18:49 +0000 | [diff] [blame] | 183 | elif average_grade<0.75: |
| 184 | shade = '75pct' |
| 185 | elif average_grade<0.85: |
| 186 | shade = '85pct' |
| 187 | elif average_grade<0.90: |
| 188 | shade = '90pct' |
| 189 | elif average_grade<0.95: |
| 190 | shade = '95pct' |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 191 | else: |
| 192 | shade = '100pct' |
| 193 | |
| 194 | return shade |
| 195 | |
| 196 | |
mbligh | 3126069 | 2008-04-16 23:12:12 +0000 | [diff] [blame] | 197 | def status_html(db, box_data, shade): |
mbligh | a997a34 | 2007-10-06 22:35:04 +0000 | [diff] [blame] | 198 | """ |
| 199 | status_count: dict mapping from status (integer key) to count |
| 200 | eg. { 'GOOD' : 4, 'FAIL' : 1 } |
| 201 | """ |
mbligh | 3126069 | 2008-04-16 23:12:12 +0000 | [diff] [blame] | 202 | status_count = box_data.status_count |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 203 | if 6 in status_count.keys(): |
mbligh | 8e7c78e | 2008-02-20 21:18:49 +0000 | [diff] [blame] | 204 | html = "%d / %d " \ |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 205 | %(status_count[6],sum(status_count.values())) |
| 206 | else: |
mbligh | 8e7c78e | 2008-02-20 21:18:49 +0000 | [diff] [blame] | 207 | html = "%d / %d " % \ |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 208 | (0, sum(status_count.values())) |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 209 | |
mbligh | 3126069 | 2008-04-16 23:12:12 +0000 | [diff] [blame] | 210 | if box_data.reasons_list: |
mbligh | bcb2a86 | 2008-06-06 14:22:41 +0000 | [diff] [blame] | 211 | reasons_list = box_data.reasons_list |
| 212 | aggregated_reasons_list = \ |
| 213 | reason_qualifier.aggregate_reason_fields(reasons_list) |
| 214 | for reason in aggregated_reasons_list: |
| 215 | ## a bit of more postprocessing |
| 216 | ## to look nicer in a cell |
| 217 | ## in future: to do subtable within the cell |
mbligh | 3126069 | 2008-04-16 23:12:12 +0000 | [diff] [blame] | 218 | reason = reason.replace('<br>','\n') |
| 219 | reason = reason.replace('<','[').replace('>',']') |
| 220 | reason = reason.replace('|','\n').replace('&',' AND ') |
| 221 | reason = reason.replace('\n','<br>') |
| 222 | html += '<br>' + reason |
| 223 | |
| 224 | tooltip = "" |
mbligh | a997a34 | 2007-10-06 22:35:04 +0000 | [diff] [blame] | 225 | for status in sorted(status_count.keys(), reverse = True): |
| 226 | status_word = db.status_word[status] |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 227 | tooltip += "%d %s " % (status_count[status], status_word) |
| 228 | return (html,tooltip) |
mbligh | a997a34 | 2007-10-06 22:35:04 +0000 | [diff] [blame] | 229 | |
| 230 | |
| 231 | def status_count_box(db, tests, link = None): |
| 232 | """ |
mbligh | 835c0e4 | 2008-03-11 21:39:54 +0000 | [diff] [blame] | 233 | Display a ratio of total number of GOOD tests |
| 234 | to total number of all tests in the group of tests. |
| 235 | More info (e.g. 10 GOOD, 2 WARN, 3 FAIL) is in tooltips |
mbligh | a997a34 | 2007-10-06 22:35:04 +0000 | [diff] [blame] | 236 | """ |
| 237 | if not tests: |
| 238 | return box(None, None) |
| 239 | |
| 240 | status_count = {} |
| 241 | for test in tests: |
| 242 | count = status_count.get(test.status_num, 0) |
| 243 | status_count[test.status_num] = count + 1 |
mbligh | 83f63a0 | 2007-12-12 19:13:04 +0000 | [diff] [blame] | 244 | return status_precounted_box(db, status_count, link) |
| 245 | |
| 246 | |
jadmanski | f9fa427 | 2008-05-02 15:43:33 +0000 | [diff] [blame] | 247 | def status_precounted_box(db, box_data, link = None, |
| 248 | x_label = None, y_label = None): |
mbligh | 83f63a0 | 2007-12-12 19:13:04 +0000 | [diff] [blame] | 249 | """ |
mbligh | 835c0e4 | 2008-03-11 21:39:54 +0000 | [diff] [blame] | 250 | Display a ratio of total number of GOOD tests |
| 251 | to total number of all tests in the group of tests. |
| 252 | More info (e.g. 10 GOOD, 2 WARN, 3 FAIL) is in tooltips |
mbligh | 3126069 | 2008-04-16 23:12:12 +0000 | [diff] [blame] | 253 | """ |
| 254 | status_count = box_data.status_count |
mbligh | 83f63a0 | 2007-12-12 19:13:04 +0000 | [diff] [blame] | 255 | if not status_count: |
| 256 | return box(None, None) |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 257 | |
| 258 | shade = shade_from_status_count(status_count) |
mbligh | 3126069 | 2008-04-16 23:12:12 +0000 | [diff] [blame] | 259 | html,tooltip = status_html(db, box_data, shade) |
jadmanski | f9fa427 | 2008-05-02 15:43:33 +0000 | [diff] [blame] | 260 | precounted_box = box(html, shade, False, link, tooltip, |
| 261 | x_label, y_label) |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 262 | return precounted_box |
mbligh | a997a34 | 2007-10-06 22:35:04 +0000 | [diff] [blame] | 263 | |
mbligh | 3126069 | 2008-04-16 23:12:12 +0000 | [diff] [blame] | 264 | |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 265 | def print_table(matrix): |
| 266 | """ |
| 267 | matrix: list of lists of boxes, giving a matrix of data |
| 268 | Each of the inner lists is a row, not a column. |
| 269 | |
| 270 | Display the given matrix of data as a table. |
| 271 | """ |
| 272 | |
mbligh | 8204f7f | 2008-06-06 14:23:40 +0000 | [diff] [blame] | 273 | print ('<table bgcolor="%s" cellspacing="1" cellpadding="5" ' |
| 274 | 'style="margin-right: 200px;">') % ( |
| 275 | color_map['borders']) |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 276 | for row in matrix: |
| 277 | print '<tr>' |
| 278 | for element in row: |
mbligh | 38757e7 | 2007-09-30 22:32:13 +0000 | [diff] [blame] | 279 | print element.html() |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 280 | print '</tr>' |
| 281 | print '</table>' |
| 282 | |
| 283 | |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 284 | def sort_tests(tests): |
| 285 | kernel_order = ['patch', 'config', 'build', 'mkinitrd', 'install'] |
| 286 | |
| 287 | results = [] |
| 288 | for kernel_op in kernel_order: |
| 289 | test = 'kernel.' + kernel_op |
| 290 | if tests.count(test): |
| 291 | results.append(test) |
| 292 | tests.remove(test) |
mbligh | 7a41a86 | 2007-11-30 17:44:24 +0000 | [diff] [blame] | 293 | if tests.count('boot'): |
| 294 | results.append('boot') |
| 295 | tests.remove('boot') |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 296 | return results + sorted(tests) |
mbligh | bfec522 | 2007-09-14 16:58:57 +0000 | [diff] [blame] | 297 | |
mbligh | 0459875 | 2007-10-01 15:49:58 +0000 | [diff] [blame] | 298 | |
| 299 | def print_main_header(): |
jadmanski | f9fa427 | 2008-05-02 15:43:33 +0000 | [diff] [blame] | 300 | hover_css="""\ |
| 301 | a.info{ |
| 302 | position:relative; /*this is the key*/ |
| 303 | z-index:1 |
| 304 | color:#000; |
| 305 | text-decoration:none} |
| 306 | |
| 307 | a.info:hover{z-index:25;} |
| 308 | |
| 309 | a.info span{display: none} |
| 310 | |
| 311 | a.info:hover span{ /*the span will display just on :hover state*/ |
| 312 | display:block; |
| 313 | position:absolute; |
| 314 | top:1em; left:1em; |
| 315 | min-width: 100px; |
| 316 | overflow: visible; |
| 317 | border:1px solid #036; |
| 318 | background-color:#fff; color:#000; |
| 319 | text-align: left |
| 320 | } |
| 321 | """ |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame] | 322 | print '<head><style type="text/css">' |
| 323 | print 'a { text-decoration: none }' |
jadmanski | f9fa427 | 2008-05-02 15:43:33 +0000 | [diff] [blame] | 324 | print hover_css |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame] | 325 | print '</style></head>' |
mbligh | 0459875 | 2007-10-01 15:49:58 +0000 | [diff] [blame] | 326 | print '<h2>' |
mbligh | dfeee94 | 2008-02-07 20:47:39 +0000 | [diff] [blame] | 327 | print '<a href="compose_query.cgi">Functional</a>' |
mbligh | 0459875 | 2007-10-01 15:49:58 +0000 | [diff] [blame] | 328 | print '   ' |
| 329 | print '<a href="machine_benchmark.cgi">Performance</a>' |
mbligh | cb0c38c | 2008-01-11 16:49:25 +0000 | [diff] [blame] | 330 | print '   ' |
| 331 | print '<a href="http://test.kernel.org/autotest">[about Autotest]</a>' |
mbligh | 0459875 | 2007-10-01 15:49:58 +0000 | [diff] [blame] | 332 | print '</h2><p>' |
mbligh | 7a41a86 | 2007-11-30 17:44:24 +0000 | [diff] [blame] | 333 | |
| 334 | |
| 335 | def group_name(group): |
| 336 | name = re.sub('_', '<br>', group.name) |
| 337 | if re.search('/', name): |
| 338 | (owner, machine) = name.split('/', 1) |
mbligh | 7a41a86 | 2007-11-30 17:44:24 +0000 | [diff] [blame] | 339 | name = owner + '<br>' + machine |
| 340 | return name |
mbligh | 5684b03 | 2008-06-06 14:25:35 +0000 | [diff] [blame^] | 341 | |