def get_results(config_name, version): if config_name: config_name = config_name.upper() base_config = getattr(configs, config_name) else: base_config = {"name": ""} config = configs.remove_wait_times(base_config) if not config_name: config["name"] = "" if version: config["version"] = version results = network.get_results(config) print "ID TASKID VERSION COMPLETED_TIME WORKER CONFIG_NAME INCIDENTS THROUGPUT" print "=== ====== ======= ================ ========== ================================================== ========= =========" for result in results: print ( "{id:3d} {taskid:6d} {config[version]:7s} {completed_time:%d.%m.%Y %H:%M} " "{worker:10s} {config[name]:50s} {incidents:9.0f} {avg_throughput:9.0f}".format(**result) )
def get_results(config_name, version): if config_name: config_name = config_name.upper() base_config = getattr(configs, config_name) else: base_config = {'name': ''} config = configs.remove_wait_times(base_config) if not config_name: config['name'] = '' if version: config['version'] = version results = network.get_results(config) print 'ID TASKID VERSION COMPLETED_TIME WORKER CONFIG_NAME INCIDENTS THROUGPUT' print '=== ====== ======= ================ ========== ================================================== ========= =========' for result in results: print( '{id:3d} {taskid:6d} {config[version]:7s} {completed_time:%d.%m.%Y %H:%M} ' '{worker:10s} {config[name]:50s} {incidents:9.0f} {avg_throughput:9.0f}' .format(**result))
def plot(config_name, version, pdf, r, stdout, max_tp, tp, name, wtp): config_name = config_name.upper() base_config = getattr(configs, config_name) config = configs.remove_wait_times(base_config) if version: config["version"] = version if r or stdout: csvstring = StringIO() csvwriter = csv.writer(csvstring) else: if pdf: fig = plt.figure(dpi=300) else: fig = plt.figure() if pdf: latexify() filename = config_name.lower() if tp: data = network.get_plot_data(config, ["results->'avg_throughput'", "results->'incidents'", "config->>'name'"]) logger.info("Got Data") if max_tp: data = [(i, x, y, name) for i, x, y, name in data if int(re.findall("\d+", name)[0]) <= max_tp] logger.info("%d points", len(data)) ids, x, y, name = zip(*data) if r or stdout: csvwriter.writerow(["x", "y"]) for row in zip(x, y): csvwriter.writerow(row) else: # fig.suptitle(runid) ax = fig.add_subplot(111) def onpick3(event): ind = event.ind for i in ind: print (ids[i]) # get_result(ids[i]) x = np.array(x) y = np.array(y) n = 1000 # distance_weight = 0.01 # def rolling_avg(ax): # indexes = np.logical_and(x > (ax-n), x < (ax + n)) # values = y[indexes] # #x_values = x[indexes] # #weights = 1/np.abs((x_values - ax) + 1) # return np.average(values) # x2 = np.arange(2000, 14000, 10) # y2 = [] # for x_val in x2: # y2.append(rolling_avg(x_val)) # ax.plot(x2, y2) ax.scatter(x, y, picker=True) # sns.regplot(x, y, lowess=True, y_jitter=0.3, x_jitter=0, ax=ax, scatter_kws={'picker': True}) fig.canvas.mpl_connect("pick_event", onpick3) # plt.ylim(-1, 12) plt.xlabel("Throughput") plt.ylabel("Incidents") plt.tight_layout() elif name: filename += ".names" data = network.get_plot_data(config, ["config->>'name'"]) logger.info("%d points", len(data)) ids, names = zip(*data) counter = Counter() for name in names: counter[name] += 1 counts = counter.most_common() counts = [(int(re.findall("\d+", name)[0]), name, cnt) for name, cnt in counts] counts.sort() width = 0.8 numbers, names, counts = zip(*counts) ind = np.arange(len(names)) plt.title(config["name"]) plt.bar(ind, counts, width=width) plt.xticks(ind + width / 2, numbers) # plt.ylim(24, 30) plt.tight_layout() elif wtp: filename += ".wanted_throughputs" data = network.get_plot_data(config, ["config->>'name'", "results->'avg_throughput'"]) logger.info("%d points", len(data)) ids, names, throughputs = zip(*data) inputs = [int(re.findall("\d+", name)[0]) for name in names] plt.title(config["name"]) plt.scatter(inputs, throughputs) # plt.ylim(24, 30) plt.tight_layout() plt.show() filename = filename + ".pdf" if r: if not os.path.exists("pdf"): os.makedirs("pdf") r_process = subprocess.Popen(["Rscript", "plot.R", os.path.join("pdf", filename)], stdin=subprocess.PIPE) r_process.communicate(csvstring.getvalue()) elif stdout: print csvstring.getvalue() elif pdf: ax = plt.gca() format_axes(ax) if not os.path.exists("pdf"): os.makedirs("pdf") plt.savefig(os.path.join("pdf", filename)) else: plt.show()
def plot(config_name, version, pdf, r, stdout, max_tp, tp, name, wtp): config_name = config_name.upper() base_config = getattr(configs, config_name) config = configs.remove_wait_times(base_config) if version: config['version'] = version if r or stdout: csvstring = StringIO() csvwriter = csv.writer(csvstring) else: if pdf: fig = plt.figure(dpi=300) else: fig = plt.figure() if pdf: latexify() filename = config_name.lower() if tp: data = network.get_plot_data(config, [ "results->'avg_throughput'", "results->'incidents'", "config->>'name'" ]) logger.info("Got Data") if max_tp: data = [(i, x, y, name) for i, x, y, name in data if int(re.findall('\d+', name)[0]) <= max_tp] logger.info('%d points', len(data)) ids, x, y, name = zip(*data) if r or stdout: csvwriter.writerow(['x', 'y']) for row in zip(x, y): csvwriter.writerow(row) else: #fig.suptitle(runid) ax = fig.add_subplot(111) def onpick3(event): ind = event.ind for i in ind: print(ids[i]) #get_result(ids[i]) x = np.array(x) y = np.array(y) n = 1000 #distance_weight = 0.01 # def rolling_avg(ax): # indexes = np.logical_and(x > (ax-n), x < (ax + n)) # values = y[indexes] # #x_values = x[indexes] # #weights = 1/np.abs((x_values - ax) + 1) # return np.average(values) # x2 = np.arange(2000, 14000, 10) # y2 = [] # for x_val in x2: # y2.append(rolling_avg(x_val)) # ax.plot(x2, y2) ax.scatter(x, y, picker=True) #sns.regplot(x, y, lowess=True, y_jitter=0.3, x_jitter=0, ax=ax, scatter_kws={'picker': True}) fig.canvas.mpl_connect('pick_event', onpick3) #plt.ylim(-1, 12) plt.xlabel('Throughput') plt.ylabel('Incidents') plt.tight_layout() elif name: filename += '.names' data = network.get_plot_data(config, ["config->>'name'"]) logger.info('%d points', len(data)) ids, names = zip(*data) counter = Counter() for name in names: counter[name] += 1 counts = counter.most_common() counts = [(int(re.findall('\d+', name)[0]), name, cnt) for name, cnt in counts] counts.sort() width = .8 numbers, names, counts = zip(*counts) ind = np.arange(len(names)) plt.title(config['name']) plt.bar(ind, counts, width=width) plt.xticks(ind + width / 2, numbers) #plt.ylim(24, 30) plt.tight_layout() elif wtp: filename += '.wanted_throughputs' data = network.get_plot_data( config, ["config->>'name'", "results->'avg_throughput'"]) logger.info('%d points', len(data)) ids, names, throughputs = zip(*data) inputs = [int(re.findall('\d+', name)[0]) for name in names] plt.title(config['name']) plt.scatter(inputs, throughputs) #plt.ylim(24, 30) plt.tight_layout() plt.show() filename = filename + '.pdf' if r: if not os.path.exists('pdf'): os.makedirs('pdf') r_process = subprocess.Popen( ['Rscript', 'plot.R', os.path.join('pdf', filename)], stdin=subprocess.PIPE) r_process.communicate(csvstring.getvalue()) elif stdout: print csvstring.getvalue() elif pdf: ax = plt.gca() format_axes(ax) if not os.path.exists('pdf'): os.makedirs('pdf') plt.savefig(os.path.join('pdf', filename)) else: plt.show()