Add max_x_displayed and create_x_page parameters for most display plugins

This commit is contained in:
Grégory Soutadé 2014-12-11 21:13:24 +01:00
parent 2df258676c
commit e012dc1b24
6 changed files with 140 additions and 93 deletions

View File

@ -1,5 +1,6 @@
import os import os
import codecs import codecs
import time
# #
# Create output HTML files # Create output HTML files
@ -21,8 +22,14 @@ class DisplayHTMLRaw(object):
if html: f.write(html) if html: f.write(html)
def build(self, f): def build(self, f):
# t1 = time.time()
self._buildHTML() self._buildHTML()
# t2 = time.time()
# print 'Time for _buildHTML : %d seconds' % (t2-t1)
# t1 = time.time()
self._build(f, self.html) self._build(f, self.html)
# t2 = time.time()
# print 'Time for _build : %d seconds' % (t2-t1)
class DisplayHTMLBlock(DisplayHTMLRaw): class DisplayHTMLBlock(DisplayHTMLRaw):
@ -312,7 +319,9 @@ class DisplayHTMLBuild(object):
os.symlink(target, link_name) os.symlink(target, link_name)
for page in self.pages: for page in self.pages:
print 'Build %s' % (page.filename)
page.build(root) page.build(root)
print 'Built'
# #
# Global functions # Global functions

View File

@ -13,7 +13,10 @@ from display import *
# post_analysis/referers # post_analysis/referers
# #
# Conf values needed : # Conf values needed :
# None # max_referers_displayed*
# create_all_referers_page*
# max_key_phrases_displayed*
# create_all_key_phrases_page*
# #
# Output files : # Output files :
# OUTPUT_ROOT/year/month/referers.html # OUTPUT_ROOT/year/month/referers.html
@ -35,6 +38,10 @@ class IWLADisplayReferers(IPlugin):
super(IWLADisplayReferers, self).__init__(iwla) super(IWLADisplayReferers, self).__init__(iwla)
self.API_VERSION = 1 self.API_VERSION = 1
self.requires = ['IWLAPostAnalysisReferers'] 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): def hook(self):
display = self.iwla.getDisplay() display = self.iwla.getDisplay()
@ -60,6 +67,7 @@ class IWLADisplayReferers(IPlugin):
index = self.iwla.getDisplayIndex() index = self.iwla.getDisplayIndex()
# All referers in a file # All referers in a file
if self.create_all_referers:
title = time.strftime('Connexion from - %B %Y', cur_time) title = time.strftime('Connexion from - %B %Y', cur_time)
filename = 'referers.html' filename = 'referers.html'
@ -71,7 +79,8 @@ class IWLADisplayReferers(IPlugin):
total_search = [0]*3 total_search = [0]*3
table.appendRow(['<b>Search Engine</b>', '', '']) table.appendRow(['<b>Search Engine</b>', '', ''])
for r,_ in top_search_engine_referers: 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']] row = [r, search_engine_referers[r]['pages'], search_engine_referers[r]['hits']]
total_search[1] += search_engine_referers[r]['pages'] total_search[1] += search_engine_referers[r]['pages']
total_search[2] += search_engine_referers[r]['hits'] total_search[2] += search_engine_referers[r]['hits']
@ -79,7 +88,8 @@ class IWLADisplayReferers(IPlugin):
total_external = [0]*3 total_external = [0]*3
table.appendRow(['<b>External URL</b>', '', '']) table.appendRow(['<b>External URL</b>', '', ''])
for r,_ in top_referers: 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']] row = [generateHTMLLink(r), referers[r]['pages'], referers[r]['hits']]
total_external[1] += referers[r]['pages'] total_external[1] += referers[r]['pages']
total_external[2] += referers[r]['hits'] total_external[2] += referers[r]['hits']
@ -87,7 +97,8 @@ class IWLADisplayReferers(IPlugin):
total_robot = [0]*3 total_robot = [0]*3
table.appendRow(['<b>External URL (robot)</b>', '', '']) table.appendRow(['<b>External URL (robot)</b>', '', ''])
for r,_ in top_robots_referers: 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']] row = [generateHTMLLink(r), robots_referers[r]['pages'], robots_referers[r]['hits']]
total_robot[1] += robots_referers[r]['pages'] total_robot[1] += robots_referers[r]['pages']
total_robot[2] += robots_referers[r]['hits'] total_robot[2] += robots_referers[r]['hits']
@ -97,11 +108,12 @@ class IWLADisplayReferers(IPlugin):
display.addPage(page) display.addPage(page)
link = '<a href=\'%s\'>All referers</a>' % (filename) 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 # Top referers in index
title = '%s - %s' % ('Connexion from', link)
table = display.createBlock(DisplayHTMLBlockTable, title, ['Origin', 'Pages', 'Hits']) table = display.createBlock(DisplayHTMLBlockTable, title, ['Origin', 'Pages', 'Hits'])
table.setColsCSSClass(['', 'iwla_page', 'iwla_hit']) table.setColsCSSClass(['', 'iwla_page', 'iwla_hit'])
@ -141,6 +153,7 @@ class IWLADisplayReferers(IPlugin):
index.appendBlock(table) index.appendBlock(table)
# All key phrases in a file # All key phrases in a file
if self.create_all_key_phrases:
title = time.strftime('Key Phrases - %B %Y', cur_time) title = time.strftime('Key Phrases - %B %Y', cur_time)
filename = 'key_phrases.html' filename = 'key_phrases.html'
@ -150,17 +163,20 @@ class IWLADisplayReferers(IPlugin):
page = display.createPage(title, path, self.iwla.getConfValue('css_path', [])) page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
table = display.createBlock(DisplayHTMLBlockTable, 'Top key phrases', ['Key phrase', 'Search']) table = display.createBlock(DisplayHTMLBlockTable, 'Top key phrases', ['Key phrase', 'Search'])
table.setColsCSSClass(['', 'iwla_search']) table.setColsCSSClass(['', 'iwla_search'])
for phrase in top_key_phrases: 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]]) table.appendRow([phrase[0], phrase[1]])
total_search[1] += phrase[1] total_search[1] += phrase[1]
page.appendBlock(table) page.appendBlock(table)
display.addPage(page) display.addPage(page)
title = 'Top key phrases'
if self.create_all_key_phrases:
link = '<a href=\'%s\'>All key phrases</a>' % (filename) link = '<a href=\'%s\'>All key phrases</a>' % (filename)
title = '%s - %s' % (title, link)
# Top key phrases in index # Top key phrases in index
title = '%s - %s' % ('Top key phrases', link)
table = display.createBlock(DisplayHTMLBlockTable, title, ['Key phrase', 'Search']) table = display.createBlock(DisplayHTMLBlockTable, title, ['Key phrase', 'Search'])
table.setColsCSSClass(['', 'iwla_search']) table.setColsCSSClass(['', 'iwla_search'])
for phrase in top_key_phrases[:10]: for phrase in top_key_phrases[:10]:

View File

@ -13,7 +13,8 @@ from display import *
# post_analysis/top_downloads # post_analysis/top_downloads
# #
# Conf values needed : # Conf values needed :
# None # max_downloads_displayed*
# create_all_downloads_page*
# #
# Output files : # Output files :
# OUTPUT_ROOT/year/month/top_downloads.html # OUTPUT_ROOT/year/month/top_downloads.html
@ -34,6 +35,8 @@ class IWLADisplayTopDownloads(IPlugin):
super(IWLADisplayTopDownloads, self).__init__(iwla) super(IWLADisplayTopDownloads, self).__init__(iwla)
self.API_VERSION = 1 self.API_VERSION = 1
self.requires = ['IWLAPostAnalysisTopDownloads'] 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): def hook(self):
display = self.iwla.getDisplay() display = self.iwla.getDisplay()
@ -41,6 +44,7 @@ class IWLADisplayTopDownloads(IPlugin):
top_downloads = sorted(top_downloads.items(), key=lambda t: t[1], reverse=True) top_downloads = sorted(top_downloads.items(), key=lambda t: t[1], reverse=True)
# All in a file # All in a file
if self.create_all_downloads:
filename = 'top_downloads.html' filename = 'top_downloads.html'
path = self.iwla.getCurDisplayPath(filename) path = self.iwla.getCurDisplayPath(filename)
title = time.strftime('All Downloads - %B %Y', self.iwla.getCurTime()) title = time.strftime('All Downloads - %B %Y', self.iwla.getCurTime())
@ -50,15 +54,18 @@ class IWLADisplayTopDownloads(IPlugin):
table.setColsCSSClass(['', 'iwla_hit']) table.setColsCSSClass(['', 'iwla_hit'])
total_entrance = [0]*2 total_entrance = [0]*2
for (uri, entrance) in top_downloads: 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]) table.appendRow([generateHTMLLink(uri), entrance])
total_entrance[1] += entrance total_entrance[1] += entrance
page.appendBlock(table) page.appendBlock(table)
display.addPage(page) display.addPage(page)
title = 'Top Downloads'
if self.create_all_downloads:
link = '<a href=\'%s\'>All Downloads</a>' % (filename) link = '<a href=\'%s\'>All Downloads</a>' % (filename)
title = '%s - %s' % ('Top Downloads', link) title = '%s - %s' % (title, link)
# Top in index # Top in index
index = self.iwla.getDisplayIndex() index = self.iwla.getDisplayIndex()

View File

@ -13,7 +13,8 @@ from display import *
# post_analysis/top_hits # post_analysis/top_hits
# #
# Conf values needed : # Conf values needed :
# None # max_hits_displayed*
# create_all_hits_page*
# #
# Output files : # Output files :
# OUTPUT_ROOT/year/month/top_hits.html # OUTPUT_ROOT/year/month/top_hits.html
@ -34,6 +35,8 @@ class IWLADisplayTopHits(IPlugin):
super(IWLADisplayTopHits, self).__init__(iwla) super(IWLADisplayTopHits, self).__init__(iwla)
self.API_VERSION = 1 self.API_VERSION = 1
self.requires = ['IWLAPostAnalysisTopHits'] 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): def hook(self):
display = self.iwla.getDisplay() display = self.iwla.getDisplay()
@ -41,6 +44,7 @@ class IWLADisplayTopHits(IPlugin):
top_hits = sorted(top_hits.items(), key=lambda t: t[1], reverse=True) top_hits = sorted(top_hits.items(), key=lambda t: t[1], reverse=True)
# All in a file # All in a file
if self.create_all_hits:
title = time.strftime('All Hits - %B %Y', self.iwla.getCurTime()) title = time.strftime('All Hits - %B %Y', self.iwla.getCurTime())
filename = 'top_hits.html' filename = 'top_hits.html'
path = self.iwla.getCurDisplayPath(filename) path = self.iwla.getCurDisplayPath(filename)
@ -49,15 +53,18 @@ class IWLADisplayTopHits(IPlugin):
table = display.createBlock(DisplayHTMLBlockTable, 'All Hits', ['URI', 'Entrance']) table = display.createBlock(DisplayHTMLBlockTable, 'All Hits', ['URI', 'Entrance'])
table.setColsCSSClass(['', 'iwla_hit']) table.setColsCSSClass(['', 'iwla_hit'])
total_hits = [0]*2 total_hits = [0]*2
for (uri, entrance) in top_hits: 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]) table.appendRow([generateHTMLLink(uri), entrance])
total_hits[1] += entrance total_hits[1] += entrance
page.appendBlock(table) page.appendBlock(table)
display.addPage(page) display.addPage(page)
link = '<a href=\'%s\'>All hits</a>' % (filename) title = 'Top Hits'
title = '%s - %s' % ('Top Hits', link) if self.create_all_hits:
link = '<a href=\'%s\'>All Hits</a>' % (filename)
title = '%s - %s' % (title, link)
# Top in index # Top in index
index = self.iwla.getDisplayIndex() index = self.iwla.getDisplayIndex()

View File

@ -13,7 +13,8 @@ from display import *
# post_analysis/top_pages # post_analysis/top_pages
# #
# Conf values needed : # Conf values needed :
# None # max_pages_displayed*
# create_all_pages_page*
# #
# Output files : # Output files :
# OUTPUT_ROOT/year/month/top_pages.html # OUTPUT_ROOT/year/month/top_pages.html
@ -34,6 +35,8 @@ class IWLADisplayTopPages(IPlugin):
super(IWLADisplayTopPages, self).__init__(iwla) super(IWLADisplayTopPages, self).__init__(iwla)
self.API_VERSION = 1 self.API_VERSION = 1
self.requires = ['IWLAPostAnalysisTopPages'] 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): def hook(self):
display = self.iwla.getDisplay() display = self.iwla.getDisplay()
@ -41,6 +44,7 @@ class IWLADisplayTopPages(IPlugin):
top_pages = sorted(top_pages.items(), key=lambda t: t[1], reverse=True) top_pages = sorted(top_pages.items(), key=lambda t: t[1], reverse=True)
# All in a page # All in a page
if self.create_all_pages:
title = time.strftime('All Pages - %B %Y', self.iwla.getCurTime()) title = time.strftime('All Pages - %B %Y', self.iwla.getCurTime())
filename = 'top_pages.html' filename = 'top_pages.html'
path = self.iwla.getCurDisplayPath(filename) path = self.iwla.getCurDisplayPath(filename)
@ -49,15 +53,18 @@ class IWLADisplayTopPages(IPlugin):
table = display.createBlock(DisplayHTMLBlockTable, 'All Pages', ['URI', 'Entrance']) table = display.createBlock(DisplayHTMLBlockTable, 'All Pages', ['URI', 'Entrance'])
table.setColsCSSClass(['', 'iwla_hit']) table.setColsCSSClass(['', 'iwla_hit'])
total_hits = [0]*2 total_hits = [0]*2
for (uri, entrance) in top_pages: 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]) table.appendRow([generateHTMLLink(uri), entrance])
total_hits[1] += entrance total_hits[1] += entrance
page.appendBlock(table) page.appendBlock(table)
display.addPage(page) display.addPage(page)
link = '<a href=\'%s\'>All pages</a>' % (filename) title = 'Top Pages'
title = '%s - %s' % ('Top Pages', link) if self.create_all_pages:
link = '<a href=\'%s\'>All Pages</a>' % (filename)
title = '%s - %s' % (title, link)
# Top in index # Top in index
index = self.iwla.getDisplayIndex() index = self.iwla.getDisplayIndex()

View File

@ -27,6 +27,7 @@ from display import *
# Statistics deletion : # Statistics deletion :
# None # None
# #
class IWLADisplayTopVisitors(IPlugin): class IWLADisplayTopVisitors(IPlugin):
def __init__(self, iwla): def __init__(self, iwla):
super(IWLADisplayTopVisitors, self).__init__(iwla) super(IWLADisplayTopVisitors, self).__init__(iwla)