mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | """ |
| 4 | Selects all rows and columns that satisfy the condition specified |
| 5 | and draws the matrix. There is a seperate SQL query made for every (x,y) |
| 6 | in the matrix. |
| 7 | """ |
| 8 | |
| 9 | |
| 10 | print "Content-type: text/html\n" |
| 11 | import cgi, cgitb, re |
mbligh | a426693 | 2007-11-05 18:12:16 +0000 | [diff] [blame] | 12 | import sys, os |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 13 | |
| 14 | tko = os.path.dirname(os.path.realpath(os.path.abspath(sys.argv[0]))) |
| 15 | sys.path.insert(0, tko) |
| 16 | |
mbligh | 2b67253 | 2007-11-05 19:24:51 +0000 | [diff] [blame] | 17 | import display, frontend, db, query_lib |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 18 | |
| 19 | cgitb.enable() |
| 20 | db = db.db() |
| 21 | |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 22 | def main(): |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame] | 23 | display.print_main_header() |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 24 | |
| 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: |
mbligh | 2b67253 | 2007-11-05 19:24:51 +0000 | [diff] [blame] | 43 | condition_list = query_lib.parse_condition(condition) |
| 44 | condition_sql, condition_value = \ |
| 45 | query_lib.generate_sql_condition(condition_list) |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 46 | |
| 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. |
mbligh | 2b67253 | 2007-11-05 19:24:51 +0000 | [diff] [blame] | 54 | 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) |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 58 | |
| 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 | |
mbligh | 2b67253 | 2007-11-05 19:24:51 +0000 | [diff] [blame] | 67 | # get all the tests that satify the given condition. |
| 68 | tests = query_lib.get_tests(condition_sql, condition_value) |
| 69 | |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 70 | for r_group in row_groups: |
| 71 | row = [display.box(r_group.name)] |
mbligh | 2b67253 | 2007-11-05 19:24:51 +0000 | [diff] [blame] | 72 | |
| 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 | |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 77 | # get individual unit values |
| 78 | for c_group in column_groups: |
mbligh | 2b67253 | 2007-11-05 19:24:51 +0000 | [diff] [blame] | 79 | # 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 | |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 106 | value_str = [str(val) for val in value] |
| 107 | link = 'test.cgi?sql=%s&values=%s' % \ |
| 108 | (sql, ','.join(value_str)) |
mbligh | 2b67253 | 2007-11-05 19:24:51 +0000 | [diff] [blame] | 109 | row.append(display.status_count_box(db, xy_test, link)) |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 110 | matrix.append(row) |
| 111 | display.print_table(matrix) |
| 112 | |
| 113 | |
| 114 | main() |