iwla

iwla Commit Details

Date:2014-12-31 14:22:46 (6 years 6 months ago)
Author:Grégory Soutadé
Branch:dev, master
Commit:f1fb8cb674e5cb0931f79a051cc35df415d5daab
Parents: a17bbbccf888f7160fe61da914c4b88827b73d74
Message:Merge with origin:dev

Changes:
A.gitignore (full)
AChangeLog (full)
Aplugins/display/istats_diff.py (full)
Mconf.py (1 diff)
Mdisplay.py (3 diffs)
Miwla.py (6 diffs)
Mplugins/display/referers.py (1 diff)
Mplugins/display/referers_diff.py (2 diffs)
Mresources/css/iwla.css (2 diffs)
Mtools/extract_doc.py (1 diff)

File differences

.gitignore
1
2
3
*~
*.pyc
*.gz
ChangeLog
1
2
3
4
5
6
7
8
9
10
v0.2 (31/12/2014)
** User **
Add referers_diff display plugin
Add year statistics in month details
** Dev **
Add istats_diff interface
** Bugs **
Forgot <body> tag
conf.py
1919
2020
2121
22
22
2323
2424
2525
# Count this addresses as hit
page_to_hit_conf = [r'^.+/logo[/]?$']
# Count this addresses as page
hit_to_page_conf = [r'^.+/category/.+$', r'^.+/tag/.+$', r'^.+/archive/.+$', r'^.+/ljdc[/]?$']
hit_to_page_conf = [r'^.+/category/.+$', r'^.+/tag/.+$', r'^.+/archive/.+$', r'^.+/ljdc[/]?$', r'^.+/source/tree/.*$']
# Because it's too long to build HTML when there is too much entries
max_hits_displayed = 100
display.py
5252
5353
5454
55
56
57
5558
5659
5760
......
287290
288291
289292
290
293
291294
292295
293296
......
305308
306309
307310
308
311
309312
310313
311
312
314
315
316
313317
314318
315319
self._buildHTML()
self._build(f, self.html)
def getTitle(self):
return ''
class DisplayHTMLBlock(DisplayHTMLRaw):
def __init__(self, iwla, title=''):
def appendBlock(self, block):
self.blocks.append(block)
def build(self, root):
def build(self, root, displayVersion=True):
filename = os.path.join(root, self.filename)
base = os.path.dirname(filename)
f.write(u'<link rel="stylesheet" href="/%s"/>' % (css))
if self.title:
f.write(u'<title>%s</title>' % (self.title))
f.write(u'</head>')
f.write(u'</head><body>')
for block in self.blocks:
block.build(f)
f.write(u'<center>Generated by <a href="%s">IWLA %s</a></center>' %
("http://indefero.soutade.fr/p/iwla", self.iwla.getVersion()))
if displayVersion:
f.write(u'<center>Generated by <a href="%s">IWLA %s</a></center>' %
("http://indefero.soutade.fr/p/iwla", self.iwla.getVersion()))
f.write(u'</body></html>')
f.close()
iwla.py
5959
6060
6161
62
6263
6364
6465
......
129130
130131
131132
132
133
133134
134135
135136
......
371372
372373
373374
375
376
374377
375378
376379
......
430433
431434
432435
436
437
433438
434439
435440
......
447452
448453
449454
455
456
457
458
450459
451460
452461
453462
454463
464
455465
456466
457467
......
460470
461471
462472
473
474
475
476
477
478
463479
464480
465481
DB_ROOT/meta.db
DB_ROOT/year/month/iwla.db
OUTPUT_ROOT/index.html
OUTPUT_ROOT/year/_stats.html
OUTPUT_ROOT/year/month/index.html
Statistics creation :
ANALYSIS_CLASS = 'HTTP'
API_VERSION = 1
IWLA_VERSION = '0.1'
IWLA_VERSION = '0.2-dev'
def __init__(self, logLevel):
self.meta_infos = {}
filename = self.getCurDisplayPath('index.html')
self.logger.info('==> Generate display (%s)' % (filename))
page = self.display.createPage(title, filename, conf.css_path)
link = DisplayHTMLRaw(self, '<iframe src="../_stats.html"></iframe>')
page.appendBlock(link)
_, nb_month_days = monthrange(cur_time.tm_year, cur_time.tm_mon)
days = self.display.createBlock(DisplayHTMLBlockTableWithGraph, self._('By day'), [self._('Day'), self._('Visits'), self._('Pages'), self._('Hits'), self._('Bandwidth'), self._('Not viewed Bandwidth')], None, nb_month_days, range(1,6))
graph_cols=range(1,7)
months = self.display.createBlock(DisplayHTMLBlockTableWithGraph, title, cols, None, 12, graph_cols)
months.setColsCSSClass(['', 'iwla_visitor', 'iwla_visit', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', 'iwla_bandwidth', ''])
months_ = self.display.createBlock(DisplayHTMLBlockTableWithGraph, title, cols[:-1], None, 12, graph_cols[:-1])
months_.setColsCSSClass(['', 'iwla_visitor', 'iwla_visit', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', 'iwla_bandwidth'])
total = [0] * len(cols)
for i in range(1, 13):
month = '%s<br/>%d' % (months_name[i], year)
months.setCellValue(i-1, 5, bytesToStr(row[5]))
months.setCellValue(i-1, 6, bytesToStr(row[6]))
months.appendShortTitle(month)
months_.appendRow(row[:-1])
months_.setCellValue(i-1, 5, bytesToStr(row[5]))
months_.setCellValue(i-1, 6, bytesToStr(row[6]))
months_.appendShortTitle(month)
if year == cur_time.tm_year and i == cur_time.tm_mon:
css = months.getCellCSSClass(i-1, 0)
if css: css = '%s %s' % (css, 'iwla_curday')
else: css = 'iwla_curday'
months.setCellCSSClass(i-1, 0, css)
months_.setCellCSSClass(i-1, 0, css)
total[0] = self._('Total')
total[5] = bytesToStr(total[5])
months.appendRow(total)
page.appendBlock(months)
months_.appendRow(total[:-1])
filename = '%d/_stats.html' % (year)
page_ = self.display.createPage(u'', filename, conf.css_path)
page_.appendBlock(months_)
page_.build(conf.DISPLAY_ROOT, False)
def _generateDisplayWholeMonthStats(self):
title = '%s %s' % (self._('Statistics for'), conf.domain_name)
filename = 'index.html'
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
190190
191191
192192
193
193
194194
195195
196196
197197
198198
199199
200
200
201201
202202
203203
# All key phrases in a file
if self.create_all_key_phrases:
title = createCurTitle(self.iwla, u'Key Phrases')
title = createCurTitle(self.iwla, u'All Key Phrases')
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, self.iwla._(u'Top 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', {})}
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'All 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()
resources/css/iwla.css
6969
7070
7171
72
73
74
7275
7376
7477
......
8588
8689
8790
91
92
.iwla_weekend { background : #ECECEC; }
.iwla_curday { font-weight: bold; }
.iwla_others { color: #668; }
.iwla_update { background : orange; }
.iwla_new { background : green }
.iwla_graph_table
{
margin-left:auto;
{
text-align:center;
}
iframe {outline:none; border:0px; width:100%; height:500px; display:block;}
tools/extract_doc.py
22
33
44
5
6
57
68
79
810
911
12
13
14
15
16
1017
1118
1219
import sys
excludes = ['istats_diff.py']
filename = sys.argv[1]
if filename.endswith('__init__.py'):
sys.exit(0)
for e in excludes:
if filename.endswith(e):
sys.stderr.write('\tSkip %s\n' % (filename))
sys.exit(0)
package_name = filename.replace('/', '.').replace('.py', '')
sys.stdout.write('%s' % (package_name))
sys.stdout.write('\n')

Archive Download the corresponding diff file

Branches

Tags