iwla

iwla Commit Details

Date:2014-12-11 21:13:24 (6 years 7 months ago)
Author:Grégory Soutadé
Branch:dev, master
Commit:e012dc1b24fb49d83c06ffc8171115f2f990e72b
Parents: 2df258676c69759a76680e6b523db43e62d58709
Message:Add max_x_displayed and create_x_page parameters for most display plugins

Changes:
Mdisplay.py (3 diffs)
Mplugins/display/referers.py (4 diffs)
Mplugins/display/top_downloads.py (3 diffs)
Mplugins/display/top_hits.py (3 diffs)
Mplugins/display/top_pages.py (3 diffs)
Mplugins/display/top_visitors.py (1 diff)

File differences

display.py
11
22
3
34
45
56
......
2122
2223
2324
25
2426
27
28
29
2530
31
32
2633
2734
2835
......
312319
313320
314321
322
315323
324
316325
317326
318327
import os
import codecs
import time
#
# Create output HTML files
if html: f.write(html)
def build(self, f):
# t1 = time.time()
self._buildHTML()
# t2 = time.time()
# print 'Time for _buildHTML : %d seconds' % (t2-t1)
# t1 = time.time()
self._build(f, self.html)
# t2 = time.time()
# print 'Time for _build : %d seconds' % (t2-t1)
class DisplayHTMLBlock(DisplayHTMLRaw):
os.symlink(target, link_name)
for page in self.pages:
print 'Build %s' % (page.filename)
page.build(root)
print 'Built'
#
# Global functions
plugins/display/referers.py
1313
1414
1515
16
16
17
18
19
1720
1821
1922
......
3538
3639
3740
41
42
43
44
3845
3946
4047
......
6067
6168
6269
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
101115
102116
103
104
105117
106118
107119
......
141153
142154
143155
144
156
157
145158
146
147
159
160
148161
149
150
151
152
153
154
155
156
162
163
164
165
166
167
168
169
170
157171
158
172
159173
160
174
175
176
177
161178
162179
163
164180
165181
166182
# post_analysis/referers
#
# Conf values needed :
# None
# max_referers_displayed*
# create_all_referers_page*
# max_key_phrases_displayed*
# create_all_key_phrases_page*
#
# Output files :
# OUTPUT_ROOT/year/month/referers.html
super(IWLADisplayReferers, self).__init__(iwla)
self.API_VERSION = 1
self.requires = ['IWLAPostAnalysisReferers']
self.max_referers = self.iwla.getConfValue('max_referers_displayed', 0)
self.create_all_referers = self.iwla.getConfValue('create_all_referers_page', True)
self.max_key_phrases = self.iwla.getConfValue('max_key_phrases_displayed', 0)
self.create_all_key_phrases = self.iwla.getConfValue('create_all_key_phrases_page', True)
def hook(self):
display = self.iwla.getDisplay()
index = self.iwla.getDisplayIndex()
# All referers in a file
title = time.strftime('Connexion from - %B %Y', cur_time)
filename = 'referers.html'
path = self.iwla.getCurDisplayPath(filename)
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
table.appendRow(['<b>Search Engine</b>', '', ''])
for r,_ in top_search_engine_referers:
row = [r, search_engine_referers[r]['pages'], search_engine_referers[r]['hits']]
total_search[1] += search_engine_referers[r]['pages']
total_search[2] += search_engine_referers[r]['hits']
table.appendRow(row)
total_external = [0]*3
table.appendRow(['<b>External URL</b>', '', ''])
for r,_ in top_referers:
row = [generateHTMLLink(r), referers[r]['pages'], referers[r]['hits']]
total_external[1] += referers[r]['pages']
total_external[2] += referers[r]['hits']
table.appendRow(row)
total_robot = [0]*3
table.appendRow(['<b>External URL (robot)</b>', '', ''])
for r,_ in top_robots_referers:
row = [generateHTMLLink(r), robots_referers[r]['pages'], robots_referers[r]['hits']]
total_robot[1] += robots_referers[r]['pages']
total_robot[2] += robots_referers[r]['hits']
table.appendRow(row)
page.appendBlock(table)
display.addPage(page)
link = '<a href=\'%s\'>All referers</a>' % (filename)
if self.create_all_referers:
title = time.strftime('Connexion from - %B %Y', cur_time)
filename = 'referers.html'
path = self.iwla.getCurDisplayPath(filename)
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
table.appendRow(['<b>Search Engine</b>', '', ''])
new_list = self.max_referers and top_search_engine_referers[:self.max_referers] or top_search_engine_referers
for r,_ in new_list:
row = [r, search_engine_referers[r]['pages'], search_engine_referers[r]['hits']]
total_search[1] += search_engine_referers[r]['pages']
total_search[2] += search_engine_referers[r]['hits']
table.appendRow(row)
total_external = [0]*3
table.appendRow(['<b>External URL</b>', '', ''])
new_list = self.max_referers and top_referers[:self.max_referers] or top_referers
for r,_ in new_list:
row = [generateHTMLLink(r), referers[r]['pages'], referers[r]['hits']]
total_external[1] += referers[r]['pages']
total_external[2] += referers[r]['hits']
table.appendRow(row)
total_robot = [0]*3
table.appendRow(['<b>External URL (robot)</b>', '', ''])
new_list = self.max_referers and top_robots_referers[:self.max_referers] or top_robots_referers
for r,_ in new_list:
row = [generateHTMLLink(r), robots_referers[r]['pages'], robots_referers[r]['hits']]
total_robot[1] += robots_referers[r]['pages']
total_robot[2] += robots_referers[r]['hits']
table.appendRow(row)
page.appendBlock(table)
display.addPage(page)
title = 'Top Referers'
if self.create_all_referers:
link = '<a href=\'%s\'>All Referers</a>' % (filename)
title = '%s - %s' % (title, link)
# Top referers in index
title = '%s - %s' % ('Connexion from', link)
table = display.createBlock(DisplayHTMLBlockTable, title, ['Origin', 'Pages', 'Hits'])
table.setColsCSSClass(['', 'iwla_page', 'iwla_hit'])
index.appendBlock(table)
# All key phrases in a file
title = time.strftime('Key Phrases - %B %Y', cur_time)
if self.create_all_key_phrases:
title = time.strftime('Key Phrases - %B %Y', cur_time)
filename = 'key_phrases.html'
path = self.iwla.getCurDisplayPath(filename)
filename = 'key_phrases.html'
path = self.iwla.getCurDisplayPath(filename)
total_search = [0]*2
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]])
total_search[1] += phrase[1]
page.appendBlock(table)
total_search = [0]*2
page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
table = display.createBlock(DisplayHTMLBlockTable, 'Top key phrases', ['Key phrase', 'Search'])
table.setColsCSSClass(['', 'iwla_search'])
new_list = self.max_key_phrases and top_key_phrases[:self.max_key_phrases] or top_key_phrases
for phrase in new_list:
table.appendRow([phrase[0], phrase[1]])
total_search[1] += phrase[1]
page.appendBlock(table)
display.addPage(page)
display.addPage(page)
link = '<a href=\'%s\'>All key phrases</a>' % (filename)
title = 'Top key phrases'
if self.create_all_key_phrases:
link = '<a href=\'%s\'>All key phrases</a>' % (filename)
title = '%s - %s' % (title, link)
# Top key phrases in index
title = '%s - %s' % ('Top key phrases', link)
table = display.createBlock(DisplayHTMLBlockTable, title, ['Key phrase', 'Search'])
table.setColsCSSClass(['', 'iwla_search'])
for phrase in top_key_phrases[:10]:
plugins/display/top_downloads.py
1313
1414
1515
16
16
17
1718
1819
1920
......
3435
3536
3637
38
39
3740
3841
3942
......
4144
4245
4346
44
45
46
47
48
49
50
4751
48
49
50
52
53
54
5155
52
53
54
55
56
56
57
58
59
60
61
5762
58
63
5964
60
61
65
66
67
68
6269
6370
6471
# post_analysis/top_downloads
#
# Conf values needed :
# None
# max_downloads_displayed*
# create_all_downloads_page*
#
# Output files :
# OUTPUT_ROOT/year/month/top_downloads.html
super(IWLADisplayTopDownloads, self).__init__(iwla)
self.API_VERSION = 1
self.requires = ['IWLAPostAnalysisTopDownloads']
self.max_downloads = self.iwla.getConfValue('max_downloads_displayed', 0)
self.create_all_downloads = self.iwla.getConfValue('create_all_downloads_page', True)
def hook(self):
display = self.iwla.getDisplay()
top_downloads = sorted(top_downloads.items(), key=lambda t: t[1], reverse=True)
# All in a file
filename = 'top_downloads.html'
path = self.iwla.getCurDisplayPath(filename)
title = time.strftime('All Downloads - %B %Y', self.iwla.getCurTime())
if self.create_all_downloads:
filename = 'top_downloads.html'
path = self.iwla.getCurDisplayPath(filename)
title = time.strftime('All Downloads - %B %Y', self.iwla.getCurTime())
page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
table = display.createBlock(DisplayHTMLBlockTable, 'All Downloads', ['URI', 'Hit'])
table.setColsCSSClass(['', 'iwla_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
for (uri, entrance) in top_downloads:
table.appendRow([generateHTMLLink(uri), entrance])
total_entrance[1] += entrance
page.appendBlock(table)
total_entrance = [0]*2
new_list = self.max_downloads and top_downloads[:self.max_downloads] or top_downloads
for (uri, entrance) in new_list:
table.appendRow([generateHTMLLink(uri), entrance])
total_entrance[1] += entrance
page.appendBlock(table)
display.addPage(page)
display.addPage(page)
link = '<a href=\'%s\'>All Downloads</a>' % (filename)
title = '%s - %s' % ('Top Downloads', link)
title = 'Top Downloads'
if self.create_all_downloads:
link = '<a href=\'%s\'>All Downloads</a>' % (filename)
title = '%s - %s' % (title, link)
# Top in index
index = self.iwla.getDisplayIndex()
plugins/display/top_hits.py
1313
1414
1515
16
16
17
1718
1819
1920
......
3435
3536
3637
38
39
3740
3841
3942
......
4144
4245
4346
44
45
46
47
48
49
50
4751
48
49
50
51
52
53
54
55
52
53
54
55
56
57
58
59
60
5661
57
62
5863
59
60
64
65
66
67
6168
6269
6370
# post_analysis/top_hits
#
# Conf values needed :
# None
# max_hits_displayed*
# create_all_hits_page*
#
# Output files :
# OUTPUT_ROOT/year/month/top_hits.html
super(IWLADisplayTopHits, self).__init__(iwla)
self.API_VERSION = 1
self.requires = ['IWLAPostAnalysisTopHits']
self.max_hits = self.iwla.getConfValue('max_hits_displayed', 0)
self.create_all_hits = self.iwla.getConfValue('create_all_hits_page', True)
def hook(self):
display = self.iwla.getDisplay()
top_hits = sorted(top_hits.items(), key=lambda t: t[1], reverse=True)
# All in a file
title = time.strftime('All Hits - %B %Y', self.iwla.getCurTime())
filename = 'top_hits.html'
path = self.iwla.getCurDisplayPath(filename)
if self.create_all_hits:
title = time.strftime('All Hits - %B %Y', self.iwla.getCurTime())
filename = 'top_hits.html'
path = self.iwla.getCurDisplayPath(filename)
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:
table.appendRow([generateHTMLLink(uri), entrance])
total_hits[1] += entrance
page.appendBlock(table)
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
new_list = self.max_hits and top_hits[:self.max_hits] or top_hits
for (uri, entrance) in new_list:
table.appendRow([generateHTMLLink(uri), entrance])
total_hits[1] += entrance
page.appendBlock(table)
display.addPage(page)
display.addPage(page)
link = '<a href=\'%s\'>All hits</a>' % (filename)
title = '%s - %s' % ('Top Hits', link)
title = 'Top Hits'
if self.create_all_hits:
link = '<a href=\'%s\'>All Hits</a>' % (filename)
title = '%s - %s' % (title, link)
# Top in index
index = self.iwla.getDisplayIndex()
plugins/display/top_pages.py
1313
1414
1515
16
16
17
1718
1819
1920
......
3435
3536
3637
38
39
3740
3841
3942
......
4144
4245
4346
44
45
46
47
48
49
50
4751
48
49
50
51
52
53
54
55
56
57
52
53
54
55
56
57
58
59
60
61
62
5863
59
60
64
65
66
67
6168
6269
6370
# post_analysis/top_pages
#
# Conf values needed :
# None
# max_pages_displayed*
# create_all_pages_page*
#
# Output files :
# OUTPUT_ROOT/year/month/top_pages.html
super(IWLADisplayTopPages, self).__init__(iwla)
self.API_VERSION = 1
self.requires = ['IWLAPostAnalysisTopPages']
self.max_pages = self.iwla.getConfValue('max_pages_displayed', 0)
self.create_all_pages = self.iwla.getConfValue('create_all_pages_page', True)
def hook(self):
display = self.iwla.getDisplay()
top_pages = sorted(top_pages.items(), key=lambda t: t[1], reverse=True)
# All in a page
title = time.strftime('All Pages - %B %Y', self.iwla.getCurTime())
filename = 'top_pages.html'
path = self.iwla.getCurDisplayPath(filename)
if self.create_all_pages:
title = time.strftime('All Pages - %B %Y', self.iwla.getCurTime())
filename = 'top_pages.html'
path = self.iwla.getCurDisplayPath(filename)
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:
table.appendRow([generateHTMLLink(uri), entrance])
total_hits[1] += entrance
page.appendBlock(table)
display.addPage(page)
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
new_list = self.max_pages and top_pages[:self.max_pages] or top_pages
for (uri, entrance) in new_list:
table.appendRow([generateHTMLLink(uri), entrance])
total_hits[1] += entrance
page.appendBlock(table)
display.addPage(page)
link = '<a href=\'%s\'>All pages</a>' % (filename)
title = '%s - %s' % ('Top Pages', link)
title = 'Top Pages'
if self.create_all_pages:
link = '<a href=\'%s\'>All Pages</a>' % (filename)
title = '%s - %s' % (title, link)
# Top in index
index = self.iwla.getDisplayIndex()
plugins/display/top_visitors.py
2727
2828
2929
30
3031
3132
3233
# Statistics deletion :
# None
#
class IWLADisplayTopVisitors(IPlugin):
def __init__(self, iwla):
super(IWLADisplayTopVisitors, self).__init__(iwla)

Archive Download the corresponding diff file

Branches

Tags