class DisplayHTMLBlockTableWithGraph() seems to work

Fix a bug : month_stats override if iwla.py called twice
This commit is contained in:
Grégory Soutadé 2014-12-02 20:49:56 +01:00
parent 63a9b40b46
commit 7d45b45e8a
4 changed files with 36 additions and 12 deletions

View File

@ -31,5 +31,5 @@ multimedia_files = ['png', 'jpg', 'jpeg', 'gif', 'ico',
'css', 'js'] 'css', 'js']
resources_path = ['resources'] resources_path = ['resources']
icon_path = ['/%s/%s' % (os.path.basename(resources_path[0]), 'icon')] icon_path = ['%s/%s' % (os.path.basename(resources_path[0]), 'icon')]
css_path = ['/%s/%s/%s' % (os.path.basename(resources_path[0]), 'css', 'iwla.css')] css_path = ['%s/%s/%s' % (os.path.basename(resources_path[0]), 'css', 'iwla.css')]

View File

@ -59,6 +59,7 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock):
self.rows = [] self.rows = []
self.cols_cssclasses = ['' for e in cols] self.cols_cssclasses = ['' for e in cols]
self.rows_cssclasses = [] self.rows_cssclasses = []
self.table_css = 'iwla_table'
def appendRow(self, row): def appendRow(self, row):
self.rows.append(listToStr(row)) self.rows.append(listToStr(row))
@ -76,7 +77,7 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock):
row >= len(self.rows) or col >= len(self.cols): row >= len(self.rows) or col >= len(self.cols):
raise ValueError('Invalid indices %d,%d' % (row, col)) raise ValueError('Invalid indices %d,%d' % (row, col))
return self.rows[row][col] self.rows[row][col] = value
def setCellCSSClass(self, row, col, value): def setCellCSSClass(self, row, col, value):
if row < 0 or col < 0 or\ if row < 0 or col < 0 or\
@ -118,7 +119,9 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock):
self.cols_cssclasses = values self.cols_cssclasses = values
def _buildHTML(self): def _buildHTML(self):
html = '<table>' style = ''
if self.table_css: style = ' class="%s"' % (self.table_css)
html = '<table%s>' % (style)
if self.cols: if self.cols:
html += '<tr>' html += '<tr>'
for i in range (0, len(self.cols)): for i in range (0, len(self.cols)):
@ -149,10 +152,11 @@ class DisplayHTMLBlockTableWithGraph(DisplayHTMLBlockTable):
self.short_titles = short_titles self.short_titles = short_titles
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'
# self.icon_path = self.iwla.getConfValue('icon_path', '/') # self.icon_path = self.iwla.getConfValue('icon_path', '/')
self.raw_rows = [] self.raw_rows = []
self.maxes = [0 for c in cols] self.maxes = [0 for c in cols]
self.table_graph_css = 'iwla_graph_table'
def appendRow(self, row): def appendRow(self, row):
self.raw_rows.append(row) self.raw_rows.append(row)
@ -187,7 +191,9 @@ class DisplayHTMLBlockTableWithGraph(DisplayHTMLBlockTable):
def _buildHTML(self): def _buildHTML(self):
self._computeMax() self._computeMax()
html = '<table>' style = ''
if self.table_graph_css: style = ' class="%s"' % (self.table_graph_css)
html = '<table%s>' % (style)
html += '<tr>' html += '<tr>'
for i in range(0, self.nb_valid_rows): for i in range(0, self.nb_valid_rows):
row = self.rows[i] row = self.rows[i]

14
iwla.py
View File

@ -245,19 +245,21 @@ class IWLA(object):
days.setColsCSSClass(['', 'iwla_visit', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', 'iwla_bandwidth']) days.setColsCSSClass(['', 'iwla_visit', '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+1): for i in range(0, nb_month_days):
cur_day = '%d %s' % (i+1, time.strftime('%b', cur_time))
full_cur_day = '%s %d' % (cur_day, cur_time.tm_year)
if i in self.current_analysis['days_stats'].keys(): if i in self.current_analysis['days_stats'].keys():
stats = self.current_analysis['days_stats'][i] stats = self.current_analysis['days_stats'][i]
row = [i, stats['nb_visitors'], stats['viewed_pages'], stats['viewed_hits'], row = [full_cur_day, stats['nb_visitors'], stats['viewed_pages'], stats['viewed_hits'],
stats['viewed_bandwidth'], stats['not_viewed_bandwidth']] stats['viewed_bandwidth'], stats['not_viewed_bandwidth']]
nb_visits += stats['nb_visitors'] nb_visits += stats['nb_visitors']
nb_days += 1 nb_days += 1
else: else:
row = [i, 0, 0, 0, 0, 0] row = [full_cur_day, 0, 0, 0, 0, 0]
days.appendRow(row) days.appendRow(row)
days.setCellValue(i, 4, bytesToStr(row[4])) days.setCellValue(i, 4, bytesToStr(row[4]))
days.setCellValue(i, 5, bytesToStr(row[5])) days.setCellValue(i, 5, bytesToStr(row[5]))
days.appendShortTitle(str(i)) days.appendShortTitle(cur_day)
stats = self.current_analysis['month_stats'] stats = self.current_analysis['month_stats']
@ -326,7 +328,11 @@ class IWLA(object):
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)
print stats print stats
if not 'month_stats' in self.current_analysis.keys():
self.current_analysis['month_stats'] = stats self.current_analysis['month_stats'] = stats
else:
for (k,v) in stats.items():
self.current_analysis['month_stats'][k] = v
self.valid_visitors = {} self.valid_visitors = {}
for (k,v) in visits.items(): for (k,v) in visits.items():

View File

@ -61,3 +61,15 @@ td:first-child
.iwla_hit { background : #66DDEE; } .iwla_hit { background : #66DDEE; }
.iwla_bandwidth { background : #2EA495; } .iwla_bandwidth { background : #2EA495; }
.iwla_search { background : #F4F090; } .iwla_search { background : #F4F090; }
.iwla_graph_table
{
margin-left:auto;
margin-right:auto;
}
table.iwla_graph_table > table.iwla_table
{
margin-left:auto;
margin-right:auto;
}