blob: 460513b3e9e10a3bcded4bdebd246ea7d2a028c1 [file] [log] [blame]
mbligh2e4e5df2007-11-05 17:22:46 +00001#!/usr/bin/python
2
3"""
4Selects all rows and columns that satisfy the condition specified
5and draws the matrix. There is a seperate SQL query made for every (x,y)
6in the matrix.
7"""
8
9
10print "Content-type: text/html\n"
11import cgi, cgitb, re
mbligha4266932007-11-05 18:12:16 +000012import sys, os
mbligh2e4e5df2007-11-05 17:22:46 +000013
14tko = os.path.dirname(os.path.realpath(os.path.abspath(sys.argv[0])))
15sys.path.insert(0, tko)
16
mbligh2b672532007-11-05 19:24:51 +000017import display, frontend, db, query_lib
mbligh2e4e5df2007-11-05 17:22:46 +000018
19cgitb.enable()
20db = db.db()
21
mbligh2e4e5df2007-11-05 17:22:46 +000022def main():
23
24 # parse the fields from the form.
25 form = cgi.FieldStorage()
26 columns = 'kernel'
27 rows = 'test'
28 condition = None
29 for field in form:
30 value = form[field].value
31 if field == 'columns':
32 columns = value
33 elif field == 'rows':
34 rows = value
35 elif field == 'condition':
36 condition = value
37
38 # parse the conditions into sql query and value list.
39 condition_sql = ""
40 condition_value = []
41 if condition:
mbligh2b672532007-11-05 19:24:51 +000042 condition_list = query_lib.parse_condition(condition)
43 condition_sql, condition_value = \
44 query_lib.generate_sql_condition(condition_list)
mbligh2e4e5df2007-11-05 17:22:46 +000045
46 # get all possible column values.
47 column_groups = frontend.anygroup.selectunique(db, columns)
48
49 # get all possible row values.
50 row_groups = frontend.anygroup.selectunique(db,rows)
51 # keep only those values in rows/columns that have a test
52 # corresponding to it.
mbligh2b672532007-11-05 19:24:51 +000053 row_groups = query_lib.prune_list(row_groups, condition_sql, \
54 condition_value)
55 column_groups = query_lib.prune_list(column_groups, condition_sql, \
56 condition_value)
mbligh2e4e5df2007-11-05 17:22:46 +000057
58 # prepare the header for the table.
59 headers = [g.name for g in column_groups]
60
61 header_row = [display.box(x, header=True) for x in headers]
62 header_row.insert(0, display.box("", header=True))
63
64 matrix = [header_row]
65
mbligh2b672532007-11-05 19:24:51 +000066 # get all the tests that satify the given condition.
67 tests = query_lib.get_tests(condition_sql, condition_value)
68
mbligh2e4e5df2007-11-05 17:22:46 +000069 for r_group in row_groups:
70 row = [display.box(r_group.name)]
mbligh2b672532007-11-05 19:24:51 +000071
72 # build the row sql for this row.
73 row_expr = [ " %s = %%s " % r_group.idx_name for val in r_group.idx_value]
74 row_sql = " (%s) " % " or ".join(row_expr)
75
mbligh2e4e5df2007-11-05 17:22:46 +000076 # get individual unit values
77 for c_group in column_groups:
mbligh2b672532007-11-05 19:24:51 +000078 # get the list of tests that belong to this x,y in the matrix.
79 xy_test = [test for test in tests
80 if query_lib.get_value(test, r_group.idx_name) \
81 in r_group.idx_value \
82 and query_lib.get_value(test,c_group.idx_name) \
83 in c_group.idx_value]
84
85 # build the column sql
86 column_expr = [ " %s = %%s " % c_group.idx_name for val in c_group.idx_value]
87 column_sql = " (%s) " % " or ".join(column_expr)
88
89 sql = "t where %s and %s " % (row_sql, column_sql)
90
91 # add the corresponding values of the fields to
92 # the value list.
93
94 value = []
95 value.extend(r_group.idx_value)
96 value.extend(c_group.idx_value)
97
98 # append the condition sql and the values to the
99 # sql/list respectively.
100 if condition_sql:
101 sql += " and "
102 sql += condition_sql
103 value.extend(condition_value)
104
mbligh2e4e5df2007-11-05 17:22:46 +0000105 value_str = [str(val) for val in value]
106 link = 'test.cgi?sql=%s&values=%s' % \
107 (sql, ','.join(value_str))
mbligh2b672532007-11-05 19:24:51 +0000108 row.append(display.status_count_box(db, xy_test, link))
mbligh2e4e5df2007-11-05 17:22:46 +0000109 matrix.append(row)
110 display.print_table(matrix)
111
112
113main()