def gen_institute_bar(self, institute, start, end, machine_category): """Generates a bar graph showing the trend usage for an institute Keyword arguments: institute -- Institute start -- start date end -- end date machine_category -- MachineCategory object """ start_str = start.strftime('%Y-%m-%d') end_str = end.strftime('%Y-%m-%d') x = gdchart.Bar() x.width = 700 x.height = 350 x.bg_color = "white" x.xtitle = "Days" x.ytitle = "CPU Time (hours)" x.title = '%s - %s-%s' % (institute.name, start_str, end_str) x.grid = "NONE" rows = get_insitutes_trend(institute, start, end, machine_category) data, colours = smooth_data(rows, start, end) x.ext_color = colours x.setData(data) #x.setComboData(data) try: x.draw("%s/institutes/bar_%s_%s-%s_%i.png" % (settings.GRAPH_ROOT, institute.id, start_str, end_str, machine_category.id)) except: pass
def gen_institutes_trend(self, start, end, machine_category): start_str = start.strftime('%Y-%m-%d') end_str = end.strftime('%Y-%m-%d') i_start = start i_end = end for i in Institute.active.all(): start = i_start end = i_end rows = get_insitutes_trend(i, start, end, machine_category) i_data, i_colours = smooth_data(rows, start, end) x = gdchart.Line() x.width = 700 x.height = 350 x.bg_color = "white" x.xtitle = "Days" x.ytitle = "CPU Time (hours)" x.title = '%s - %s-%s' % (i.name, start_str, end_str) x.grid = "NONE" x.setData(i_data) x.draw("%s/i_trends/%s_%s_%s-trend.png" % (settings.GRAPH_ROOT, i.name.replace(' ', '').lower(), start_str, end_str))
def gen_trend_graph(self, start, end, machine_category): """Generates a bar graph showing the trend usage for a machine category Keyword arguments: start -- start date end -- end date machine_category -- MachineCategory object """ start_str = start.strftime('%Y-%m-%d') end_str = end.strftime('%Y-%m-%d') x = gdchart.Bar() x.width = 700 x.height = 350 x.bg_color = "white" x.xtitle = "Days" x.ytitle = "CPU Time (hours)" x.title = '%s - %s-%s' % (machine_category.name, start_str, end_str) x.grid = "NONE" mc_ids = tuple([(int(m.id)) for m in machine_category.machine_set.all()]) if len(mc_ids) == 1: mc_ids = "(%i)" % mc_ids[0] cursor = connection.cursor() sql = "SELECT date, SUM( cpu_usage ) FROM `cpu_job` WHERE `machine_id` IN %s AND `date` >= '%s' AND `date` <= '%s' Group By date" % (mc_ids, start_str, end_str) cursor.execute(sql) rows = dict(cursor.fetchall()) data, colours = smooth_data(rows, start, end) x.ext_color = colours x.setData(data) try: x.draw("%s/trends/trend_%i_%s-%s.png" % (settings.GRAPH_ROOT, machine_category.id, start_str, end_str)) except: pass