Work on index (not finished)

This commit is contained in:
Grégory Soutadé 2014-12-03 21:58:55 +01:00
parent 269b8e54de
commit 897f96232c
2 changed files with 63 additions and 10 deletions

View File

@ -146,9 +146,9 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock):
class DisplayHTMLBlockTableWithGraph(DisplayHTMLBlockTable):
def __init__(self, title, cols, short_titles=[], nb_valid_rows=0):
def __init__(self, title, cols, short_titles=None, nb_valid_rows=0):
super(DisplayHTMLBlockTableWithGraph, self).__init__(title=title, cols=cols)
self.short_titles = short_titles
self.short_titles = short_titles or []
self.nb_valid_rows = nb_valid_rows
# TOFIX
self.icon_path = 'resources/icon'

69
iwla.py
View File

@ -237,7 +237,7 @@ class IWLA(object):
return self.display.getPage(filename)
def _generateDisplayDaysStat(self):
def _generateDisplayDaysStats(self):
cur_time = self.meta_infos['last_time']
title = 'Stats %d/%d' % (cur_time.tm_mon, cur_time.tm_year)
filename = self.getCurDisplayPath('index.html')
@ -245,8 +245,8 @@ class IWLA(object):
page = DisplayHTMLPage(title, filename, conf.css_path)
_, nb_month_days = monthrange(cur_time.tm_year, cur_time.tm_mon)
days = DisplayHTMLBlockTableWithGraph('By day', ['Day', 'Visits', 'Pages', 'Hits', 'Bandwidth', 'Not viewed Bandwidth'], nb_valid_rows=nb_month_days)
days.setColsCSSClass(['', 'iwla_visit', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', 'iwla_bandwidth'])
days = DisplayHTMLBlockTableWithGraph('By day', ['Day', 'Visitors', 'Pages', 'Hits', 'Bandwidth', 'Not viewed Bandwidth'], nb_valid_rows=nb_month_days)
days.setColsCSSClass(['', 'iwla_visitor', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', 'iwla_bandwidth'])
nb_visits = 0
nb_days = 0
for i in range(0, nb_month_days):
@ -294,9 +294,60 @@ class IWLA(object):
page.appendBlock(days)
self.display.addPage(page)
def _generateDisplayMonthStats(self, page, year, month_stats):
title = 'Summary %d' % (year)
cols = ['Month', 'Visitors', 'Pages', 'Hits', 'Bandwidth', 'Not viewed Bandwidth']
months = DisplayHTMLBlockTableWithGraph(title, cols, nb_valid_rows=12)
months.setColsCSSClass(['', 'iwla_visit', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', 'iwla_bandwidth'])
total = [0] * len(cols)
for i in range(0, 12):
month = '%s<br/>%d' % ('Jan', year)
full_month = '%s %d' % ('Jan', year)
if i in month_stats.keys():
stats = month_stats[i]
row = [full_month, stats['nb_visitors'], stats['viewed_pages'], stats['viewed_hits'],
stats['viewed_bandwidth'], stats['not_viewed_bandwidth']]
for i in range(1, len(row[1:])):
total[i] += row[i]
else:
row = [full_month, 0, 0, 0, 0, 0]
months.appendRow(row)
months.setCellValue(i, 4, bytesToStr(row[4]))
months.setCellValue(i, 5, bytesToStr(row[5]))
months.appendShortTitle(month)
# adate = date(cur_time.tm_year, cur_time.tm_mon, i+1)
# week_day = adate.weekday()
# if week_day == 5 or week_day == 6:
# months.setRowCSSClass(i, 'iwla_weekend')
# if adate == date.today():
# css = months.getCellCSSClass(i, 0)
# if css: css = '%s %s' % (css, 'iwla_curday')
# else: css = 'iwla_curday'
# months.setCellCSSClass(i, 0, css)
total[0] = 'Total'
total[4] = bytesToStr(total[4])
total[5] = bytesToStr(total[5])
months.appendRow(total)
page.appendBlock(months)
def _generateDisplayWholeMonthStats(self):
title = 'Stats for %s' % (conf.domain_name)
filename = 'index.html'
print '==> Generate main page (%s)' % (filename)
page = DisplayHTMLPage(title, filename, conf.css_path)
for year in self.meta_infos['stats'].keys():
self._generateDisplayMonthStats(page, year, self.meta_infos['stats'][year])
self.display.addPage(page)
def _generateDisplay(self):
self._generateDisplayDaysStat()
self._generateDisplayDaysStats()
self._callPlugins(conf.DISPLAY_HOOK_DIRECTORY)
self._generateDisplayWholeMonthStats()
self.display.build(conf.DISPLAY_ROOT)
def _generateStats(self, visits):
@ -355,6 +406,8 @@ class IWLA(object):
continue
self.valid_visitors[k] = v
duplicated_stats['visitors'] = stats['visitors'] = len(self.valid_visitors.keys())
self._callPlugins(conf.POST_HOOK_DIRECTORY)
path = self.getDBFilename(cur_time)
@ -365,17 +418,17 @@ class IWLA(object):
self._serialize(self.current_analysis, path)
self._generateDisplay()
# Save month stats
year = '%d' % (cur_time.tm_year)
month = '%d' % (cur_time.tm_mon)
year = cur_time.tm_year
month = 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
self._generateDisplay()
def _generateDayStats(self):
visits = self.current_analysis['visits']