iwla

iwla Commit Details

Date:2014-12-02 16:53:54 (6 years 7 months ago)
Author:Grégory Soutadé
Branch:dev, master
Commit:63a9b40b4699c6f54bdb98089b9006ad23ec4241
Parents: 2846394dad766a59505e922868ba0c774b7ba53f
Message:Work for DisplayHTMLBlockTableWithGraph class

Changes:
Mdefault_conf.py (1 diff)
Mdisplay.py (1 diff)
Miwla.py (1 diff)

File differences

default_conf.py
3131
3232
3333
34
35
36
34
35
'css', 'js']
resources_path = ['resources']
css_path = [os.path.join( '/',
os.path.basename(resources_path[0]),
os.path.join('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')]
display.py
138138
139139
140140
141
141
142142
143143
144144
145145
146146
147
147
148148
149
149
150150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
151166
152167
153168
154169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
155220
156221
157222
html += '</tr>'
html += '</table>'
self.html = html
self.html += html
super(DisplayHTMLBlockTable, self)._buildHTML()
class DisplayHTMLBlockTableWithGraph(DisplayHTMLBlockTable):
def __init__(self, title, cols, short_title, nb_valid_rows=0):
def __init__(self, title, cols, short_titles=[], nb_valid_rows=0):
super(DisplayHTMLBlockTableWithGraph, self).__init__(title=title, cols=cols)
self.short_title = short_title
self.short_titles = short_titles
self.nb_valid_rows = nb_valid_rows
# TOFIX
self.icon_path = '/resources/icon'
# self.icon_path = self.iwla.getConfValue('icon_path', '/')
self.raw_rows = []
self.maxes = [0 for c in cols]
def appendRow(self, row):
self.raw_rows.append(row)
super(DisplayHTMLBlockTableWithGraph, self).appendRow(row)
def appendShortTitle(self, short_title):
self.short_titles.append(short_title)
def setShortTitle(self, short_titles):
self.short_titles = short_titles
def setNbValidRows(self, nb_valid_rows):
self.nb_valid_rows = nb_valid_rows
def _computeMax(self):
for i in range(0, self.nb_valid_rows):
row = self.raw_rows[i]
for j in range(1, len(row)):
if row[j] > self.maxes[j]:
self.maxes[j] = row[j]
def _getIconFromStyle(self, style):
if style.startswith('iwla_page'): icon = 'vp.png'
elif style.startswith('iwla_hit'): icon = 'vh.png'
elif style.startswith('iwla_bandwidth'): icon = 'vk.png'
elif style.startswith('iwla_visit'): icon = 'vv.png'
elif style.startswith('iwla_search'): icon = 'vu.png'
else: return ''
return '%s/%s' % (self.icon_path, icon)
def _buildHTML(self):
self._computeMax()
html = '<table>'
html += '<tr>'
for i in range(0, self.nb_valid_rows):
row = self.rows[i]
html += '<td>'
for j in range(1, len(row)):
style = self.getColCSSClass(j)
icon = self._getIconFromStyle(style)
if not icon: continue
if style: style = ' class="%s"' % (style)
alt = '%s: %s' % (row[j], self.cols[j])
if self.maxes[j]:
height = int((self.raw_rows[i][j] * 100) / self.maxes[j])
else:
height = 0
html += '<img%s align="bottom" src="%s" height="%d" width="6" alt="%s" title="%s" />' % (style, icon, height, alt, alt)
html += '</td>'
html += '</tr>'
html += '<tr>'
for i in range(0, len(self.short_titles)):
style = self.getCellCSSClass(0, j)
if style: style = ' class="%s"' % (style)
html += '<td%s>%s</td>' % (style, self.short_titles[i])
html += '</tr>'
html += '</table>'
self.html += html
super(DisplayHTMLBlockTableWithGraph, self)._buildHTML()
class DisplayHTMLPage(object):
def __init__(self, title, filename, css_path):
iwla.py
240240
241241
242242
243
243
244
244245
245246
246247
247
248248
249249
250250
251251
252
252
253253
254254
255255
256
256
257257
258
259
260
258261
259262
260263
print '==> Generate display (%s)' % (filename)
page = DisplayHTMLPage(title, filename, conf.css_path)
days = DisplayHTMLBlockTable('By day', ['Day', 'Visits', 'Pages', 'Hits', 'Bandwidth', 'Not viewed Bandwidth'])
_, 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'])
nb_visits = 0
nb_days = 0
_, nb_month_days = monthrange(cur_time.tm_year, cur_time.tm_mon)
for i in range(0, nb_month_days+1):
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'],
bytesToStr(stats['viewed_bandwidth']), bytesToStr(stats['not_viewed_bandwidth'])]
stats['viewed_bandwidth'], stats['not_viewed_bandwidth']]
nb_visits += stats['nb_visitors']
nb_days += 1
else:
row = [i, '', '', '', '', '']
row = [i, 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))
stats = self.current_analysis['month_stats']

Archive Download the corresponding diff file

Branches

Tags