Commit ba3a6033 authored by Vincent Pelletier's avatar Vincent Pelletier

Move apdex column related code to top level for easier reuse.

parent 9aa3b814
......@@ -74,6 +74,30 @@ def getClassForStatusHit(hit, status):
return 'problem'
return ''
def getApdexStyle(apdex):
return 'color: #%s; background-color: #%s' % (
(apdex < .5 and 'f' or '0') * 3,
('%x' % (apdex * 0xf)) * 3,
)
def getApdexStatsAsHtml(data, threshold):
apdex = data.getApdex()
average = data.getAverage()
maximum = data.getMax()
return '<td style="%s">%i%%</td>' \
'<td>%s</td><td class="%s">%.2f</td><td class="%s">%.2f</td>' % (
getApdexStyle(apdex),
apdex * 100,
data.hit,
getClassForDuration(average, threshold),
average,
getClassForDuration(maximum, threshold),
maximum,
)
APDEX_TABLE_HEADERS = ''.join('<th>' + x + '</th>' for x in (
'apdex', 'hits', 'avg (s)', 'max (s)'))
class APDEXStats(object):
def __init__(self, threshold):
threshold *= US_PER_S
......@@ -295,29 +319,15 @@ class ERP5SiteStats(GenericSiteStats):
append('<th colspan="4">%s</th>' % date)
append('</tr><tr>')
for _ in xrange(len(column_list) + 1):
append('<th>Apdex</th><th>hits</th><th>avg (s)</th>'
'<th>max (s)</th>')
append(APDEX_TABLE_HEADERS)
append('</tr>')
def apdexStatsAsHtml(data):
apdex = data.getApdex()
return '<td style="color: #%s; background-color: #%s">%i%%</td>' \
'<td>%s</td><td class="%s">%.2f</td><td class="%s">%.2f</td>' % (
(apdex < .5 and 'f' or '0') * 3,
('%x' % (apdex * 0xf)) * 3,
apdex * 100,
data.hit,
getClassForDuration(data.getAverage(), self.threshold),
data.getAverage(),
getClassForDuration(data.getMax(), self.threshold),
data.getMax(),
)
def apdexAsColumns(data_dict):
data_total = APDEXStats(self.threshold)
for data in data_dict.values():
data_total.accumulateFrom(data)
append(apdexStatsAsHtml(data_total))
append(getApdexStatsAsHtml(data_total, self.threshold))
for date in column_list:
append(apdexStatsAsHtml(data_dict[date]))
append(getApdexStatsAsHtml(data_dict[date], self.threshold))
for module_id, data_dict in sorted(filtered_module.iteritems(),
key=ITEMGETTER0):
append('<tr><th rowspan="2">%s</th><th>module</th>' % module_id)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment