Start refactoring statistics computation
This commit is contained in:
parent
f116eacbcc
commit
bb7ce4af90
54
iwla.py
54
iwla.py
|
@ -449,34 +449,14 @@ class IWLA(object):
|
|||
self._generateDisplayWholeMonthStats()
|
||||
self.display.build(conf.DISPLAY_ROOT)
|
||||
|
||||
def _generateStats(self, visits):
|
||||
def _createEmptyStats(self):
|
||||
stats = {}
|
||||
stats['viewed_bandwidth'] = 0
|
||||
stats['not_viewed_bandwidth'] = 0
|
||||
stats['viewed_pages'] = 0
|
||||
stats['viewed_hits'] = 0
|
||||
#stats['requests'] = set()
|
||||
stats['nb_visitors'] = 0
|
||||
|
||||
for (k, super_hit) in visits.items():
|
||||
if super_hit['robot']:
|
||||
stats['not_viewed_bandwidth'] += super_hit['bandwidth']
|
||||
continue
|
||||
|
||||
#print "[%s] =>\t%d/%d" % (k, super_hit['viewed_pages'], super_hit['viewed_hits'])
|
||||
|
||||
if conf.count_hit_only_visitors or\
|
||||
super_hit['viewed_pages']:
|
||||
stats['nb_visitors'] += 1
|
||||
stats['viewed_bandwidth'] += super_hit['bandwidth']
|
||||
stats['viewed_pages'] += super_hit['viewed_pages']
|
||||
stats['viewed_hits'] += super_hit['viewed_hits']
|
||||
|
||||
# for p in super_hit['requests']:
|
||||
# if not p['is_page']: continue
|
||||
# req = p['extract_request']
|
||||
# stats['requests'].add(req['extract_uri'])
|
||||
|
||||
return stats
|
||||
|
||||
def _generateMonthStats(self):
|
||||
|
@ -484,7 +464,11 @@ class IWLA(object):
|
|||
|
||||
visits = self.current_analysis['visits']
|
||||
|
||||
stats = self._generateStats(visits)
|
||||
stats = self._createEmptyStats()
|
||||
for (day, stat) in self.current_analysis['days_stats'].items():
|
||||
for k in stats.keys():
|
||||
stats[k] += stat[k]
|
||||
|
||||
duplicated_stats = {k:v for (k,v) in stats.items()}
|
||||
|
||||
cur_time = self.meta_infos['last_time']
|
||||
|
@ -529,12 +513,24 @@ class IWLA(object):
|
|||
|
||||
def _generateDayStats(self):
|
||||
visits = self.current_analysis['visits']
|
||||
cur_time = self.meta_infos['last_time']
|
||||
|
||||
self._callPlugins(conf.PRE_HOOK_DIRECTORY)
|
||||
|
||||
stats = self._generateStats(visits)
|
||||
stats = self._createEmptyStats()
|
||||
|
||||
for (k, super_hit) in visits.items():
|
||||
if super_hit['robot']:
|
||||
stats['not_viewed_bandwidth'] += super_hit['bandwidth']
|
||||
continue
|
||||
if (conf.count_hit_only_visitors or\
|
||||
super_hit['viewed_pages']) and\
|
||||
super_hit['last_access'].tm_mday == cur_time.tm_mday:
|
||||
stats['nb_visitors'] += 1
|
||||
stats['viewed_bandwidth'] += super_hit['bandwidth']
|
||||
stats['viewed_pages'] += super_hit['viewed_pages']
|
||||
stats['viewed_hits'] += super_hit['viewed_hits']
|
||||
|
||||
cur_time = self.meta_infos['last_time']
|
||||
print "== Stats for %d/%02d/%d ==" % (cur_time.tm_year, cur_time.tm_mon, cur_time.tm_mday)
|
||||
|
||||
if cur_time.tm_mday > 1:
|
||||
|
@ -545,15 +541,9 @@ class IWLA(object):
|
|||
last_day -= 1
|
||||
if last_day:
|
||||
for k in stats.keys():
|
||||
if k != 'nb_visitors':
|
||||
print '%s : %d %d' % (k, stats[k], self.current_analysis['days_stats'][last_day][k])
|
||||
stats[k] -= self.current_analysis['days_stats'][last_day][k]
|
||||
stats['nb_visitors'] = 0
|
||||
for (k,v) in visits.items():
|
||||
if v['robot']: continue
|
||||
if conf.count_hit_only_visitors and\
|
||||
(not v['viewed_pages']):
|
||||
continue
|
||||
if v['last_access'].tm_mday == cur_time.tm_mday:
|
||||
stats['nb_visitors'] += 1
|
||||
print stats
|
||||
|
||||
self.current_analysis['days_stats'][cur_time.tm_mday] = stats
|
||||
|
|
Loading…
Reference in New Issue
Block a user