def drawStepByStep(cls, methods, nSteps, nmethods, pdf, stepByStep): fig = 1 ncols = nSteps + 1 # steps + baseline nlines = nmethods for name, method in methods.iteritems(): # draw baseline bl = stepByStep[name]["baseline"] for pair in method["pairs"]: val = zip(*bl[pair.getPair()]) Graph.subplot(nlines, ncols, fig) Graph.errorbar( val[0], val[1], yerr=val[2], fmt=".", color=Graph.getColor(pair.getPair()), label="%s,%s" % pair.getPair(), ) Graph.hold = True Graph.decorate( g_xlabel="Time (s)", g_ylabel="RTT time", g_title="Measures for %s, baseline" % name, g_grid=True ) Graph.legend(loc=2) dfig = 1 k = sorted(stepByStep[name].keys()) k.remove("baseline") for step in k: Graph.subplot(nlines, ncols, fig + dfig) for pair in method["pairs"]: val = zip(*stepByStep[name][step][pair.getPair()]) Graph.errorbar( val[0], val[1], yerr=val[2], fmt=".", color=Graph.getColor(pair.getPair()), label="%s,%s" % pair.getPair(), ) Graph.hold = True Graph.axhline(2 * step, color=Graph.getColor(step)) Graph.decorate( g_xlabel="Time (s)", g_ylabel="RTT time", g_title="Measures for %s, step 2x%sms" % (name, step), g_grid=True, ) Graph.legend(loc=2) dfig += 1 fig += ncols fig = Graph.gcf() fig.set_size_inches(50, 25) pdf.savefig(bbox_inches="tight") #'checks/delay.pdf', format = 'pdf', ) Graph.close()
def drawStepByStep(cls, methods, nSteps, nmethods, pdf, stepByStep): fig = 1 ncols = nSteps + 1 # steps + baseline nlines = nmethods for name, method in methods.iteritems(): # draw baseline bl = stepByStep[name]['baseline'] for pair in method['pairs']: val = zip(*bl[pair.getPair()]) Graph.subplot(nlines, ncols, fig) Graph.errorbar(val[0], val[1], yerr=val[2], fmt='.', color=Graph.getColor(pair.getPair()), label="%s,%s" % pair.getPair()) Graph.hold = True Graph.decorate(g_xlabel='Time (s)', g_ylabel='RTT time', g_title='Measures for %s, baseline' % name, g_grid=True) Graph.legend(loc=2) dfig = 1 k = sorted(stepByStep[name].keys()) k.remove('baseline') for step in k: Graph.subplot(nlines, ncols, fig + dfig) for pair in method["pairs"]: val = zip(*stepByStep[name][step][pair.getPair()]) Graph.errorbar(val[0], val[1], yerr=val[2], fmt='.', color=Graph.getColor(pair.getPair()), label="%s,%s" % pair.getPair()) Graph.hold = True Graph.axhline(2 * step, color=Graph.getColor(step)) Graph.decorate(g_xlabel='Time (s)', g_ylabel='RTT time', g_title='Measures for %s, step 2x%sms' % (name, step), g_grid=True) Graph.legend(loc=2) dfig += 1 fig += ncols fig = Graph.gcf() fig.set_size_inches(50, 25) pdf.savefig( bbox_inches='tight') #'checks/delay.pdf', format = 'pdf', ) Graph.close()
def drawMethodsSummary(cls, nmethods, madiffs, mavgs, mdevs, methods, mrdiffs, msteps, mts, pdf): line = 1 ncols = 3 nlines = nmethods nbins = 15 # plot the data for name, method in methods.iteritems(): ts = mts[name] devs = mdevs[name] avgs = mavgs[name] steps = msteps[name] rdiffs = mrdiffs[name] adiffs = madiffs[name] Graph.subplot(nlines, ncols, line) for pair in method["pairs"]: Graph.errorbar( ts[pair.getPair()], avgs[pair.getPair()], yerr=devs[pair.getPair()], fmt=".", color=Graph.getColor(pair.getPair()), label="%s,%s" % pair.getPair(), ) Graph.hold = True for target, tsteps in steps.iteritems(): Graph.step(tsteps[0], tsteps[1], "r", where="post", label=target, color=Graph.getColor(target)) Graph.hold = True Graph.decorate(g_xlabel="Time (s)", g_ylabel="RTT time", g_title="Measures for %s" % name) Graph.legend(loc=2) Graph.subplot(nlines, ncols, line + 1) n, bins, patches = Graph.hist( rdiffs.values(), nbins, normed=1, label=["%s,%s" % x for x in rdiffs.keys()], g_xlabel="Logarithmic Relative error", g_title="Logarithmic Relative error for %s" % name, ) Graph.legend(loc="upper left", bbox_to_anchor=(0.9, 1.0), ncol=1) # ax.set_xticklabels([lab.get_text() for lab in ax.get_xaxis().get_ticklabels()]) Graph.subplot(nlines, ncols, line + 2) Graph.hist( adiffs.values(), nbins, label=["%s,%s" % x for x in adiffs.keys()], g_xlabel="Absolute error", g_title="Absolute error for %s" % name, ) Graph.legend(loc="upper left", bbox_to_anchor=(0.9, 1.0), ncol=1) # plt.hist(diffs.values(), stacked = True) # plt.xticks(bins, ["2^%s" % i for i in bins]) # plt.hold(True) # plt.plot(steps_time, steps_val, 'r,-') # plt.axis([0, 60, 0, 2000]) # ax = plt.gca() # ax.yaxis.grid(True, linestyle = '-', which = 'major', color = 'lightgrey', # alpha = 0.5) Graph.draw() line += ncols fig = Graph.gcf() fig.set_size_inches(20, 25) pdf.savefig(bbox_inches="tight") #'checks/delay.pdf', format = 'pdf', ) Graph.close()
def drawBoxPlots(cls, mboxes, methods, nmethods, pdf): bl = mboxes.pop("baseline") blm = mboxes.pop("baselineMeasures") mets = sorted(methods.keys()) for outliers in ("^", ""): nstep = 1 # compare methods to each other ncols = nmethods + 2 Graph.clf() Graph.subplot(1, ncols, nstep) d = 1.0 / (2 * len(bl)) # make sure we iterate with the same order over methods for pair, data in bl.iteritems(): vals = [[], []] for me in mets: vals[0].append(data[me][0]) vals[1].append(data[me][1]) Graph.errorbar( [d + i for i in range(1, len(mets) + 1)], vals[0], yerr=vals[1], fmt=".", color=Graph.getColor(pair), label="%s,%s" % pair, ) Graph.hold = True d += 1.0 / len(bl) for l in range(1, len(mets) + 1): Graph.axvspan( l, l + 1, facecolor=Graph.getColor(mets[l - 1]), alpha=0.1, hold=True ) # , linestyle = '--') Graph.legend(loc=2) Graph.xticks(rotation=50) Graph.decorate( g_xtickslab=[""] + mets, g_xticks=[0.5 + i for i in range(0, len(methods) + 1)], g_grid=True, g_xlabel="Measurement method", g_ylabel="Measured delays with stddev (ms)", g_title="Baseline for all methods", ) nstep += 1 Graph.subplot(1, ncols, nstep) Graph.boxplot([blm[met] for met in mets], sym=outliers) Graph.xticks(rotation=50) Graph.decorate( g_xtickslab=mets, g_grid=True, g_xlabel="Measurement method", g_ylabel="Measured baseline (ms)", g_title="Measures for baseline", ) nstep += 1 for step in sorted(mboxes.keys()): m_datas = mboxes[step] Graph.subplot(1, ncols, nstep) Graph.xticks(rotation=50) Graph.boxplot([m_datas[met] for met in mets], sym=outliers) Graph.axhline(2 * step, color="r") Graph.decorate( g_xtickslab=mets, g_grid=True, g_xlabel="Measurement method", g_ylabel="Measured delays - baseline (ms)", g_title="Measures for step 2x%sms" % step, ) nstep += 1 fig = Graph.gcf() fig.set_size_inches(28, 8) pdf.savefig(bbox_inches="tight") #'checks/boxdelay.pdf', format = 'pdf', ) Graph.close()
def makeResults(cls, methods, checkName="bw", saveResults=True): """Make result to graphics :param methods : results to process :param checkName: name of the current check being processed :param saveResults : save results to json file ?""" if saveResults: try: fn = cls.saveResults(methods, checkName) info("Saved bandwidth results to file %s\n" % fn) except Exception as e: error("Could not save bandwidth results : %s\n" % e) import numpy as np from matplotlib.backends.backend_pdf import PdfPages try: for name, method in methods.iteritems(): info("Result of measures for method %s:" % name) for pair in method["pairs"]: info(pair.printAll()) info("\n") except Exception as e: error("Could not print results %s\n" % e) nmethods = len(methods) gr = 1 ncols = 3 nlines = nmethods nbins = 15 # dict(step : dict(method, data)) # mboxes = {} try: fn = "checks/%s.pdf" % checkName pdf = PdfPages(fn) for name, method in methods.iteritems(): avgs = {} ts = {} adiffs = {} rdiffs = {} steps = {"total": None} for target, tsteps in method["real_steps"].iteritems(): st = zip(*tsteps) step_time = np.array((0,) + st[1]) step_values = np.array((0,) + st[0]) steps[target] = (step_time, step_values) steps["total"] = ( (step_time, np.minimum(steps["total"][1], step_values)) if steps["total"] is not None else (step_time, step_values) ) for pair in method["pairs"]: avg = map(lambda measure: measure.bw / (1000 ** 2), pair.measures) adiff = map(lambda measure: measure.bw / (1000 ** 2) - measure.step, pair.measures) rdiff = map( lambda measure: abs(measure.bw / (1000.0 ** 2) - measure.step) / float(measure.step), pair.measures, ) t = map(lambda measure: measure.timestamp, pair.measures) avgs[pair.getPair()] = np.array(avg) ts[pair.getPair()] = np.array(t) adiffs[pair.getPair()] = np.array(adiff) rdiffs[pair.getPair()] = np.array(rdiff) # plot the data Graph.subplot(nlines, ncols, gr) for pair in method["pairs"]: Graph.scatter( ts[pair.getPair()], avgs[pair.getPair()], color=Graph.getColor(pair.getPair()), label="%s,%s" % pair.getPair(), ) Graph.hold = True for target, tsteps in steps.iteritems(): Graph.step(tsteps[0], tsteps[1], "r", where="post", label=target, color=Graph.getColor(target)) Graph.hold = True Graph.decorate( g_xlabel="Time (s)", g_ylabel="BW estimation with %s (Mbps)" % name, g_title="Measure for Bandwidth for tool %s" % name, ) ax = Graph.gca() ax.set_yscale("log") Graph.legend(loc=2) Graph.draw() Graph.subplot(nlines, ncols, gr + 1) Graph.hist( rdiffs.values(), nbins, label=["%s,%s" % x for x in rdiffs.keys()], g_xlabel="Relative error", g_title="Relative error for tool %s" % name, ) Graph.legend(loc=2) # ax = Graph.gca() # ax.set_yscale('log') Graph.subplot(nlines, ncols, gr + 2) Graph.hist( adiffs.values(), nbins, label=["%s,%s" % x for x in adiffs.keys()], g_xlabel="Absolute error (Mbps)", g_title="Absolute error for tool %s" % name, ) Graph.legend(loc=2) gr += ncols fig = Graph.gcf() fig.set_size_inches(20, 30) pdf.savefig(bbox_inches="tight") # 'checks/delay.pdf', format = 'pdf', ) Graph.close() d = pdf.infodict() d["Title"] = "Bandwidth measurement" d["Author"] = u"Francois Espinet" d["Subject"] = "Bandwidth measurement" d["Keywords"] = "measurement bw bandwidth" d["ModDate"] = datetime.datetime.today() finally: pdf.close() info("Saved graphics to %s\n" % fn) Graph.show()
def drawMethodsSummary(cls, nmethods, madiffs, mavgs, mdevs, methods, mrdiffs, msteps, mts, pdf): line = 1 ncols = 3 nlines = nmethods nbins = 15 # plot the data for name, method in methods.iteritems(): ts = mts[name] devs = mdevs[name] avgs = mavgs[name] steps = msteps[name] rdiffs = mrdiffs[name] adiffs = madiffs[name] Graph.subplot(nlines, ncols, line) for pair in method['pairs']: Graph.errorbar(ts[pair.getPair()], avgs[pair.getPair()], yerr=devs[pair.getPair()], fmt='.', color=Graph.getColor(pair.getPair()), label="%s,%s" % pair.getPair()) Graph.hold = True for target, tsteps in steps.iteritems(): Graph.step(tsteps[0], tsteps[1], 'r', where='post', label=target, color=Graph.getColor(target)) Graph.hold = True Graph.decorate(g_xlabel='Time (s)', g_ylabel='RTT time', g_title='Measures for %s' % name) Graph.legend(loc=2) Graph.subplot(nlines, ncols, line + 1) n, bins, patches = Graph.hist( rdiffs.values(), nbins, normed=1, label=["%s,%s" % x for x in rdiffs.keys()], g_xlabel='Logarithmic Relative error', g_title='Logarithmic Relative error for %s' % name) Graph.legend(loc='upper left', bbox_to_anchor=(0.9, 1.0), ncol=1) # ax.set_xticklabels([lab.get_text() for lab in ax.get_xaxis().get_ticklabels()]) Graph.subplot(nlines, ncols, line + 2) Graph.hist(adiffs.values(), nbins, label=["%s,%s" % x for x in adiffs.keys()], g_xlabel='Absolute error', g_title='Absolute error for %s' % name) Graph.legend(loc='upper left', bbox_to_anchor=(0.9, 1.0), ncol=1) # plt.hist(diffs.values(), stacked = True) # plt.xticks(bins, ["2^%s" % i for i in bins]) # plt.hold(True) # plt.plot(steps_time, steps_val, 'r,-') # plt.axis([0, 60, 0, 2000]) # ax = plt.gca() # ax.yaxis.grid(True, linestyle = '-', which = 'major', color = 'lightgrey', # alpha = 0.5) Graph.draw() line += ncols fig = Graph.gcf() fig.set_size_inches(20, 25) pdf.savefig( bbox_inches='tight') #'checks/delay.pdf', format = 'pdf', ) Graph.close()
def drawBoxPlots(cls, mboxes, methods, nmethods, pdf): bl = mboxes.pop('baseline') blm = mboxes.pop('baselineMeasures') mets = sorted(methods.keys()) for outliers in ('^', ''): nstep = 1 #compare methods to each other ncols = nmethods + 2 Graph.clf() Graph.subplot(1, ncols, nstep) d = 1.0 / (2 * len(bl)) # make sure we iterate with the same order over methods for pair, data in bl.iteritems(): vals = [[], []] for me in mets: vals[0].append(data[me][0]) vals[1].append(data[me][1]) Graph.errorbar([d + i for i in range(1, len(mets) + 1)], vals[0], yerr=vals[1], fmt='.', color=Graph.getColor(pair), label='%s,%s' % pair) Graph.hold = True d += 1.0 / len(bl) for l in range(1, len(mets) + 1): Graph.axvspan(l, l + 1, facecolor=Graph.getColor(mets[l - 1]), alpha=0.1, hold=True) #, linestyle = '--') Graph.legend(loc=2) Graph.xticks(rotation=50) Graph.decorate( g_xtickslab=[ '', ] + mets, g_xticks=[0.5 + i for i in range(0, len(methods) + 1)], g_grid=True, g_xlabel='Measurement method', g_ylabel='Measured delays with stddev (ms)', g_title='Baseline for all methods') nstep += 1 Graph.subplot(1, ncols, nstep) Graph.boxplot([blm[met] for met in mets], sym=outliers) Graph.xticks(rotation=50) Graph.decorate(g_xtickslab=mets, g_grid=True, g_xlabel='Measurement method', g_ylabel='Measured baseline (ms)', g_title='Measures for baseline') nstep += 1 for step in sorted(mboxes.keys()): m_datas = mboxes[step] Graph.subplot(1, ncols, nstep) Graph.xticks(rotation=50) Graph.boxplot([m_datas[met] for met in mets], sym=outliers) Graph.axhline(2 * step, color='r') Graph.decorate(g_xtickslab=mets, g_grid=True, g_xlabel='Measurement method', g_ylabel='Measured delays - baseline (ms)', g_title='Measures for step 2x%sms' % step) nstep += 1 fig = Graph.gcf() fig.set_size_inches(28, 8) pdf.savefig( bbox_inches='tight') #'checks/boxdelay.pdf', format = 'pdf', ) Graph.close()
def makeResults(cls, methods, checkName='bw', saveResults=True): """Make result to graphics :param methods : results to process :param checkName: name of the current check being processed :param saveResults : save results to json file ?""" if saveResults: try: fn = cls.saveResults(methods, checkName) info("Saved bandwidth results to file %s\n" % fn) except Exception as e: error("Could not save bandwidth results : %s\n" % e) import numpy as np from matplotlib.backends.backend_pdf import PdfPages try: for name, method in methods.iteritems(): info("Result of measures for method %s:" % name) for pair in method['pairs']: info(pair.printAll()) info("\n") except Exception as e: error("Could not print results %s\n" % e) nmethods = len(methods) gr = 1 ncols = 3 nlines = nmethods nbins = 15 # dict(step : dict(method, data)) # mboxes = {} try: fn = 'checks/%s.pdf' % checkName pdf = PdfPages(fn) for name, method in methods.iteritems(): avgs = {} ts = {} adiffs = {} rdiffs = {} steps = {'total': None} for target, tsteps in method['real_steps'].iteritems(): st = zip(*tsteps) step_time = np.array((0, ) + st[1]) step_values = np.array((0, ) + st[0]) steps[target] = (step_time, step_values) steps['total'] = ( step_time, np.minimum(steps['total'][1], step_values) ) if steps['total'] is not None else (step_time, step_values) for pair in method['pairs']: avg = map(lambda measure: measure.bw / (1000**2), pair.measures) adiff = map( lambda measure: measure.bw / (1000**2) - measure.step, pair.measures) rdiff = map( lambda measure: abs(measure.bw / (1000.0**2) - measure. step) / float(measure.step), pair.measures) t = map(lambda measure: measure.timestamp, pair.measures) avgs[pair.getPair()] = np.array(avg) ts[pair.getPair()] = np.array(t) adiffs[pair.getPair()] = np.array(adiff) rdiffs[pair.getPair()] = np.array(rdiff) # plot the data Graph.subplot(nlines, ncols, gr) for pair in method['pairs']: Graph.scatter(ts[pair.getPair()], avgs[pair.getPair()], color=Graph.getColor(pair.getPair()), label="%s,%s" % pair.getPair()) Graph.hold = True for target, tsteps in steps.iteritems(): Graph.step(tsteps[0], tsteps[1], 'r', where='post', label=target, color=Graph.getColor(target)) Graph.hold = True Graph.decorate(g_xlabel='Time (s)', g_ylabel='BW estimation with %s (Mbps)' % name, g_title='Measure for Bandwidth for tool %s' % name) ax = Graph.gca() ax.set_yscale('log') Graph.legend(loc=2) Graph.draw() Graph.subplot(nlines, ncols, gr + 1) Graph.hist(rdiffs.values(), nbins, label=["%s,%s" % x for x in rdiffs.keys()], g_xlabel='Relative error', g_title='Relative error for tool %s' % name) Graph.legend(loc=2) # ax = Graph.gca() # ax.set_yscale('log') Graph.subplot(nlines, ncols, gr + 2) Graph.hist(adiffs.values(), nbins, label=["%s,%s" % x for x in adiffs.keys()], g_xlabel='Absolute error (Mbps)', g_title='Absolute error for tool %s' % name) Graph.legend(loc=2) gr += ncols fig = Graph.gcf() fig.set_size_inches(20, 30) pdf.savefig( bbox_inches='tight') # 'checks/delay.pdf', format = 'pdf', ) Graph.close() d = pdf.infodict() d['Title'] = 'Bandwidth measurement' d['Author'] = u'Francois Espinet' d['Subject'] = 'Bandwidth measurement' d['Keywords'] = 'measurement bw bandwidth' d['ModDate'] = datetime.datetime.today() finally: pdf.close() info("Saved graphics to %s\n" % fn) Graph.show()