forked from shaba/openuds
Fixes
This commit is contained in:
parent
2ce130786a
commit
52e703f9c2
@ -162,7 +162,7 @@ class Services(DetailHandler): # pylint: disable=too-many-public-methods
|
||||
service = parent.services.get(uuid=processUuid(item))
|
||||
service.__dict__.update(fields)
|
||||
|
||||
service.tags = [Tag.objects.get_or_create(tag=val)[0] for val in tags]
|
||||
service.tags.set([Tag.objects.get_or_create(tag=val)[0] for val in tags])
|
||||
service.proxy = proxy
|
||||
|
||||
service.data = service.getInstance(self._params).serialize() # This may launch an validation exception (the getInstance(...) part)
|
||||
@ -242,10 +242,10 @@ class Services(DetailHandler): # pylint: disable=too-many-public-methods
|
||||
for f in [{
|
||||
'name': 'proxy_id',
|
||||
'values': [gui.choiceItem(-1, '')] + gui.sortedChoices([gui.choiceItem(v.uuid, v.name) for v in Proxy.objects.all()]),
|
||||
'label': ugettext('Proxy'),
|
||||
'tooltip': ugettext('Proxy for services behind a firewall'),
|
||||
'label': _('Proxy'),
|
||||
'tooltip': _('Proxy for services behind a firewall'),
|
||||
'type': gui.InputField.CHOICE_TYPE,
|
||||
'tab': ugettext('Advanced'),
|
||||
'tab': _('Advanced'),
|
||||
'order': 132,
|
||||
},
|
||||
]:
|
||||
|
@ -34,4 +34,4 @@ from __future__ import unicode_literals
|
||||
|
||||
from .BaseReport import Report
|
||||
|
||||
__updated__ = '2015-04-28'
|
||||
__updated__ = '2018-04-19'
|
||||
|
74
server/src/uds/core/reports/graphs.py
Normal file
74
server/src/uds/core/reports/graphs.py
Normal file
@ -0,0 +1,74 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#
|
||||
# Copyright (c) 2018 Virtual Cable S.L.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
# * Neither the name of Virtual Cable S.L. nor the names of its contributors
|
||||
# may be used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# 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.
|
||||
|
||||
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
|
||||
from matplotlib.figure import Figure
|
||||
import io
|
||||
|
||||
|
||||
def barChart(size, data, output):
|
||||
data = {
|
||||
'x': [1, 2, 3, 4, 5, 6],
|
||||
'xticks': ['uno', 'dos', 'tres', 'cuatro', 'cinco', 'seis'],
|
||||
'xlabel': 'Data X',
|
||||
'y': [
|
||||
{
|
||||
'label': 'First',
|
||||
'data': [1, 2, 4, 8, 16, 32],
|
||||
},
|
||||
{
|
||||
'label': 'Second',
|
||||
'data': [31, 15, 7, 3, 1, 0],
|
||||
}
|
||||
],
|
||||
'ylabel': 'Data YYYYY'
|
||||
}
|
||||
|
||||
width = 0.35
|
||||
fig = Figure(figsize=(size[0], size[1]), dpi=size[2])
|
||||
|
||||
axis = fig.add_subplot(1, 1, 1)
|
||||
|
||||
xs = data['x'] # x axis
|
||||
xticks = [''] + [l for l in data['xticks']] + [''] # Iterables
|
||||
ys = data['y'] # List of dictionaries
|
||||
|
||||
bottom = [0] * len(ys[0]['data'])
|
||||
plts = []
|
||||
for y in ys:
|
||||
plts.append(axis.bar(xs, y['data'], width, bottom=bottom, label=y.get('label')))
|
||||
bottom = y['data']
|
||||
|
||||
axis.set_xlabel(data['xlabel'])
|
||||
axis.set_ylabel(data['ylabel'])
|
||||
axis.set_xticklabels(xticks)
|
||||
axis.legend()
|
||||
|
||||
canvas = FigureCanvas(fig)
|
||||
canvas.print_png(output)
|
@ -32,6 +32,9 @@
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import csv
|
||||
import six
|
||||
|
||||
from django.utils.translation import ugettext, ugettext_lazy as _
|
||||
from django.db.models import Count
|
||||
import django.template.defaultfilters as filters
|
||||
@ -39,13 +42,7 @@ import django.template.defaultfilters as filters
|
||||
from uds.core.ui.UserInterface import gui
|
||||
from uds.core.util.stats import events
|
||||
|
||||
import csv
|
||||
import six
|
||||
|
||||
import cairo
|
||||
# import pycha.line
|
||||
# import pycha.bar
|
||||
import pycha.stackedbar
|
||||
from uds.core.reports import graphs
|
||||
|
||||
from .base import StatsReport
|
||||
|
||||
@ -57,10 +54,10 @@ import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
__updated__ = '2018-02-08'
|
||||
__updated__ = '2018-04-19'
|
||||
|
||||
# several constants as Width height, margins, ..
|
||||
WIDTH, HEIGHT = 1920, 1080
|
||||
WIDTH, HEIGHT, DPI = 19.2, 10.8, 100
|
||||
|
||||
|
||||
class PoolPerformanceReport(StatsReport):
|
||||
@ -193,11 +190,12 @@ class PoolPerformanceReport(StatsReport):
|
||||
end = self.endDate.stamp()
|
||||
|
||||
xLabelFormat, poolsData, reportData = self.getRangeData()
|
||||
size = (WIDTH, HEIGHT, DPI)
|
||||
|
||||
graph1 = six.BytesIO()
|
||||
graph2 = six.BytesIO()
|
||||
|
||||
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT) # @UndefinedVariable
|
||||
# surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT) # @UndefinedVariable
|
||||
|
||||
options = {
|
||||
'encoding': 'utf-8',
|
||||
@ -243,9 +241,11 @@ class PoolPerformanceReport(StatsReport):
|
||||
'title': _('Users by pool'),
|
||||
}
|
||||
|
||||
# chart = pycha.line.LineChart(surface, options)
|
||||
# chart = pycha.bar.VerticalBarChart(surface, options)
|
||||
chart = pycha.stackedbar.StackedVerticalBarChart(surface, options)
|
||||
data = {}
|
||||
|
||||
graphs.barChart(size, data, graph1)
|
||||
|
||||
# chart = pycha.stackedbar.StackedVerticalBarChart(surface, options)
|
||||
|
||||
dataset = []
|
||||
for pool in poolsData:
|
||||
@ -255,19 +255,37 @@ class PoolPerformanceReport(StatsReport):
|
||||
dataset.append((ugettext('Users for {}').format(pool['name']), ds))
|
||||
|
||||
logger.debug('Dataset: {}'.format(dataset))
|
||||
chart.addDataset(dataset)
|
||||
# chart.addDataset(dataset)
|
||||
|
||||
chart.render()
|
||||
# chart.render()
|
||||
|
||||
surface.write_to_png(graph1)
|
||||
# surface.write_to_png(graph1)
|
||||
|
||||
del chart
|
||||
del surface # calls finish, flushing to image
|
||||
# del chart
|
||||
# del surface # calls finish, flushing to image
|
||||
|
||||
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT) # @UndefinedVariable
|
||||
# surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT) # @UndefinedVariable
|
||||
|
||||
# Accesses
|
||||
chart = pycha.stackedbar.StackedVerticalBarChart(surface, options)
|
||||
# chart = pycha.stackedbar.StackedVerticalBarChart(surface, options)
|
||||
data = {
|
||||
'x': [1, 2, 3, 4, 5, 6],
|
||||
'xticks': [filters.date(datetime.datetime.fromtimestamp(l), xLabelFormat) for l in range(start, end, int((end - start) / self.samplingPoints.num()))],
|
||||
'xlabel': _('Date'),
|
||||
'y': [
|
||||
{
|
||||
'label': 'First',
|
||||
'data': [1, 2, 4, 8, 16, 32],
|
||||
},
|
||||
{
|
||||
'label': 'Second',
|
||||
'data': [31, 15, 7, 3, 1, 0],
|
||||
}
|
||||
],
|
||||
'ylabel': 'Data YYYYY'
|
||||
}
|
||||
|
||||
graphs.barChart(size, data, graph2)
|
||||
|
||||
dataset = []
|
||||
for pool in poolsData:
|
||||
@ -277,14 +295,14 @@ class PoolPerformanceReport(StatsReport):
|
||||
dataset.append((ugettext('Accesses for {}').format(pool['name']), ds))
|
||||
|
||||
logger.debug('Dataset: {}'.format(dataset))
|
||||
chart.addDataset(dataset)
|
||||
# chart.addDataset(dataset)
|
||||
|
||||
chart.render()
|
||||
# chart.render()
|
||||
|
||||
surface.write_to_png(graph2)
|
||||
# surface.write_to_png(graph2)
|
||||
|
||||
del chart
|
||||
del surface # calls finish, flushing to image
|
||||
# del chart
|
||||
# del surface # calls finish, flushing to image
|
||||
|
||||
# Generate Data for pools, basically joining all pool data
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user