iwla

iwla Commit Details

Date:2014-12-28 18:07:57 (6 years 6 months ago)
Author:Grégory Soutadé
Commit:7cb91ec00e84abb16908edb0313ea8a278a58f16
Parents: 8393e7ea20a7a1c86873f67f06b6984129717b93
Message:Add generic interface istats_diff

Changes:
Aplugins/display/istats_diff.py (full)
Mplugins/display/referers.py (1 diff)
Mplugins/display/referers_diff.py (2 diffs)

File differences

plugins/display/istats_diff.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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
# -*- coding: utf-8 -*-
#
# Copyright Grégory Soutadé 2015
# This file is part of iwla
# iwla is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# iwla is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with iwla. If not, see <http://www.gnu.org/licenses/>.
#
from iwla import IWLA
from iplugin import IPlugin
from display import *
import logging
"""
Display hook itnerface
Enlight new and updated statistics
Plugin requirements :
None
Conf values needed :
None
Output files :
None
Statistics creation :
None
Statistics update :
None
Statistics deletion :
None
"""
class IWLADisplayStatsDiff(IPlugin):
def __init__(self, iwla):
super(IWLADisplayStatsDiff, self).__init__(iwla)
self.API_VERSION = 1
self.month_stats_key = None
# Set >= if month_stats[self.month_stats_key] is a list or a tuple
self.stats_index = -1
self.filename = None
self.block_name = None
self.logger = logging.getLogger(__name__)
def load(self):
if not self.month_stats_key or not self.filename or\
not self.block_name:
self.logger('Bad parametrization')
return False
month_stats = self.iwla.getMonthStats()
self.cur_stats = {k:v for (k,v) in month_stats.get(self.month_stats_key, {}).items()}
return True
def hook(self):
display = self.iwla.getDisplay()
month_stats = self.iwla.getMonthStats()
path = self.iwla.getCurDisplayPath(self.filename)
page = display.getPage(path)
if not page: return
title = self.iwla._(self.block_name)
block = page.getBlock(title)
if not block:
self.logger.error('Block %s not found' % (title))
return
stats_diff = {}
for (k, v) in month_stats[self.month_stats_key].items():
new_value = self.cur_stats.get(k, 0)
if new_value:
if self.stats_index != -1:
if new_value[self.stats_index] != v[self.stats_index]:
stats_diff[k] = 'iwla_update'
else:
if new_value != v:
stats_diff[k] = 'iwla_update'
else:
stats_diff[k] = 'iwla_new'
for (idx, row) in enumerate(block.rows):
if row[0] in stats_diff.keys():
block.setCellCSSClass(idx, 0, stats_diff[row[0]])
plugins/display/referers.py
197197
198198
199199
200
200
201201
202202
203203
total_search = [0]*2
page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
table = display.createBlock(DisplayHTMLBlockTable, self.iwla._(u'All key phrases'), [self.iwla._(u'Key phrase'), self.iwla._(u'Search')])
table = display.createBlock(DisplayHTMLBlockTable, self.iwla._(u'Key phrases'), [self.iwla._(u'Key phrase'), self.iwla._(u'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:
plugins/display/referers_diff.py
1919
2020
2121
22
22
2323
2424
2525
......
4646
4747
4848
49
49
5050
5151
5252
5353
54
55
56
5457
5558
5659
5760
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
61
#
from iwla import IWLA
from iplugin import IPlugin
from istats_diff import IWLADisplayStatsDiff
from display import *
"""
None
"""
class IWLADisplayReferersDiff(IPlugin):
class IWLADisplayReferersDiff(IWLADisplayStatsDiff):
def __init__(self, iwla):
super(IWLADisplayReferersDiff, self).__init__(iwla)
self.API_VERSION = 1
self.requires = ['IWLADisplayReferers']
self.month_stats_key = 'key_phrases'
self.filename = 'key_phrases.html'
self.block_name = u'Key phrases'
def load(self):
if not self.iwla.getConfValue('create_all_key_phrases_page', True):
return False
month_stats = self.iwla.getMonthStats()
self.cur_key_phrases = {k:v for (k,v) in month_stats.get('key_phrases', {}).items()}
return True
def hook(self):
display = self.iwla.getDisplay()
month_stats = self.iwla.getMonthStats()
filename = 'key_phrases.html'
path = self.iwla.getCurDisplayPath(filename)
page = display.getPage(path)
if not page: return
title = self.iwla._(u'Key phrases')
referers_block = page.getBlock(title)
kp_diff = {}
for (k, v) in month_stats['key_phrases'].items():
new_value = self.cur_key_phrases.get(k, 0)
if new_value:
if new_value != v:
kp_diff[k] = 'iwla_update'
else:
kp_diff[k] = 'iwla_new'
for (idx, row) in enumerate(referers_block.rows):
if row[0] in kp_diff.keys():
referers_block.setCellCSSClass(idx, 0, kp_diff[row[0]])
return super(IWLADisplayReferersDiff, self).load()

Archive Download the corresponding diff file

Branches

Tags