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
61 REGEX_NIC = re.compile(r'(\d*ge\dp\d\D*\d*[a-z]*)-')
64 def generate_plots(spec, data):
65 """Generate all plots specified in the specification file.
67 :param spec: Specification read from the specification file.
68 :param data: Data to process.
69 :type spec: Specification
74 u"plot_nf_reconf_box_name": plot_nf_reconf_box_name,
75 u"plot_perf_box_name": plot_perf_box_name,
76 u"plot_tsa_name": plot_tsa_name,
77 u"plot_http_server_perf_box": plot_http_server_perf_box,
78 u"plot_nf_heatmap": plot_nf_heatmap,
79 u"plot_hdrh_lat_by_percentile": plot_hdrh_lat_by_percentile
82 logging.info(u"Generating the plots ...")
83 for index, plot in enumerate(spec.plots):
85 logging.info(f" Plot nr {index + 1}: {plot.get(u'title', u'')}")
86 plot[u"limits"] = spec.configuration[u"limits"]
87 generator[plot[u"algorithm"]](plot, data)
88 logging.info(u" Done.")
89 except NameError as err:
91 f"Probably algorithm {plot[u'algorithm']} is not defined: "
94 logging.info(u"Done.")
97 def plot_hdrh_lat_by_percentile(plot, input_data):
98 """Generate the plot(s) with algorithm: plot_hdrh_lat_by_percentile
99 specified in the specification file.
101 :param plot: Plot to generate.
102 :param input_data: Data to process.
103 :type plot: pandas.Series
104 :type input_data: InputData
109 f" Creating the data set for the {plot.get(u'type', u'')} "
110 f"{plot.get(u'title', u'')}."
112 if plot.get(u"include", None):
113 data = input_data.filter_tests_by_name(
115 params=[u"name", u"latency", u"parent", u"tags", u"type"]
117 elif plot.get(u"filter", None):
118 data = input_data.filter_data(
120 params=[u"name", u"latency", u"parent", u"tags", u"type"],
121 continue_on_error=True
124 job = list(plot[u"data"].keys())[0]
125 build = str(plot[u"data"][job][0])
126 data = input_data.tests(job, build)
128 if data is None or len(data) == 0:
129 logging.error(u"No data.")
133 u"LAT0": u"No-load.",
134 u"PDR10": u"Low-load, 10% PDR.",
135 u"PDR50": u"Mid-load, 50% PDR.",
136 u"PDR90": u"High-load, 90% PDR.",
137 u"PDR": u"Full-load, 100% PDR.",
138 u"NDR10": u"Low-load, 10% NDR.",
139 u"NDR50": u"Mid-load, 50% NDR.",
140 u"NDR90": u"High-load, 90% NDR.",
141 u"NDR": u"Full-load, 100% NDR."
151 file_links = plot.get(u"output-file-links", None)
152 target_links = plot.get(u"target-links", None)
156 if test[u"type"] not in (u"NDRPDR",):
157 logging.warning(f"Invalid test type: {test[u'type']}")
159 name = re.sub(REGEX_NIC, u"", test[u"parent"].
160 replace(u'-ndrpdr', u'').replace(u'2n1l-', u''))
162 nic = re.search(REGEX_NIC, test[u"parent"]).group(1)
163 except (IndexError, AttributeError, KeyError, ValueError):
165 name_link = f"{nic}-{test[u'name']}".replace(u'-ndrpdr', u'')
167 logging.info(f" Generating the graph: {name_link}")
170 layout = deepcopy(plot[u"layout"])
172 for color, graph in enumerate(graphs):
173 for idx, direction in enumerate((u"direction1", u"direction2")):
177 f"<b>{desc[graph]}</b><br>"
178 f"Direction: {(u'W-E', u'E-W')[idx % 2]}<br>"
179 f"Percentile: 0.0%<br>"
183 decoded = hdrh.histogram.HdrHistogram.decode(
184 test[u"latency"][graph][direction][u"hdrh"]
186 except hdrh.codec.HdrLengthException:
188 f"No data for direction {(u'W-E', u'E-W')[idx % 2]}"
192 for item in decoded.get_recorded_iterator():
193 percentile = item.percentile_level_iterated_to
194 if percentile > 99.9:
196 xaxis.append(percentile)
197 yaxis.append(item.value_iterated_to)
199 f"<b>{desc[graph]}</b><br>"
200 f"Direction: {(u'W-E', u'E-W')[idx % 2]}<br>"
201 f"Percentile: {percentile:.5f}%<br>"
202 f"Latency: {item.value_iterated_to}uSec"
210 legendgroup=desc[graph],
211 showlegend=bool(idx),
214 dash=u"dash" if idx % 2 else u"solid"
221 layout[u"title"][u"text"] = f"<b>Latency:</b> {name}"
222 fig.update_layout(layout)
225 file_name = f"{plot[u'output-file']}-{name_link}.html"
226 logging.info(f" Writing file {file_name}")
230 ploff.plot(fig, show_link=False, auto_open=False,
232 # Add link to the file:
233 if file_links and target_links:
234 with open(file_links, u"a") as file_handler:
237 f"<{target_links}/{file_name.split(u'/')[-1]}>`_\n"
239 except FileNotFoundError as err:
241 f"Not possible to write the link to the file "
242 f"{file_links}\n{err}"
244 except PlotlyError as err:
245 logging.error(f" Finished with error: {repr(err)}")
247 except hdrh.codec.HdrLengthException as err:
248 logging.warning(repr(err))
251 except (ValueError, KeyError) as err:
252 logging.warning(repr(err))
256 def plot_nf_reconf_box_name(plot, input_data):
257 """Generate the plot(s) with algorithm: plot_nf_reconf_box_name
258 specified in the specification file.
260 :param plot: Plot to generate.
261 :param input_data: Data to process.
262 :type plot: pandas.Series
263 :type input_data: InputData
268 f" Creating the data set for the {plot.get(u'type', u'')} "
269 f"{plot.get(u'title', u'')}."
271 data = input_data.filter_tests_by_name(
272 plot, params=[u"result", u"parent", u"tags", u"type"]
275 logging.error(u"No data.")
278 # Prepare the data for the plot
279 y_vals = OrderedDict()
284 if y_vals.get(test[u"parent"], None) is None:
285 y_vals[test[u"parent"]] = list()
286 loss[test[u"parent"]] = list()
288 y_vals[test[u"parent"]].append(test[u"result"][u"time"])
289 loss[test[u"parent"]].append(test[u"result"][u"loss"])
290 except (KeyError, TypeError):
291 y_vals[test[u"parent"]].append(None)
293 # Add None to the lists with missing data
295 nr_of_samples = list()
296 for val in y_vals.values():
297 if len(val) > max_len:
299 nr_of_samples.append(len(val))
300 for val in y_vals.values():
301 if len(val) < max_len:
302 val.extend([None for _ in range(max_len - len(val))])
306 df_y = pd.DataFrame(y_vals)
308 for i, col in enumerate(df_y.columns):
309 tst_name = re.sub(REGEX_NIC, u"",
310 col.lower().replace(u'-ndrpdr', u'').
311 replace(u'2n1l-', u''))
313 traces.append(plgo.Box(
314 x=[str(i + 1) + u'.'] * len(df_y[col]),
315 y=[y if y else None for y in df_y[col]],
318 f"({nr_of_samples[i]:02d} "
319 f"run{u's' if nr_of_samples[i] > 1 else u''}, "
320 f"packets lost average: {mean(loss[col]):.1f}) "
321 f"{u'-'.join(tst_name.split(u'-')[3:-2])}"
327 layout = deepcopy(plot[u"layout"])
328 layout[u"title"] = f"<b>Time Lost:</b> {layout[u'title']}"
329 layout[u"yaxis"][u"title"] = u"<b>Effective Blocked Time [s]</b>"
330 layout[u"legend"][u"font"][u"size"] = 14
331 layout[u"yaxis"].pop(u"range")
332 plpl = plgo.Figure(data=traces, layout=layout)
335 file_type = plot.get(u"output-file-type", u".html")
336 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
341 filename=f"{plot[u'output-file']}{file_type}"
343 except PlotlyError as err:
345 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
350 def plot_perf_box_name(plot, input_data):
351 """Generate the plot(s) with algorithm: plot_perf_box_name
352 specified in the specification file.
354 :param plot: Plot to generate.
355 :param input_data: Data to process.
356 :type plot: pandas.Series
357 :type input_data: InputData
362 f" Creating data set for the {plot.get(u'type', u'')} "
363 f"{plot.get(u'title', u'')}."
365 data = input_data.filter_tests_by_name(
367 params=[u"throughput", u"gbps", u"result", u"parent", u"tags", u"type"])
369 logging.error(u"No data.")
372 # Prepare the data for the plot
373 plot_title = plot.get(u"title", u"").lower()
375 if u"-gbps" in plot_title:
379 value = u"throughput"
381 y_vals = OrderedDict()
386 if y_vals.get(test[u"parent"], None) is None:
387 y_vals[test[u"parent"]] = list()
389 if test[u"type"] in (u"NDRPDR", ):
390 test_type = u"NDRPDR"
392 if u"-pdr" in plot_title:
394 elif u"-ndr" in plot_title:
398 u"Wrong title. No information about test type. "
399 u"Add '-ndr' or '-pdr' to the test title."
402 y_vals[test[u"parent"]].append(
403 test[value][ttype][u"LOWER"] * multiplier
406 elif test[u"type"] in (u"SOAK", ):
407 y_vals[test[u"parent"]].\
408 append(test[u"throughput"][u"LOWER"])
411 elif test[u"type"] in (u"HOSTSTACK", ):
412 if u"LDPRELOAD" in test[u"tags"]:
413 y_vals[test[u"parent"]].append(
414 float(test[u"result"][u"bits_per_second"]) / 1e3
416 elif u"VPPECHO" in test[u"tags"]:
417 y_vals[test[u"parent"]].append(
418 (float(test[u"result"][u"client"][u"tx_data"])
420 ((float(test[u"result"][u"client"][u"time"]) +
421 float(test[u"result"][u"server"][u"time"])) /
424 test_type = u"HOSTSTACK"
429 except (KeyError, TypeError):
430 y_vals[test[u"parent"]].append(None)
432 # Add None to the lists with missing data
434 nr_of_samples = list()
435 for val in y_vals.values():
436 if len(val) > max_len:
438 nr_of_samples.append(len(val))
439 for val in y_vals.values():
440 if len(val) < max_len:
441 val.extend([None for _ in range(max_len - len(val))])
445 df_y = pd.DataFrame(y_vals)
448 for i, col in enumerate(df_y.columns):
449 tst_name = re.sub(REGEX_NIC, u"",
450 col.lower().replace(u'-ndrpdr', u'').
451 replace(u'2n1l-', u''))
453 x=[str(i + 1) + u'.'] * len(df_y[col]),
454 y=[y / 1e6 if y else None for y in df_y[col]],
457 f"({nr_of_samples[i]:02d} "
458 f"run{u's' if nr_of_samples[i] > 1 else u''}) "
463 if test_type in (u"SOAK", ):
464 kwargs[u"boxpoints"] = u"all"
466 traces.append(plgo.Box(**kwargs))
469 val_max = max(df_y[col])
471 y_max.append(int(val_max / 1e6) + 2)
472 except (ValueError, TypeError) as err:
473 logging.error(repr(err))
478 layout = deepcopy(plot[u"layout"])
479 if layout.get(u"title", None):
480 if test_type in (u"HOSTSTACK", ):
481 layout[u"title"] = f"<b>Bandwidth:</b> {layout[u'title']}"
483 layout[u"title"] = f"<b>Throughput:</b> {layout[u'title']}"
485 layout[u"yaxis"][u"range"] = [0, max(y_max)]
486 plpl = plgo.Figure(data=traces, layout=layout)
489 logging.info(f" Writing file {plot[u'output-file']}.html.")
494 filename=f"{plot[u'output-file']}.html"
496 except PlotlyError as err:
498 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
503 def plot_tsa_name(plot, input_data):
504 """Generate the plot(s) with algorithm:
506 specified in the specification file.
508 :param plot: Plot to generate.
509 :param input_data: Data to process.
510 :type plot: pandas.Series
511 :type input_data: InputData
515 plot_title = plot.get(u"title", u"")
517 f" Creating data set for the {plot.get(u'type', u'')} {plot_title}."
519 data = input_data.filter_tests_by_name(
521 params=[u"throughput", u"gbps", u"parent", u"tags", u"type"]
524 logging.error(u"No data.")
527 plot_title = plot_title.lower()
529 if u"-gbps" in plot_title:
534 value = u"throughput"
538 y_vals = OrderedDict()
542 if y_vals.get(test[u"parent"], None) is None:
543 y_vals[test[u"parent"]] = {
549 if test[u"type"] not in (u"NDRPDR",):
552 if u"-pdr" in plot_title:
554 elif u"-ndr" in plot_title:
559 if u"1C" in test[u"tags"]:
560 y_vals[test[u"parent"]][u"1"]. \
561 append(test[value][ttype][u"LOWER"] * multiplier)
562 elif u"2C" in test[u"tags"]:
563 y_vals[test[u"parent"]][u"2"]. \
564 append(test[value][ttype][u"LOWER"] * multiplier)
565 elif u"4C" in test[u"tags"]:
566 y_vals[test[u"parent"]][u"4"]. \
567 append(test[value][ttype][u"LOWER"] * multiplier)
568 except (KeyError, TypeError):
572 logging.warning(f"No data for the plot {plot.get(u'title', u'')}")
576 for test_name, test_vals in y_vals.items():
577 for key, test_val in test_vals.items():
579 avg_val = sum(test_val) / len(test_val)
580 y_vals[test_name][key] = [avg_val, len(test_val)]
581 ideal = avg_val / (int(key) * 1e6)
582 if test_name not in y_1c_max or ideal > y_1c_max[test_name]:
583 y_1c_max[test_name] = ideal
590 for test_name, test_vals in y_vals.items():
592 if test_vals[u"1"][1]:
596 test_name.replace(u'-ndrpdr', u'').replace(u'2n1l-', u'')
598 vals[name] = OrderedDict()
599 y_val_1 = test_vals[u"1"][0] / 1e6
600 y_val_2 = test_vals[u"2"][0] / 1e6 if test_vals[u"2"][0] \
602 y_val_4 = test_vals[u"4"][0] / 1e6 if test_vals[u"4"][0] \
605 vals[name][u"val"] = [y_val_1, y_val_2, y_val_4]
606 vals[name][u"rel"] = [1.0, None, None]
607 vals[name][u"ideal"] = [
609 y_1c_max[test_name] * 2,
610 y_1c_max[test_name] * 4
612 vals[name][u"diff"] = [
613 (y_val_1 - y_1c_max[test_name]) * 100 / y_val_1, None, None
615 vals[name][u"count"] = [
622 val_max = max(vals[name][u"val"])
623 except ValueError as err:
624 logging.error(repr(err))
627 y_max.append(val_max)
630 vals[name][u"rel"][1] = round(y_val_2 / y_val_1, 2)
631 vals[name][u"diff"][1] = \
632 (y_val_2 - vals[name][u"ideal"][1]) * 100 / y_val_2
634 vals[name][u"rel"][2] = round(y_val_4 / y_val_1, 2)
635 vals[name][u"diff"][2] = \
636 (y_val_4 - vals[name][u"ideal"][2]) * 100 / y_val_4
637 except IndexError as err:
638 logging.warning(f"No data for {test_name}")
639 logging.warning(repr(err))
642 if u"x520" in test_name:
643 limit = plot[u"limits"][u"nic"][u"x520"]
644 elif u"x710" in test_name:
645 limit = plot[u"limits"][u"nic"][u"x710"]
646 elif u"xxv710" in test_name:
647 limit = plot[u"limits"][u"nic"][u"xxv710"]
648 elif u"xl710" in test_name:
649 limit = plot[u"limits"][u"nic"][u"xl710"]
650 elif u"x553" in test_name:
651 limit = plot[u"limits"][u"nic"][u"x553"]
652 elif u"cx556a" in test_name:
653 limit = plot[u"limits"][u"nic"][u"cx556a"]
656 if limit > nic_limit:
659 mul = 2 if u"ge2p" in test_name else 1
660 if u"10ge" in test_name:
661 limit = plot[u"limits"][u"link"][u"10ge"] * mul
662 elif u"25ge" in test_name:
663 limit = plot[u"limits"][u"link"][u"25ge"] * mul
664 elif u"40ge" in test_name:
665 limit = plot[u"limits"][u"link"][u"40ge"] * mul
666 elif u"100ge" in test_name:
667 limit = plot[u"limits"][u"link"][u"100ge"] * mul
670 if limit > lnk_limit:
673 if u"cx556a" in test_name:
674 limit = plot[u"limits"][u"pci"][u"pci-g3-x8"]
676 limit = plot[u"limits"][u"pci"][u"pci-g3-x16"]
677 if limit > pci_limit:
685 if u"-gbps" not in plot_title:
689 min_limit = min((nic_limit, lnk_limit, pci_limit))
690 if nic_limit == min_limit:
691 traces.append(plgo.Scatter(
693 y=[nic_limit, ] * len(x_vals),
694 name=f"NIC: {nic_limit:.2f}Mpps",
703 annotations.append(dict(
710 text=f"NIC: {nic_limit:.2f}Mpps",
718 y_max.append(nic_limit)
719 elif lnk_limit == min_limit:
720 traces.append(plgo.Scatter(
722 y=[lnk_limit, ] * len(x_vals),
723 name=f"Link: {lnk_limit:.2f}Mpps",
732 annotations.append(dict(
739 text=f"Link: {lnk_limit:.2f}Mpps",
747 y_max.append(lnk_limit)
748 elif pci_limit == min_limit:
749 traces.append(plgo.Scatter(
751 y=[pci_limit, ] * len(x_vals),
752 name=f"PCIe: {pci_limit:.2f}Mpps",
761 annotations.append(dict(
768 text=f"PCIe: {pci_limit:.2f}Mpps",
776 y_max.append(pci_limit)
778 # Perfect and measured:
780 for name, val in vals.items():
783 for idx in range(len(val[u"val"])):
785 if isinstance(val[u"val"][idx], float):
787 f"No. of Runs: {val[u'count'][idx]}<br>"
788 f"Mean: {val[u'val'][idx]:.2f}{h_unit}<br>"
790 if isinstance(val[u"diff"][idx], float):
791 htext += f"Diff: {round(val[u'diff'][idx]):.0f}%<br>"
792 if isinstance(val[u"rel"][idx], float):
793 htext += f"Speedup: {val[u'rel'][idx]:.2f}"
794 hovertext.append(htext)
801 mode=u"lines+markers",
810 hoverinfo=u"text+name"
817 name=f"{name} perfect",
825 text=[f"Perfect: {y:.2f}Mpps" for y in val[u"ideal"]],
830 except (IndexError, ValueError, KeyError) as err:
831 logging.warning(f"No data for {name}\n{repr(err)}")
835 file_type = plot.get(u"output-file-type", u".html")
836 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
837 layout = deepcopy(plot[u"layout"])
838 if layout.get(u"title", None):
839 layout[u"title"] = f"<b>Speedup Multi-core:</b> {layout[u'title']}"
840 layout[u"yaxis"][u"range"] = [0, int(max(y_max) * 1.1)]
841 layout[u"annotations"].extend(annotations)
842 plpl = plgo.Figure(data=traces, layout=layout)
849 filename=f"{plot[u'output-file']}{file_type}"
851 except PlotlyError as err:
853 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
858 def plot_http_server_perf_box(plot, input_data):
859 """Generate the plot(s) with algorithm: plot_http_server_perf_box
860 specified in the specification file.
862 :param plot: Plot to generate.
863 :param input_data: Data to process.
864 :type plot: pandas.Series
865 :type input_data: InputData
870 f" Creating the data set for the {plot.get(u'type', u'')} "
871 f"{plot.get(u'title', u'')}."
873 data = input_data.filter_data(plot)
875 logging.error(u"No data.")
878 # Prepare the data for the plot
883 if y_vals.get(test[u"name"], None) is None:
884 y_vals[test[u"name"]] = list()
886 y_vals[test[u"name"]].append(test[u"result"])
887 except (KeyError, TypeError):
888 y_vals[test[u"name"]].append(None)
890 # Add None to the lists with missing data
892 nr_of_samples = list()
893 for val in y_vals.values():
894 if len(val) > max_len:
896 nr_of_samples.append(len(val))
897 for val in y_vals.values():
898 if len(val) < max_len:
899 val.extend([None for _ in range(max_len - len(val))])
903 df_y = pd.DataFrame(y_vals)
905 for i, col in enumerate(df_y.columns):
908 f"({nr_of_samples[i]:02d} " \
909 f"run{u's' if nr_of_samples[i] > 1 else u''}) " \
910 f"{col.lower().replace(u'-ndrpdr', u'')}"
912 name_lst = name.split(u'-')
915 for segment in name_lst:
916 if (len(name) + len(segment) + 1) > 50 and split_name:
919 name += segment + u'-'
922 traces.append(plgo.Box(x=[str(i + 1) + u'.'] * len(df_y[col]),
928 plpl = plgo.Figure(data=traces, layout=plot[u"layout"])
932 f" Writing file {plot[u'output-file']}"
933 f"{plot[u'output-file-type']}."
939 filename=f"{plot[u'output-file']}{plot[u'output-file-type']}"
941 except PlotlyError as err:
943 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
948 def plot_nf_heatmap(plot, input_data):
949 """Generate the plot(s) with algorithm: plot_nf_heatmap
950 specified in the specification file.
952 :param plot: Plot to generate.
953 :param input_data: Data to process.
954 :type plot: pandas.Series
955 :type input_data: InputData
958 regex_cn = re.compile(r'^(\d*)R(\d*)C$')
959 regex_test_name = re.compile(r'^.*-(\d+ch|\d+pl)-'
961 r'(\d+vm\d+t|\d+dcr\d+t|\d+dcr\d+c).*$')
966 f" Creating the data set for the {plot.get(u'type', u'')} "
967 f"{plot.get(u'title', u'')}."
969 data = input_data.filter_data(plot, continue_on_error=True)
970 if data is None or data.empty:
971 logging.error(u"No data.")
977 for tag in test[u"tags"]:
978 groups = re.search(regex_cn, tag)
980 chain = str(groups.group(1))
981 node = str(groups.group(2))
985 groups = re.search(regex_test_name, test[u"name"])
986 if groups and len(groups.groups()) == 3:
988 f"{str(groups.group(1))}-"
989 f"{str(groups.group(2))}-"
990 f"{str(groups.group(3))}"
994 if vals.get(chain, None) is None:
996 if vals[chain].get(node, None) is None:
997 vals[chain][node] = dict(
1005 if plot[u"include-tests"] == u"MRR":
1006 result = test[u"result"][u"receive-rate"]
1007 elif plot[u"include-tests"] == u"PDR":
1008 result = test[u"throughput"][u"PDR"][u"LOWER"]
1009 elif plot[u"include-tests"] == u"NDR":
1010 result = test[u"throughput"][u"NDR"][u"LOWER"]
1017 vals[chain][node][u"vals"].append(result)
1020 logging.error(u"No data.")
1026 txt_chains.append(key_c)
1027 for key_n in vals[key_c].keys():
1028 txt_nodes.append(key_n)
1029 if vals[key_c][key_n][u"vals"]:
1030 vals[key_c][key_n][u"nr"] = len(vals[key_c][key_n][u"vals"])
1031 vals[key_c][key_n][u"mean"] = \
1032 round(mean(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1033 vals[key_c][key_n][u"stdev"] = \
1034 round(stdev(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1035 txt_nodes = list(set(txt_nodes))
1037 def sort_by_int(value):
1038 """Makes possible to sort a list of strings which represent integers.
1040 :param value: Integer as a string.
1042 :returns: Integer representation of input parameter 'value'.
1047 txt_chains = sorted(txt_chains, key=sort_by_int)
1048 txt_nodes = sorted(txt_nodes, key=sort_by_int)
1050 chains = [i + 1 for i in range(len(txt_chains))]
1051 nodes = [i + 1 for i in range(len(txt_nodes))]
1053 data = [list() for _ in range(len(chains))]
1054 for chain in chains:
1057 val = vals[txt_chains[chain - 1]][txt_nodes[node - 1]][u"mean"]
1058 except (KeyError, IndexError):
1060 data[chain - 1].append(val)
1063 my_green = [[0.0, u"rgb(235, 249, 242)"],
1064 [1.0, u"rgb(45, 134, 89)"]]
1066 my_blue = [[0.0, u"rgb(236, 242, 248)"],
1067 [1.0, u"rgb(57, 115, 172)"]]
1069 my_grey = [[0.0, u"rgb(230, 230, 230)"],
1070 [1.0, u"rgb(102, 102, 102)"]]
1073 annotations = list()
1075 text = (u"Test: {name}<br>"
1080 for chain, _ in enumerate(txt_chains):
1082 for node, _ in enumerate(txt_nodes):
1083 if data[chain][node] is not None:
1092 text=str(data[chain][node]),
1100 hover_line.append(text.format(
1101 name=vals[txt_chains[chain]][txt_nodes[node]][u"name"],
1102 nr=vals[txt_chains[chain]][txt_nodes[node]][u"nr"],
1103 val=data[chain][node],
1104 stdev=vals[txt_chains[chain]][txt_nodes[node]][u"stdev"]))
1105 hovertext.append(hover_line)
1113 title=plot.get(u"z-axis", u""),
1127 colorscale=my_green,
1133 for idx, item in enumerate(txt_nodes):
1151 for idx, item in enumerate(txt_chains):
1178 text=plot.get(u"x-axis", u""),
1195 text=plot.get(u"y-axis", u""),
1204 updatemenus = list([
1215 u"colorscale": [my_green, ],
1216 u"reversescale": False
1225 u"colorscale": [my_blue, ],
1226 u"reversescale": False
1235 u"colorscale": [my_grey, ],
1236 u"reversescale": False
1247 layout = deepcopy(plot[u"layout"])
1248 except KeyError as err:
1249 logging.error(f"Finished with error: No layout defined\n{repr(err)}")
1252 layout[u"annotations"] = annotations
1253 layout[u'updatemenus'] = updatemenus
1257 plpl = plgo.Figure(data=traces, layout=layout)
1260 logging.info(f" Writing file {plot[u'output-file']}.html")
1265 filename=f"{plot[u'output-file']}.html"
1267 except PlotlyError as err:
1269 f" Finished with error: {repr(err)}".replace(u"\n", u" ")