Save month stats in meta dictionary

This commit is contained in:
Grégory Soutadé 2014-12-01 21:13:35 +01:00
parent 81c3aa8099
commit 5d6362105b
2 changed files with 12 additions and 2 deletions

View File

@ -9,7 +9,7 @@ HOOKS_ROOT = 'plugins'
PRE_HOOK_DIRECTORY = HOOKS_ROOT + '.pre_analysis' PRE_HOOK_DIRECTORY = HOOKS_ROOT + '.pre_analysis'
POST_HOOK_DIRECTORY = HOOKS_ROOT + '.post_analysis' POST_HOOK_DIRECTORY = HOOKS_ROOT + '.post_analysis'
DISPLAY_HOOK_DIRECTORY = HOOKS_ROOT + '.display' DISPLAY_HOOK_DIRECTORY = HOOKS_ROOT + '.display'
META_PATH = DB_ROOT + 'meta.db' META_PATH = os.path.join(DB_ROOT, 'meta.db')
DB_FILENAME = 'iwla.db' DB_FILENAME = 'iwla.db'
log_format = '$server_name:$server_port $remote_addr - $remote_user [$time_local] ' +\ log_format = '$server_name:$server_port $remote_addr - $remote_user [$time_local] ' +\

12
iwla.py
View File

@ -114,7 +114,7 @@ class IWLA(object):
os.makedirs(base) os.makedirs(base)
# TODO : remove return # TODO : remove return
return #return
with open(filename + '.tmp', 'wb+') as f: with open(filename + '.tmp', 'wb+') as f:
pickle.dump(obj, f) pickle.dump(obj, f)
@ -317,6 +317,7 @@ class IWLA(object):
visits = self.current_analysis['visits'] visits = self.current_analysis['visits']
stats = self._generateStats(visits) stats = self._generateStats(visits)
duplicated_stats = {k:v for (k,v) in stats.items()}
cur_time = self.meta_infos['last_time'] cur_time = self.meta_infos['last_time']
print "== Stats for %d/%d ==" % (cur_time.tm_year, cur_time.tm_mon) print "== Stats for %d/%d ==" % (cur_time.tm_year, cur_time.tm_mon)
@ -344,6 +345,15 @@ class IWLA(object):
self._generateDisplay() self._generateDisplay()
# Save month stats
year = '%d' % (cur_time.tm_year)
month = '%d' % (cur_time.tm_mon)
if not 'stats' in self.meta_infos.keys():
self.meta_infos['stats'] = {}
if not year in self.meta_infos['stats'].keys():
self.meta_infos['stats'][year] = {}
self.meta_infos['stats'][year][month] = duplicated_stats
def _generateDayStats(self): def _generateDayStats(self):
visits = self.current_analysis['visits'] visits = self.current_analysis['visits']