1 # Copyright (c) 2023 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 """Plotly Dash HTML layout override.
20 import dash_bootstrap_components as dbc
22 from flask import Flask
25 from dash import callback_context, no_update, ALL
26 from dash import Input, Output, State
27 from dash.exceptions import PreventUpdate
28 from yaml import load, FullLoader, YAMLError
29 from ast import literal_eval
31 from ..utils.constants import Constants as C
32 from ..utils.control_panel import ControlPanel
33 from ..utils.trigger import Trigger
34 from ..utils.utils import show_tooltip, label, sync_checklists, gen_new_url, \
35 generate_options, get_list_group_items, graph_hdrh_latency
36 from ..utils.url_processing import url_decode
37 from .graphs import graph_iterative, select_iterative_data
40 # Control panel partameters and their default values.
46 "dd-dutver-opt": list(),
47 "dd-dutver-dis": True,
48 "dd-dutver-val": str(),
52 "dd-area-opt": list(),
55 "dd-test-opt": list(),
58 "cl-core-opt": list(),
59 "cl-core-val": list(),
60 "cl-core-all-val": list(),
61 "cl-core-all-opt": C.CL_ALL_DISABLED,
62 "cl-frmsize-opt": list(),
63 "cl-frmsize-val": list(),
64 "cl-frmsize-all-val": list(),
65 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
66 "cl-tsttype-opt": list(),
67 "cl-tsttype-val": list(),
68 "cl-tsttype-all-val": list(),
69 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
71 "cl-normalize-val": list()
76 """The layout of the dash app and the callbacks.
82 data_iterative: pd.DataFrame,
83 html_layout_file: str,
84 graph_layout_file: str,
88 - save the input parameters,
89 - read and pre-process the data,
90 - prepare data for the control panel,
91 - read HTML layout file,
92 - read tooltips from the tooltip file.
94 :param app: Flask application running the dash application.
95 :param html_layout_file: Path and name of the file specifying the HTML
96 layout of the dash application.
97 :param graph_layout_file: Path and name of the file with layout of
99 :param tooltip_file: Path and name of the yaml file specifying the
102 :type html_layout_file: str
103 :type graph_layout_file: str
104 :type tooltip_file: str
109 self._html_layout_file = html_layout_file
110 self._graph_layout_file = graph_layout_file
111 self._tooltip_file = tooltip_file
112 self._data = data_iterative
114 # Get structure of tests:
117 "job", "test_id", "test_type", "dut_version", "tg_type", "release"
119 for _, row in self._data[cols].drop_duplicates().iterrows():
121 lst_job = row["job"].split("-")
123 d_ver = row["dut_version"]
124 tbed = "-".join(lst_job[-2:])
125 lst_test_id = row["test_id"].split(".")
129 area = ".".join(lst_test_id[3:-2])
130 suite = lst_test_id[-2].replace("2n1l-", "").replace("1n1l-", "").\
132 test = lst_test_id[-1]
133 nic = suite.split("-")[0]
134 for drv in C.DRIVERS:
136 driver = drv.replace("-", "_")
137 test = test.replace(f"{drv}-", "")
141 infra = "-".join((tbed, nic, driver))
142 lst_test = test.split("-")
143 framesize = lst_test[0]
144 core = lst_test[1] if lst_test[1] else "8C"
145 test = "-".join(lst_test[2: -1])
147 if tbs.get(rls, None) is None:
149 if tbs[rls].get(dut, None) is None:
150 tbs[rls][dut] = dict()
151 if tbs[rls][dut].get(d_ver, None) is None:
152 tbs[rls][dut][d_ver] = dict()
153 if tbs[rls][dut][d_ver].get(area, None) is None:
154 tbs[rls][dut][d_ver][area] = dict()
155 if tbs[rls][dut][d_ver][area].get(test, None) is None:
156 tbs[rls][dut][d_ver][area][test] = dict()
157 if tbs[rls][dut][d_ver][area][test].get(infra, None) is None:
158 tbs[rls][dut][d_ver][area][test][infra] = {
160 "frame-size": list(),
163 tst_params = tbs[rls][dut][d_ver][area][test][infra]
164 if core.upper() not in tst_params["core"]:
165 tst_params["core"].append(core.upper())
166 if framesize.upper() not in tst_params["frame-size"]:
167 tst_params["frame-size"].append(framesize.upper())
168 if row["test_type"] == "mrr":
169 if "MRR" not in tst_params["test-type"]:
170 tst_params["test-type"].append("MRR")
171 elif row["test_type"] == "ndrpdr":
172 if "NDR" not in tst_params["test-type"]:
173 tst_params["test-type"].extend(("NDR", "PDR", ))
174 elif row["test_type"] == "hoststack" and \
175 row["tg_type"] in ("iperf", "vpp"):
176 if "BPS" not in tst_params["test-type"]:
177 tst_params["test-type"].append("BPS")
178 elif row["test_type"] == "hoststack" and row["tg_type"] == "ab":
179 if "CPS" not in tst_params["test-type"]:
180 tst_params["test-type"].extend(("CPS", "RPS"))
184 self._html_layout = str()
185 self._graph_layout = None
186 self._tooltips = dict()
189 with open(self._html_layout_file, "r") as file_read:
190 self._html_layout = file_read.read()
191 except IOError as err:
193 f"Not possible to open the file {self._html_layout_file}\n{err}"
197 with open(self._graph_layout_file, "r") as file_read:
198 self._graph_layout = load(file_read, Loader=FullLoader)
199 except IOError as err:
201 f"Not possible to open the file {self._graph_layout_file}\n"
204 except YAMLError as err:
206 f"An error occurred while parsing the specification file "
207 f"{self._graph_layout_file}\n{err}"
211 with open(self._tooltip_file, "r") as file_read:
212 self._tooltips = load(file_read, Loader=FullLoader)
213 except IOError as err:
215 f"Not possible to open the file {self._tooltip_file}\n{err}"
217 except YAMLError as err:
219 f"An error occurred while parsing the specification file "
220 f"{self._tooltip_file}\n{err}"
224 if self._app is not None and hasattr(self, "callbacks"):
225 self.callbacks(self._app)
228 def html_layout(self):
229 return self._html_layout
231 def add_content(self):
232 """Top level method which generated the web page.
235 - Store for user input data,
237 - Main area with control panel and ploting area.
239 If no HTML layout is provided, an error message is displayed instead.
241 :returns: The HTML div with the whole page.
245 if self.html_layout and self._spec_tbs:
261 dcc.Store(id="store-selected-tests"),
262 dcc.Store(id="store-control-panel"),
263 dcc.Location(id="url", refresh=False),
264 self._add_ctrl_col(),
265 self._add_plotting_col()
271 id="offcanvas-metadata",
272 title="Throughput And Latency",
276 dbc.Row(id="metadata-tput-lat"),
277 dbc.Row(id="metadata-hdrh-graph")
280 delay_show=C.SPINNER_DELAY
284 id="offcanvas-documentation",
285 title="Documentation",
288 children=html.Iframe(
289 src=C.URL_DOC_REL_NOTES,
309 def _add_navbar(self):
310 """Add nav element with navigation panel. It is placed on the top.
312 :returns: Navigation bar.
313 :rtype: dbc.NavbarSimple
315 return dbc.NavbarSimple(
316 id="navbarsimple-main",
318 dbc.NavItem(dbc.NavLink(
324 dbc.NavItem(dbc.NavLink(
329 dbc.NavItem(dbc.NavLink(
334 dbc.NavItem(dbc.NavLink(
336 id="btn-documentation",
341 brand_external_link=True,
346 def _add_ctrl_col(self) -> dbc.Col:
347 """Add column with controls. It is placed on the left side.
349 :returns: Column with the control panel.
354 children=self._add_ctrl_panel(),
355 className="sticky-top"
359 def _add_plotting_col(self) -> dbc.Col:
360 """Add column with plots. It is placed on the right side.
362 :returns: Column with plots.
366 id="col-plotting-area",
372 class_name="g-0 p-0",
383 def _add_ctrl_panel(self) -> list:
384 """Add control panel.
386 :returns: Control panel.
391 class_name="g-0 p-1",
396 children=show_tooltip(
403 id={"type": "ctrl-dd", "index": "rls"},
404 placeholder="Select a Release...",
407 {"label": k, "value": k} \
408 for k in self._spec_tbs.keys()
410 key=lambda d: d["label"]
419 class_name="g-0 p-1",
424 children=show_tooltip(
431 id={"type": "ctrl-dd", "index": "dut"},
432 placeholder="Select a Device under Test..."
440 class_name="g-0 p-1",
445 children=show_tooltip(
452 id={"type": "ctrl-dd", "index": "dutver"},
454 "Select a Version of Device under Test..."
462 class_name="g-0 p-1",
467 children=show_tooltip(
474 id={"type": "ctrl-dd", "index": "area"},
475 placeholder="Select an Area..."
483 class_name="g-0 p-1",
488 children=show_tooltip(
495 id={"type": "ctrl-dd", "index": "test"},
496 placeholder="Select a Test..."
504 class_name="g-0 p-1",
509 children=show_tooltip(
516 id={"type": "ctrl-dd", "index": "phy"},
518 "Select a Physical Test Bed Topology..."
526 class_name="g-0 p-1",
531 children=show_tooltip(
542 "index": "frmsize-all"
544 options=C.CL_ALL_DISABLED,
563 style={"align-items": "center"},
569 class_name="g-0 p-1",
574 children=show_tooltip(
587 options=C.CL_ALL_DISABLED,
606 style={"align-items": "center"},
612 class_name="g-0 p-1",
617 children=show_tooltip(
628 "index": "tsttype-all"
630 options=C.CL_ALL_DISABLED,
649 style={"align-items": "center"},
655 class_name="g-0 p-1",
660 children=show_tooltip(
671 "value": "normalize",
673 "Normalize to CPU frequency "
684 style={"align-items": "center"},
690 class_name="g-0 p-1",
693 id={"type": "ctrl-btn", "index": "add-test"},
694 children="Add Selected",
700 id="row-card-sel-tests",
701 class_name="g-0 p-1",
702 style=C.STYLE_DISABLED,
705 class_name="overflow-auto p-0",
708 style={"max-height": "20em"},
714 id="row-btns-sel-tests",
715 class_name="g-0 p-1",
716 style=C.STYLE_DISABLED,
719 dbc.ButtonGroup(children=[
721 id={"type": "ctrl-btn", "index": "rm-test"},
722 children="Remove Selected",
728 id={"type": "ctrl-btn", "index": "rm-test-all"},
729 children="Remove All",
735 dbc.ButtonGroup(children=[
744 id="plot-btn-download",
745 children="Download Data",
755 def _get_plotting_area(
761 """Generate the plotting area with all its content.
763 :param tests: List of tests to be displayed in the graphs.
764 :param normalize: If true, the values in graphs are normalized.
765 :param url: URL to be displayed in the modal window.
767 :type normalize: bool
769 :returns: List of rows with elements to be displayed in the plotting
777 graph_iterative(self._data, tests, self._graph_layout, normalize)
785 id={"type": "graph", "index": "tput"},
797 id={"type": "graph", "index": "bandwidth"},
801 tab_id="tab-bandwidth"
809 id={"type": "graph", "index": "lat"},
822 active_tab="tab-tput",
828 dbc.ModalHeader(dbc.ModalTitle("URL")),
836 dcc.Download(id="download-iterative-data")
839 def callbacks(self, app):
840 """Callbacks for the whole application.
842 :param app: The application.
848 Output("store-control-panel", "data"),
849 Output("store-selected-tests", "data"),
850 Output("plotting-area", "children"),
851 Output("row-card-sel-tests", "style"),
852 Output("row-btns-sel-tests", "style"),
853 Output("lg-selected", "children"),
855 Output({"type": "ctrl-dd", "index": "rls"}, "value"),
856 Output({"type": "ctrl-dd", "index": "dut"}, "options"),
857 Output({"type": "ctrl-dd", "index": "dut"}, "disabled"),
858 Output({"type": "ctrl-dd", "index": "dut"}, "value"),
859 Output({"type": "ctrl-dd", "index": "dutver"}, "options"),
860 Output({"type": "ctrl-dd", "index": "dutver"}, "disabled"),
861 Output({"type": "ctrl-dd", "index": "dutver"}, "value"),
862 Output({"type": "ctrl-dd", "index": "phy"}, "options"),
863 Output({"type": "ctrl-dd", "index": "phy"}, "disabled"),
864 Output({"type": "ctrl-dd", "index": "phy"}, "value"),
865 Output({"type": "ctrl-dd", "index": "area"}, "options"),
866 Output({"type": "ctrl-dd", "index": "area"}, "disabled"),
867 Output({"type": "ctrl-dd", "index": "area"}, "value"),
868 Output({"type": "ctrl-dd", "index": "test"}, "options"),
869 Output({"type": "ctrl-dd", "index": "test"}, "disabled"),
870 Output({"type": "ctrl-dd", "index": "test"}, "value"),
871 Output({"type": "ctrl-cl", "index": "core"}, "options"),
872 Output({"type": "ctrl-cl", "index": "core"}, "value"),
873 Output({"type": "ctrl-cl", "index": "core-all"}, "value"),
874 Output({"type": "ctrl-cl", "index": "core-all"}, "options"),
875 Output({"type": "ctrl-cl", "index": "frmsize"}, "options"),
876 Output({"type": "ctrl-cl", "index": "frmsize"}, "value"),
877 Output({"type": "ctrl-cl", "index": "frmsize-all"}, "value"),
878 Output({"type": "ctrl-cl", "index": "frmsize-all"}, "options"),
879 Output({"type": "ctrl-cl", "index": "tsttype"}, "options"),
880 Output({"type": "ctrl-cl", "index": "tsttype"}, "value"),
881 Output({"type": "ctrl-cl", "index": "tsttype-all"}, "value"),
882 Output({"type": "ctrl-cl", "index": "tsttype-all"}, "options"),
883 Output({"type": "ctrl-btn", "index": "add-test"}, "disabled"),
884 Output("normalize", "value")
887 State("store-control-panel", "data"),
888 State("store-selected-tests", "data"),
889 State({"type": "sel-cl", "index": ALL}, "value")
892 Input("url", "href"),
893 Input("normalize", "value"),
895 Input({"type": "ctrl-dd", "index": ALL}, "value"),
896 Input({"type": "ctrl-cl", "index": ALL}, "value"),
897 Input({"type": "ctrl-btn", "index": ALL}, "n_clicks")
900 def _update_application(
908 """Update the application when the event is detected.
911 ctrl_panel = ControlPanel(CP_PARAMS, control_panel)
915 parsed_url = url_decode(href)
917 url_params = parsed_url["params"]
921 plotting_area = no_update
922 row_card_sel_tests = no_update
923 row_btns_sel_tests = no_update
924 lg_selected = no_update
926 trigger = Trigger(callback_context.triggered)
928 if trigger.type == "url" and url_params:
930 store_sel = literal_eval(url_params["store_sel"][0])
931 normalize = literal_eval(url_params["norm"][0])
932 except (KeyError, IndexError, AttributeError):
935 row_card_sel_tests = C.STYLE_ENABLED
936 row_btns_sel_tests = C.STYLE_ENABLED
937 last_test = store_sel[-1]
938 test = self._spec_tbs[last_test["rls"]][last_test["dut"]]\
939 [last_test["dutver"]][last_test["area"]]\
940 [last_test["test"]][last_test["phy"]]
942 "dd-rls-val": last_test["rls"],
943 "dd-dut-val": last_test["dut"],
944 "dd-dut-opt": generate_options(
945 self._spec_tbs[last_test["rls"]].keys()
948 "dd-dutver-val": last_test["dutver"],
949 "dd-dutver-opt": generate_options(
950 self._spec_tbs[last_test["rls"]]\
951 [last_test["dut"]].keys()
953 "dd-dutver-dis": False,
954 "dd-area-val": last_test["area"],
956 {"label": label(v), "value": v} for v in \
957 sorted(self._spec_tbs[last_test["rls"]]\
959 [last_test["dutver"]].keys())
961 "dd-area-dis": False,
962 "dd-test-val": last_test["test"],
963 "dd-test-opt": generate_options(
964 self._spec_tbs[last_test["rls"]][last_test["dut"]]\
965 [last_test["dutver"]][last_test["area"]].keys()
967 "dd-test-dis": False,
968 "dd-phy-val": last_test["phy"],
969 "dd-phy-opt": generate_options(
970 self._spec_tbs[last_test["rls"]][last_test["dut"]]\
971 [last_test["dutver"]][last_test["area"]]\
972 [last_test["test"]].keys()
975 "cl-core-opt": generate_options(test["core"]),
976 "cl-core-val": [last_test["core"].upper(), ],
977 "cl-core-all-val": list(),
978 "cl-core-all-opt": C.CL_ALL_ENABLED,
979 "cl-frmsize-opt": generate_options(test["frame-size"]),
980 "cl-frmsize-val": [last_test["framesize"].upper(), ],
981 "cl-frmsize-all-val": list(),
982 "cl-frmsize-all-opt": C.CL_ALL_ENABLED,
983 "cl-tsttype-opt": generate_options(test["test-type"]),
984 "cl-tsttype-val": [last_test["testtype"].upper(), ],
985 "cl-tsttype-all-val": list(),
986 "cl-tsttype-all-opt": C.CL_ALL_ENABLED,
987 "cl-normalize-val": normalize,
991 elif trigger.type == "normalize":
992 ctrl_panel.set({"cl-normalize-val": normalize})
994 elif trigger.type == "ctrl-dd":
995 if trigger.idx == "rls":
997 options = generate_options(
998 self._spec_tbs[trigger.value].keys()
1005 "dd-rls-val": trigger.value,
1006 "dd-dut-val": str(),
1007 "dd-dut-opt": options,
1008 "dd-dut-dis": disabled,
1009 "dd-dutver-val": str(),
1010 "dd-dutver-opt": list(),
1011 "dd-dutver-dis": True,
1012 "dd-phy-val": str(),
1013 "dd-phy-opt": list(),
1015 "dd-area-val": str(),
1016 "dd-area-opt": list(),
1017 "dd-area-dis": True,
1018 "dd-test-val": str(),
1019 "dd-test-opt": list(),
1020 "dd-test-dis": True,
1021 "cl-core-opt": list(),
1022 "cl-core-val": list(),
1023 "cl-core-all-val": list(),
1024 "cl-core-all-opt": C.CL_ALL_DISABLED,
1025 "cl-frmsize-opt": list(),
1026 "cl-frmsize-val": list(),
1027 "cl-frmsize-all-val": list(),
1028 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1029 "cl-tsttype-opt": list(),
1030 "cl-tsttype-val": list(),
1031 "cl-tsttype-all-val": list(),
1032 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1035 elif trigger.idx == "dut":
1037 rls = ctrl_panel.get("dd-rls-val")
1038 dut = self._spec_tbs[rls][trigger.value]
1039 options = generate_options(dut.keys())
1045 "dd-dut-val": trigger.value,
1046 "dd-dutver-val": str(),
1047 "dd-dutver-opt": options,
1048 "dd-dutver-dis": disabled,
1049 "dd-phy-val": str(),
1050 "dd-phy-opt": list(),
1052 "dd-area-val": str(),
1053 "dd-area-opt": list(),
1054 "dd-area-dis": True,
1055 "dd-test-val": str(),
1056 "dd-test-opt": list(),
1057 "dd-test-dis": True,
1058 "cl-core-opt": list(),
1059 "cl-core-val": list(),
1060 "cl-core-all-val": list(),
1061 "cl-core-all-opt": C.CL_ALL_DISABLED,
1062 "cl-frmsize-opt": list(),
1063 "cl-frmsize-val": list(),
1064 "cl-frmsize-all-val": list(),
1065 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1066 "cl-tsttype-opt": list(),
1067 "cl-tsttype-val": list(),
1068 "cl-tsttype-all-val": list(),
1069 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1072 elif trigger.idx == "dutver":
1074 rls = ctrl_panel.get("dd-rls-val")
1075 dut = ctrl_panel.get("dd-dut-val")
1076 dutver = self._spec_tbs[rls][dut][trigger.value]
1077 options = [{"label": label(v), "value": v} \
1078 for v in sorted(dutver.keys())]
1084 "dd-dutver-val": trigger.value,
1085 "dd-area-val": str(),
1086 "dd-area-opt": options,
1087 "dd-area-dis": disabled,
1088 "dd-test-val": str(),
1089 "dd-test-opt": list(),
1090 "dd-test-dis": True,
1091 "dd-phy-val": str(),
1092 "dd-phy-opt": list(),
1094 "cl-core-opt": list(),
1095 "cl-core-val": list(),
1096 "cl-core-all-val": list(),
1097 "cl-core-all-opt": C.CL_ALL_DISABLED,
1098 "cl-frmsize-opt": list(),
1099 "cl-frmsize-val": list(),
1100 "cl-frmsize-all-val": list(),
1101 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1102 "cl-tsttype-opt": list(),
1103 "cl-tsttype-val": list(),
1104 "cl-tsttype-all-val": list(),
1105 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1108 elif trigger.idx == "area":
1110 rls = ctrl_panel.get("dd-rls-val")
1111 dut = ctrl_panel.get("dd-dut-val")
1112 dutver = ctrl_panel.get("dd-dutver-val")
1113 area = self._spec_tbs[rls][dut][dutver][trigger.value]
1114 options = generate_options(area.keys())
1120 "dd-area-val": trigger.value,
1121 "dd-test-val": str(),
1122 "dd-test-opt": options,
1123 "dd-test-dis": disabled,
1124 "dd-phy-val": str(),
1125 "dd-phy-opt": list(),
1127 "cl-core-opt": list(),
1128 "cl-core-val": list(),
1129 "cl-core-all-val": list(),
1130 "cl-core-all-opt": C.CL_ALL_DISABLED,
1131 "cl-frmsize-opt": list(),
1132 "cl-frmsize-val": list(),
1133 "cl-frmsize-all-val": list(),
1134 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1135 "cl-tsttype-opt": list(),
1136 "cl-tsttype-val": list(),
1137 "cl-tsttype-all-val": list(),
1138 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1141 elif trigger.idx == "test":
1143 rls = ctrl_panel.get("dd-rls-val")
1144 dut = ctrl_panel.get("dd-dut-val")
1145 dutver = ctrl_panel.get("dd-dutver-val")
1146 area = ctrl_panel.get("dd-area-val")
1147 test = self._spec_tbs[rls][dut][dutver][area]\
1149 options = generate_options(test.keys())
1155 "dd-test-val": trigger.value,
1156 "dd-phy-val": str(),
1157 "dd-phy-opt": options,
1158 "dd-phy-dis": disabled,
1159 "cl-core-opt": list(),
1160 "cl-core-val": list(),
1161 "cl-core-all-val": list(),
1162 "cl-core-all-opt": C.CL_ALL_DISABLED,
1163 "cl-frmsize-opt": list(),
1164 "cl-frmsize-val": list(),
1165 "cl-frmsize-all-val": list(),
1166 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1167 "cl-tsttype-opt": list(),
1168 "cl-tsttype-val": list(),
1169 "cl-tsttype-all-val": list(),
1170 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1173 elif trigger.idx == "phy":
1174 rls = ctrl_panel.get("dd-rls-val")
1175 dut = ctrl_panel.get("dd-dut-val")
1176 dutver = ctrl_panel.get("dd-dutver-val")
1177 area = ctrl_panel.get("dd-area-val")
1178 test = ctrl_panel.get("dd-test-val")
1179 if all((rls, dut, dutver, area, test, trigger.value, )):
1180 phy = self._spec_tbs[rls][dut][dutver][area][test]\
1183 "dd-phy-val": trigger.value,
1184 "cl-core-opt": generate_options(phy["core"]),
1185 "cl-core-val": list(),
1186 "cl-core-all-val": list(),
1187 "cl-core-all-opt": C.CL_ALL_ENABLED,
1189 generate_options(phy["frame-size"]),
1190 "cl-frmsize-val": list(),
1191 "cl-frmsize-all-val": list(),
1192 "cl-frmsize-all-opt": C.CL_ALL_ENABLED,
1194 generate_options(phy["test-type"]),
1195 "cl-tsttype-val": list(),
1196 "cl-tsttype-all-val": list(),
1197 "cl-tsttype-all-opt": C.CL_ALL_ENABLED,
1200 elif trigger.type == "ctrl-cl":
1201 param = trigger.idx.split("-")[0]
1202 if "-all" in trigger.idx:
1203 c_sel, c_all, c_id = list(), trigger.value, "all"
1205 c_sel, c_all, c_id = trigger.value, list(), str()
1206 val_sel, val_all = sync_checklists(
1207 options=ctrl_panel.get(f"cl-{param}-opt"),
1213 f"cl-{param}-val": val_sel,
1214 f"cl-{param}-all-val": val_all,
1216 if all((ctrl_panel.get("cl-core-val"),
1217 ctrl_panel.get("cl-frmsize-val"),
1218 ctrl_panel.get("cl-tsttype-val"), )):
1219 ctrl_panel.set({"btn-add-dis": False})
1221 ctrl_panel.set({"btn-add-dis": True})
1222 elif trigger.type == "ctrl-btn":
1224 if trigger.idx == "add-test":
1225 rls = ctrl_panel.get("dd-rls-val")
1226 dut = ctrl_panel.get("dd-dut-val")
1227 dutver = ctrl_panel.get("dd-dutver-val")
1228 phy = ctrl_panel.get("dd-phy-val")
1229 area = ctrl_panel.get("dd-area-val")
1230 test = ctrl_panel.get("dd-test-val")
1231 # Add selected test to the list of tests in store:
1232 if store_sel is None:
1234 for core in ctrl_panel.get("cl-core-val"):
1235 for framesize in ctrl_panel.get("cl-frmsize-val"):
1236 for ttype in ctrl_panel.get("cl-tsttype-val"):
1243 phy.replace("af_xdp", "af-xdp"),
1250 if tid not in [i["id"] for i in store_sel]:
1259 "framesize": framesize.lower(),
1260 "core": core.lower(),
1261 "testtype": ttype.lower()
1263 store_sel = sorted(store_sel, key=lambda d: d["id"])
1264 if C.CLEAR_ALL_INPUTS:
1265 ctrl_panel.set(ctrl_panel.defaults)
1266 elif trigger.idx == "rm-test" and lst_sel:
1267 new_store_sel = list()
1268 for idx, item in enumerate(store_sel):
1269 if not lst_sel[idx]:
1270 new_store_sel.append(item)
1271 store_sel = new_store_sel
1272 elif trigger.idx == "rm-test-all":
1277 lg_selected = get_list_group_items(
1278 store_sel, "sel-cl", add_index=True
1280 plotting_area = self._get_plotting_area(
1285 {"store_sel": store_sel, "norm": normalize}
1288 row_card_sel_tests = C.STYLE_ENABLED
1289 row_btns_sel_tests = C.STYLE_ENABLED
1291 plotting_area = C.PLACEHOLDER
1292 row_card_sel_tests = C.STYLE_DISABLED
1293 row_btns_sel_tests = C.STYLE_DISABLED
1304 ret_val.extend(ctrl_panel.values)
1308 Output("plot-mod-url", "is_open"),
1309 Output("plot-btn-url", "n_clicks"),
1310 Input("plot-btn-url", "n_clicks"),
1311 State("plot-mod-url", "is_open")
1313 def toggle_plot_mod_url(n, is_open):
1314 """Toggle the modal window with url.
1317 return not is_open, 0
1321 Output("download-iterative-data", "data"),
1322 State("store-selected-tests", "data"),
1323 Input("plot-btn-download", "n_clicks"),
1324 prevent_initial_call=True
1326 def _download_iterative_data(store_sel, _):
1327 """Download the data
1329 :param store_sel: List of tests selected by user stored in the
1331 :type store_sel: list
1332 :returns: dict of data frame content (base64 encoded) and meta data
1333 used by the Download component.
1341 for itm in store_sel:
1342 sel_data = select_iterative_data(self._data, itm)
1343 if sel_data is None:
1345 df = pd.concat([df, sel_data], ignore_index=True)
1347 return dcc.send_data_frame(df.to_csv, C.REPORT_DOWNLOAD_FILE_NAME)
1350 Output("metadata-tput-lat", "children"),
1351 Output("metadata-hdrh-graph", "children"),
1352 Output("offcanvas-metadata", "is_open"),
1353 Input({"type": "graph", "index": ALL}, "clickData"),
1354 prevent_initial_call=True
1356 def _show_metadata_from_graphs(graph_data: dict) -> tuple:
1357 """Generates the data for the offcanvas displayed when a particular
1358 point in a graph is clicked on.
1360 :param graph_data: The data from the clicked point in the graph.
1361 :type graph_data: dict
1362 :returns: The data to be displayed on the offcanvas and the
1363 information to show the offcanvas.
1364 :rtype: tuple(list, list, bool)
1367 trigger = Trigger(callback_context.triggered)
1369 if trigger.idx == "tput":
1371 elif trigger.idx == "bandwidth":
1373 elif trigger.idx == "lat":
1374 idx = len(graph_data) - 1
1376 return list(), list(), False
1379 graph_data = graph_data[idx]["points"]
1380 except (IndexError, KeyError, ValueError, TypeError):
1383 def _process_stats(data: list, param: str) -> list:
1384 """Process statistical data provided by plot.ly box graph.
1386 :param data: Statistical data provided by plot.ly box graph.
1387 :param param: Parameter saying if the data come from "tput" or
1391 :returns: Listo of tuples where the first value is the
1392 statistic's name and the secont one it's value.
1396 stats = ("max", "upper fence", "q3", "median", "q1",
1397 "lower fence", "min")
1398 elif len(data) == 9:
1399 stats = ("outlier", "max", "upper fence", "q3", "median",
1400 "q1", "lower fence", "min", "outlier")
1401 elif len(data) == 1:
1403 stats = ("average latency at 50% PDR", )
1404 elif param == "bandwidth":
1405 stats = ("bandwidth", )
1407 stats = ("throughput", )
1410 unit = " [us]" if param == "lat" else str()
1411 return [(f"{stat}{unit}", f"{value['y']:,.0f}")
1412 for stat, value in zip(stats, data)]
1414 customdata = graph_data[0].get("customdata", dict())
1415 datapoint = customdata.get("metadata", dict())
1416 hdrh_data = customdata.get("hdrh", dict())
1418 list_group_items = list()
1419 for k, v in datapoint.items():
1421 if len(graph_data) > 1:
1423 list_group_item = dbc.ListGroupItem([
1425 html.A(v, href=f"{C.URL_JENKINS}{v}", target="_blank")
1428 list_group_item = dbc.ListGroupItem([dbc.Badge(k), v])
1429 list_group_items.append(list_group_item)
1432 if trigger.idx == "tput":
1433 title = "Throughput"
1434 elif trigger.idx == "bandwidth":
1436 elif trigger.idx == "lat":
1438 if len(graph_data) == 1:
1441 class_name="gy-2 p-0",
1443 dbc.CardHeader(hdrh_data.pop("name")),
1444 dbc.CardBody(dcc.Graph(
1445 id="hdrh-latency-graph",
1446 figure=graph_hdrh_latency(
1447 hdrh_data, self._graph_layout
1455 for k, v in _process_stats(graph_data, trigger.idx):
1456 list_group_items.append(dbc.ListGroupItem([dbc.Badge(k), v]))
1460 class_name="gy-2 p-0",
1462 dbc.CardHeader(children=[
1464 target_id="tput-lat-metadata",
1466 style={"display": "inline-block"}
1471 dbc.ListGroup(list_group_items, flush=True),
1472 id="tput-lat-metadata",
1479 return metadata, graph, True
1482 Output("offcanvas-documentation", "is_open"),
1483 Input("btn-documentation", "n_clicks"),
1484 State("offcanvas-documentation", "is_open")
1486 def toggle_offcanvas_documentation(n_clicks, is_open):