iwla

iwla Git Source Tree

Root/plugins/display/hours_stats.py

1# -*- coding: utf-8 -*-
2#
3# Copyright Grégory Soutadé 2015
4
5# This file is part of iwla
6
7# iwla is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# iwla is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with iwla. If not, see <http://www.gnu.org/licenses/>.
19#
20
21from iwla import IWLA
22from iplugin import IPlugin
23from display import *
24
25"""
26Display hook
27
28Display statistics by hour/week day
29
30Plugin requirements :
31 post_analysis/hours_stats
32
33Conf values needed :
34 None
35
36Output files :
37 OUTPUT_ROOT/year/month/index.html
38
39Statistics creation :
40 None
41
42Statistics update :
43 None
44
45Statistics deletion :
46 None
47"""
48
49class IWLADisplayHoursStats(IPlugin):
50 def __init__(self, iwla):
51 super(IWLADisplayHoursStats, self).__init__(iwla)
52 self.API_VERSION = 1
53 self.requires = ['IWLAPostAnalysisHoursStats']
54
55 def hook(self):
56 display = self.iwla.getDisplay()
57 month_stats = self.iwla.getMonthStats()
58
59 hours_stats = month_stats.get('hours_stats', {})
60 if not hours_stats:
61 for i in range(0, 24):
62 hours_stats[i] = {'pages':0, 'hits':0, 'bandwidth':0}
63 days_stats = month_stats.get('days_stats', {})
64 if not days_stats:
65 for i in range(0, 7):
66 days_stats[i] = {'pages':0, 'hits':0, 'bandwidth':0}
67
68 index = self.iwla.getDisplayIndex()
69
70 # By Day
71 title = self.iwla._(u'By day')
72 days = [self.iwla._('Mon'), self.iwla._('Tue'), self.iwla._('Wed'), self.iwla._('Thu'), self.iwla._('Fri'), self.iwla._('Sat'), self.iwla._('Sun')]
73 table = display.createBlock(DisplayHTMLBlockTableWithGraph, title, [self.iwla._('Day'), self.iwla._('Pages'), self.iwla._('Hits'), self.iwla._('Bandwidth')], days, 7, range(1,4), [3])
74 table.setColsCSSClass(['', 'iwla_page', 'iwla_hit', 'iwla_bandwidth'])
75 for i in range(0,7):
76 table.appendRow([days[i], days_stats[i]['pages'], days_stats[i]['hits'], days_stats[i]['bandwidth']])
77 table.setCellValue(i, 3, days_stats[i]['bandwidth'])
78 index.appendBlock(table)
79
80 # By Hours
81 title = self.iwla._(u'By Hours')
82 hours = ['%02d' % i for i in range(0, 24)]
83 table = display.createBlock(DisplayHTMLBlockTableWithGraph, title, [self.iwla._('Hours'), self.iwla._('Pages'), self.iwla._('Hits'), self.iwla._('Bandwidth')], hours, 24, range(1,4), [3])
84 table.setColsCSSClass(['', 'iwla_page', 'iwla_hit', 'iwla_bandwidth'])
85 for i in range(0,24):
86 table.appendRow([hours[i], hours_stats[i]['pages'], hours_stats[i]['hits'], hours_stats[i]['bandwidth']])
87 table.setCellValue(i, 3, hours_stats[i]['bandwidth'])
88 index.appendBlock(table)

Archive Download this file

Branches

Tags