forked from shaba/openuds
Fixed another report (removed pycha)
This commit is contained in:
parent
51cc23b223
commit
1406b036f7
@ -26,6 +26,10 @@
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
@ -56,10 +60,43 @@ def barChart(size, data, output):
|
||||
axis.set_xlabel(data['xlabel'])
|
||||
axis.set_ylabel(data['ylabel'])
|
||||
|
||||
axis.set_xticks(ind)
|
||||
axis.set_xticklabels([data['xtickFnc'](v) for v in axis.get_xticks()])
|
||||
if data.get('allTicks', True) is True:
|
||||
axis.set_xticks(ind)
|
||||
|
||||
if 'xtickFnc' in data:
|
||||
axis.set_xticklabels([data['xtickFnc'](v) for v in axis.get_xticks()])
|
||||
|
||||
axis.legend()
|
||||
FigureCanvas(fig) # Stores canvas on fig.canvas
|
||||
|
||||
canvas = FigureCanvas(fig)
|
||||
canvas.print_png(output)
|
||||
fig.savefig(output, format='png', transparent=True)
|
||||
|
||||
|
||||
def lineChart(size, data, output):
|
||||
x = data['x']
|
||||
y = data['y']
|
||||
|
||||
fig = Figure(figsize=(size[0], size[1]), dpi=size[2])
|
||||
|
||||
axis = fig.add_subplot(111)
|
||||
axis.grid(color='r', linestyle='dotted', linewidth=0.1, alpha=0.5)
|
||||
|
||||
for i in y:
|
||||
yy = i['data']
|
||||
axis.plot(x, yy, label=i.get('label'), marker='.', color='orange')
|
||||
axis.fill_between(x, yy, 0)
|
||||
|
||||
axis.set_title(data.get('title', ''))
|
||||
axis.set_xlabel(data['xlabel'])
|
||||
axis.set_ylabel(data['ylabel'])
|
||||
|
||||
if data.get('allTicks', True) is True:
|
||||
axis.set_xticks(x)
|
||||
|
||||
if 'xtickFnc' in data:
|
||||
axis.set_xticklabels([data['xtickFnc'](v) for v in axis.get_xticks()])
|
||||
|
||||
axis.legend()
|
||||
FigureCanvas(fig) # Stores canvas on fig.canvas
|
||||
|
||||
fig.savefig(output, format='png', transparent=True)
|
||||
|
@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#
|
||||
# Copyright (c) 2015 Virtual Cable S.L.
|
||||
# Copyright (c) 2015-2018 Virtual Cable S.L.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
@ -30,8 +30,6 @@
|
||||
"""
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import io
|
||||
import csv
|
||||
import datetime
|
||||
@ -57,6 +55,7 @@ __updated__ = '2018-04-24'
|
||||
|
||||
# several constants as Width height, margins, ..
|
||||
WIDTH, HEIGHT, DPI = 19.2, 10.8, 100
|
||||
SIZE = (WIDTH, HEIGHT, DPI)
|
||||
|
||||
|
||||
class PoolPerformanceReport(StatsReport):
|
||||
@ -186,7 +185,6 @@ class PoolPerformanceReport(StatsReport):
|
||||
def generate(self):
|
||||
# Generate the sampling intervals and get dataUsers from db
|
||||
xLabelFormat, poolsData, reportData = self.getRangeData()
|
||||
size = (WIDTH, HEIGHT, DPI)
|
||||
|
||||
graph1 = io.BytesIO()
|
||||
graph2 = io.BytesIO()
|
||||
@ -197,7 +195,7 @@ class PoolPerformanceReport(StatsReport):
|
||||
|
||||
X = [v[0] for v in poolsData[0]['dataUsers']]
|
||||
data = {
|
||||
'title': 'Distinct Users',
|
||||
'title': _('Distinct Users'),
|
||||
'x': X,
|
||||
'xtickFnc': lambda l: filters.date(datetime.datetime.fromtimestamp(X[int(l)]), xLabelFormat) if int(l) >= 0 else '',
|
||||
'xlabel': _('Date'),
|
||||
@ -207,14 +205,14 @@ class PoolPerformanceReport(StatsReport):
|
||||
'data': [v[1] for v in p['dataUsers']]
|
||||
}
|
||||
for p in poolsData],
|
||||
'ylabel': 'Users'
|
||||
'ylabel': _('Users')
|
||||
}
|
||||
|
||||
graphs.barChart(size, data, graph1)
|
||||
graphs.barChart(SIZE, data, graph1)
|
||||
|
||||
X = [v[0] for v in poolsData[0]['dataAccesses']]
|
||||
data = {
|
||||
'title': 'Accesses',
|
||||
'title': _('Accesses'),
|
||||
'x': X,
|
||||
'xtickFnc': lambda l: filters.date(datetime.datetime.fromtimestamp(X[int(l)]), xLabelFormat) if int(l) >= 0 else '',
|
||||
'xlabel': _('Date'),
|
||||
@ -224,10 +222,10 @@ class PoolPerformanceReport(StatsReport):
|
||||
'data': [v[1] for v in p['dataAccesses']]
|
||||
}
|
||||
for p in poolsData],
|
||||
'ylabel': 'Accesses'
|
||||
'ylabel': _('Accesses')
|
||||
}
|
||||
|
||||
graphs.barChart(size, data, graph2)
|
||||
graphs.barChart(SIZE, data, graph2)
|
||||
|
||||
# Generate Data for pools, basically joining all pool data
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#
|
||||
# Copyright (c) 2015 Virtual Cable S.L.
|
||||
# Copyright (c) 2015-2018 Virtual Cable S.L.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
@ -30,34 +30,29 @@
|
||||
"""
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
import csv
|
||||
import io
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
from django.utils.translation import ugettext, ugettext_lazy as _
|
||||
import django.template.defaultfilters as filters
|
||||
|
||||
from uds.core.ui.UserInterface import gui
|
||||
from uds.core.util.stats import events
|
||||
|
||||
import csv
|
||||
|
||||
import cairo
|
||||
import pycha.line
|
||||
import pycha.bar
|
||||
from uds.core.reports import graphs
|
||||
|
||||
from .base import StatsReport
|
||||
|
||||
from uds.core.util import tools
|
||||
|
||||
import datetime
|
||||
import six
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
__updated__ = '2018-02-08'
|
||||
__updated__ = '2018-04-24'
|
||||
|
||||
# several constants as Width height
|
||||
WIDTH, HEIGHT = 1920, 1080
|
||||
WIDTH, HEIGHT, DPI = 19.2, 10.8, 100
|
||||
SIZE = (WIDTH, HEIGHT, DPI)
|
||||
|
||||
|
||||
class StatsReportLogin(StatsReport):
|
||||
@ -171,131 +166,62 @@ class StatsReportLogin(StatsReport):
|
||||
#
|
||||
# User access by date graph
|
||||
#
|
||||
graph1 = six.BytesIO()
|
||||
graph2 = six.BytesIO()
|
||||
graph3 = six.BytesIO()
|
||||
graph1 = io.BytesIO()
|
||||
|
||||
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT) # @UndefinedVariable
|
||||
|
||||
dataset = ((ugettext('Users access to UDS'), data),)
|
||||
|
||||
options = {
|
||||
'encoding': 'utf-8',
|
||||
'axis': {
|
||||
'x': {
|
||||
'ticks': [
|
||||
dict(v=i, label=filters.date(datetime.datetime.fromtimestamp(i), xLabelFormat)) for i in range(start, end, int((end - start) / 11))
|
||||
],
|
||||
'range': (start, end),
|
||||
'showLines': True,
|
||||
},
|
||||
'y': {
|
||||
'tickCount': 10,
|
||||
'showLines': True,
|
||||
},
|
||||
'tickFontSize': 16,
|
||||
},
|
||||
'background': {
|
||||
'chartColor': '#f0f0f0',
|
||||
'baseColor': '#f0f0f0',
|
||||
'lineColor': '#187FF2'
|
||||
},
|
||||
'colorScheme': {
|
||||
'name': 'rainbow',
|
||||
'args': {
|
||||
'initialColor': '#B8CA16',
|
||||
},
|
||||
},
|
||||
'legend': {
|
||||
'hide': False,
|
||||
'legendFontSize': 16,
|
||||
'position': {
|
||||
'left': 48,
|
||||
'bottom': 8,
|
||||
X = [v[0] for v in data]
|
||||
d = {
|
||||
'title': _('Users Access (global)'),
|
||||
'x': X,
|
||||
'xtickFnc': lambda l: filters.date(datetime.datetime.fromtimestamp(l), xLabelFormat),
|
||||
'xlabel': _('Date'),
|
||||
'y': [
|
||||
{
|
||||
'label': 'Users',
|
||||
'data': [v[1] for v in data]
|
||||
}
|
||||
},
|
||||
'padding': {
|
||||
'left': 48,
|
||||
'top': 16,
|
||||
'right': 48,
|
||||
'bottom': 48,
|
||||
},
|
||||
'title': _('Users access to UDS')
|
||||
],
|
||||
'ylabel': 'Users',
|
||||
'allTicks': False
|
||||
}
|
||||
|
||||
chart = pycha.line.LineChart(surface, options)
|
||||
chart.addDataset(dataset)
|
||||
chart.render()
|
||||
graphs.lineChart(SIZE, d, graph1)
|
||||
|
||||
surface.write_to_png(graph1)
|
||||
|
||||
del chart
|
||||
del surface # calls finish, flushing to image
|
||||
|
||||
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT) # @UndefinedVariable
|
||||
|
||||
#
|
||||
# User access by day of week
|
||||
#
|
||||
graph2 = io.BytesIO()
|
||||
graph3 = io.BytesIO()
|
||||
dataWeek, dataHour = self.getWeekHourlyData()
|
||||
|
||||
dataset = ((ugettext('Users access to UDS'), [(i, dataWeek[i]) for i in range(0, 7)]),)
|
||||
|
||||
options['axis'] = {
|
||||
'x': {
|
||||
'ticks': [
|
||||
dict(v=i, label='Day {}'.format(i)) for i in range(0, 7)
|
||||
],
|
||||
'range': (0, 6),
|
||||
'showLines': True,
|
||||
},
|
||||
'y': {
|
||||
'tickCount': 10,
|
||||
'showLines': True,
|
||||
},
|
||||
'tickFontSize': 16,
|
||||
X = list(range(7))
|
||||
d = {
|
||||
'title': _('Users Access (by week)'),
|
||||
'x': X,
|
||||
'xtickFnc': lambda l: [_('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday'), _('Sunday')][l],
|
||||
'xlabel': _('Day of Week'),
|
||||
'y': [
|
||||
{
|
||||
'label': 'Users',
|
||||
'data': [v for v in dataWeek]
|
||||
}
|
||||
],
|
||||
'ylabel': 'Users'
|
||||
}
|
||||
|
||||
chart = pycha.bar.VerticalBarChart(surface, options)
|
||||
chart.addDataset(dataset)
|
||||
chart.render()
|
||||
graphs.barChart(SIZE, d, graph2)
|
||||
|
||||
surface.write_to_png(graph2)
|
||||
|
||||
del chart
|
||||
del surface # calls finish, flushing to image
|
||||
|
||||
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT) # @UndefinedVariable
|
||||
|
||||
# Hourly chart
|
||||
dataset = ((ugettext('Users access to UDS'), [(i, dataHour[i]) for i in range(0, 24)]),)
|
||||
|
||||
options['axis'] = {
|
||||
'x': {
|
||||
'ticks': [
|
||||
dict(v=i, label='{}:00'.format(i)) for i in range(0, 24)
|
||||
],
|
||||
'range': (0, 24),
|
||||
'showLines': True,
|
||||
},
|
||||
'y': {
|
||||
'tickCount': 10,
|
||||
'showLines': True,
|
||||
},
|
||||
'tickFontSize': 16,
|
||||
X = list(range(24))
|
||||
d = {
|
||||
'title': _('Users Access (by hour)'),
|
||||
'x': X,
|
||||
'xlabel': _('Hour'),
|
||||
'y': [
|
||||
{
|
||||
'label': 'Users',
|
||||
'data': [v for v in dataHour]
|
||||
}
|
||||
],
|
||||
'ylabel': 'Users'
|
||||
}
|
||||
|
||||
chart = pycha.bar.VerticalBarChart(surface, options)
|
||||
chart.addDataset(dataset)
|
||||
chart.render()
|
||||
|
||||
surface.write_to_png(graph3)
|
||||
|
||||
with open('/home/dkmaster/kk/kk.png', 'wb') as f:
|
||||
f.write(graph3.getvalue())
|
||||
|
||||
del chart
|
||||
del surface # calls finish, flushing to image
|
||||
graphs.barChart(SIZE, d, graph3)
|
||||
|
||||
return self.templateAsPDF(
|
||||
'uds/reports/stats/user-access.html',
|
||||
|
Loading…
Reference in New Issue
Block a user