+
+def plot_http_server_perf_box(plot, input_data):
+ """Generate the plot(s) with algorithm: plot_http_server_perf_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
+ """
+
+ # Transform the data
+ logging.info(
+ f" Creating the data set for the {plot.get(u'type', u'')} "
+ f"{plot.get(u'title', u'')}."
+ )
+ data = input_data.filter_data(plot)
+ if data is None:
+ logging.error(u"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[u"name"], None) is None:
+ y_vals[test[u"name"]] = list()
+ try:
+ y_vals[test[u"name"]].append(test[u"result"])
+ except (KeyError, TypeError):
+ y_vals[test[u"name"]].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 val in y_vals.values():
+ if len(val) < max_len:
+ val.extend([None for _ in range(max_len - len(val))])
+
+ # Add plot traces
+ traces = list()
+ df_y = pd.DataFrame(y_vals)
+ df_y.head()
+ for i, col in enumerate(df_y.columns):
+ name = \
+ f"{i + 1}. " \
+ f"({nr_of_samples[i]:02d} " \
+ f"run{u's' if nr_of_samples[i] > 1 else u''}) " \
+ f"{col.lower().replace(u'-ndrpdr', u'')}"
+ if len(name) > 50:
+ name_lst = name.split(u'-')
+ name = u""
+ split_name = True
+ for segment in name_lst:
+ if (len(name) + len(segment) + 1) > 50 and split_name:
+ name += u"<br> "
+ split_name = False
+ name += segment + u'-'
+ name = name[:-1]
+
+ traces.append(plgo.Box(x=[str(i + 1) + u'.'] * len(df_y[col]),
+ y=df_y[col],
+ name=name,
+ **plot[u"traces"]))
+ try:
+ # Create plot
+ plpl = plgo.Figure(data=traces, layout=plot[u"layout"])
+
+ # Export Plot
+ logging.info(
+ f" Writing file {plot[u'output-file']}"
+ f"{plot[u'output-file-type']}."
+ )
+ ploff.plot(
+ plpl,
+ show_link=False,
+ auto_open=False,
+ filename=f"{plot[u'output-file']}{plot[u'output-file-type']}"
+ )
+ except PlotlyError as err:
+ logging.error(
+ f" Finished with error: {repr(err)}".replace(u"\n", u" ")
+ )
+ return
+
+
+def plot_nf_heatmap(plot, input_data):
+ """Generate the plot(s) with algorithm: plot_nf_heatmap
+ specified in the specification file.
+
+ :param plot: Plot to generate.
+ :param input_data: Data to process.
+ :type plot: pandas.Series
+ :type input_data: InputData
+ """
+
+ regex_cn = re.compile(r'^(\d*)R(\d*)C$')
+ regex_test_name = re.compile(r'^.*-(\d+ch|\d+pl)-'
+ r'(\d+mif|\d+vh)-'
+ r'(\d+vm\d+t|\d+dcr\d+t|\d+dcr\d+c).*$')
+ vals = dict()
+
+ # Transform the data
+ logging.info(
+ f" Creating the data set for the {plot.get(u'type', u'')} "
+ f"{plot.get(u'title', u'')}."
+ )
+ data = input_data.filter_data(plot, continue_on_error=True)
+ if data is None or data.empty:
+ logging.error(u"No data.")
+ return
+
+ for job in data:
+ for build in job:
+ for test in build:
+ for tag in test[u"tags"]:
+ groups = re.search(regex_cn, tag)
+ if groups:
+ chain = str(groups.group(1))
+ node = str(groups.group(2))
+ break
+ else:
+ continue
+ groups = re.search(regex_test_name, test[u"name"])
+ if groups and len(groups.groups()) == 3:
+ hover_name = (
+ f"{str(groups.group(1))}-"
+ f"{str(groups.group(2))}-"
+ f"{str(groups.group(3))}"
+ )
+ else:
+ hover_name = u""
+ if vals.get(chain, None) is None:
+ vals[chain] = dict()
+ if vals[chain].get(node, None) is None:
+ vals[chain][node] = dict(
+ name=hover_name,
+ vals=list(),
+ nr=None,
+ mean=None,
+ stdev=None
+ )
+ try:
+ if plot[u"include-tests"] == u"MRR":
+ result = test[u"result"][u"receive-rate"]
+ elif plot[u"include-tests"] == u"PDR":
+ result = test[u"throughput"][u"PDR"][u"LOWER"]
+ elif plot[u"include-tests"] == u"NDR":
+ result = test[u"throughput"][u"NDR"][u"LOWER"]
+ else:
+ result = None
+ except TypeError:
+ result = None
+
+ if result:
+ vals[chain][node][u"vals"].append(result)
+
+ if not vals:
+ logging.error(u"No data.")
+ return
+
+ txt_chains = list()
+ txt_nodes = list()
+ for key_c in vals:
+ txt_chains.append(key_c)
+ for key_n in vals[key_c].keys():
+ txt_nodes.append(key_n)
+ if vals[key_c][key_n][u"vals"]:
+ vals[key_c][key_n][u"nr"] = len(vals[key_c][key_n][u"vals"])
+ vals[key_c][key_n][u"mean"] = \
+ round(mean(vals[key_c][key_n][u"vals"]) / 1000000, 1)
+ vals[key_c][key_n][u"stdev"] = \
+ round(stdev(vals[key_c][key_n][u"vals"]) / 1000000, 1)
+ txt_nodes = list(set(txt_nodes))
+
+ def sort_by_int(value):
+ """Makes possible to sort a list of strings which represent integers.
+
+ :param value: Integer as a string.
+ :type value: str
+ :returns: Integer representation of input parameter 'value'.
+ :rtype: int
+ """
+ return int(value)
+
+ txt_chains = sorted(txt_chains, key=sort_by_int)
+ txt_nodes = sorted(txt_nodes, key=sort_by_int)
+
+ chains = [i + 1 for i in range(len(txt_chains))]
+ nodes = [i + 1 for i in range(len(txt_nodes))]
+
+ data = [list() for _ in range(len(chains))]
+ for chain in chains:
+ for node in nodes:
+ try:
+ val = vals[txt_chains[chain - 1]][txt_nodes[node - 1]][u"mean"]
+ except (KeyError, IndexError):
+ val = None
+ data[chain - 1].append(val)
+
+ # Color scales:
+ my_green = [[0.0, u"rgb(235, 249, 242)"],
+ [1.0, u"rgb(45, 134, 89)"]]
+
+ my_blue = [[0.0, u"rgb(236, 242, 248)"],
+ [1.0, u"rgb(57, 115, 172)"]]
+
+ my_grey = [[0.0, u"rgb(230, 230, 230)"],
+ [1.0, u"rgb(102, 102, 102)"]]
+
+ hovertext = list()
+ annotations = list()
+
+ text = (u"Test: {name}<br>"
+ u"Runs: {nr}<br>"
+ u"Thput: {val}<br>"
+ u"StDev: {stdev}")
+
+ for chain, _ in enumerate(txt_chains):
+ hover_line = list()
+ for node, _ in enumerate(txt_nodes):
+ if data[chain][node] is not None:
+ annotations.append(
+ dict(
+ x=node+1,
+ y=chain+1,
+ xref=u"x",
+ yref=u"y",
+ xanchor=u"center",
+ yanchor=u"middle",
+ text=str(data[chain][node]),
+ font=dict(
+ size=14,
+ ),
+ align=u"center",
+ showarrow=False
+ )
+ )
+ hover_line.append(text.format(
+ name=vals[txt_chains[chain]][txt_nodes[node]][u"name"],
+ nr=vals[txt_chains[chain]][txt_nodes[node]][u"nr"],
+ val=data[chain][node],
+ stdev=vals[txt_chains[chain]][txt_nodes[node]][u"stdev"]))
+ hovertext.append(hover_line)
+
+ traces = [
+ plgo.Heatmap(
+ x=nodes,
+ y=chains,
+ z=data,
+ colorbar=dict(
+ title=plot.get(u"z-axis", u""),
+ titleside=u"right",
+ titlefont=dict(
+ size=16
+ ),
+ tickfont=dict(
+ size=16,
+ ),
+ tickformat=u".1f",
+ yanchor=u"bottom",
+ y=-0.02,
+ len=0.925,
+ ),
+ showscale=True,
+ colorscale=my_green,
+ text=hovertext,
+ hoverinfo=u"text"
+ )
+ ]
+
+ for idx, item in enumerate(txt_nodes):
+ # X-axis, numbers:
+ annotations.append(
+ dict(
+ x=idx+1,
+ y=0.05,
+ xref=u"x",
+ yref=u"y",
+ xanchor=u"center",
+ yanchor=u"top",
+ text=item,
+ font=dict(
+ size=16,
+ ),
+ align=u"center",
+ showarrow=False
+ )
+ )
+ for idx, item in enumerate(txt_chains):
+ # Y-axis, numbers:
+ annotations.append(
+ dict(
+ x=0.35,
+ y=idx+1,
+ xref=u"x",
+ yref=u"y",
+ xanchor=u"right",
+ yanchor=u"middle",
+ text=item,
+ font=dict(
+ size=16,
+ ),
+ align=u"center",
+ showarrow=False
+ )
+ )
+ # X-axis, title:
+ annotations.append(
+ dict(
+ x=0.55,
+ y=-0.15,
+ xref=u"paper",
+ yref=u"y",
+ xanchor=u"center",
+ yanchor=u"bottom",
+ text=plot.get(u"x-axis", u""),
+ font=dict(
+ size=16,
+ ),
+ align=u"center",
+ showarrow=False
+ )
+ )
+ # Y-axis, title:
+ annotations.append(
+ dict(
+ x=-0.1,
+ y=0.5,
+ xref=u"x",
+ yref=u"paper",
+ xanchor=u"center",
+ yanchor=u"middle",
+ text=plot.get(u"y-axis", u""),
+ font=dict(
+ size=16,
+ ),
+ align=u"center",
+ textangle=270,
+ showarrow=False
+ )
+ )
+ updatemenus = list([
+ dict(
+ x=1.0,
+ y=0.0,
+ xanchor=u"right",
+ yanchor=u"bottom",
+ direction=u"up",
+ buttons=list([
+ dict(
+ args=[
+ {
+ u"colorscale": [my_green, ],
+ u"reversescale": False
+ }
+ ],
+ label=u"Green",
+ method=u"update"
+ ),
+ dict(
+ args=[
+ {
+ u"colorscale": [my_blue, ],
+ u"reversescale": False
+ }
+ ],
+ label=u"Blue",
+ method=u"update"
+ ),
+ dict(
+ args=[
+ {
+ u"colorscale": [my_grey, ],
+ u"reversescale": False
+ }
+ ],
+ label=u"Grey",
+ method=u"update"
+ )
+ ])
+ )
+ ])
+
+ try:
+ layout = deepcopy(plot[u"layout"])
+ except KeyError as err:
+ logging.error(f"Finished with error: No layout defined\n{repr(err)}")
+ return
+
+ layout[u"annotations"] = annotations
+ layout[u'updatemenus'] = updatemenus
+
+ try:
+ # Create plot
+ plpl = plgo.Figure(data=traces, layout=layout)
+
+ # Export Plot
+ logging.info(f" Writing file {plot[u'output-file']}.html")
+ ploff.plot(
+ plpl,
+ show_link=False,
+ auto_open=False,
+ filename=f"{plot[u'output-file']}.html"
+ )
+ except PlotlyError as err:
+ logging.error(
+ f" Finished with error: {repr(err)}".replace(u"\n", u" ")
+ )
+ return