From 7d45b45e8af6ec10b70238791e25228215dee92d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Tue, 2 Dec 2014 20:49:56 +0100 Subject: [PATCH] class DisplayHTMLBlockTableWithGraph() seems to work Fix a bug : month_stats override if iwla.py called twice --- default_conf.py | 4 ++-- display.py | 14 ++++++++++---- iwla.py | 16 +++++++++++----- resources/css/iwla.css | 14 +++++++++++++- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/default_conf.py b/default_conf.py index 6e78888..3812624 100644 --- a/default_conf.py +++ b/default_conf.py @@ -31,5 +31,5 @@ multimedia_files = ['png', 'jpg', 'jpeg', 'gif', 'ico', 'css', 'js'] resources_path = ['resources'] -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')] +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')] diff --git a/display.py b/display.py index 50fbbeb..646d049 100644 --- a/display.py +++ b/display.py @@ -59,6 +59,7 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock): self.rows = [] self.cols_cssclasses = ['' for e in cols] self.rows_cssclasses = [] + self.table_css = 'iwla_table' def appendRow(self, row): self.rows.append(listToStr(row)) @@ -76,7 +77,7 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock): row >= len(self.rows) or col >= len(self.cols): raise ValueError('Invalid indices %d,%d' % (row, col)) - return self.rows[row][col] + self.rows[row][col] = value def setCellCSSClass(self, row, col, value): if row < 0 or col < 0 or\ @@ -118,7 +119,9 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock): self.cols_cssclasses = values def _buildHTML(self): - html = '' + style = '' + if self.table_css: style = ' class="%s"' % (self.table_css) + html = '' % (style) if self.cols: html += '' for i in range (0, len(self.cols)): @@ -149,10 +152,11 @@ class DisplayHTMLBlockTableWithGraph(DisplayHTMLBlockTable): self.short_titles = short_titles self.nb_valid_rows = nb_valid_rows # TOFIX - self.icon_path = '/resources/icon' + self.icon_path = 'resources/icon' # self.icon_path = self.iwla.getConfValue('icon_path', '/') self.raw_rows = [] self.maxes = [0 for c in cols] + self.table_graph_css = 'iwla_graph_table' def appendRow(self, row): self.raw_rows.append(row) @@ -187,7 +191,9 @@ class DisplayHTMLBlockTableWithGraph(DisplayHTMLBlockTable): def _buildHTML(self): self._computeMax() - html = '
' + style = '' + if self.table_graph_css: style = ' class="%s"' % (self.table_graph_css) + html = '' % (style) html += '' for i in range(0, self.nb_valid_rows): row = self.rows[i] diff --git a/iwla.py b/iwla.py index 5fd1bde..6192312 100755 --- a/iwla.py +++ b/iwla.py @@ -245,19 +245,21 @@ class IWLA(object): days.setColsCSSClass(['', 'iwla_visit', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', 'iwla_bandwidth']) nb_visits = 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(): 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']] nb_visits += stats['nb_visitors'] nb_days += 1 else: - row = [i, 0, 0, 0, 0, 0] + row = [full_cur_day, 0, 0, 0, 0, 0] days.appendRow(row) days.setCellValue(i, 4, bytesToStr(row[4])) days.setCellValue(i, 5, bytesToStr(row[5])) - days.appendShortTitle(str(i)) + days.appendShortTitle(cur_day) 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 - self.current_analysis['month_stats'] = stats + if not 'month_stats' in self.current_analysis.keys(): + self.current_analysis['month_stats'] = stats + else: + for (k,v) in stats.items(): + self.current_analysis['month_stats'][k] = v self.valid_visitors = {} for (k,v) in visits.items(): diff --git a/resources/css/iwla.css b/resources/css/iwla.css index 7566123..a694c21 100644 --- a/resources/css/iwla.css +++ b/resources/css/iwla.css @@ -60,4 +60,16 @@ td:first-child .iwla_page { background : #4477DD; } .iwla_hit { background : #66DDEE; } .iwla_bandwidth { background : #2EA495; } -.iwla_search { background : #F4F090; } \ No newline at end of file +.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; +} \ No newline at end of file