Clean up the table-within-a-table abstraction for printing
the status counts in a box - move to display.py
Signed-off-by: Martin J. Bligh <mbligh@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@761 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/tko/display.py b/tko/display.py
index caba11f..4578033 100755
--- a/tko/display.py
+++ b/tko/display.py
@@ -39,6 +39,43 @@
(box_html, self.color, data, box_html)
+def status_html(db, status_count):
+ """
+ status_count: dict mapping from status (integer key) to count
+ eg. { 'GOOD' : 4, 'FAIL' : 1 }
+ """
+# total = sum(status_count.values())
+# status_pct = {}
+# for status in status_count.keys():
+# status_pct[status] = (100 * status_count[status]) / total
+ rows = []
+ for status in sorted(status_count.keys(), reverse = True):
+ status_word = db.status_word[status]
+ # string = "%d (%d%%)" % (status_count[status], status_pct[status])
+ string = "%d %s" % (status_count[status], status_word)
+ rows.append("<tr>%s</tr>" % box(string, status_word).html())
+ return '<table>%s</table>' % '\n'.join(rows)
+
+
+def status_count_box(db, tests, link = None):
+ """
+ Display a table within a box, representing the status count of
+ the group of tests (e.g. 10 GOOD, 2 WARN, 3 FAIL)
+ """
+ if not tests:
+ return box(None, None)
+
+ status_count = {}
+ for test in tests:
+ count = status_count.get(test.status_num, 0)
+ status_count[test.status_num] = count + 1
+ worst = sorted(status_count.keys())[0]
+ html = status_html(db, status_count)
+ if link:
+ html = '<a href="%s">%s</a>' % (link, html)
+ return box(html, db.status_word[worst])
+
+
def print_table(matrix):
"""
matrix: list of lists of boxes, giving a matrix of data