def detailchart(self, chartable): theme.reinitialize() min_y = 0 max_y = 0 capture = chartable.get('capture') for sortname, sortfn in self.sorts: data = capture[sortname] m = median(data) if m > max_y: max_y = m max_x = max(self.limits) min_x = min(self.limits) ipoints = 10.0 x_interval = (max_x - min_x) / ipoints y_interval = (max_y - min_y) / ipoints xaxis = axis.X(label='Limit', tic_interval = x_interval, format='/4{}%d') yaxis = axis.Y(label='Seconds', tic_interval = y_interval, format='/4{}%0.3f') ar = area.T( x_range = (min_x, max_x), y_range = (min_y, max_y), x_axis = xaxis, y_axis = yaxis, legend = legend.T(), ) tb = text_box.T(loc=(140,90), text='Rlen\n%s' % chartable['rlen']) for sortname, sortfn in self.sorts: data = capture[sortname] linedata = [ (self.limits[x], data[x]) for x in range(len(data)) ] ar.add_plot( line_plot.T(label="%s" % sortname, data=linedata) ) fd = open('detail-%s-%s.pdf' % (self.dbkey, chartable['rlen']), 'w') can = canvas.init(fd, 'pdf') ar.draw(can) tb.draw(can) can.close()
def bar_chart(self, data, name): canvas.init format_extension = 'png' theme.output_format = format_extension theme.output_file = 'charts/' + name + '.' + format_extension theme.use_color = 1 theme.reinitialize() xaxis = axis.X(label="Char", format='/a90{}%s', tic_interval=30) yaxis = axis.Y(label="Frequency", tic_interval=0.1) ar = area.T(size=(300, 150), y_range=(0, 1), x_range=(0, 255), x_axis=xaxis, y_axis=yaxis ) ar.add_plot(bar_plot.T(label="Frequency", data=data, width=0.1),) ar.draw() canvas.close()
def create_graph(label_x, label_y, data_x, alldata_y, filename, title, start_date, end_date, start_y, end_y): """ main func """ # alter file name (linpng do not seems to like spaces in filenames filename = filename.replace(' ', '_') # Graph style theme.get_options() theme.use_color = True theme.default_font_size = 12 theme.default_font_family = "AvantGarde-Book" theme.reinitialize() colors = [ color.blue, color.red, color.green, color.magenta, color.cyan1, color.orange, ] can = canvas.init("%s" % filename) # Draw graph title newtitle = "/hL/20%s" % title left = WIDTH / 2 - font.text_width(newtitle) / 2 can.show(left, HEIGHT + DELTA, newtitle) int_to_date = lambda x: '/a60{}' + time.strftime("%H:%M", time.localtime(x) ) xaxis = axis.X(format=int_to_date, label="/20%s" % label_x, label_offset=(0, -DELTA), minor_tic_interval=X_MINOR_TICK_INTERVAL, tic_interval=X_TICK_INTERVAL) yaxis = axis.Y( label="/20%s" % label_y, label_offset=(-DELTA, 0), minor_tic_interval=(end_y - start_y) / 20, tic_interval=(end_y - start_y) / 5, ) ar = area.T(size=(WIDTH, HEIGHT), x_axis=xaxis, y_axis=yaxis, x_grid_style=line_style.gray70_dash3, x_range=(start_date, end_date), y_range=(start_y, end_y), x_grid_interval=X_GRID_INTERVAL, y_grid_interval=(end_y - start_y) / 5) i = 0 # Draw a line for each columns for title, data_y in alldata_y.iteritems(): plot = line_plot.T(label=title, data=zip(data_x, data_y), line_style=line_style.T(color=colors[i], width=1)) ar.add_plot(plot) i += 1 ar.draw() can.close() return True
def create_graph(label_x, label_y, data_x, alldata_y, filename, title, start_date, end_date): # alter file name (linpng do not seems to like spaces in filenames filename = filename.replace(' ', '_') # Graph style theme.get_options() theme.use_color = True theme.default_font_size = 12 theme.default_font_family = "AvantGarde-Book" theme.reinitialize() colors = [ color.blue, color.red, color.green, color.magenta, color.cyan1, color.orange, ] can = canvas.init("%s"%filename) # Draw graph title newtitle = "/hL/20%s"%title left = WIDTH / 2 - font.text_width(newtitle)/2 can.show(left, HEIGHT + DELTA, newtitle) zip(data_x) int_to_date = lambda x: '/a60{}' + time.strftime("%H:%M", time.localtime(x)) xaxis = axis.X( format = int_to_date, label = "/20%s" % label_x, label_offset = (0, -DELTA), minor_tic_interval = X_MINOR_TICK_INTERVAL, tic_interval = X_TICK_INTERVAL ) yaxis = axis.Y( label = "/20%s" % label_y, label_offset = (-DELTA, 0), minor_tic_interval = Y_MINOR_TICK_INTERVAL, tic_interval = Y_TICK_INTERVAL ) ar = area.T( size = (WIDTH, HEIGHT), x_axis = xaxis, y_axis = yaxis, x_grid_style = line_style.gray70_dash3, x_range = (start_date, end_date), y_range = (0, Y_MAX), x_grid_interval = X_GRID_INTERVAL, y_grid_interval = Y_GRID_INTERVAL ) i = 0 # Draw a line for each columns for title, data_y in alldata_y.iteritems(): plot = line_plot.T( label = title, data = zip(data_x,data_y), line_style = line_style.T( color = colors[i], width = 1 ) ) ar.add_plot(plot) i += 1 ar.draw() can.close() return True
def plotPie( r, s, q, b, availCpus ): if not doPie: return [], [], [] if availCpus <= 0: availCpus = 1 # return [], [], {} # availCpus is the total number of online/up cpus. # NOTE: offlined nodes that are still running jobs can push the total to >100% ! running, totalCpus, totalGpus = r suspended, totalSuspendedCpus, totalSuspendedGpus = s queued, totalQueuedCpus = q blocked, totalBlockedCpus = b #print 'running', r #print 'suspended', s #print 'queued', q #print 'blocked', b #sys.exit(1) theme.use_color = 1 theme.scale_factor = 1 theme.default_font_size = 12 theme.reinitialize() # filenames in /tmp/ where the png's are written names = [] # titles of the plots ie. Running, Queued, or Blocked titles = [] tmpFilename = tempfile.mktemp() n = string.split( tmpFilename, '/' ) # pull off the initial /tmp/ names.append( n[-1] ) titles.append( 'Running' ) can = canvas.init( tmpFilename + '.png' ) size=( 600, 450 ) ar = area.T(size=size, legend=None, x_grid_style = None, y_grid_style = None) colours = [ fill_style.red, fill_style.darkseagreen, fill_style.blue, fill_style.aquamarine1, fill_style.gray70, fill_style.darkorchid, fill_style.yellow, fill_style.green, fill_style.gray50, fill_style.goldenrod, fill_style.brown, fill_style.gray20 ] pieColours = [ 'red', 'darkseagreen', 'blue', rgbToHex( ( 0.498039, 1.0, 0.831373 ), scaleBy=255 ), # aquamarine1 rgbToHex( ( 0.7, 0.7, 0.7 ), scaleBy=255 ), # gray70 'darkorchid', 'yellow', 'green', rgbToHex( ( 0.5, 0.5, 0.5 ), scaleBy=255 ), # gray50 'goldenrod', 'brown', rgbToHex( ( 0.2, 0.2, 0.2 ), scaleBy=255 ) ] # gray20 # re-order the sorted 'running' so that the labels fit on the pie better if len(running) > 1: lastC, lastClist, lastU = running[-1] if lastU == 'idle': # but keep 'idle' last running = bigSmallOrder( running[:-1] ) running.append( ( lastC, lastClist, lastU ) ) else: running = bigSmallOrder( running ) # need to generate colours for both running and suspended pies because we # can draw those jobs on the node grid. prob wouldn't hurt to extend this to # all jobs? all = [] all.extend(running) all.extend(suspended) #all.extend(queued) #all.extend(blocked) # prescribe the colours for current biggest users. eg. biggest user is always in red userColour = {} # dict of colours that have been used for specific users cnt = 0 for cpus, cpusList, username in all: if username != 'idle': # username could be both in running and suspended, so only take the first (running) if username not in userColour.keys(): userColour[username] = cnt cnt += 1 if cnt == len(colours): break # the rest of the colours are hashes of the username for cpus, cpusList, username in all: if username not in userColourHash.keys(): h = hashlib.md5(username).hexdigest() h = int(h, 16) % len(colours) # random colour number userColourHash[username] = int(h) # cast to int from long if username not in userColour.keys(): userColour[username] = userColourHash[username] data = [] arcOffsets = [] colour = [] for cpus, cpusList, username in running: percent = 100.0*float(cpus)/float(availCpus) stri = username + ' %d%%' % ( percent + 0.5 ) if username != 'idle': if len(cpusList) == 1: stri += ' (1 job)' else: stri += ' (%d jobs)' % len(cpusList) data.append( ( stri, percent ) ) if username != 'idle': arcOffsets.append( 0 ) colour.append( colours[userColour[username]] ) else: arcOffsets.append( 20 ) colour.append( fill_style.white ) # offline nodes that are running jobs can make the total of the pie sum to more # than 100, so use the standard auto-scaling pie chart here. runPlot = pie_plot.T( data=data, arc_offsets=arcOffsets, fill_styles=colour, #shadow = (2, -2, fill_style.gray50), label_fill_style = None, label_offset = 25, arrow_style = arrow.a0 ) ar.add_plot(runPlot) ar.draw(can) can.close() # flush to file ASAP queuedPies( suspended, 'Suspended', 75, names, titles, size, availCpus, colours, userColour ) queuedPies( queued, 'Queued', 60, names, titles, size, availCpus, colours, userColour ) queuedPies( blocked, 'Blocked/Held', 40, names, titles, size, availCpus, colours, userColour ) # map userColour numbers to colour names c = {} for k, v in userColour.iteritems(): c[k] = pieColours[v] return names, titles, c
def detailchart(self, chartable): theme.reinitialize()
def create_graph(label_x, label_y, data_x, alldata_y, filename, title, start_date, end_date, start_y, end_y): """ main func """ # alter file name (linpng do not seems to like spaces in filenames filename = filename.replace(" ", "_") # Graph style theme.get_options() theme.use_color = True theme.default_font_size = 12 theme.default_font_family = "AvantGarde-Book" theme.reinitialize() colors = [ color.blue, color.red, color.green, color.magenta, color.cyan1, color.orange, color.darkblue, color.darkred, color.darkgreen, color.darkmagenta, color.darkcyan, color.gold, color.lightblue1, color.orangered, color.lightgreen, color.pink, color.lightcyan, color.goldenrod, color.mistyrose, color.honeydew, color.gainsboro, color.yellow, color.peachpuff, color.turquoise, color.chartreuse1, color.pink, color.brown, color.blue, color.red, color.green, color.magenta, color.cyan1, color.orange, color.darkblue, color.darkred, color.darkgreen, color.darkmagenta, color.darkcyan, color.gold, color.lightblue1, color.orangered, color.lightgreen, color.pink, color.lightcyan, color.goldenrod, color.mistyrose, color.honeydew, color.gainsboro, color.yellow, color.peachpuff, color.turquoise, color.chartreuse1, color.pink, color.brown, ] can = canvas.init("%s" % filename) # Draw graph title newtitle = "/hL/20%s" % title left = WIDTH / 2 - font.text_width(newtitle) / 2 can.show(left, HEIGHT + DELTA, newtitle) int_to_date = lambda x: "/a60{}" + time.strftime("%H:%M", time.localtime(x)) xaxis = axis.X( format=int_to_date, label="/20%s" % label_x, label_offset=(0, -DELTA), minor_tic_interval=X_MINOR_TICK_INTERVAL, tic_interval=X_TICK_INTERVAL, ) yaxis = axis.Y( label="/20%s" % label_y, label_offset=(-DELTA, 0), minor_tic_interval=(end_y - start_y) / 20, tic_interval=(end_y - start_y) / 5, ) ar = area.T( size=(WIDTH, HEIGHT), x_axis=xaxis, y_axis=yaxis, x_grid_style=line_style.gray70_dash3, x_range=(start_date, end_date), y_range=(start_y, end_y), x_grid_interval=X_GRID_INTERVAL, y_grid_interval=(end_y - start_y) / 5, ) i = 0 # Draw a line for each columns for title, data_y in alldata_y.iteritems(): plot = line_plot.T(label=title, data=zip(data_x, data_y), line_style=line_style.T(color=colors[i], width=1)) ar.add_plot(plot) i += 1 ar.draw() can.close() return True