add subtables inside each table for the main box that indicate what
percentage of tests passed

Signed-off-by: Martin J. Bligh <mbligh@google.com>



git-svn-id: http://test.kernel.org/svn/autotest/trunk@727 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/tko/display.py b/tko/display.py
index e898849..fc8375e 100755
--- a/tko/display.py
+++ b/tko/display.py
@@ -24,7 +24,7 @@
 		self.header = header
 
 
-	def display(self):
+	def html(self):
 		if self.data:
 			data = self.data
 		else:
@@ -35,9 +35,8 @@
 		else:
 			box_html = 'td'
 
-		print "<%s bgcolor=%s>" % (box_html, self.color)
-		print data
-		print "</%s>" % box_html
+		return "<%s bgcolor=%s>%s</%s>" % \
+					(box_html, self.color, data, box_html)
 
 
 def print_table(matrix):
@@ -53,7 +52,7 @@
 		print '<tr>'
 		for element in row:
 			print element
-			element.display()
+			print element.html()
 		print '</tr>'
 	print '</table>'
 
diff --git a/tko/machine_kernel.cgi b/tko/machine_kernel.cgi
index 5d62362..da36d72 100755
--- a/tko/machine_kernel.cgi
+++ b/tko/machine_kernel.cgi
@@ -20,20 +20,39 @@
 	print_machines_vs_all_kernels(machines)
 
 
+def status_html(status_count):
+	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 status_pct.keys():
+		string = "%d%% %s" % (status_pct[status], status)
+		box = display.box(string, status)
+		rows.append("<tr>%s</tr>" % box.html())
+	return '<table>%s</table>' % '\n'.join(rows)
+
+
 def kernel_machine_box(kernel, machine):
 	status = None
 	status_word = ''
 	tests = frontend.test.select(db, { 'kernel_idx' : kernel.idx ,
 					   'machine' : machine })
+
+	status_count = {}
 	for t in tests:
 		if not status or t.status_num < status:
 			status = t.status_num
 			status_word = db.status_word[status]
+			if status_count.has_key(status_word):
+				status_count[status_word] += 1
+			else:
+				status_count[status_word] = 1
 
 	link = 'machine_kernel_test.cgi?machine=%s&kernel=%s' % \
 					(machine, kernel.idx)
 	if status_word:
-		html = '<a href="%s">%s</a>' % (link, status_word)
+		html = '<a href="%s">%s</a>' % (link, status_html(status_count))
 	else:
 		html = None
 	return display.box(html, color_key = status_word)