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,48 +67,53 @@ class IWLADisplayReferers(IPlugin):
index = self.iwla.getDisplayIndex() index = self.iwla.getDisplayIndex()
# All referers in a file # 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' filename = 'referers.html'
path = self.iwla.getCurDisplayPath(filename) path = self.iwla.getCurDisplayPath(filename)
page = display.createPage(title, path, self.iwla.getConfValue('css_path', [])) page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
table = display.createBlock(DisplayHTMLBlockTable, 'Connexion from', ['Origin', 'Pages', 'Hits']) table = display.createBlock(DisplayHTMLBlockTable, 'Connexion from', ['Origin', 'Pages', 'Hits'])
table.setColsCSSClass(['', 'iwla_page', 'iwla_hit']) table.setColsCSSClass(['', 'iwla_page', 'iwla_hit'])
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
row = [r, search_engine_referers[r]['pages'], search_engine_referers[r]['hits']] for r,_ in new_list:
total_search[1] += search_engine_referers[r]['pages'] row = [r, search_engine_referers[r]['pages'], search_engine_referers[r]['hits']]
total_search[2] += search_engine_referers[r]['hits'] total_search[1] += search_engine_referers[r]['pages']
table.appendRow(row) total_search[2] += search_engine_referers[r]['hits']
table.appendRow(row)
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
row = [generateHTMLLink(r), referers[r]['pages'], referers[r]['hits']] for r,_ in new_list:
total_external[1] += referers[r]['pages'] row = [generateHTMLLink(r), referers[r]['pages'], referers[r]['hits']]
total_external[2] += referers[r]['hits'] total_external[1] += referers[r]['pages']
table.appendRow(row) total_external[2] += referers[r]['hits']
table.appendRow(row)
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
row = [generateHTMLLink(r), robots_referers[r]['pages'], robots_referers[r]['hits']] for r,_ in new_list:
total_robot[1] += robots_referers[r]['pages'] row = [generateHTMLLink(r), robots_referers[r]['pages'], robots_referers[r]['hits']]
total_robot[2] += robots_referers[r]['hits'] total_robot[1] += robots_referers[r]['pages']
table.appendRow(row) total_robot[2] += robots_referers[r]['hits']
table.appendRow(row)
page.appendBlock(table) page.appendBlock(table)
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,26 +153,30 @@ class IWLADisplayReferers(IPlugin):
index.appendBlock(table) index.appendBlock(table)
# All key phrases in a file # 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' filename = 'key_phrases.html'
path = self.iwla.getCurDisplayPath(filename) path = self.iwla.getCurDisplayPath(filename)
total_search = [0]*2 total_search = [0]*2
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
table.appendRow([phrase[0], phrase[1]]) for phrase in new_list:
total_search[1] += phrase[1] table.appendRow([phrase[0], phrase[1]])
page.appendBlock(table) 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 # 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,24 +44,28 @@ 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
filename = 'top_downloads.html' if self.create_all_downloads:
path = self.iwla.getCurDisplayPath(filename) filename = 'top_downloads.html'
title = time.strftime('All Downloads - %B %Y', self.iwla.getCurTime()) 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', [])) page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
table = display.createBlock(DisplayHTMLBlockTable, 'All Downloads', ['URI', 'Hit']) table = display.createBlock(DisplayHTMLBlockTable, 'All Downloads', ['URI', 'Hit'])
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
table.appendRow([generateHTMLLink(uri), entrance]) for (uri, entrance) in new_list:
total_entrance[1] += entrance table.appendRow([generateHTMLLink(uri), entrance])
page.appendBlock(table) total_entrance[1] += entrance
page.appendBlock(table)
display.addPage(page) display.addPage(page)
link = '<a href=\'%s\'>All Downloads</a>' % (filename) title = 'Top Downloads'
title = '%s - %s' % ('Top Downloads', link) if self.create_all_downloads:
link = '<a href=\'%s\'>All Downloads</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_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,23 +44,27 @@ 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
title = time.strftime('All Hits - %B %Y', self.iwla.getCurTime()) if self.create_all_hits:
filename = 'top_hits.html' title = time.strftime('All Hits - %B %Y', self.iwla.getCurTime())
path = self.iwla.getCurDisplayPath(filename) filename = 'top_hits.html'
path = self.iwla.getCurDisplayPath(filename)
page = display.createPage(title, path, self.iwla.getConfValue('css_path', [])) page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
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
table.appendRow([generateHTMLLink(uri), entrance]) for (uri, entrance) in new_list:
total_hits[1] += entrance table.appendRow([generateHTMLLink(uri), entrance])
page.appendBlock(table) total_hits[1] += entrance
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,23 +44,27 @@ 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
title = time.strftime('All Pages - %B %Y', self.iwla.getCurTime()) if self.create_all_pages:
filename = 'top_pages.html' title = time.strftime('All Pages - %B %Y', self.iwla.getCurTime())
path = self.iwla.getCurDisplayPath(filename) filename = 'top_pages.html'
path = self.iwla.getCurDisplayPath(filename)
page = display.createPage(title, path, self.iwla.getConfValue('css_path', [])) page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
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
table.appendRow([generateHTMLLink(uri), entrance]) for (uri, entrance) in new_list:
total_hits[1] += entrance table.appendRow([generateHTMLLink(uri), entrance])
page.appendBlock(table) total_hits[1] += entrance
page.appendBlock(table)
display.addPage(page)
link = '<a href=\'%s\'>All pages</a>' % (filename) display.addPage(page)
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 # 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)