X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Ftools%2Fpresentation%2Fgenerator_plots.py;h=a90dd0a9c5b530e0be84f7a61cada8998827ac61;hp=66656679d070f4964f0ebd41f34c3b318cfe849c;hb=f4b2f3a853b246513e7517217b7efafbf70ccac7;hpb=b4b7fac76d29cc780b3ccd865379ad2ed38c0586 diff --git a/resources/tools/presentation/generator_plots.py b/resources/tools/presentation/generator_plots.py index 66656679d0..a90dd0a9c5 100644 --- a/resources/tools/presentation/generator_plots.py +++ b/resources/tools/presentation/generator_plots.py @@ -19,6 +19,7 @@ import logging import pandas as pd import plotly.offline as ploff import plotly.graph_objs as plgo + from plotly.exceptions import PlotlyError from utils import mean @@ -38,14 +39,14 @@ def generate_plots(spec, data): try: logging.info(" Plot nr {0}:".format(index + 1)) eval(plot["algorithm"])(plot, data) - except NameError: - logging.error("The algorithm '{0}' is not defined.". - format(plot["algorithm"])) + except NameError as err: + logging.error("Probably algorithm '{alg}' is not defined: {err}". + format(alg=plot["algorithm"], err=repr(err))) logging.info("Done.") def plot_performance_box(plot, input_data): - """Generate the plot(s) with algorithm: table_detailed_test_results + """Generate the plot(s) with algorithm: plot_performance_box specified in the specification file. :param plot: Plot to generate. @@ -58,6 +59,9 @@ def plot_performance_box(plot, input_data): format(plot.get("title", ""))) # 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_data(plot) if data is None: logging.error("No data.") @@ -71,7 +75,17 @@ def plot_performance_box(plot, input_data): if y_vals.get(test["parent"], None) is None: y_vals[test["parent"]] = list() try: - y_vals[test["parent"]].append(test["throughput"]["value"]) + if test["type"] in ("NDRPDR", ): + if "-pdr" in plot_title.lower(): + y_vals[test["parent"]].\ + append(test["throughput"]["PDR"]["LOWER"]) + elif "-ndr" in plot_title.lower(): + y_vals[test["parent"]]. \ + append(test["throughput"]["NDR"]["LOWER"]) + else: + continue + else: + continue except (KeyError, TypeError): y_vals[test["parent"]].append(None) @@ -89,7 +103,8 @@ def plot_performance_box(plot, input_data): df = pd.DataFrame(y_vals) df.head() for i, col in enumerate(df.columns): - name = "{0}. {1}".format(i + 1, col.lower().replace('-ndrpdrdisc', '')) + name = "{0}. {1}".format(i + 1, col.lower().replace('-ndrpdrdisc', ''). + replace('-ndrpdr', '')) traces.append(plgo.Box(x=[str(i + 1) + '.'] * len(df[col]), y=df[col], name=name, @@ -128,6 +143,9 @@ def plot_latency_box(plot, input_data): format(plot.get("title", ""))) # 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_data(plot) if data is None: logging.error("No data.") @@ -148,18 +166,27 @@ def plot_latency_box(plot, input_data): list() # direction2, max ] try: - y_tmp_vals[test["parent"]][0].append( - test["latency"]["direction1"]["50"]["min"]) - y_tmp_vals[test["parent"]][1].append( - test["latency"]["direction1"]["50"]["avg"]) - y_tmp_vals[test["parent"]][2].append( - test["latency"]["direction1"]["50"]["max"]) - y_tmp_vals[test["parent"]][3].append( - test["latency"]["direction2"]["50"]["min"]) - y_tmp_vals[test["parent"]][4].append( - test["latency"]["direction2"]["50"]["avg"]) - y_tmp_vals[test["parent"]][5].append( - test["latency"]["direction2"]["50"]["max"]) + if test["type"] in ("NDRPDR", ): + if "-pdr" in plot_title.lower(): + ttype = "PDR" + elif "-ndr" in plot_title.lower(): + ttype = "NDR" + else: + continue + y_tmp_vals[test["parent"]][0].append( + test["latency"][ttype]["direction1"]["min"]) + y_tmp_vals[test["parent"]][1].append( + test["latency"][ttype]["direction1"]["avg"]) + y_tmp_vals[test["parent"]][2].append( + test["latency"][ttype]["direction1"]["max"]) + y_tmp_vals[test["parent"]][3].append( + test["latency"][ttype]["direction2"]["min"]) + y_tmp_vals[test["parent"]][4].append( + test["latency"][ttype]["direction2"]["avg"]) + y_tmp_vals[test["parent"]][5].append( + test["latency"][ttype]["direction2"]["max"]) + else: + continue except (KeyError, TypeError): pass @@ -185,7 +212,8 @@ def plot_latency_box(plot, input_data): return for i, col in enumerate(df.columns): - name = "{0}. {1}".format(i + 1, col.lower().replace('-ndrpdrdisc', '')) + name = "{0}. {1}".format(i + 1, col.lower().replace('-ndrpdrdisc', ''). + replace('-ndrpdr', '')) traces.append(plgo.Box(x=['TGint1-to-SUT1-to-SUT2-to-TGint2', 'TGint1-to-SUT1-to-SUT2-to-TGint2', 'TGint1-to-SUT1-to-SUT2-to-TGint2', @@ -235,6 +263,9 @@ def plot_throughput_speedup_analysis(plot, input_data): format(plot.get("title", ""))) # 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_data(plot) if data is None: logging.error("No data.") @@ -249,15 +280,22 @@ def plot_throughput_speedup_analysis(plot, input_data): "2": list(), "4": list()} try: - if "1T1C" in test["tags"]: - throughput[test["parent"]]["1"].\ - append(test["throughput"]["value"]) - elif "2T2C" in test["tags"]: - throughput[test["parent"]]["2"]. \ - append(test["throughput"]["value"]) - elif "4T4C" in test["tags"]: - throughput[test["parent"]]["4"]. \ - append(test["throughput"]["value"]) + if test["type"] in ("NDRPDR", ): + if "-pdr" in plot_title.lower(): + ttype = "PDR" + elif "-ndr" in plot_title.lower(): + ttype = "NDR" + else: + continue + if "1T1C" in test["tags"]: + throughput[test["parent"]]["1"].\ + append(test["throughput"][ttype]["LOWER"]) + elif "2T2C" in test["tags"]: + throughput[test["parent"]]["2"]. \ + append(test["throughput"][ttype]["LOWER"]) + elif "4T4C" in test["tags"]: + throughput[test["parent"]]["4"]. \ + append(test["throughput"][ttype]["LOWER"]) except (KeyError, TypeError): pass @@ -318,3 +356,75 @@ def plot_throughput_speedup_analysis(plot, input_data): return logging.info(" Done.") + + +def plot_http_server_performance_box(plot, input_data): + """Generate the plot(s) with algorithm: plot_http_server_performance_box + specified in the specification file. + + :param plot: Plot to generate. + :param input_data: Data to process. + :type plot: pandas.Series + :type input_data: InputData + """ + + logging.info(" Generating the plot {0} ...". + format(plot.get("title", ""))) + + # Transform the data + logging.info(" Creating the data set for the {0} '{1}'.". + format(plot.get("type", ""), plot.get("title", ""))) + data = input_data.filter_data(plot) + if data is None: + logging.error("No data.") + return + + # Prepare the data for the plot + y_vals = dict() + for job in data: + for build in job: + for test in build: + if y_vals.get(test["name"], None) is None: + y_vals[test["name"]] = list() + try: + y_vals[test["name"]].append(test["result"]) + except (KeyError, TypeError): + y_vals[test["name"]].append(None) + + # Add None to the lists with missing data + max_len = 0 + for val in y_vals.values(): + if len(val) > max_len: + max_len = 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() + for i, col in enumerate(df.columns): + name = "{0}. {1}".format(i + 1, col.lower().replace('-cps', ''). + replace('-rps', '')) + traces.append(plgo.Box(x=[str(i + 1) + '.'] * len(df[col]), + y=df[col], + name=name, + **plot["traces"])) + try: + # Create plot + plpl = plgo.Figure(data=traces, layout=plot["layout"]) + + # Export Plot + logging.info(" Writing file '{0}{1}'.". + format(plot["output-file"], plot["output-file-type"])) + ploff.plot(plpl, + show_link=False, auto_open=False, + filename='{0}{1}'.format(plot["output-file"], + plot["output-file-type"])) + except PlotlyError as err: + logging.error(" Finished with error: {}". + format(str(err).replace("\n", " "))) + return + + logging.info(" Done.")