89 lines
3.1 KiB
Python
89 lines
3.1 KiB
Python
|
# -*- 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)
|