X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Ftools%2Fpresentation%2Fgenerator_plots.py;h=3e5da63c9e53a651d221f3d0cb4cba6ee2d99330;hp=f5bcb0abfafdd096ddcc35799c42e1c24b7a57cb;hb=38201acbd8778f30e31909c952adc9a895d75fa6;hpb=1fac7da55c5b6d5a5651bc3ecac8aa945de49ef8 diff --git a/resources/tools/presentation/generator_plots.py b/resources/tools/presentation/generator_plots.py index f5bcb0abfa..3e5da63c9e 100644 --- a/resources/tools/presentation/generator_plots.py +++ b/resources/tools/presentation/generator_plots.py @@ -61,8 +61,109 @@ def generate_plots(spec, data): logging.info("Done.") -def plot_performance_name_box(plot, input_data): - """Generate the plot(s) with algorithm: plot_performance_name_box +def plot_service_density_reconf_box_name(plot, input_data): + """Generate the plot(s) with algorithm: plot_service_density_reconf_box_name + specified in the specification file. + + :param plot: Plot to generate. + :param input_data: Data to process. + :type plot: pandas.Series + :type input_data: InputData + """ + + # Transform the data + plot_title = plot.get("title", "") + logging.info(" Creating the data set for the {0} '{1}'.". + format(plot.get("type", ""), plot_title)) + data = input_data.filter_tests_by_name( + plot, params=["result", "parent", "tags", "type"]) + if data is None: + logging.error("No data.") + return + + # Prepare the data for the plot + y_vals = OrderedDict() + loss = dict() + for job in data: + for build in job: + for test in build: + if y_vals.get(test["parent"], None) is None: + y_vals[test["parent"]] = list() + loss[test["parent"]] = list() + try: + y_vals[test["parent"]].append(test["result"]["time"]) + loss[test["parent"]].append(test["result"]["loss"]) + except (KeyError, TypeError): + y_vals[test["parent"]].append(None) + + # Add None to the lists with missing data + max_len = 0 + nr_of_samples = list() + for val in y_vals.values(): + if len(val) > max_len: + max_len = len(val) + nr_of_samples.append(len(val)) + for key, val in y_vals.items(): + if len(val) < max_len: + val.extend([None for _ in range(max_len - len(val))]) + + # Add plot traces + traces = list() + df = pd.DataFrame(y_vals) + df.head() + y_max = list() + for i, col in enumerate(df.columns): + tst_name = re.sub(REGEX_NIC, "", + col.lower().replace('-ndrpdr', ''). + replace('2n1l-', '')) + tst_name = "-".join(tst_name.split("-")[3:-2]) + name = "{nr}. ({samples:02d} run{plural}, avg pkt loss: {loss:.1f}, " \ + "stdev: {stdev:.2f}) {name}".format( + nr=(i + 1), + samples=nr_of_samples[i], + plural='s' if nr_of_samples[i] > 1 else '', + name=tst_name, + loss=mean(loss[col]) / 1000000, + stdev=stdev(loss[col]) / 1000000) + + traces.append(plgo.Box(x=[str(i + 1) + '.'] * len(df[col]), + y=[y if y else None for y in df[col]], + name=name, + hoverinfo="x+y", + boxpoints="outliers", + whiskerwidth=0)) + try: + val_max = max(df[col]) + except ValueError as err: + logging.error(repr(err)) + continue + if val_max: + y_max.append(int(val_max) + 1) + + try: + # Create plot + layout = deepcopy(plot["layout"]) + layout["title"] = "Time Lost: {0}".format(layout["title"]) + layout["yaxis"]["title"] = "Implied Time Lost [s]" + layout["legend"]["font"]["size"] = 14 + if y_max: + layout["yaxis"]["range"] = [0, max(y_max)] + plpl = plgo.Figure(data=traces, layout=layout) + + # Export Plot + file_type = plot.get("output-file-type", ".html") + logging.info(" Writing file '{0}{1}'.". + format(plot["output-file"], file_type)) + ploff.plot(plpl, show_link=False, auto_open=False, + filename='{0}{1}'.format(plot["output-file"], file_type)) + except PlotlyError as err: + logging.error(" Finished with error: {}". + format(repr(err).replace("\n", " "))) + return + + +def plot_performance_box_name(plot, input_data): + """Generate the plot(s) with algorithm: plot_performance_box_name specified in the specification file. :param plot: Plot to generate. @@ -1691,9 +1792,9 @@ def plot_service_density_heatmap(plot, input_data): """ REGEX_CN = re.compile(r'^(\d*)R(\d*)C$') - REGEX_TEST_NAME = re.compile(r'^.*-(\d+vhost|\d+memif)-' - r'(\d+chain|\d+pipe)-' - r'(\d+vm|\d+dcr|\d+drc).*$') + REGEX_TEST_NAME = re.compile(r'^.*-(\d+ch|\d+pl)-' + r'(\d+mif|\d+vh)-' + r'(\d+vm\d+t|\d+dcr\d+t).*$') txt_chains = list() txt_nodes = list() @@ -1720,9 +1821,9 @@ def plot_service_density_heatmap(plot, input_data): continue groups = re.search(REGEX_TEST_NAME, test["name"]) if groups and len(groups.groups()) == 3: - hover_name = "{vhost}-{chain}-{vm}".format( - vhost=str(groups.group(1)), - chain=str(groups.group(2)), + hover_name = "{chain}-{vhost}-{vm}".format( + chain=str(groups.group(1)), + vhost=str(groups.group(2)), vm=str(groups.group(3))) else: hover_name = "" @@ -1975,8 +2076,8 @@ def plot_service_density_heatmap_compare(plot, input_data): REGEX_CN = re.compile(r'^(\d*)R(\d*)C$') REGEX_TEST_NAME = re.compile(r'^.*-(\d+ch|\d+pl)-' - r'(\d+vh|\d+mif)-' - r'(\d+vm|\d+dcr).*$') + r'(\d+mif|\d+vh)-' + r'(\d+vm\d+t|\d+dcr\d+t).*$') REGEX_THREADS = re.compile(r'^(\d+)(VM|DCR)(\d+)T$') txt_chains = list()