Commit 8cde1631 authored by Vincent Pelletier's avatar Vincent Pelletier

Objectify APDEXStats HTML rendering.

parent d14743d9
......@@ -83,51 +83,6 @@ 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, overall=False):
apdex = data.getApdex()
average = data.getAverage()
maximum = data.getMax()
hit = data.hit
if hit:
extra_class = ''
apdex_style = getApdexStyle(apdex)
else:
extra_class = 'no_hit'
apdex_style = ''
if overall:
extra_right_class = 'overall_right'
else:
extra_right_class = ''
return '<td style="%(apdex_style)s" class="%(extra_class)s group_left">' \
'%(apdex)i%%</td><td class="%(extra_class)s">%(hit)s</td>' \
'<td class="%(average_class)s %(extra_class)s">%(average).2f</td>' \
'<td class="%(max_class)s %(extra_class)s group_right ' \
'%(extra_right_class)s">%(max).2f</td>' % {
'extra_class': extra_class,
'apdex_style': apdex_style,
'apdex': apdex * 100,
'hit': hit,
'average_class': getClassForDuration(average, threshold),
'average': average,
'max_class': getClassForDuration(maximum, threshold),
'max': maximum,
'extra_right_class': extra_right_class,
}
def getApdexTableHeader(overall=False):
if overall:
extra = ' class="overall_right"'
else:
extra = ''
return '<th>apdex</th><th>hits</th><th>avg (s)</th>' \
'<th%s>max (s)</th>' % extra
def getDataPoints(apdex_dict):
return [
(date, apdex.getApdex() * 100, apdex.hit) for date, apdex
......@@ -249,6 +204,45 @@ class APDEXStats(object):
def getMax(self):
return float(self.duration_max) / US_PER_S
@staticmethod
def asHTMLHeader(overall=False):
return '<th>apdex</th><th>hits</th><th>avg (s)</th>' \
'<th%s>max (s)</th>' % (overall and ' class="overall_right"' or '')
def asHTML(self, threshold, overall=False):
apdex = self.getApdex()
average = self.getAverage()
maximum = self.getMax()
hit = self.hit
if hit:
extra_class = ''
apdex_style = 'color: #%s; background-color: #%s' % (
(apdex < .5 and 'f' or '0') * 3,
('%x' % (apdex * 0xf)) * 3,
)
else:
extra_class = 'no_hit'
apdex_style = ''
if overall:
extra_right_class = 'overall_right'
else:
extra_right_class = ''
return '<td style="%(apdex_style)s" class="%(extra_class)s group_left">' \
'%(apdex)i%%</td><td class="%(extra_class)s">%(hit)s</td>' \
'<td class="%(average_class)s %(extra_class)s">%(average).2f</td>' \
'<td class="%(max_class)s %(extra_class)s group_right ' \
'%(extra_right_class)s">%(max).2f</td>' % {
'extra_class': extra_class,
'apdex_style': apdex_style,
'apdex': apdex * 100,
'hit': hit,
'average_class': getClassForDuration(average, threshold),
'average': average,
'max_class': getClassForDuration(maximum, threshold),
'max': maximum,
'extra_right_class': extra_right_class,
}
class GenericSiteStats(object):
def __init__(self, threshold, getDuration, suffix, error_detail=False):
self.threshold = threshold
......@@ -298,16 +292,16 @@ class GenericSiteStats(object):
for data in self.apdex.itervalues():
apdex.accumulateFrom(data)
append('<h2>Overall</h2><table class="stats"><tr>')
append(getApdexTableHeader())
append(APDEXStats.asHTMLHeader())
append('</tr><tr>')
append(getApdexStatsAsHtml(apdex, self.threshold))
append(apdex.asHTML(self.threshold))
append('</tr></table><h2>Hottest pages</h2><table class="stats"><tr>')
append(getApdexTableHeader())
append(APDEXStats.asHTMLHeader())
append('<th>url</th></tr>')
for url, data in sorted(self.url_apdex.iteritems(), key=lambda x: x[1].getAverage() * x[1].hit,
reverse=True)[:N_SLOWEST]:
append('<tr>')
append(getApdexStatsAsHtml(data, self.threshold))
append(data.asHTML(self.threshold))
append('<td class="text">%s</td></tr>' % escape(url))
append('</table>')
column_set = set()
......@@ -457,15 +451,15 @@ class ERP5SiteStats(GenericSiteStats):
append('<th colspan="4">%s</th>' % date)
append('</tr><tr>')
for i in xrange(len(column_list) + 1):
append(getApdexTableHeader(i == 0))
append(APDEXStats.asHTMLHeader(i == 0))
append('</tr>')
def apdexAsColumns(data_dict):
data_total = APDEXStats(self.threshold, None)
for data in data_dict.values():
data_total.accumulateFrom(data)
append(getApdexStatsAsHtml(data_total, self.threshold, True))
append(data_total.asHTML(self.threshold, True))
for date in column_list:
append(getApdexStatsAsHtml(data_dict[date], self.threshold))
append(data_dict[date].asHTML(self.threshold))
def hiddenGraph(data_dict, title):
append('<td class="text group_right hidden_graph">')
data = getDataPoints(data_dict)
......
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