Add computeRatio method to display. Enable it in browsers display plugin
This commit is contained in:
parent
1d9bf71b4b
commit
616b0d8052
29
display.py
29
display.py
|
@ -102,6 +102,21 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock):
|
|||
self.rows.append(listToStr(row))
|
||||
self.rows_cssclasses.append([u''] * len(row))
|
||||
|
||||
def insertCol(self, col_number, col_title='', col_css_class=''):
|
||||
self.cols.insert(col_number, col_title)
|
||||
for r in self.rows:
|
||||
r.insert(col_number, u'')
|
||||
for r in self.rows_cssclasses:
|
||||
v = r[0]
|
||||
# If all cells have the same CSS class, set it
|
||||
for cur_value in r:
|
||||
if v != cur_value:
|
||||
v = None
|
||||
break
|
||||
v = v or u''
|
||||
r.insert(col_number, v)
|
||||
self.cols_cssclasses.insert(col_number, col_css_class)
|
||||
|
||||
def getNbRows(self):
|
||||
return len(self.rows)
|
||||
|
||||
|
@ -160,6 +175,20 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock):
|
|||
|
||||
self.cols_cssclasses = listToStr(values)
|
||||
|
||||
def computeRatio(self, column, column_insertion=None):
|
||||
if column_insertion is None:
|
||||
column_insertion = column+1
|
||||
|
||||
total = 0
|
||||
for r in self.rows:
|
||||
if r[column]:
|
||||
total += int(r[column])
|
||||
|
||||
self.insertCol(column_insertion, self.iwla._('Ratio'), u'iwla_hit')
|
||||
for (index, r) in enumerate(self.rows):
|
||||
val = r[column] and int(r[column]) or 0
|
||||
self.setCellValue(index, column_insertion, '%.1f%%' % (float(val*100)/float(total)))
|
||||
|
||||
def _buildHTML(self):
|
||||
style = u''
|
||||
if self.table_css: style = u' class="%s"' % (self.table_css)
|
||||
|
|
|
@ -128,4 +128,5 @@ class IWLADisplayBrowsers(IPlugin):
|
|||
total_browsers[1] = self.iwla._(u'Others')
|
||||
table.appendRow(total_browsers)
|
||||
table.setCellCSSClass(table.getNbRows()-1, 0, 'iwla_others')
|
||||
table.computeRatio(2)
|
||||
index.appendBlock(table)
|
||||
|
|
Loading…
Reference in New Issue
Block a user