iwla

iwla Commit Details

Date:2014-12-08 14:13:26 (6 years 7 months ago)
Author:Grégory Soutadé
Branch:dev, master
Commit:010c16cacad0016d21ea439a124fb73a4e411627
Parents: fd858034fb1e2badc2b5e7d482c9f7d0f1bce67e
Message:Give iwla to each display class Add generic functions createPage() and createBlock() in DisplayHTMLBuild Add and display IWLA version

Changes:
Mdefault_conf.py (1 diff)
Mdisplay.py (8 diffs)
Miwla.py (5 diffs)
Mplugins/display/all_visits.py (4 diffs)
Mplugins/display/referers.py (6 diffs)
Mplugins/display/top_downloads.py (4 diffs)
Mplugins/display/top_hits.py (4 diffs)
Mplugins/display/top_pages.py (4 diffs)
Mplugins/display/top_visitors.py (2 diffs)

File differences

default_conf.py
3131
3232
3333
34
34
3535
'css', 'js']
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')]
display.py
33
44
55
6
6
7
78
89
910
......
2122
2223
2324
24
25
25
26
2627
2728
2829
......
5455
5556
5657
57
58
58
59
5960
6061
6162
......
153154
154155
155156
156
157
157
158
158159
159160
160161
161
162
163
162
164163
165164
166165
......
195194
196195
197196
198
197
199198
200199
201200
......
236235
237236
238237
239
238
239
240240
241241
242242
......
273273
274274
275275
276
277
276278
277279
278280
......
282284
283285
284286
287
288
289
290
291
292
285293
286294
287295
class DisplayHTMLRaw(object):
def __init__(self, html=u''):
def __init__(self, iwla, html=u''):
self.iwla = iwla
self.html = html
def setRawHTML(self, html):
class DisplayHTMLBlock(DisplayHTMLRaw):
def __init__(self, title=''):
super(DisplayHTMLBlock, self).__init__(html='')
def __init__(self, iwla, title=''):
super(DisplayHTMLBlock, self).__init__(iwla, html='')
self.title = title
self.cssclass = u'iwla_block'
self.title_cssclass = u'iwla_block_title'
class DisplayHTMLBlockTable(DisplayHTMLBlock):
def __init__(self, title, cols):
super(DisplayHTMLBlockTable, self).__init__(title=title)
def __init__(self, iwla, title, cols):
super(DisplayHTMLBlockTable, self).__init__(iwla=iwla, title=title)
self.cols = listToStr(cols)
self.rows = []
self.cols_cssclasses = [u''] * len(cols)
class DisplayHTMLBlockTableWithGraph(DisplayHTMLBlockTable):
def __init__(self, title, cols, short_titles=None, nb_valid_rows=0, graph_cols=None):
super(DisplayHTMLBlockTableWithGraph, self).__init__(title=title, cols=cols)
def __init__(self, iwla, title, cols, short_titles=None, nb_valid_rows=0, graph_cols=None):
super(DisplayHTMLBlockTableWithGraph, self).__init__(iwla=iwla, title=title, cols=cols)
self.short_titles = short_titles or []
self.short_titles = listToStr(self.short_titles)
self.nb_valid_rows = nb_valid_rows
# TOFIX
self.icon_path = u'/resources/icon'
# self.icon_path = self.iwla.getConfValue('icon_path', '/')
self.icon_path = self.iwla.getConfValue('icon_path', '/')
self.raw_rows = []
self.maxes = [0] * len(cols)
self.table_graph_css = u'iwla_graph_table'
elif style.startswith(u'iwla_visit'): icon = u'vv.png'
else: return ''
return u'%s/%s' % (self.icon_path, icon)
return u'/%s/%s' % (self.icon_path, icon)
def _buildHTML(self):
self._computeMax()
class DisplayHTMLPage(object):
def __init__(self, title, filename, css_path):
def __init__(self, iwla, title, filename, css_path):
self.iwla = iwla
self.title = unicode(title)
self.filename = filename
self.blocks = []
f.write(u'</head>')
for block in self.blocks:
block.build(f)
f.write(u'<center>Generated by <a href="%s">IWLA %s</a></center>' %
("http://indefero.soutade.fr/p/iwla", self.iwla.getVersion()))
f.write(u'</body></html>')
f.close()
self.pages = []
self.iwla = iwla
def createPage(self, *args):
return DisplayHTMLPage(self.iwla, *args)
def createBlock(self, _class, *args):
return _class(self.iwla, *args)
def getPage(self, filename):
for page in self.pages:
if page.getFilename() == filename:
iwla.py
2424
2525
2626
27
2728
2829
2930
......
4445
4546
4647
48
49
50
4751
4852
4953
......
242246
243247
244248
245
249
246250
247251
248
252
249253
250254
251255
......
300304
301305
302306
303
307
304308
305309
306310
......
336340
337341
338342
339
343
340344
341345
342
346
343347
344348
345349
ANALYSIS_CLASS = 'HTTP'
API_VERSION = 1
IWLA_VERSION = '0.1'
def __init__(self):
print '==> Start'
(conf.POST_HOOK_DIRECTORY , conf.post_analysis_hooks),
(conf.DISPLAY_HOOK_DIRECTORY , conf.display_hooks)]
def getVersion(self):
return IWLA.IWLA_VERSION
def getConfValue(self, key, default=None):
if not key in dir(conf):
return default
title = 'Stats %d/%d' % (cur_time.tm_mon, cur_time.tm_year)
filename = self.getCurDisplayPath('index.html')
print '==> Generate display (%s)' % (filename)
page = DisplayHTMLPage(title, filename, conf.css_path)
page = self.display.createPage(title, filename, conf.css_path)
_, nb_month_days = monthrange(cur_time.tm_year, cur_time.tm_mon)
days = DisplayHTMLBlockTableWithGraph('By day', ['Day', 'Visitors', 'Pages', 'Hits', 'Bandwidth', 'Not viewed Bandwidth'], nb_valid_rows=nb_month_days, graph_cols=range(1,6))
days = self.display.createBlock(DisplayHTMLBlockTableWithGraph, 'By day', ['Day', 'Visitors', 'Pages', 'Hits', 'Bandwidth', 'Not viewed Bandwidth'], None, nb_month_days, range(1,6))
days.setColsCSSClass(['', 'iwla_visitor', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', 'iwla_bandwidth'])
nb_visits = 0
nb_days = 0
title = 'Summary %d' % (year)
cols = ['Month', 'Visitors', 'Pages', 'Hits', 'Bandwidth', 'Not viewed Bandwidth', 'Details']
graph_cols=range(1,6)
months = DisplayHTMLBlockTableWithGraph(title, cols, nb_valid_rows=12, graph_cols=graph_cols)
months = self.display.createBlock(DisplayHTMLBlockTableWithGraph, title, cols, None, 12, graph_cols)
months.setColsCSSClass(['', 'iwla_visitor', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', 'iwla_bandwidth', ''])
total = [0] * len(cols)
for i in range(1, 13):
filename = 'index.html'
print '==> Generate main page (%s)' % (filename)
page = DisplayHTMLPage(title, filename, conf.css_path)
page = self.display.createPage(title, filename, conf.css_path)
last_update = '<b>Last update</b> %s<br />' % (time.strftime('%d %b %Y %H:%M', time.localtime()))
page.appendBlock(DisplayHTMLRaw(last_update))
page.appendBlock(self.display.createBlock(DisplayHTMLRaw, last_update))
for year in self.meta_infos['stats'].keys():
self._generateDisplayMonthStats(page, year, self.meta_infos['stats'][year])
plugins/display/all_visits.py
1010
1111
1212
13
1314
1415
1516
......
2021
2122
2223
23
24
24
25
2526
2627
2728
......
4041
4142
4243
43
4444
4545
4646
......
4949
5050
5151
52
52
5353
5454
self.API_VERSION = 1
def hook(self):
display = self.iwla.getDisplay()
hits = self.iwla.getValidVisitors()
display_visitor_ip = self.iwla.getConfValue('display_visitor_ip', False)
filename = 'all_visits.html'
path = self.iwla.getCurDisplayPath(filename)
page = DisplayHTMLPage(title, path, self.iwla.getConfValue('css_path', []))
table = DisplayHTMLBlockTable('Last seen', ['Host', 'Pages', 'Hits', 'Bandwidth', 'Last seen'])
page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
table = display.createBlock(DisplayHTMLBlockTable, 'Last seen', ['Host', 'Pages', 'Hits', 'Bandwidth', 'Last seen'])
table.setColsCSSClass(['', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', ''])
for super_hit in last_access:
table.appendRow(row)
page.appendBlock(table)
display = self.iwla.getDisplay()
display.addPage(page)
index = self.iwla.getDisplayIndex()
if block:
block.setTitle('%s - %s' % (block.getTitle(), link))
else:
block = DisplayHTMLRawBlock()
block = display.createBlock(DisplayHTMLRawBlock)
block.setRawHTML(link)
index.appendBlock(block)
plugins/display/referers.py
1111
1212
1313
14
1415
1516
1617
......
3839
3940
4041
41
42
42
43
4344
4445
4546
......
6869
6970
7071
71
7272
7373
7474
......
7676
7777
7878
79
79
8080
8181
8282
......
121121
122122
123123
124
125
124
125
126126
127127
128128
......
135135
136136
137137
138
138
139139
140140
141141
self.requires = ['IWLAPostAnalysisReferers']
def hook(self):
display = self.iwla.getDisplay()
month_stats = self.iwla.getMonthStats()
referers = month_stats.get('referers', {})
robots_referers = month_stats.get('robots_referers', {})
filename = 'referers.html'
path = self.iwla.getCurDisplayPath(filename)
page = DisplayHTMLPage(title, path, self.iwla.getConfValue('css_path', []))
table = DisplayHTMLBlockTable('Connexion from', ['Origin', 'Pages', 'Hits'])
page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
table = display.createBlock(DisplayHTMLBlockTable, 'Connexion from', ['Origin', 'Pages', 'Hits'])
table.setColsCSSClass(['', 'iwla_page', 'iwla_hit'])
total_search = [0]*3
page.appendBlock(table)
display = self.iwla.getDisplay()
display.addPage(page)
link = '<a href=\'%s\'>All referers</a>' % (filename)
# Top referers in index
title = '%s - %s' % ('Connexion from', link)
table = DisplayHTMLBlockTable(title, ['Origin', 'Pages', 'Hits'])
table = display.createBlock(DisplayHTMLBlockTable, title, ['Origin', 'Pages', 'Hits'])
table.setColsCSSClass(['', 'iwla_page', 'iwla_hit'])
table.appendRow(['<b>Search Engine</b>', '', ''])
path = self.iwla.getCurDisplayPath(filename)
total_search = [0]*2
page = DisplayHTMLPage(title, path, self.iwla.getConfValue('css_path', []))
table = DisplayHTMLBlockTable('Top key phrases', ['Key phrase', 'Search'])
page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
table = display.createBlock(DisplayHTMLBlockTable, 'Top key phrases', ['Key phrase', 'Search'])
table.setColsCSSClass(['', 'iwla_search'])
for phrase in top_key_phrases:
table.appendRow([phrase[0], phrase[1]])
# Top key phrases in index
title = '%s - %s' % ('Top key phrases', link)
table = DisplayHTMLBlockTable(title, ['Key phrase', 'Search'])
table = display.createBlock(DisplayHTMLBlockTable, title, ['Key phrase', 'Search'])
table.setColsCSSClass(['', 'iwla_search'])
for phrase in top_key_phrases[:10]:
table.appendRow([phrase[0], phrase[1]])
plugins/display/top_downloads.py
1111
1212
1313
14
1415
1516
1617
......
1920
2021
2122
22
23
23
24
2425
2526
2627
......
2930
3031
3132
32
33
3334
3435
3536
......
3738
3839
3940
40
41
4142
4243
4344
self.requires = ['IWLAPostAnalysisTopDownloads']
def hook(self):
display = self.iwla.getDisplay()
top_downloads = self.iwla.getMonthStats()['top_downloads']
top_downloads = sorted(top_downloads.items(), key=lambda t: t[1], reverse=True)
path = self.iwla.getCurDisplayPath(filename)
title = time.strftime('All Downloads - %B %Y', self.iwla.getCurTime())
page = DisplayHTMLPage(title, path, self.iwla.getConfValue('css_path', []))
table = DisplayHTMLBlockTable('All Downloads', ['URI', 'Hit'])
page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
table = display.createBlock(DisplayHTMLBlockTable, 'All Downloads', ['URI', 'Hit'])
table.setColsCSSClass(['', 'iwla_hit'])
total_entrance = [0]*2
total_entrance[1] += entrance
page.appendBlock(table)
self.iwla.getDisplay().addPage(page)
display.addPage(page)
link = '<a href=\'%s\'>All Downloads</a>' % (filename)
title = '%s - %s' % ('Top Downloads', link)
# Top in index
index = self.iwla.getDisplayIndex()
table = DisplayHTMLBlockTable(title, ['URI', 'Hits'])
table = display.createBlock(DisplayHTMLBlockTable, title, ['URI', 'Hits'])
table.setColsCSSClass(['', 'iwla_hit'])
for (uri, entrance) in top_downloads[:10]:
table.appendRow([generateHTMLLink(uri), entrance])
plugins/display/top_hits.py
1111
1212
1313
14
1415
1516
1617
......
1920
2021
2122
22
23
23
24
2425
2526
2627
......
2829
2930
3031
31
32
3233
3334
3435
......
3637
3738
3839
39
40
4041
4142
4243
self.requires = ['IWLAPostAnalysisTopHits']
def hook(self):
display = self.iwla.getDisplay()
top_hits = self.iwla.getMonthStats()['top_hits']
top_hits = sorted(top_hits.items(), key=lambda t: t[1], reverse=True)
filename = 'top_hits.html'
path = self.iwla.getCurDisplayPath(filename)
page = DisplayHTMLPage(title, path, self.iwla.getConfValue('css_path', []))
table = DisplayHTMLBlockTable('All Hits', ['URI', 'Entrance'])
page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
table = display.createBlock(DisplayHTMLBlockTable, 'All Hits', ['URI', 'Entrance'])
table.setColsCSSClass(['', 'iwla_hit'])
total_hits = [0]*2
for (uri, entrance) in top_hits:
total_hits[1] += entrance
page.appendBlock(table)
self.iwla.getDisplay().addPage(page)
display.addPage(page)
link = '<a href=\'%s\'>All hits</a>' % (filename)
title = '%s - %s' % ('Top Hits', link)
# Top in index
index = self.iwla.getDisplayIndex()
table = DisplayHTMLBlockTable(title, ['URI', 'Entrance'])
table = display.createBlock(DisplayHTMLBlockTable, title, ['URI', 'Entrance'])
table.setColsCSSClass(['', 'iwla_hit'])
for (uri, entrance) in top_hits[:10]:
table.appendRow([generateHTMLLink(uri), entrance])
plugins/display/top_pages.py
1111
1212
1313
14
1415
1516
1617
......
1920
2021
2122
22
23
23
24
2425
2526
2627
......
2829
2930
3031
31
32
3233
3334
3435
......
3637
3738
3839
39
40
4041
4142
4243
self.requires = ['IWLAPostAnalysisTopPages']
def hook(self):
display = self.iwla.getDisplay()
top_pages = self.iwla.getMonthStats()['top_pages']
top_pages = sorted(top_pages.items(), key=lambda t: t[1], reverse=True)
filename = 'top_pages.html'
path = self.iwla.getCurDisplayPath(filename)
page = DisplayHTMLPage(title, path, self.iwla.getConfValue('css_path', []))
table = DisplayHTMLBlockTable('All Pages', ['URI', 'Entrance'])
page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
table = display.createBlock(DisplayHTMLBlockTable, 'All Pages', ['URI', 'Entrance'])
table.setColsCSSClass(['', 'iwla_hit'])
total_hits = [0]*2
for (uri, entrance) in top_pages:
total_hits[1] += entrance
page.appendBlock(table)
self.iwla.getDisplay().addPage(page)
display.addPage(page)
link = '<a href=\'%s\'>All pages</a>' % (filename)
title = '%s - %s' % ('Top Pages', link)
# Top in index
index = self.iwla.getDisplayIndex()
table = DisplayHTMLBlockTable(title, ['URI', 'Entrance'])
table = display.createBlock(DisplayHTMLBlockTable, title, ['URI', 'Entrance'])
table.setColsCSSClass(['', 'iwla_hit'])
for (uri, entrance) in top_pages[:10]:
table.appendRow([generateHTMLLink(uri), entrance])
plugins/display/top_visitors.py
1111
1212
1313
14
1415
1516
1617
......
2425
2526
2627
27
28
2829
2930
3031
def hook(self):
hits = self.iwla.getValidVisitors()
display = self.iwla.getDisplay()
display_visitor_ip = self.iwla.getConfValue('display_visitor_ip', False)
total = [0]*5
top_visitors = [hits[h[0]] for h in top_bandwidth[:10]]
index = self.iwla.getDisplayIndex()
table = DisplayHTMLBlockTable('Top visitors', ['Host', 'Pages', 'Hits', 'Bandwidth', 'Last seen'])
table = display.createBlock(DisplayHTMLBlockTable, 'Top visitors', ['Host', 'Pages', 'Hits', 'Bandwidth', 'Last seen'])
table.setColsCSSClass(['', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', ''])
for super_hit in top_visitors:
address = super_hit['remote_addr']

Archive Download the corresponding diff file

Branches

Tags