Work on index (not finished)
This commit is contained in:
parent
269b8e54de
commit
897f96232c
|
@ -146,9 +146,9 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock):
|
||||||
|
|
||||||
class DisplayHTMLBlockTableWithGraph(DisplayHTMLBlockTable):
|
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)
|
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
|
self.nb_valid_rows = nb_valid_rows
|
||||||
# TOFIX
|
# TOFIX
|
||||||
self.icon_path = 'resources/icon'
|
self.icon_path = 'resources/icon'
|
||||||
|
|
69
iwla.py
69
iwla.py
|
@ -237,7 +237,7 @@ class IWLA(object):
|
||||||
|
|
||||||
return self.display.getPage(filename)
|
return self.display.getPage(filename)
|
||||||
|
|
||||||
def _generateDisplayDaysStat(self):
|
def _generateDisplayDaysStats(self):
|
||||||
cur_time = self.meta_infos['last_time']
|
cur_time = self.meta_infos['last_time']
|
||||||
title = 'Stats %d/%d' % (cur_time.tm_mon, cur_time.tm_year)
|
title = 'Stats %d/%d' % (cur_time.tm_mon, cur_time.tm_year)
|
||||||
filename = self.getCurDisplayPath('index.html')
|
filename = self.getCurDisplayPath('index.html')
|
||||||
|
@ -245,8 +245,8 @@ class IWLA(object):
|
||||||
page = DisplayHTMLPage(title, filename, conf.css_path)
|
page = DisplayHTMLPage(title, filename, conf.css_path)
|
||||||
|
|
||||||
_, nb_month_days = monthrange(cur_time.tm_year, cur_time.tm_mon)
|
_, 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 = DisplayHTMLBlockTableWithGraph('By day', ['Day', 'Visitors', '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.setColsCSSClass(['', 'iwla_visitor', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', 'iwla_bandwidth'])
|
||||||
nb_visits = 0
|
nb_visits = 0
|
||||||
nb_days = 0
|
nb_days = 0
|
||||||
for i in range(0, nb_month_days):
|
for i in range(0, nb_month_days):
|
||||||
|
@ -294,9 +294,60 @@ class IWLA(object):
|
||||||
page.appendBlock(days)
|
page.appendBlock(days)
|
||||||
self.display.addPage(page)
|
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):
|
def _generateDisplay(self):
|
||||||
self._generateDisplayDaysStat()
|
self._generateDisplayDaysStats()
|
||||||
self._callPlugins(conf.DISPLAY_HOOK_DIRECTORY)
|
self._callPlugins(conf.DISPLAY_HOOK_DIRECTORY)
|
||||||
|
self._generateDisplayWholeMonthStats()
|
||||||
self.display.build(conf.DISPLAY_ROOT)
|
self.display.build(conf.DISPLAY_ROOT)
|
||||||
|
|
||||||
def _generateStats(self, visits):
|
def _generateStats(self, visits):
|
||||||
|
@ -355,6 +406,8 @@ class IWLA(object):
|
||||||
continue
|
continue
|
||||||
self.valid_visitors[k] = v
|
self.valid_visitors[k] = v
|
||||||
|
|
||||||
|
duplicated_stats['visitors'] = stats['visitors'] = len(self.valid_visitors.keys())
|
||||||
|
|
||||||
self._callPlugins(conf.POST_HOOK_DIRECTORY)
|
self._callPlugins(conf.POST_HOOK_DIRECTORY)
|
||||||
|
|
||||||
path = self.getDBFilename(cur_time)
|
path = self.getDBFilename(cur_time)
|
||||||
|
@ -365,17 +418,17 @@ class IWLA(object):
|
||||||
|
|
||||||
self._serialize(self.current_analysis, path)
|
self._serialize(self.current_analysis, path)
|
||||||
|
|
||||||
self._generateDisplay()
|
|
||||||
|
|
||||||
# Save month stats
|
# Save month stats
|
||||||
year = '%d' % (cur_time.tm_year)
|
year = cur_time.tm_year
|
||||||
month = '%d' % (cur_time.tm_mon)
|
month = cur_time.tm_mon
|
||||||
if not 'stats' in self.meta_infos.keys():
|
if not 'stats' in self.meta_infos.keys():
|
||||||
self.meta_infos['stats'] = {}
|
self.meta_infos['stats'] = {}
|
||||||
if not year in self.meta_infos['stats'].keys():
|
if not year in self.meta_infos['stats'].keys():
|
||||||
self.meta_infos['stats'][year] = {}
|
self.meta_infos['stats'][year] = {}
|
||||||
self.meta_infos['stats'][year][month] = duplicated_stats
|
self.meta_infos['stats'][year][month] = duplicated_stats
|
||||||
|
|
||||||
|
self._generateDisplay()
|
||||||
|
|
||||||
def _generateDayStats(self):
|
def _generateDayStats(self):
|
||||||
visits = self.current_analysis['visits']
|
visits = self.current_analysis['visits']
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user