Commit 2c0837f3 authored by Vincent Pelletier's avatar Vincent Pelletier

Compute hits per day from site data.

Speeds up parsing a bit, and makes future extensions easier.
parent 4e9ac582
...@@ -392,6 +392,19 @@ class ERP5SiteStats(GenericSiteStats): ...@@ -392,6 +392,19 @@ class ERP5SiteStats(GenericSiteStats):
else: else:
self.no_module[date].accumulate(match) self.no_module[date].accumulate(match)
def getApdexData(self):
asDict = lambda apdex_data: dict((x, (y, z)) for (x, y, z) in apdex_data)
date_dict = asDict(super(ERP5SiteStats, self).getApdexData())
for date, (apdex, hit) in asDict(getDataPoints(self.no_module)
).iteritems():
super_apdex, super_hit = date_dict.get(date, (0, 100))
new_hit = hit + super_hit
if super_hit:
new_apdex = super_apdex * new_hit / super_hit + apdex * new_hit / hit
date_dict[date] = (new_apdex, new_hit)
return sorted(((date, apdex, hit)
for date, (apdex, hit) in date_dict.iteritems()), key=ITEMGETTER0)
def asHTML(self, date_format, placeholder_delta, graph_period, def asHTML(self, date_format, placeholder_delta, graph_period,
stat_filter=lambda x: x): stat_filter=lambda x: x):
result = [] result = []
...@@ -695,7 +708,6 @@ def main(): ...@@ -695,7 +708,6 @@ def main():
error_detail = args.error_detail error_detail = args.error_detail
file_count = len(infile_list) file_count = len(infile_list)
per_site = {} per_site = {}
hit_per_day = defaultdict(int)
skip_user_agent = list(itertools.chain(*args.skip_user_agent)) skip_user_agent = list(itertools.chain(*args.skip_user_agent))
malformed_lines = 0 malformed_lines = 0
skipped_lines = 0 skipped_lines = 0
...@@ -745,7 +757,6 @@ def main(): ...@@ -745,7 +757,6 @@ def main():
skipped_lines += 1 skipped_lines += 1
continue continue
date = asDate(match.group('timestamp')) date = asDate(match.group('timestamp'))
hit_per_day[decimator(date)] += 1
try: try:
site_data = per_site[site] site_data = per_site[site]
except KeyError: except KeyError:
...@@ -788,6 +799,10 @@ def main(): ...@@ -788,6 +799,10 @@ def main():
caption, value)) caption, value))
out.write('</table><h2>Hits per period</h2><table class="stats">' out.write('</table><h2>Hits per period</h2><table class="stats">'
'<tr><th>date</th><th>hits</th></tr>') '<tr><th>date</th><th>hits</th></tr>')
hit_per_day = defaultdict(int)
for site_data in per_site.itervalues():
for date, _, hit in site_data.getApdexData():
hit_per_day[decimator(date)] += hit
for date, hit in sorted(hit_per_day.iteritems(), key=ITEMGETTER0): for date, hit in sorted(hit_per_day.iteritems(), key=ITEMGETTER0):
out.write('<tr><td>%s</td><td>%s</td></tr>' % (date, hit)) out.write('<tr><td>%s</td><td>%s</td></tr>' % (date, hit))
out.write('</table>') out.write('</table>')
......
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