iwla

iwla Commit Details

Date:2015-03-02 19:44:10 (6 years 4 months ago)
Author:Grégory Soutadé
Branch:dev, master
Commit:f853ad808e19ba07452c0578ebb3177becf5f2fb
Parents: b563609b2482e15322c4a5af79d8f2e3f62f2a99
Message:Add hours_stats plugin

Changes:
Cplugins/post_analysis/top_pages.py → plugins/post_analysis/hours_stats.py
Aplugins/display/hours_stats.py (full)

File differences

plugins/display/hours_stats.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
# -*- 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 *
"""
Display hook
Display statistics by hour/week day
Plugin requirements :
post_analysis/hours_stats
Conf values needed :
None
Output files :
OUTPUT_ROOT/year/month/index.html
Statistics creation :
None
Statistics update :
None
Statistics deletion :
None
"""
class IWLADisplayHoursStats(IPlugin):
def __init__(self, iwla):
super(IWLADisplayHoursStats, self).__init__(iwla)
self.API_VERSION = 1
self.requires = ['IWLAPostAnalysisHoursStats']
def hook(self):
display = self.iwla.getDisplay()
month_stats = self.iwla.getMonthStats()
hours_stats = month_stats.get('hours_stats', {})
if not hours_stats:
for i in range(0, 24):
hours_stats[i] = {'pages':0, 'hits':0, 'bandwidth':0}
days_stats = month_stats.get('days_stats', {})
if not days_stats:
for i in range(0, 7):
days_stats[i] = {'pages':0, 'hits':0, 'bandwidth':0}
index = self.iwla.getDisplayIndex()
# By Day
title = self.iwla._(u'By day')
days = [self.iwla._('Mon'), self.iwla._('Tue'), self.iwla._('Wed'), self.iwla._('Thu'), self.iwla._('Fri'), self.iwla._('Sat'), self.iwla._('Sun')]
table = display.createBlock(DisplayHTMLBlockTableWithGraph, title, [self.iwla._('Day'), self.iwla._('Pages'), self.iwla._('Hits'), self.iwla._('Bandwidth')], days, 7, range(1,4))
table.setColsCSSClass(['', 'iwla_page', 'iwla_hit', 'iwla_bandwidth'])
for i in range(0,7):
table.appendRow([days[i], days_stats[i]['pages'], days_stats[i]['hits'], days_stats[i]['bandwidth']])
table.setCellValue(i, 3, bytesToStr(days_stats[i]['bandwidth']))
index.appendBlock(table)
# By Hours
title = self.iwla._(u'By Hours')
hours = ['%02d' % i for i in range(0, 24)]
table = display.createBlock(DisplayHTMLBlockTableWithGraph, title, [self.iwla._('Hours'), self.iwla._('Pages'), self.iwla._('Hits'), self.iwla._('Bandwidth')], hours, 24, range(1,4))
table.setColsCSSClass(['', 'iwla_page', 'iwla_hit', 'iwla_bandwidth'])
for i in range(0,24):
table.appendRow([hours[i], hours_stats[i]['pages'], hours_stats[i]['hits'], hours_stats[i]['bandwidth']])
table.setCellValue(i, 3, bytesToStr(hours_stats[i]['bandwidth']))
index.appendBlock(table)
plugins/post_analysis/hours_stats.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
# -*- 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
"""
Post analysis hook
Count pages, hits and bandwidth by hour/week day
Plugin requirements :
None
Conf values needed :
None
Output files :
None
Statistics creation :
month_stats:
hours_stats =>
00 .. 23 =>
pages
hits
bandwidth
days_stats =>
0 .. 6 =>
pages
hits
bandwidth
Statistics update :
None
Statistics deletion :
None
"""
class IWLAPostAnalysisHoursStats(IPlugin):
def __init__(self, iwla):
super(IWLAPostAnalysisHoursStats, self).__init__(iwla)
self.API_VERSION = 1
def hook(self):
stats = self.iwla.getCurrentVisists()
month_stats = self.iwla.getMonthStats()
hours_stats = month_stats.get('hours_stats', {})
if not hours_stats:
for i in range(0, 24):
hours_stats[i] = {'pages':0, 'hits':0, 'bandwidth':0}
days_stats = month_stats.get('days_stats', {})
if not days_stats:
for i in range(0, 7):
days_stats[i] = {'pages':0, 'hits':0, 'bandwidth':0}
for super_hit in stats.values():
if super_hit['robot']: continue
for r in super_hit['requests'][::-1]:
if not self.iwla.isValidForCurrentAnalysis(r):
break
if not self.iwla.hasBeenViewed(r): continue
key = r['is_page'] and 'pages' or 'hits'
t = r['time_decoded']
hours_stats[t.tm_hour][key] += 1
hours_stats[t.tm_hour]['bandwidth'] += int(r['body_bytes_sent'])
days_stats[t.tm_wday][key] += 1
days_stats[t.tm_wday]['bandwidth'] += int(r['body_bytes_sent'])
month_stats['hours_stats'] = hours_stats
month_stats['days_stats'] = days_stats

Archive Download the corresponding diff file

Branches

Tags