diff --git a/display.py b/display.py index 99cf33e..ed5546f 100644 --- a/display.py +++ b/display.py @@ -1,5 +1,6 @@ import os import codecs +import time # # Create output HTML files @@ -21,8 +22,14 @@ class DisplayHTMLRaw(object): 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): @@ -312,7 +319,9 @@ class DisplayHTMLBuild(object): os.symlink(target, link_name) for page in self.pages: + print 'Build %s' % (page.filename) page.build(root) + print 'Built' # # Global functions diff --git a/plugins/display/referers.py b/plugins/display/referers.py index c2c2105..6bdb043 100644 --- a/plugins/display/referers.py +++ b/plugins/display/referers.py @@ -13,7 +13,10 @@ from display import * # 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 @@ -35,6 +38,10 @@ class IWLADisplayReferers(IPlugin): 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() @@ -60,48 +67,53 @@ class IWLADisplayReferers(IPlugin): index = self.iwla.getDisplayIndex() # All referers in a file - title = time.strftime('Connexion from - %B %Y', cur_time) + if self.create_all_referers: + title = time.strftime('Connexion from - %B %Y', cur_time) - filename = 'referers.html' - path = self.iwla.getCurDisplayPath(filename) + 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']) + 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(['Search Engine', '', '']) - 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_search = [0]*3 + table.appendRow(['Search Engine', '', '']) + 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(['External URL', '', '']) - 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_external = [0]*3 + table.appendRow(['External URL', '', '']) + 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(['External URL (robot)', '', '']) - 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) + total_robot = [0]*3 + table.appendRow(['External URL (robot)', '', '']) + 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) + page.appendBlock(table) - display.addPage(page) + display.addPage(page) - link = 'All referers' % (filename) + title = 'Top Referers' + if self.create_all_referers: + link = 'All Referers' % (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']) @@ -141,26 +153,30 @@ class IWLADisplayReferers(IPlugin): 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 = 'All key phrases' % (filename) + title = 'Top key phrases' + if self.create_all_key_phrases: + link = 'All key phrases' % (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]: diff --git a/plugins/display/top_downloads.py b/plugins/display/top_downloads.py index c2351bd..97d7f4a 100644 --- a/plugins/display/top_downloads.py +++ b/plugins/display/top_downloads.py @@ -13,7 +13,8 @@ from display import * # post_analysis/top_downloads # # Conf values needed : -# None +# max_downloads_displayed* +# create_all_downloads_page* # # Output files : # OUTPUT_ROOT/year/month/top_downloads.html @@ -34,6 +35,8 @@ class IWLADisplayTopDownloads(IPlugin): 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() @@ -41,24 +44,28 @@ class IWLADisplayTopDownloads(IPlugin): 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 = 'All Downloads' % (filename) - title = '%s - %s' % ('Top Downloads', link) + title = 'Top Downloads' + if self.create_all_downloads: + link = 'All Downloads' % (filename) + title = '%s - %s' % (title, link) # Top in index index = self.iwla.getDisplayIndex() diff --git a/plugins/display/top_hits.py b/plugins/display/top_hits.py index f4c27c8..bf9496d 100644 --- a/plugins/display/top_hits.py +++ b/plugins/display/top_hits.py @@ -13,7 +13,8 @@ from display import * # post_analysis/top_hits # # Conf values needed : -# None +# max_hits_displayed* +# create_all_hits_page* # # Output files : # OUTPUT_ROOT/year/month/top_hits.html @@ -34,6 +35,8 @@ class IWLADisplayTopHits(IPlugin): 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() @@ -41,23 +44,27 @@ class IWLADisplayTopHits(IPlugin): 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 = 'All hits' % (filename) - title = '%s - %s' % ('Top Hits', link) + title = 'Top Hits' + if self.create_all_hits: + link = 'All Hits' % (filename) + title = '%s - %s' % (title, link) # Top in index index = self.iwla.getDisplayIndex() diff --git a/plugins/display/top_pages.py b/plugins/display/top_pages.py index 30ee110..b41ef43 100644 --- a/plugins/display/top_pages.py +++ b/plugins/display/top_pages.py @@ -13,7 +13,8 @@ from display import * # post_analysis/top_pages # # Conf values needed : -# None +# max_pages_displayed* +# create_all_pages_page* # # Output files : # OUTPUT_ROOT/year/month/top_pages.html @@ -34,6 +35,8 @@ class IWLADisplayTopPages(IPlugin): 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() @@ -41,23 +44,27 @@ class IWLADisplayTopPages(IPlugin): 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) - link = 'All pages' % (filename) - title = '%s - %s' % ('Top Pages', link) + display.addPage(page) + + title = 'Top Pages' + if self.create_all_pages: + link = 'All Pages' % (filename) + title = '%s - %s' % (title, link) # Top in index index = self.iwla.getDisplayIndex() diff --git a/plugins/display/top_visitors.py b/plugins/display/top_visitors.py index b501009..4562980 100644 --- a/plugins/display/top_visitors.py +++ b/plugins/display/top_visitors.py @@ -27,6 +27,7 @@ from display import * # Statistics deletion : # None # + class IWLADisplayTopVisitors(IPlugin): def __init__(self, iwla): super(IWLADisplayTopVisitors, self).__init__(iwla)