Fixing up, removing pycha and using matplotlib instead

This commit is contained in:
Adolfo Gómez García 2018-04-23 15:08:58 +02:00
parent 52e703f9c2
commit 2ad3517bcd
6 changed files with 47 additions and 146 deletions

View File

@ -7,8 +7,8 @@ pycrypto==2.6.1
dnspython==1.15.0
lxml==3.6.0
ovirt-engine-sdk-python==4.1.7
pycha==0.7.0 # This has to be fixed, does not work with default pycha, needs a couple of fixes for python3
pycurl==7.43.0
matplotlib==2.1.2
pyOpenSSL==16.2.0
mysqlclient==1.3.12
python-ldap==3.0.0b4

View File

@ -1,10 +0,0 @@
import six
if six.PY2:
import sys
# noinspection PyCompatibility
reload(sys)
# noinspection PyUnresolvedReferences
sys.setdefaultencoding('utf-8') # @UndefinedVariable

View File

@ -280,19 +280,11 @@ class ServicesPools(ModelHandler):
}, {
'name': 'account_id',
'values': [gui.choiceItem(-1, '')] + gui.sortedChoices([gui.choiceItem(v.uuid, v.name) for v in Account.objects.all()]),
'label': ugettext('Account'),
'label': ugettext('Accounting'),
'tooltip': ugettext('Account associated to this service pool'),
'type': gui.InputField.CHOICE_TYPE,
'tab': ugettext('Advanced'),
'order': 131,
}, {
'name': 'allow_users_remove',
'value': False,
'label': ugettext('Allow removal by users'),
'tooltip': ugettext('If active, the user will be allowed to remove the service "manually". Be care with this, because the user will have the "poser" to delete it\'s own service'),
'type': gui.InputField.CHECKBOX_TYPE,
'tab': ugettext('Advanced'),
'order': 131,
}
]:

View File

@ -27,47 +27,38 @@
# 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.
import logging
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
import io
import numpy as np
logger = logging.getLogger(__name__)
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'
}
d = data['x']
ind = np.arange(len(d))
ys = data['y']
width = 0.35
fig = Figure(figsize=(size[0], size[1]), dpi=size[2])
axis = fig.add_subplot(1, 1, 1)
axis = fig.add_subplot(111)
axis.grid(color='r', linestyle='dotted', linewidth=0.1, alpha=0.5)
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 = []
bottom = np.zeros(len(ys[0]['data']))
for y in ys:
plts.append(axis.bar(xs, y['data'], width, bottom=bottom, label=y.get('label')))
bottom = y['data']
axis.bar(ind, y['data'], width, bottom=bottom, label=y.get('label'))
bottom += np.array(y['data'])
axis.set_title(data.get('title', ''))
axis.set_xlabel(data['xlabel'])
axis.set_ylabel(data['ylabel'])
axis.set_xticklabels(xticks)
axis.set_xticks(ind)
axis.set_xticklabels([data['xtickFnc'](v) for v in axis.get_xticks()])
axis.legend()
canvas = FigureCanvas(fig)

View File

@ -54,7 +54,7 @@ import logging
logger = logging.getLogger(__name__)
__updated__ = '2018-04-19'
__updated__ = '2018-04-23'
# several constants as Width height, margins, ..
WIDTH, HEIGHT, DPI = 19.2, 10.8, 100
@ -197,113 +197,42 @@ class PoolPerformanceReport(StatsReport):
# surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT) # @UndefinedVariable
options = {
'encoding': 'utf-8',
'axis': {
'x': {
'ticks': [
dict(v=i, label=filters.date(datetime.datetime.fromtimestamp(l), xLabelFormat)) for i, l in enumerate(range(start, end, int((end - start) / self.samplingPoints.num())))
],
'range': (0, self.samplingPoints.num()),
'showLines': True,
},
'y': {
'tickCount': 10,
'showLines': True,
},
'tickFontSize': 16,
},
'background': {
'chartColor': '#f0f0f0',
'baseColor': '#f0f0f0',
'lineColor': '#187FF2'
},
'colorScheme': {
'name': 'gradient',
'args': {
'initialColor': 'blue',
},
},
'legend': {
'hide': False,
'legendFontSize': 16,
'position': {
'left': 96,
'top': 40,
}
},
'padding': {
'left': 48,
'top': 16,
'right': 48,
'bottom': 48,
},
'title': _('Users by pool'),
}
# logger.debug('PoolsData: %s', poolsData)
data = {}
graphs.barChart(size, data, graph1)
# chart = pycha.stackedbar.StackedVerticalBarChart(surface, options)
dataset = []
for pool in poolsData:
logger.debug(pool['dataUsers'])
ds = list((i, l[1]) for i, l in enumerate(pool['dataUsers']))
logger.debug(ds)
dataset.append((ugettext('Users for {}').format(pool['name']), ds))
logger.debug('Dataset: {}'.format(dataset))
# chart.addDataset(dataset)
# chart.render()
# surface.write_to_png(graph1)
# del chart
# del surface # calls finish, flushing to image
# surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT) # @UndefinedVariable
# Accesses
# chart = pycha.stackedbar.StackedVerticalBarChart(surface, options)
X = [v[0] for v in poolsData[0]['dataUsers']]
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()))],
'title': 'Distinct Users',
'x': X,
'xtickFnc': lambda l: filters.date(datetime.datetime.fromtimestamp(X[int(l)]), xLabelFormat) if int(l) >= 0 else '',
'xlabel': _('Date'),
'y': [
{
'label': 'First',
'data': [1, 2, 4, 8, 16, 32],
},
{
'label': 'Second',
'data': [31, 15, 7, 3, 1, 0],
'label': p['name'],
'data': [v[1] + 2 for v in p['dataUsers']]
}
],
'ylabel': 'Data YYYYY'
for p in poolsData],
'ylabel': 'Users'
}
graphs.barChart(size, data, graph1)
X = [v[0] for v in poolsData[0]['dataAccesses']]
data = {
'title': 'Accesses',
'x': X,
'xtickFnc': lambda l: filters.date(datetime.datetime.fromtimestamp(X[int(l)]), xLabelFormat) if int(l) >= 0 else '',
'xlabel': _('Date'),
'y': [
{
'label': p['name'],
'data': [v[1] + 2 for v in p['dataAccesses']]
}
for p in poolsData],
'ylabel': 'Accesses'
}
graphs.barChart(size, data, graph2)
dataset = []
for pool in poolsData:
logger.debug(pool['dataAccesses'])
ds = list((i, l[1]) for i, l in enumerate(pool['dataAccesses']))
logger.debug(ds)
dataset.append((ugettext('Accesses for {}').format(pool['name']), ds))
logger.debug('Dataset: {}'.format(dataset))
# chart.addDataset(dataset)
# chart.render()
# surface.write_to_png(graph2)
# del chart
# del surface # calls finish, flushing to image
# Generate Data for pools, basically joining all pool data
return self.templateAsPDF(

View File

@ -194,7 +194,6 @@ class XenServer(object):
def getTaskInfo(self, task):
progress = 0
result = None
status = 'unknown'
destroyTask = False
try:
status = self.task.get_status(task)