blob: 1073c1238492c2e380522923c45034dfb303cee0 [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():
mbligh1405f4e2007-11-05 19:26:23 +000023 display.print_main_header()
mbligh2e4e5df2007-11-05 17:22:46 +000024
25 # parse the fields from the form.
26 form = cgi.FieldStorage()
27 columns = 'kernel'
28 rows = 'test'
29 condition = None
30 for field in form:
31 value = form[field].value
32 if field == 'columns':
33 columns = value
34 elif field == 'rows':
35 rows = value
36 elif field == 'condition':
37 condition = value
38
39 # parse the conditions into sql query and value list.
40 condition_sql = ""
41 condition_value = []
42 if condition:
mbligh2b672532007-11-05 19:24:51 +000043 condition_list = query_lib.parse_condition(condition)
44 condition_sql, condition_value = \
45 query_lib.generate_sql_condition(condition_list)
mbligh2e4e5df2007-11-05 17:22:46 +000046
47 # get all possible column values.
48 column_groups = frontend.anygroup.selectunique(db, columns)
49
50 # get all possible row values.
51 row_groups = frontend.anygroup.selectunique(db,rows)
52 # keep only those values in rows/columns that have a test
53 # corresponding to it.
mbligh2b672532007-11-05 19:24:51 +000054 row_groups = query_lib.prune_list(row_groups, condition_sql, \
55 condition_value)
56 column_groups = query_lib.prune_list(column_groups, condition_sql, \
57 condition_value)
mbligh2e4e5df2007-11-05 17:22:46 +000058
59 # prepare the header for the table.
60 headers = [g.name for g in column_groups]
61
62 header_row = [display.box(x, header=True) for x in headers]
63 header_row.insert(0, display.box("", header=True))
64
65 matrix = [header_row]
66
mbligh2b672532007-11-05 19:24:51 +000067 # get all the tests that satify the given condition.
68 tests = query_lib.get_tests(condition_sql, condition_value)
69
mbligh2e4e5df2007-11-05 17:22:46 +000070 for r_group in row_groups:
71 row = [display.box(r_group.name)]
mbligh2b672532007-11-05 19:24:51 +000072
73 # build the row sql for this row.
74 row_expr = [ " %s = %%s " % r_group.idx_name for val in r_group.idx_value]
75 row_sql = " (%s) " % " or ".join(row_expr)
76
mbligh2e4e5df2007-11-05 17:22:46 +000077 # get individual unit values
78 for c_group in column_groups:
mbligh2b672532007-11-05 19:24:51 +000079 # get the list of tests that belong to this x,y in the matrix.
80 xy_test = [test for test in tests
81 if query_lib.get_value(test, r_group.idx_name) \
82 in r_group.idx_value \
83 and query_lib.get_value(test,c_group.idx_name) \
84 in c_group.idx_value]
85
86 # build the column sql
87 column_expr = [ " %s = %%s " % c_group.idx_name for val in c_group.idx_value]
88 column_sql = " (%s) " % " or ".join(column_expr)
89
90 sql = "t where %s and %s " % (row_sql, column_sql)
91
92 # add the corresponding values of the fields to
93 # the value list.
94
95 value = []
96 value.extend(r_group.idx_value)
97 value.extend(c_group.idx_value)
98
99 # append the condition sql and the values to the
100 # sql/list respectively.
101 if condition_sql:
102 sql += " and "
103 sql += condition_sql
104 value.extend(condition_value)
105
mbligh2e4e5df2007-11-05 17:22:46 +0000106 value_str = [str(val) for val in value]
107 link = 'test.cgi?sql=%s&values=%s' % \
108 (sql, ','.join(value_str))
mbligh2b672532007-11-05 19:24:51 +0000109 row.append(display.status_count_box(db, xy_test, link))
mbligh2e4e5df2007-11-05 17:22:46 +0000110 matrix.append(row)
111 display.print_table(matrix)
112
113
114main()