def generate(self): items = self.getData() graph1 = io.BytesIO() X = list(range(24)) d = { 'title': _('Services by hour'), 'x': X, 'xtickFnc': lambda l: '{:02d}'.format(l), 'xlabel': _('Hour'), 'y': [ { 'label': i['name'], 'data': [i['hours'][v] for v in X] } for i in items ], 'ylabel': 'Services' } graphs.barChart(SIZE, d, graph1) return self.templateAsPDF( 'uds/reports/stats/pools-usage-day.html', dct={ 'data': items, 'pools': [v.name for v in ServicePool.objects.filter(uuid__in=self.pools.value)], 'beginning': self.startDate.date(), }, header=ugettext('Services usage report for a day'), water=ugettext('Service usage report'), images={'graph1': graph1.getvalue()}, )
def generate(self): # Generate the sampling intervals and get dataUsers from db xLabelFormat, poolsData, reportData = self.getRangeData() graph1 = io.BytesIO() graph2 = io.BytesIO() # surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT) # @UndefinedVariable # logger.debug('PoolsData: %s', poolsData) X = [v[0] for v in poolsData[0]['dataUsers']] data = { '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': p['name'], 'data': [v[1] for v in p['dataUsers']] } 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] for v in p['dataAccesses']] } for p in poolsData], 'ylabel': _('Accesses') } graphs.barChart(SIZE, data, graph2) # Generate Data for pools, basically joining all pool data return self.templateAsPDF( 'uds/reports/stats/pools-performance.html', dct={ 'data': reportData, 'pools': [i[1] for i in self.getPools()], 'beginning': self.startDate.date(), 'ending': self.endDate.date(), 'intervals': self.samplingPoints.num(), }, header=ugettext('UDS Pools Performance Report'), water=ugettext('Pools Performance'), images={'graph1': graph1.getvalue(), 'graph2': graph2.getvalue()}, )
def generate(self): # Sample query: # 'SELECT *, count(*) as number, CEIL(stamp/(3600))*3600 as block' # ' FROM {table}' # ' WHERE event_type = 0 and stamp >= {start} and stamp <= {end}' # ' GROUP BY CEIL(stamp/(3600))' # ' ORDER BY block' xLabelFormat, data, reportData = self.getRangeData() # # User access by date graph # graph1 = io.BytesIO() 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] }], 'ylabel': 'Users', 'allTicks': False } graphs.lineChart(SIZE, d, graph1) graph2 = io.BytesIO() graph3 = io.BytesIO() graph4 = io.BytesIO() dataWeek, dataHour, dataWeekHour = self.getWeekHourlyData() 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' } graphs.barChart(SIZE, d, graph2) 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' } graphs.barChart(SIZE, d, graph3) X = list(range(24)) Y = list(range(7)) d = { 'title': _('Users Access (by hour)'), 'x': X, 'xlabel': _('Hour'), 'xtickFnc': lambda l: l, 'y': Y, 'ylabel': _('Day of week'), 'ytickFnc': lambda l: [ _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday'), _('Sunday') ][l], 'z': dataWeekHour, 'zlabel': _('Users') } graphs.surfaceChart(SIZE, d, graph4) return self.templateAsPDF( 'uds/reports/stats/user-access.html', dct={ 'data': reportData, 'beginning': self.startDate.date(), 'ending': self.endDate.date(), 'intervals': self.samplingPoints.num(), }, header=ugettext('Users access to UDS'), water=ugettext('UDS Report for users access'), images={ 'graph1': graph1.getvalue(), 'graph2': graph2.getvalue(), 'graph3': graph3.getvalue(), 'graph4': graph4.getvalue() }, )
def generate(self): # Generate the sampling intervals and get dataUsers from db xLabelFormat, poolsData, reportData = self.getRangeData() graph1 = io.BytesIO() graph2 = io.BytesIO() # surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT) # @UndefinedVariable # logger.debug('PoolsData: %s', poolsData) X = [v[0] for v in poolsData[0]['dataUsers']] data = { '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': p['name'], 'data': [v[1] for v in p['dataUsers']] } 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] for v in p['dataAccesses']] } for p in poolsData], 'ylabel': _('Accesses') } graphs.barChart(SIZE, data, graph2) # Generate Data for pools, basically joining all pool data return self.templateAsPDF( 'uds/reports/stats/pools-performance.html', dct={ 'data': reportData, 'pools': [i[1] for i in self.getPools()], 'beginning': self.startDate.date(), 'ending': self.endDate.date(), 'intervals': self.samplingPoints.num(), }, header=ugettext('UDS Pools Performance Report'), water=ugettext('Pools Performance'), images={ 'graph1': graph1.getvalue(), 'graph2': graph2.getvalue() }, )
def generate(self): # Sample query: # 'SELECT *, count(*) as number, CEIL(stamp/(3600))*3600 as block' # ' FROM {table}' # ' WHERE event_type = 0 and stamp >= {start} and stamp <= {end}' # ' GROUP BY CEIL(stamp/(3600))' # ' ORDER BY block' xLabelFormat, data, reportData = self.getRangeData() # # User access by date graph # graph1 = io.BytesIO() 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] } ], 'ylabel': 'Users', 'allTicks': False } graphs.lineChart(SIZE, d, graph1) graph2 = io.BytesIO() graph3 = io.BytesIO() graph4 = io.BytesIO() dataWeek, dataHour, dataWeekHour = self.getWeekHourlyData() 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' } graphs.barChart(SIZE, d, graph2) 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' } graphs.barChart(SIZE, d, graph3) X = list(range(24)) Y = list(range(7)) d = { 'title': _('Users Access (by hour)'), 'x': X, 'xlabel': _('Hour'), 'xtickFnc': lambda l: l, 'y': Y, 'ylabel': _('Day of week'), 'ytickFnc': lambda l: [_('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday'), _('Sunday')][l], 'z': dataWeekHour, 'zlabel': _('Users') } graphs.surfaceChart(SIZE, d, graph4) return self.templateAsPDF( 'uds/reports/stats/user-access.html', dct={ 'data': reportData, 'beginning': self.startDate.date(), 'ending': self.endDate.date(), 'intervals': self.samplingPoints.num(), }, header=ugettext('Users access to UDS'), water=ugettext('UDS Report for users access'), images={'graph1': graph1.getvalue(), 'graph2': graph2.getvalue(), 'graph3': graph3.getvalue(), 'graph4': graph4.getvalue()}, )