1 # Copyright (c) 2020 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
14 """Algorithms to generate plots.
21 from collections import OrderedDict
22 from copy import deepcopy
27 import plotly.offline as ploff
28 import plotly.graph_objs as plgo
30 from plotly.exceptions import PlotlyError
32 from pal_utils import mean, stdev
35 COLORS = [u"SkyBlue", u"Olive", u"Purple", u"Coral", u"Indigo", u"Pink",
36 u"Chocolate", u"Brown", u"Magenta", u"Cyan", u"Orange", u"Black",
37 u"Violet", u"Blue", u"Yellow", u"BurlyWood", u"CadetBlue", u"Crimson",
38 u"DarkBlue", u"DarkCyan", u"DarkGreen", u"Green", u"GoldenRod",
39 u"LightGreen", u"LightSeaGreen", u"LightSkyBlue", u"Maroon",
40 u"MediumSeaGreen", u"SeaGreen", u"LightSlateGrey"]
42 REGEX_NIC = re.compile(r'(\d*ge\dp\d\D*\d*[a-z]*)-')
45 def generate_plots(spec, data):
46 """Generate all plots specified in the specification file.
48 :param spec: Specification read from the specification file.
49 :param data: Data to process.
50 :type spec: Specification
55 u"plot_nf_reconf_box_name": plot_nf_reconf_box_name,
56 u"plot_perf_box_name": plot_perf_box_name,
57 u"plot_tsa_name": plot_tsa_name,
58 u"plot_http_server_perf_box": plot_http_server_perf_box,
59 u"plot_nf_heatmap": plot_nf_heatmap,
60 u"plot_hdrh_lat_by_percentile": plot_hdrh_lat_by_percentile
63 logging.info(u"Generating the plots ...")
64 for index, plot in enumerate(spec.plots):
66 logging.info(f" Plot nr {index + 1}: {plot.get(u'title', u'')}")
67 plot[u"limits"] = spec.configuration[u"limits"]
68 generator[plot[u"algorithm"]](plot, data)
69 logging.info(u" Done.")
70 except NameError as err:
72 f"Probably algorithm {plot[u'algorithm']} is not defined: "
75 logging.info(u"Done.")
78 def plot_hdrh_lat_by_percentile(plot, input_data):
79 """Generate the plot(s) with algorithm: plot_hdrh_lat_by_percentile
80 specified in the specification file.
82 :param plot: Plot to generate.
83 :param input_data: Data to process.
84 :type plot: pandas.Series
85 :type input_data: InputData
90 f" Creating the data set for the {plot.get(u'type', u'')} "
91 f"{plot.get(u'title', u'')}."
93 if plot.get(u"include", None):
94 data = input_data.filter_tests_by_name(
96 params=[u"name", u"latency", u"parent", u"tags", u"type"]
98 elif plot.get(u"filter", None):
99 data = input_data.filter_data(
101 params=[u"name", u"latency", u"parent", u"tags", u"type"],
102 continue_on_error=True
105 job = list(plot[u"data"].keys())[0]
106 build = str(plot[u"data"][job][0])
107 data = input_data.tests(job, build)
109 if data is None or len(data) == 0:
110 logging.error(u"No data.")
114 u"LAT0": u"No-load.",
115 u"PDR10": u"Low-load, 10% PDR.",
116 u"PDR50": u"Mid-load, 50% PDR.",
117 u"PDR90": u"High-load, 90% PDR.",
118 u"PDR": u"Full-load, 100% PDR.",
119 u"NDR10": u"Low-load, 10% NDR.",
120 u"NDR50": u"Mid-load, 50% NDR.",
121 u"NDR90": u"High-load, 90% NDR.",
122 u"NDR": u"Full-load, 100% NDR."
132 file_links = plot.get(u"output-file-links", None)
133 target_links = plot.get(u"target-links", None)
137 if test[u"type"] not in (u"NDRPDR",):
138 logging.warning(f"Invalid test type: {test[u'type']}")
140 name = re.sub(REGEX_NIC, u"", test[u"parent"].
141 replace(u'-ndrpdr', u'').replace(u'2n1l-', u''))
143 nic = re.search(REGEX_NIC, test[u"parent"]).group(1)
144 except (IndexError, AttributeError, KeyError, ValueError):
146 name_link = f"{nic}-{test[u'name']}".replace(u'-ndrpdr', u'')
148 logging.info(f" Generating the graph: {name_link}")
151 layout = deepcopy(plot[u"layout"])
153 for color, graph in enumerate(graphs):
154 for idx, direction in enumerate((u"direction1", u"direction2")):
158 f"<b>{desc[graph]}</b><br>"
159 f"Direction: {(u'W-E', u'E-W')[idx % 2]}<br>"
160 f"Percentile: 0.0%<br>"
163 decoded = hdrh.histogram.HdrHistogram.decode(
164 test[u"latency"][graph][direction][u"hdrh"]
166 for item in decoded.get_recorded_iterator():
167 percentile = item.percentile_level_iterated_to
168 if percentile > 99.9:
170 xaxis.append(percentile)
171 yaxis.append(item.value_iterated_to)
173 f"<b>{desc[graph]}</b><br>"
174 f"Direction: {(u'W-E', u'E-W')[idx % 2]}<br>"
175 f"Percentile: {percentile:.5f}%<br>"
176 f"Latency: {item.value_iterated_to}uSec"
184 legendgroup=desc[graph],
185 showlegend=bool(idx),
188 dash=u"solid" if idx % 2 else u"dash"
195 layout[u"title"][u"text"] = f"<b>Latency:</b> {name}"
196 fig.update_layout(layout)
199 file_name = f"{plot[u'output-file']}-{name_link}.html"
200 logging.info(f" Writing file {file_name}")
204 ploff.plot(fig, show_link=False, auto_open=False,
206 # Add link to the file:
207 if file_links and target_links:
208 with open(file_links, u"a") as file_handler:
211 f"<{target_links}/{file_name.split(u'/')[-1]}>`_\n"
213 except FileNotFoundError as err:
215 f"Not possible to write the link to the file "
216 f"{file_links}\n{err}"
218 except PlotlyError as err:
219 logging.error(f" Finished with error: {repr(err)}")
221 except hdrh.codec.HdrLengthException as err:
222 logging.warning(repr(err))
225 except (ValueError, KeyError) as err:
226 logging.warning(repr(err))
230 def plot_nf_reconf_box_name(plot, input_data):
231 """Generate the plot(s) with algorithm: plot_nf_reconf_box_name
232 specified in the specification file.
234 :param plot: Plot to generate.
235 :param input_data: Data to process.
236 :type plot: pandas.Series
237 :type input_data: InputData
242 f" Creating the data set for the {plot.get(u'type', u'')} "
243 f"{plot.get(u'title', u'')}."
245 data = input_data.filter_tests_by_name(
246 plot, params=[u"result", u"parent", u"tags", u"type"]
249 logging.error(u"No data.")
252 # Prepare the data for the plot
253 y_vals = OrderedDict()
258 if y_vals.get(test[u"parent"], None) is None:
259 y_vals[test[u"parent"]] = list()
260 loss[test[u"parent"]] = list()
262 y_vals[test[u"parent"]].append(test[u"result"][u"time"])
263 loss[test[u"parent"]].append(test[u"result"][u"loss"])
264 except (KeyError, TypeError):
265 y_vals[test[u"parent"]].append(None)
267 # Add None to the lists with missing data
269 nr_of_samples = list()
270 for val in y_vals.values():
271 if len(val) > max_len:
273 nr_of_samples.append(len(val))
274 for val in y_vals.values():
275 if len(val) < max_len:
276 val.extend([None for _ in range(max_len - len(val))])
280 df_y = pd.DataFrame(y_vals)
282 for i, col in enumerate(df_y.columns):
283 tst_name = re.sub(REGEX_NIC, u"",
284 col.lower().replace(u'-ndrpdr', u'').
285 replace(u'2n1l-', u''))
287 traces.append(plgo.Box(
288 x=[str(i + 1) + u'.'] * len(df_y[col]),
289 y=[y if y else None for y in df_y[col]],
292 f"({nr_of_samples[i]:02d} "
293 f"run{u's' if nr_of_samples[i] > 1 else u''}, "
294 f"packets lost average: {mean(loss[col]):.1f}) "
295 f"{u'-'.join(tst_name.split(u'-')[3:-2])}"
301 layout = deepcopy(plot[u"layout"])
302 layout[u"title"] = f"<b>Time Lost:</b> {layout[u'title']}"
303 layout[u"yaxis"][u"title"] = u"<b>Implied Time Lost [s]</b>"
304 layout[u"legend"][u"font"][u"size"] = 14
305 layout[u"yaxis"].pop(u"range")
306 plpl = plgo.Figure(data=traces, layout=layout)
309 file_type = plot.get(u"output-file-type", u".html")
310 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
315 filename=f"{plot[u'output-file']}{file_type}"
317 except PlotlyError as err:
319 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
324 def plot_perf_box_name(plot, input_data):
325 """Generate the plot(s) with algorithm: plot_perf_box_name
326 specified in the specification file.
328 :param plot: Plot to generate.
329 :param input_data: Data to process.
330 :type plot: pandas.Series
331 :type input_data: InputData
336 f" Creating data set for the {plot.get(u'type', u'')} "
337 f"{plot.get(u'title', u'')}."
339 data = input_data.filter_tests_by_name(
340 plot, params=[u"throughput", u"result", u"parent", u"tags", u"type"])
342 logging.error(u"No data.")
345 # Prepare the data for the plot
346 y_vals = OrderedDict()
351 if y_vals.get(test[u"parent"], None) is None:
352 y_vals[test[u"parent"]] = list()
354 if (test[u"type"] in (u"NDRPDR", ) and
355 u"-pdr" in plot.get(u"title", u"").lower()):
356 y_vals[test[u"parent"]].\
357 append(test[u"throughput"][u"PDR"][u"LOWER"])
358 test_type = u"NDRPDR"
359 elif (test[u"type"] in (u"NDRPDR", ) and
360 u"-ndr" in plot.get(u"title", u"").lower()):
361 y_vals[test[u"parent"]]. \
362 append(test[u"throughput"][u"NDR"][u"LOWER"])
363 test_type = u"NDRPDR"
364 elif test[u"type"] in (u"SOAK", ):
365 y_vals[test[u"parent"]].\
366 append(test[u"throughput"][u"LOWER"])
368 elif test[u"type"] in (u"HOSTSTACK", ):
369 if u"LDPRELOAD" in test[u"tags"]:
370 y_vals[test[u"parent"]].append(
371 float(test[u"result"][u"bits_per_second"]) / 1e3
373 elif u"VPPECHO" in test[u"tags"]:
374 y_vals[test[u"parent"]].append(
375 (float(test[u"result"][u"client"][u"tx_data"])
377 ((float(test[u"result"][u"client"][u"time"]) +
378 float(test[u"result"][u"server"][u"time"])) /
381 test_type = u"HOSTSTACK"
384 except (KeyError, TypeError):
385 y_vals[test[u"parent"]].append(None)
387 # Add None to the lists with missing data
389 nr_of_samples = list()
390 for val in y_vals.values():
391 if len(val) > max_len:
393 nr_of_samples.append(len(val))
394 for val in y_vals.values():
395 if len(val) < max_len:
396 val.extend([None for _ in range(max_len - len(val))])
400 df_y = pd.DataFrame(y_vals)
403 for i, col in enumerate(df_y.columns):
404 tst_name = re.sub(REGEX_NIC, u"",
405 col.lower().replace(u'-ndrpdr', u'').
406 replace(u'2n1l-', u''))
408 x=[str(i + 1) + u'.'] * len(df_y[col]),
409 y=[y / 1e6 if y else None for y in df_y[col]],
412 f"({nr_of_samples[i]:02d} "
413 f"run{u's' if nr_of_samples[i] > 1 else u''}) "
418 if test_type in (u"SOAK", ):
419 kwargs[u"boxpoints"] = u"all"
421 traces.append(plgo.Box(**kwargs))
424 val_max = max(df_y[col])
426 y_max.append(int(val_max / 1e6) + 2)
427 except (ValueError, TypeError) as err:
428 logging.error(repr(err))
433 layout = deepcopy(plot[u"layout"])
434 if layout.get(u"title", None):
435 if test_type in (u"HOSTSTACK", ):
436 layout[u"title"] = f"<b>Bandwidth:</b> {layout[u'title']}"
438 layout[u"title"] = f"<b>Throughput:</b> {layout[u'title']}"
440 layout[u"yaxis"][u"range"] = [0, max(y_max)]
441 plpl = plgo.Figure(data=traces, layout=layout)
444 logging.info(f" Writing file {plot[u'output-file']}.html.")
449 filename=f"{plot[u'output-file']}.html"
451 except PlotlyError as err:
453 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
458 def plot_tsa_name(plot, input_data):
459 """Generate the plot(s) with algorithm:
461 specified in the specification file.
463 :param plot: Plot to generate.
464 :param input_data: Data to process.
465 :type plot: pandas.Series
466 :type input_data: InputData
470 plot_title = plot.get(u"title", u"")
472 f" Creating data set for the {plot.get(u'type', u'')} {plot_title}."
474 data = input_data.filter_tests_by_name(
475 plot, params=[u"throughput", u"parent", u"tags", u"type"])
477 logging.error(u"No data.")
480 y_vals = OrderedDict()
484 if y_vals.get(test[u"parent"], None) is None:
485 y_vals[test[u"parent"]] = {
491 if test[u"type"] not in (u"NDRPDR",):
494 if u"-pdr" in plot_title.lower():
496 elif u"-ndr" in plot_title.lower():
501 if u"1C" in test[u"tags"]:
502 y_vals[test[u"parent"]][u"1"]. \
503 append(test[u"throughput"][ttype][u"LOWER"])
504 elif u"2C" in test[u"tags"]:
505 y_vals[test[u"parent"]][u"2"]. \
506 append(test[u"throughput"][ttype][u"LOWER"])
507 elif u"4C" in test[u"tags"]:
508 y_vals[test[u"parent"]][u"4"]. \
509 append(test[u"throughput"][ttype][u"LOWER"])
510 except (KeyError, TypeError):
514 logging.warning(f"No data for the plot {plot.get(u'title', u'')}")
518 for test_name, test_vals in y_vals.items():
519 for key, test_val in test_vals.items():
521 avg_val = sum(test_val) / len(test_val)
522 y_vals[test_name][key] = [avg_val, len(test_val)]
523 ideal = avg_val / (int(key) * 1e6)
524 if test_name not in y_1c_max or ideal > y_1c_max[test_name]:
525 y_1c_max[test_name] = ideal
531 pci_limit = plot[u"limits"][u"pci"][u"pci-g3-x8"]
532 for test_name, test_vals in y_vals.items():
534 if test_vals[u"1"][1]:
538 test_name.replace(u'-ndrpdr', u'').replace(u'2n1l-', u'')
540 vals[name] = OrderedDict()
541 y_val_1 = test_vals[u"1"][0] / 1e6
542 y_val_2 = test_vals[u"2"][0] / 1e6 if test_vals[u"2"][0] \
544 y_val_4 = test_vals[u"4"][0] / 1e6 if test_vals[u"4"][0] \
547 vals[name][u"val"] = [y_val_1, y_val_2, y_val_4]
548 vals[name][u"rel"] = [1.0, None, None]
549 vals[name][u"ideal"] = [
551 y_1c_max[test_name] * 2,
552 y_1c_max[test_name] * 4
554 vals[name][u"diff"] = [
555 (y_val_1 - y_1c_max[test_name]) * 100 / y_val_1, None, None
557 vals[name][u"count"] = [
564 val_max = max(vals[name][u"val"])
565 except ValueError as err:
566 logging.error(repr(err))
569 y_max.append(val_max)
572 vals[name][u"rel"][1] = round(y_val_2 / y_val_1, 2)
573 vals[name][u"diff"][1] = \
574 (y_val_2 - vals[name][u"ideal"][1]) * 100 / y_val_2
576 vals[name][u"rel"][2] = round(y_val_4 / y_val_1, 2)
577 vals[name][u"diff"][2] = \
578 (y_val_4 - vals[name][u"ideal"][2]) * 100 / y_val_4
579 except IndexError as err:
580 logging.warning(f"No data for {test_name}")
581 logging.warning(repr(err))
584 if u"x520" in test_name:
585 limit = plot[u"limits"][u"nic"][u"x520"]
586 elif u"x710" in test_name:
587 limit = plot[u"limits"][u"nic"][u"x710"]
588 elif u"xxv710" in test_name:
589 limit = plot[u"limits"][u"nic"][u"xxv710"]
590 elif u"xl710" in test_name:
591 limit = plot[u"limits"][u"nic"][u"xl710"]
592 elif u"x553" in test_name:
593 limit = plot[u"limits"][u"nic"][u"x553"]
594 elif u"cx556a" in test_name:
595 limit = plot[u"limits"][u"nic"][u"cx556a"]
598 if limit > nic_limit:
601 mul = 2 if u"ge2p" in test_name else 1
602 if u"10ge" in test_name:
603 limit = plot[u"limits"][u"link"][u"10ge"] * mul
604 elif u"25ge" in test_name:
605 limit = plot[u"limits"][u"link"][u"25ge"] * mul
606 elif u"40ge" in test_name:
607 limit = plot[u"limits"][u"link"][u"40ge"] * mul
608 elif u"100ge" in test_name:
609 limit = plot[u"limits"][u"link"][u"100ge"] * mul
612 if limit > lnk_limit:
621 threshold = 1.1 * max(y_max) # 10%
622 except ValueError as err:
626 traces.append(plgo.Scatter(
628 y=[nic_limit, ] * len(x_vals),
629 name=f"NIC: {nic_limit:.2f}Mpps",
638 annotations.append(dict(
645 text=f"NIC: {nic_limit:.2f}Mpps",
653 y_max.append(nic_limit)
656 if lnk_limit < threshold:
657 traces.append(plgo.Scatter(
659 y=[lnk_limit, ] * len(x_vals),
660 name=f"Link: {lnk_limit:.2f}Mpps",
669 annotations.append(dict(
676 text=f"Link: {lnk_limit:.2f}Mpps",
684 y_max.append(lnk_limit)
687 if (pci_limit < threshold and
688 (pci_limit < lnk_limit * 0.95 or lnk_limit > lnk_limit * 1.05)):
689 traces.append(plgo.Scatter(
691 y=[pci_limit, ] * len(x_vals),
692 name=f"PCIe: {pci_limit:.2f}Mpps",
701 annotations.append(dict(
708 text=f"PCIe: {pci_limit:.2f}Mpps",
716 y_max.append(pci_limit)
718 # Perfect and measured:
720 for name, val in vals.items():
723 for idx in range(len(val[u"val"])):
725 if isinstance(val[u"val"][idx], float):
727 f"No. of Runs: {val[u'count'][idx]}<br>"
728 f"Mean: {val[u'val'][idx]:.2f}Mpps<br>"
730 if isinstance(val[u"diff"][idx], float):
731 htext += f"Diff: {round(val[u'diff'][idx]):.0f}%<br>"
732 if isinstance(val[u"rel"][idx], float):
733 htext += f"Speedup: {val[u'rel'][idx]:.2f}"
734 hovertext.append(htext)
741 mode=u"lines+markers",
750 hoverinfo=u"text+name"
757 name=f"{name} perfect",
765 text=[f"Perfect: {y:.2f}Mpps" for y in val[u"ideal"]],
770 except (IndexError, ValueError, KeyError) as err:
771 logging.warning(f"No data for {name}\n{repr(err)}")
775 file_type = plot.get(u"output-file-type", u".html")
776 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
777 layout = deepcopy(plot[u"layout"])
778 if layout.get(u"title", None):
779 layout[u"title"] = f"<b>Speedup Multi-core:</b> {layout[u'title']}"
780 layout[u"yaxis"][u"range"] = [0, int(max(y_max) * 1.1)]
781 layout[u"annotations"].extend(annotations)
782 plpl = plgo.Figure(data=traces, layout=layout)
789 filename=f"{plot[u'output-file']}{file_type}"
791 except PlotlyError as err:
793 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
798 def plot_http_server_perf_box(plot, input_data):
799 """Generate the plot(s) with algorithm: plot_http_server_perf_box
800 specified in the specification file.
802 :param plot: Plot to generate.
803 :param input_data: Data to process.
804 :type plot: pandas.Series
805 :type input_data: InputData
810 f" Creating the data set for the {plot.get(u'type', u'')} "
811 f"{plot.get(u'title', u'')}."
813 data = input_data.filter_data(plot)
815 logging.error(u"No data.")
818 # Prepare the data for the plot
823 if y_vals.get(test[u"name"], None) is None:
824 y_vals[test[u"name"]] = list()
826 y_vals[test[u"name"]].append(test[u"result"])
827 except (KeyError, TypeError):
828 y_vals[test[u"name"]].append(None)
830 # Add None to the lists with missing data
832 nr_of_samples = list()
833 for val in y_vals.values():
834 if len(val) > max_len:
836 nr_of_samples.append(len(val))
837 for val in y_vals.values():
838 if len(val) < max_len:
839 val.extend([None for _ in range(max_len - len(val))])
843 df_y = pd.DataFrame(y_vals)
845 for i, col in enumerate(df_y.columns):
848 f"({nr_of_samples[i]:02d} " \
849 f"run{u's' if nr_of_samples[i] > 1 else u''}) " \
850 f"{col.lower().replace(u'-ndrpdr', u'')}"
852 name_lst = name.split(u'-')
855 for segment in name_lst:
856 if (len(name) + len(segment) + 1) > 50 and split_name:
859 name += segment + u'-'
862 traces.append(plgo.Box(x=[str(i + 1) + u'.'] * len(df_y[col]),
868 plpl = plgo.Figure(data=traces, layout=plot[u"layout"])
872 f" Writing file {plot[u'output-file']}"
873 f"{plot[u'output-file-type']}."
879 filename=f"{plot[u'output-file']}{plot[u'output-file-type']}"
881 except PlotlyError as err:
883 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
888 def plot_nf_heatmap(plot, input_data):
889 """Generate the plot(s) with algorithm: plot_nf_heatmap
890 specified in the specification file.
892 :param plot: Plot to generate.
893 :param input_data: Data to process.
894 :type plot: pandas.Series
895 :type input_data: InputData
898 regex_cn = re.compile(r'^(\d*)R(\d*)C$')
899 regex_test_name = re.compile(r'^.*-(\d+ch|\d+pl)-'
901 r'(\d+vm\d+t|\d+dcr\d+t|\d+dcr\d+c).*$')
906 f" Creating the data set for the {plot.get(u'type', u'')} "
907 f"{plot.get(u'title', u'')}."
909 data = input_data.filter_data(plot, continue_on_error=True)
910 if data is None or data.empty:
911 logging.error(u"No data.")
917 for tag in test[u"tags"]:
918 groups = re.search(regex_cn, tag)
920 chain = str(groups.group(1))
921 node = str(groups.group(2))
925 groups = re.search(regex_test_name, test[u"name"])
926 if groups and len(groups.groups()) == 3:
928 f"{str(groups.group(1))}-"
929 f"{str(groups.group(2))}-"
930 f"{str(groups.group(3))}"
934 if vals.get(chain, None) is None:
936 if vals[chain].get(node, None) is None:
937 vals[chain][node] = dict(
945 if plot[u"include-tests"] == u"MRR":
946 result = test[u"result"][u"receive-rate"]
947 elif plot[u"include-tests"] == u"PDR":
948 result = test[u"throughput"][u"PDR"][u"LOWER"]
949 elif plot[u"include-tests"] == u"NDR":
950 result = test[u"throughput"][u"NDR"][u"LOWER"]
957 vals[chain][node][u"vals"].append(result)
960 logging.error(u"No data.")
966 txt_chains.append(key_c)
967 for key_n in vals[key_c].keys():
968 txt_nodes.append(key_n)
969 if vals[key_c][key_n][u"vals"]:
970 vals[key_c][key_n][u"nr"] = len(vals[key_c][key_n][u"vals"])
971 vals[key_c][key_n][u"mean"] = \
972 round(mean(vals[key_c][key_n][u"vals"]) / 1000000, 1)
973 vals[key_c][key_n][u"stdev"] = \
974 round(stdev(vals[key_c][key_n][u"vals"]) / 1000000, 1)
975 txt_nodes = list(set(txt_nodes))
977 def sort_by_int(value):
978 """Makes possible to sort a list of strings which represent integers.
980 :param value: Integer as a string.
982 :returns: Integer representation of input parameter 'value'.
987 txt_chains = sorted(txt_chains, key=sort_by_int)
988 txt_nodes = sorted(txt_nodes, key=sort_by_int)
990 chains = [i + 1 for i in range(len(txt_chains))]
991 nodes = [i + 1 for i in range(len(txt_nodes))]
993 data = [list() for _ in range(len(chains))]
997 val = vals[txt_chains[chain - 1]][txt_nodes[node - 1]][u"mean"]
998 except (KeyError, IndexError):
1000 data[chain - 1].append(val)
1003 my_green = [[0.0, u"rgb(235, 249, 242)"],
1004 [1.0, u"rgb(45, 134, 89)"]]
1006 my_blue = [[0.0, u"rgb(236, 242, 248)"],
1007 [1.0, u"rgb(57, 115, 172)"]]
1009 my_grey = [[0.0, u"rgb(230, 230, 230)"],
1010 [1.0, u"rgb(102, 102, 102)"]]
1013 annotations = list()
1015 text = (u"Test: {name}<br>"
1020 for chain, _ in enumerate(txt_chains):
1022 for node, _ in enumerate(txt_nodes):
1023 if data[chain][node] is not None:
1032 text=str(data[chain][node]),
1040 hover_line.append(text.format(
1041 name=vals[txt_chains[chain]][txt_nodes[node]][u"name"],
1042 nr=vals[txt_chains[chain]][txt_nodes[node]][u"nr"],
1043 val=data[chain][node],
1044 stdev=vals[txt_chains[chain]][txt_nodes[node]][u"stdev"]))
1045 hovertext.append(hover_line)
1053 title=plot.get(u"z-axis", u""),
1067 colorscale=my_green,
1073 for idx, item in enumerate(txt_nodes):
1091 for idx, item in enumerate(txt_chains):
1118 text=plot.get(u"x-axis", u""),
1135 text=plot.get(u"y-axis", u""),
1144 updatemenus = list([
1155 u"colorscale": [my_green, ],
1156 u"reversescale": False
1165 u"colorscale": [my_blue, ],
1166 u"reversescale": False
1175 u"colorscale": [my_grey, ],
1176 u"reversescale": False
1187 layout = deepcopy(plot[u"layout"])
1188 except KeyError as err:
1189 logging.error(f"Finished with error: No layout defined\n{repr(err)}")
1192 layout[u"annotations"] = annotations
1193 layout[u'updatemenus'] = updatemenus
1197 plpl = plgo.Figure(data=traces, layout=layout)
1200 logging.info(f" Writing file {plot[u'output-file']}.html")
1205 filename=f"{plot[u'output-file']}.html"
1207 except PlotlyError as err:
1209 f" Finished with error: {repr(err)}".replace(u"\n", u" ")