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()
384 for item in plot.get(u"include", tuple()):
385 reg_ex = re.compile(str(item).lower())
388 for test_id, test in build.iteritems():
389 if not re.match(reg_ex, str(test_id).lower()):
391 if y_vals.get(test[u"parent"], None) is None:
392 y_vals[test[u"parent"]] = list()
394 if test[u"type"] in (u"NDRPDR", u"CPS"):
395 test_type = test[u"type"]
397 if u"-pdr" in plot_title:
399 elif u"-ndr" in plot_title:
403 u"Wrong title. No information about test "
404 u"type. Add '-ndr' or '-pdr' to the test "
408 y_vals[test[u"parent"]].append(
409 test[value][ttype][u"LOWER"] * multiplier
412 elif test[u"type"] in (u"SOAK",):
413 y_vals[test[u"parent"]]. \
414 append(test[u"throughput"][u"LOWER"])
417 elif test[u"type"] in (u"HOSTSTACK",):
418 if u"LDPRELOAD" in test[u"tags"]:
419 y_vals[test[u"parent"]].append(
421 test[u"result"][u"bits_per_second"]
424 elif u"VPPECHO" in test[u"tags"]:
425 y_vals[test[u"parent"]].append(
427 test[u"result"][u"client"][u"tx_data"]
430 test[u"result"][u"client"][u"time"]
433 test[u"result"][u"server"][u"time"])
436 test_type = u"HOSTSTACK"
441 except (KeyError, TypeError):
442 y_vals[test[u"parent"]].append(None)
444 # Add None to the lists with missing data
446 nr_of_samples = list()
447 for val in y_vals.values():
448 if len(val) > max_len:
450 nr_of_samples.append(len(val))
451 for val in y_vals.values():
452 if len(val) < max_len:
453 val.extend([None for _ in range(max_len - len(val))])
457 df_y = pd.DataFrame(y_vals)
460 for i, col in enumerate(df_y.columns):
461 tst_name = re.sub(REGEX_NIC, u"",
462 col.lower().replace(u'-ndrpdr', u'').
463 replace(u'2n1l-', u''))
465 x=[str(i + 1) + u'.'] * len(df_y[col]),
466 y=[y / 1e6 if y else None for y in df_y[col]],
469 f"({nr_of_samples[i]:02d} "
470 f"run{u's' if nr_of_samples[i] > 1 else u''}) "
475 if test_type in (u"SOAK", ):
476 kwargs[u"boxpoints"] = u"all"
478 traces.append(plgo.Box(**kwargs))
481 val_max = max(df_y[col])
483 y_max.append(int(val_max / 1e6) + 2)
484 except (ValueError, TypeError) as err:
485 logging.error(repr(err))
490 layout = deepcopy(plot[u"layout"])
491 if layout.get(u"title", None):
492 if test_type in (u"HOSTSTACK", ):
493 layout[u"title"] = f"<b>Bandwidth:</b> {layout[u'title']}"
494 elif test_type in (u"CPS", ):
495 layout[u"title"] = f"<b>CPS:</b> {layout[u'title']}"
497 layout[u"title"] = f"<b>Throughput:</b> {layout[u'title']}"
499 layout[u"yaxis"][u"range"] = [0, max(y_max)]
500 plpl = plgo.Figure(data=traces, layout=layout)
503 logging.info(f" Writing file {plot[u'output-file']}.html.")
508 filename=f"{plot[u'output-file']}.html"
510 except PlotlyError as err:
512 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
517 def plot_tsa_name(plot, input_data):
518 """Generate the plot(s) with algorithm:
520 specified in the specification file.
522 :param plot: Plot to generate.
523 :param input_data: Data to process.
524 :type plot: pandas.Series
525 :type input_data: InputData
529 plot_title = plot.get(u"title", u"")
531 f" Creating data set for the {plot.get(u'type', u'')} {plot_title}."
533 data = input_data.filter_tests_by_name(
535 params=[u"throughput", u"gbps", u"parent", u"tags", u"type"]
538 logging.error(u"No data.")
541 plot_title = plot_title.lower()
543 if u"-gbps" in plot_title:
548 value = u"throughput"
552 y_vals = OrderedDict()
553 for item in plot.get(u"include", tuple()):
554 reg_ex = re.compile(str(item).lower())
557 for test_id, test in build.iteritems():
558 if re.match(reg_ex, str(test_id).lower()):
559 if y_vals.get(test[u"parent"], None) is None:
560 y_vals[test[u"parent"]] = {
566 if test[u"type"] not in (u"NDRPDR", u"CPS"):
569 if u"-pdr" in plot_title:
571 elif u"-ndr" in plot_title:
576 if u"1C" in test[u"tags"]:
577 y_vals[test[u"parent"]][u"1"].append(
578 test[value][ttype][u"LOWER"] * multiplier
580 elif u"2C" in test[u"tags"]:
581 y_vals[test[u"parent"]][u"2"].append(
582 test[value][ttype][u"LOWER"] * multiplier
584 elif u"4C" in test[u"tags"]:
585 y_vals[test[u"parent"]][u"4"].append(
586 test[value][ttype][u"LOWER"] * multiplier
588 except (KeyError, TypeError):
592 logging.warning(f"No data for the plot {plot.get(u'title', u'')}")
596 for test_name, test_vals in y_vals.items():
597 for key, test_val in test_vals.items():
599 avg_val = sum(test_val) / len(test_val)
600 y_vals[test_name][key] = [avg_val, len(test_val)]
601 ideal = avg_val / (int(key) * 1e6)
602 if test_name not in y_1c_max or ideal > y_1c_max[test_name]:
603 y_1c_max[test_name] = ideal
610 for test_name, test_vals in y_vals.items():
612 if test_vals[u"1"][1]:
616 test_name.replace(u'-ndrpdr', u'').replace(u'2n1l-', u'')
618 vals[name] = OrderedDict()
619 y_val_1 = test_vals[u"1"][0] / 1e6
620 y_val_2 = test_vals[u"2"][0] / 1e6 if test_vals[u"2"][0] \
622 y_val_4 = test_vals[u"4"][0] / 1e6 if test_vals[u"4"][0] \
625 vals[name][u"val"] = [y_val_1, y_val_2, y_val_4]
626 vals[name][u"rel"] = [1.0, None, None]
627 vals[name][u"ideal"] = [
629 y_1c_max[test_name] * 2,
630 y_1c_max[test_name] * 4
632 vals[name][u"diff"] = [
633 (y_val_1 - y_1c_max[test_name]) * 100 / y_val_1, None, None
635 vals[name][u"count"] = [
642 val_max = max(vals[name][u"val"])
643 except ValueError as err:
644 logging.error(repr(err))
647 y_max.append(val_max)
650 vals[name][u"rel"][1] = round(y_val_2 / y_val_1, 2)
651 vals[name][u"diff"][1] = \
652 (y_val_2 - vals[name][u"ideal"][1]) * 100 / y_val_2
654 vals[name][u"rel"][2] = round(y_val_4 / y_val_1, 2)
655 vals[name][u"diff"][2] = \
656 (y_val_4 - vals[name][u"ideal"][2]) * 100 / y_val_4
657 except IndexError as err:
658 logging.warning(f"No data for {test_name}")
659 logging.warning(repr(err))
662 if u"x520" in test_name:
663 limit = plot[u"limits"][u"nic"][u"x520"]
664 elif u"x710" in test_name:
665 limit = plot[u"limits"][u"nic"][u"x710"]
666 elif u"xxv710" in test_name:
667 limit = plot[u"limits"][u"nic"][u"xxv710"]
668 elif u"xl710" in test_name:
669 limit = plot[u"limits"][u"nic"][u"xl710"]
670 elif u"x553" in test_name:
671 limit = plot[u"limits"][u"nic"][u"x553"]
672 elif u"cx556a" in test_name:
673 limit = plot[u"limits"][u"nic"][u"cx556a"]
676 if limit > nic_limit:
679 mul = 2 if u"ge2p" in test_name else 1
680 if u"10ge" in test_name:
681 limit = plot[u"limits"][u"link"][u"10ge"] * mul
682 elif u"25ge" in test_name:
683 limit = plot[u"limits"][u"link"][u"25ge"] * mul
684 elif u"40ge" in test_name:
685 limit = plot[u"limits"][u"link"][u"40ge"] * mul
686 elif u"100ge" in test_name:
687 limit = plot[u"limits"][u"link"][u"100ge"] * mul
690 if limit > lnk_limit:
693 if u"cx556a" in test_name:
694 limit = plot[u"limits"][u"pci"][u"pci-g3-x8"]
696 limit = plot[u"limits"][u"pci"][u"pci-g3-x16"]
697 if limit > pci_limit:
705 if u"-gbps" not in plot_title and u"-cps-" not in plot_title:
709 min_limit = min((nic_limit, lnk_limit, pci_limit))
710 if nic_limit == min_limit:
711 traces.append(plgo.Scatter(
713 y=[nic_limit, ] * len(x_vals),
714 name=f"NIC: {nic_limit:.2f}Mpps",
723 annotations.append(dict(
730 text=f"NIC: {nic_limit:.2f}Mpps",
738 y_max.append(nic_limit)
739 elif lnk_limit == min_limit:
740 traces.append(plgo.Scatter(
742 y=[lnk_limit, ] * len(x_vals),
743 name=f"Link: {lnk_limit:.2f}Mpps",
752 annotations.append(dict(
759 text=f"Link: {lnk_limit:.2f}Mpps",
767 y_max.append(lnk_limit)
768 elif pci_limit == min_limit:
769 traces.append(plgo.Scatter(
771 y=[pci_limit, ] * len(x_vals),
772 name=f"PCIe: {pci_limit:.2f}Mpps",
781 annotations.append(dict(
788 text=f"PCIe: {pci_limit:.2f}Mpps",
796 y_max.append(pci_limit)
798 # Perfect and measured:
800 for name, val in vals.items():
803 for idx in range(len(val[u"val"])):
805 if isinstance(val[u"val"][idx], float):
807 f"No. of Runs: {val[u'count'][idx]}<br>"
808 f"Mean: {val[u'val'][idx]:.2f}{h_unit}<br>"
810 if isinstance(val[u"diff"][idx], float):
811 htext += f"Diff: {round(val[u'diff'][idx]):.0f}%<br>"
812 if isinstance(val[u"rel"][idx], float):
813 htext += f"Speedup: {val[u'rel'][idx]:.2f}"
814 hovertext.append(htext)
821 mode=u"lines+markers",
830 hoverinfo=u"text+name"
837 name=f"{name} perfect",
845 text=[f"Perfect: {y:.2f}Mpps" for y in val[u"ideal"]],
850 except (IndexError, ValueError, KeyError) as err:
851 logging.warning(f"No data for {name}\n{repr(err)}")
855 file_type = plot.get(u"output-file-type", u".html")
856 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
857 layout = deepcopy(plot[u"layout"])
858 if layout.get(u"title", None):
859 layout[u"title"] = f"<b>Speedup Multi-core:</b> {layout[u'title']}"
860 layout[u"yaxis"][u"range"] = [0, int(max(y_max) * 1.1)]
861 layout[u"annotations"].extend(annotations)
862 plpl = plgo.Figure(data=traces, layout=layout)
869 filename=f"{plot[u'output-file']}{file_type}"
871 except PlotlyError as err:
873 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
878 def plot_http_server_perf_box(plot, input_data):
879 """Generate the plot(s) with algorithm: plot_http_server_perf_box
880 specified in the specification file.
882 :param plot: Plot to generate.
883 :param input_data: Data to process.
884 :type plot: pandas.Series
885 :type input_data: InputData
890 f" Creating the data set for the {plot.get(u'type', u'')} "
891 f"{plot.get(u'title', u'')}."
893 data = input_data.filter_data(plot)
895 logging.error(u"No data.")
898 # Prepare the data for the plot
903 if y_vals.get(test[u"name"], None) is None:
904 y_vals[test[u"name"]] = list()
906 y_vals[test[u"name"]].append(test[u"result"])
907 except (KeyError, TypeError):
908 y_vals[test[u"name"]].append(None)
910 # Add None to the lists with missing data
912 nr_of_samples = list()
913 for val in y_vals.values():
914 if len(val) > max_len:
916 nr_of_samples.append(len(val))
917 for val in y_vals.values():
918 if len(val) < max_len:
919 val.extend([None for _ in range(max_len - len(val))])
923 df_y = pd.DataFrame(y_vals)
925 for i, col in enumerate(df_y.columns):
928 f"({nr_of_samples[i]:02d} " \
929 f"run{u's' if nr_of_samples[i] > 1 else u''}) " \
930 f"{col.lower().replace(u'-ndrpdr', u'')}"
932 name_lst = name.split(u'-')
935 for segment in name_lst:
936 if (len(name) + len(segment) + 1) > 50 and split_name:
939 name += segment + u'-'
942 traces.append(plgo.Box(x=[str(i + 1) + u'.'] * len(df_y[col]),
948 plpl = plgo.Figure(data=traces, layout=plot[u"layout"])
952 f" Writing file {plot[u'output-file']}"
953 f"{plot[u'output-file-type']}."
959 filename=f"{plot[u'output-file']}{plot[u'output-file-type']}"
961 except PlotlyError as err:
963 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
968 def plot_nf_heatmap(plot, input_data):
969 """Generate the plot(s) with algorithm: plot_nf_heatmap
970 specified in the specification file.
972 :param plot: Plot to generate.
973 :param input_data: Data to process.
974 :type plot: pandas.Series
975 :type input_data: InputData
978 regex_cn = re.compile(r'^(\d*)R(\d*)C$')
979 regex_test_name = re.compile(r'^.*-(\d+ch|\d+pl)-'
981 r'(\d+vm\d+t|\d+dcr\d+t|\d+dcr\d+c).*$')
986 f" Creating the data set for the {plot.get(u'type', u'')} "
987 f"{plot.get(u'title', u'')}."
989 data = input_data.filter_data(plot, continue_on_error=True)
990 if data is None or data.empty:
991 logging.error(u"No data.")
997 for tag in test[u"tags"]:
998 groups = re.search(regex_cn, tag)
1000 chain = str(groups.group(1))
1001 node = str(groups.group(2))
1005 groups = re.search(regex_test_name, test[u"name"])
1006 if groups and len(groups.groups()) == 3:
1008 f"{str(groups.group(1))}-"
1009 f"{str(groups.group(2))}-"
1010 f"{str(groups.group(3))}"
1014 if vals.get(chain, None) is None:
1015 vals[chain] = dict()
1016 if vals[chain].get(node, None) is None:
1017 vals[chain][node] = dict(
1025 if plot[u"include-tests"] == u"MRR":
1026 result = test[u"result"][u"receive-rate"]
1027 elif plot[u"include-tests"] == u"PDR":
1028 result = test[u"throughput"][u"PDR"][u"LOWER"]
1029 elif plot[u"include-tests"] == u"NDR":
1030 result = test[u"throughput"][u"NDR"][u"LOWER"]
1037 vals[chain][node][u"vals"].append(result)
1040 logging.error(u"No data.")
1046 txt_chains.append(key_c)
1047 for key_n in vals[key_c].keys():
1048 txt_nodes.append(key_n)
1049 if vals[key_c][key_n][u"vals"]:
1050 vals[key_c][key_n][u"nr"] = len(vals[key_c][key_n][u"vals"])
1051 vals[key_c][key_n][u"mean"] = \
1052 round(mean(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1053 vals[key_c][key_n][u"stdev"] = \
1054 round(stdev(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1055 txt_nodes = list(set(txt_nodes))
1057 def sort_by_int(value):
1058 """Makes possible to sort a list of strings which represent integers.
1060 :param value: Integer as a string.
1062 :returns: Integer representation of input parameter 'value'.
1067 txt_chains = sorted(txt_chains, key=sort_by_int)
1068 txt_nodes = sorted(txt_nodes, key=sort_by_int)
1070 chains = [i + 1 for i in range(len(txt_chains))]
1071 nodes = [i + 1 for i in range(len(txt_nodes))]
1073 data = [list() for _ in range(len(chains))]
1074 for chain in chains:
1077 val = vals[txt_chains[chain - 1]][txt_nodes[node - 1]][u"mean"]
1078 except (KeyError, IndexError):
1080 data[chain - 1].append(val)
1083 my_green = [[0.0, u"rgb(235, 249, 242)"],
1084 [1.0, u"rgb(45, 134, 89)"]]
1086 my_blue = [[0.0, u"rgb(236, 242, 248)"],
1087 [1.0, u"rgb(57, 115, 172)"]]
1089 my_grey = [[0.0, u"rgb(230, 230, 230)"],
1090 [1.0, u"rgb(102, 102, 102)"]]
1093 annotations = list()
1095 text = (u"Test: {name}<br>"
1100 for chain, _ in enumerate(txt_chains):
1102 for node, _ in enumerate(txt_nodes):
1103 if data[chain][node] is not None:
1112 text=str(data[chain][node]),
1120 hover_line.append(text.format(
1121 name=vals[txt_chains[chain]][txt_nodes[node]][u"name"],
1122 nr=vals[txt_chains[chain]][txt_nodes[node]][u"nr"],
1123 val=data[chain][node],
1124 stdev=vals[txt_chains[chain]][txt_nodes[node]][u"stdev"]))
1125 hovertext.append(hover_line)
1133 title=plot.get(u"z-axis", u""),
1147 colorscale=my_green,
1153 for idx, item in enumerate(txt_nodes):
1171 for idx, item in enumerate(txt_chains):
1198 text=plot.get(u"x-axis", u""),
1215 text=plot.get(u"y-axis", u""),
1224 updatemenus = list([
1235 u"colorscale": [my_green, ],
1236 u"reversescale": False
1245 u"colorscale": [my_blue, ],
1246 u"reversescale": False
1255 u"colorscale": [my_grey, ],
1256 u"reversescale": False
1267 layout = deepcopy(plot[u"layout"])
1268 except KeyError as err:
1269 logging.error(f"Finished with error: No layout defined\n{repr(err)}")
1272 layout[u"annotations"] = annotations
1273 layout[u'updatemenus'] = updatemenus
1277 plpl = plgo.Figure(data=traces, layout=layout)
1280 logging.info(f" Writing file {plot[u'output-file']}.html")
1285 filename=f"{plot[u'output-file']}.html"
1287 except PlotlyError as err:
1289 f" Finished with error: {repr(err)}".replace(u"\n", u" ")