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,
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",
740 def _get_plotting_area(
746 """Generate the plotting area with all its content.
748 :param tests: List of tests to be displayed in the graphs.
749 :param normalize: If true, the values in graphs are normalized.
750 :param url: URL to be displayed in the modal window.
752 :type normalize: bool
754 :returns: List of rows with elements to be displayed in the plotting
761 figs = graph_iterative(self._data, tests, self._graph_layout, normalize)
769 id={"type": "graph", "index": "tput"},
772 class_name="g-0 p-1",
781 id={"type": "graph", "index": "lat"},
784 class_name="g-0 p-1",
792 class_name="g-0 p-0",
804 "text-transform": "none",
805 "padding": "0rem 1rem"
810 dbc.ModalHeader(dbc.ModalTitle("URL")),
819 id="plot-btn-download",
820 children="Download Data",
824 "text-transform": "none",
825 "padding": "0rem 1rem"
828 dcc.Download(id="download-iterative-data")
831 "d-grid gap-0 d-md-flex justify-content-md-end"
838 def callbacks(self, app):
839 """Callbacks for the whole application.
841 :param app: The application.
847 Output("store-control-panel", "data"),
848 Output("store-selected-tests", "data"),
849 Output("plotting-area", "children"),
850 Output("row-card-sel-tests", "style"),
851 Output("row-btns-sel-tests", "style"),
852 Output("lg-selected", "children"),
854 Output({"type": "ctrl-dd", "index": "rls"}, "value"),
855 Output({"type": "ctrl-dd", "index": "dut"}, "options"),
856 Output({"type": "ctrl-dd", "index": "dut"}, "disabled"),
857 Output({"type": "ctrl-dd", "index": "dut"}, "value"),
858 Output({"type": "ctrl-dd", "index": "dutver"}, "options"),
859 Output({"type": "ctrl-dd", "index": "dutver"}, "disabled"),
860 Output({"type": "ctrl-dd", "index": "dutver"}, "value"),
861 Output({"type": "ctrl-dd", "index": "phy"}, "options"),
862 Output({"type": "ctrl-dd", "index": "phy"}, "disabled"),
863 Output({"type": "ctrl-dd", "index": "phy"}, "value"),
864 Output({"type": "ctrl-dd", "index": "area"}, "options"),
865 Output({"type": "ctrl-dd", "index": "area"}, "disabled"),
866 Output({"type": "ctrl-dd", "index": "area"}, "value"),
867 Output({"type": "ctrl-dd", "index": "test"}, "options"),
868 Output({"type": "ctrl-dd", "index": "test"}, "disabled"),
869 Output({"type": "ctrl-dd", "index": "test"}, "value"),
870 Output({"type": "ctrl-cl", "index": "core"}, "options"),
871 Output({"type": "ctrl-cl", "index": "core"}, "value"),
872 Output({"type": "ctrl-cl", "index": "core-all"}, "value"),
873 Output({"type": "ctrl-cl", "index": "core-all"}, "options"),
874 Output({"type": "ctrl-cl", "index": "frmsize"}, "options"),
875 Output({"type": "ctrl-cl", "index": "frmsize"}, "value"),
876 Output({"type": "ctrl-cl", "index": "frmsize-all"}, "value"),
877 Output({"type": "ctrl-cl", "index": "frmsize-all"}, "options"),
878 Output({"type": "ctrl-cl", "index": "tsttype"}, "options"),
879 Output({"type": "ctrl-cl", "index": "tsttype"}, "value"),
880 Output({"type": "ctrl-cl", "index": "tsttype-all"}, "value"),
881 Output({"type": "ctrl-cl", "index": "tsttype-all"}, "options"),
882 Output({"type": "ctrl-btn", "index": "add-test"}, "disabled"),
883 Output("normalize", "value")
886 State("store-control-panel", "data"),
887 State("store-selected-tests", "data"),
888 State({"type": "sel-cl", "index": ALL}, "value")
891 Input("url", "href"),
892 Input("normalize", "value"),
894 Input({"type": "ctrl-dd", "index": ALL}, "value"),
895 Input({"type": "ctrl-cl", "index": ALL}, "value"),
896 Input({"type": "ctrl-btn", "index": ALL}, "n_clicks")
899 def _update_application(
907 """Update the application when the event is detected.
910 ctrl_panel = ControlPanel(CP_PARAMS, control_panel)
914 parsed_url = url_decode(href)
916 url_params = parsed_url["params"]
920 plotting_area = no_update
921 row_card_sel_tests = no_update
922 row_btns_sel_tests = no_update
923 lg_selected = no_update
925 trigger = Trigger(callback_context.triggered)
927 if trigger.type == "url" and url_params:
929 store_sel = literal_eval(url_params["store_sel"][0])
930 normalize = literal_eval(url_params["norm"][0])
931 except (KeyError, IndexError, AttributeError):
934 row_card_sel_tests = C.STYLE_ENABLED
935 row_btns_sel_tests = C.STYLE_ENABLED
936 last_test = store_sel[-1]
937 test = self._spec_tbs[last_test["rls"]][last_test["dut"]]\
938 [last_test["dutver"]][last_test["area"]]\
939 [last_test["test"]][last_test["phy"]]
941 "dd-rls-val": last_test["rls"],
942 "dd-dut-val": last_test["dut"],
943 "dd-dut-opt": generate_options(
944 self._spec_tbs[last_test["rls"]].keys()
947 "dd-dutver-val": last_test["dutver"],
948 "dd-dutver-opt": generate_options(
949 self._spec_tbs[last_test["rls"]]\
950 [last_test["dut"]].keys()
952 "dd-dutver-dis": False,
953 "dd-area-val": last_test["area"],
955 {"label": label(v), "value": v} for v in \
956 sorted(self._spec_tbs[last_test["rls"]]\
958 [last_test["dutver"]].keys())
960 "dd-area-dis": False,
961 "dd-test-val": last_test["test"],
962 "dd-test-opt": generate_options(
963 self._spec_tbs[last_test["rls"]][last_test["dut"]]\
964 [last_test["dutver"]][last_test["area"]].keys()
966 "dd-test-dis": False,
967 "dd-phy-val": last_test["phy"],
968 "dd-phy-opt": generate_options(
969 self._spec_tbs[last_test["rls"]][last_test["dut"]]\
970 [last_test["dutver"]][last_test["area"]]\
971 [last_test["test"]].keys()
974 "cl-core-opt": generate_options(test["core"]),
975 "cl-core-val": [last_test["core"].upper(), ],
976 "cl-core-all-val": list(),
977 "cl-core-all-opt": C.CL_ALL_ENABLED,
978 "cl-frmsize-opt": generate_options(test["frame-size"]),
979 "cl-frmsize-val": [last_test["framesize"].upper(), ],
980 "cl-frmsize-all-val": list(),
981 "cl-frmsize-all-opt": C.CL_ALL_ENABLED,
982 "cl-tsttype-opt": generate_options(test["test-type"]),
983 "cl-tsttype-val": [last_test["testtype"].upper(), ],
984 "cl-tsttype-all-val": list(),
985 "cl-tsttype-all-opt": C.CL_ALL_ENABLED,
986 "cl-normalize-val": normalize,
990 elif trigger.type == "normalize":
991 ctrl_panel.set({"cl-normalize-val": normalize})
993 elif trigger.type == "ctrl-dd":
994 if trigger.idx == "rls":
996 options = generate_options(
997 self._spec_tbs[trigger.value].keys()
1004 "dd-rls-val": trigger.value,
1005 "dd-dut-val": str(),
1006 "dd-dut-opt": options,
1007 "dd-dut-dis": disabled,
1008 "dd-dutver-val": str(),
1009 "dd-dutver-opt": list(),
1010 "dd-dutver-dis": True,
1011 "dd-phy-val": str(),
1012 "dd-phy-opt": list(),
1014 "dd-area-val": str(),
1015 "dd-area-opt": list(),
1016 "dd-area-dis": True,
1017 "dd-test-val": str(),
1018 "dd-test-opt": list(),
1019 "dd-test-dis": True,
1020 "cl-core-opt": list(),
1021 "cl-core-val": list(),
1022 "cl-core-all-val": list(),
1023 "cl-core-all-opt": C.CL_ALL_DISABLED,
1024 "cl-frmsize-opt": list(),
1025 "cl-frmsize-val": list(),
1026 "cl-frmsize-all-val": list(),
1027 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1028 "cl-tsttype-opt": list(),
1029 "cl-tsttype-val": list(),
1030 "cl-tsttype-all-val": list(),
1031 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1034 elif trigger.idx == "dut":
1036 rls = ctrl_panel.get("dd-rls-val")
1037 dut = self._spec_tbs[rls][trigger.value]
1038 options = generate_options(dut.keys())
1044 "dd-dut-val": trigger.value,
1045 "dd-dutver-val": str(),
1046 "dd-dutver-opt": options,
1047 "dd-dutver-dis": disabled,
1048 "dd-phy-val": str(),
1049 "dd-phy-opt": list(),
1051 "dd-area-val": str(),
1052 "dd-area-opt": list(),
1053 "dd-area-dis": True,
1054 "dd-test-val": str(),
1055 "dd-test-opt": list(),
1056 "dd-test-dis": True,
1057 "cl-core-opt": list(),
1058 "cl-core-val": list(),
1059 "cl-core-all-val": list(),
1060 "cl-core-all-opt": C.CL_ALL_DISABLED,
1061 "cl-frmsize-opt": list(),
1062 "cl-frmsize-val": list(),
1063 "cl-frmsize-all-val": list(),
1064 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1065 "cl-tsttype-opt": list(),
1066 "cl-tsttype-val": list(),
1067 "cl-tsttype-all-val": list(),
1068 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1071 elif trigger.idx == "dutver":
1073 rls = ctrl_panel.get("dd-rls-val")
1074 dut = ctrl_panel.get("dd-dut-val")
1075 dutver = self._spec_tbs[rls][dut][trigger.value]
1076 options = [{"label": label(v), "value": v} \
1077 for v in sorted(dutver.keys())]
1083 "dd-dutver-val": trigger.value,
1084 "dd-area-val": str(),
1085 "dd-area-opt": options,
1086 "dd-area-dis": disabled,
1087 "dd-test-val": str(),
1088 "dd-test-opt": list(),
1089 "dd-test-dis": True,
1090 "dd-phy-val": str(),
1091 "dd-phy-opt": list(),
1093 "cl-core-opt": list(),
1094 "cl-core-val": list(),
1095 "cl-core-all-val": list(),
1096 "cl-core-all-opt": C.CL_ALL_DISABLED,
1097 "cl-frmsize-opt": list(),
1098 "cl-frmsize-val": list(),
1099 "cl-frmsize-all-val": list(),
1100 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1101 "cl-tsttype-opt": list(),
1102 "cl-tsttype-val": list(),
1103 "cl-tsttype-all-val": list(),
1104 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1107 elif trigger.idx == "area":
1109 rls = ctrl_panel.get("dd-rls-val")
1110 dut = ctrl_panel.get("dd-dut-val")
1111 dutver = ctrl_panel.get("dd-dutver-val")
1112 area = self._spec_tbs[rls][dut][dutver][trigger.value]
1113 options = generate_options(area.keys())
1119 "dd-area-val": trigger.value,
1120 "dd-test-val": str(),
1121 "dd-test-opt": options,
1122 "dd-test-dis": disabled,
1123 "dd-phy-val": str(),
1124 "dd-phy-opt": list(),
1126 "cl-core-opt": list(),
1127 "cl-core-val": list(),
1128 "cl-core-all-val": list(),
1129 "cl-core-all-opt": C.CL_ALL_DISABLED,
1130 "cl-frmsize-opt": list(),
1131 "cl-frmsize-val": list(),
1132 "cl-frmsize-all-val": list(),
1133 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1134 "cl-tsttype-opt": list(),
1135 "cl-tsttype-val": list(),
1136 "cl-tsttype-all-val": list(),
1137 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1140 elif trigger.idx == "test":
1142 rls = ctrl_panel.get("dd-rls-val")
1143 dut = ctrl_panel.get("dd-dut-val")
1144 dutver = ctrl_panel.get("dd-dutver-val")
1145 area = ctrl_panel.get("dd-area-val")
1146 test = self._spec_tbs[rls][dut][dutver][area]\
1148 options = generate_options(test.keys())
1154 "dd-test-val": trigger.value,
1155 "dd-phy-val": str(),
1156 "dd-phy-opt": options,
1157 "dd-phy-dis": disabled,
1158 "cl-core-opt": list(),
1159 "cl-core-val": list(),
1160 "cl-core-all-val": list(),
1161 "cl-core-all-opt": C.CL_ALL_DISABLED,
1162 "cl-frmsize-opt": list(),
1163 "cl-frmsize-val": list(),
1164 "cl-frmsize-all-val": list(),
1165 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1166 "cl-tsttype-opt": list(),
1167 "cl-tsttype-val": list(),
1168 "cl-tsttype-all-val": list(),
1169 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1172 elif trigger.idx == "phy":
1173 rls = ctrl_panel.get("dd-rls-val")
1174 dut = ctrl_panel.get("dd-dut-val")
1175 dutver = ctrl_panel.get("dd-dutver-val")
1176 area = ctrl_panel.get("dd-area-val")
1177 test = ctrl_panel.get("dd-test-val")
1178 if all((rls, dut, dutver, area, test, trigger.value, )):
1179 phy = self._spec_tbs[rls][dut][dutver][area][test]\
1182 "dd-phy-val": trigger.value,
1183 "cl-core-opt": generate_options(phy["core"]),
1184 "cl-core-val": list(),
1185 "cl-core-all-val": list(),
1186 "cl-core-all-opt": C.CL_ALL_ENABLED,
1188 generate_options(phy["frame-size"]),
1189 "cl-frmsize-val": list(),
1190 "cl-frmsize-all-val": list(),
1191 "cl-frmsize-all-opt": C.CL_ALL_ENABLED,
1193 generate_options(phy["test-type"]),
1194 "cl-tsttype-val": list(),
1195 "cl-tsttype-all-val": list(),
1196 "cl-tsttype-all-opt": C.CL_ALL_ENABLED,
1199 elif trigger.type == "ctrl-cl":
1200 param = trigger.idx.split("-")[0]
1201 if "-all" in trigger.idx:
1202 c_sel, c_all, c_id = list(), trigger.value, "all"
1204 c_sel, c_all, c_id = trigger.value, list(), str()
1205 val_sel, val_all = sync_checklists(
1206 options=ctrl_panel.get(f"cl-{param}-opt"),
1212 f"cl-{param}-val": val_sel,
1213 f"cl-{param}-all-val": val_all,
1215 if all((ctrl_panel.get("cl-core-val"),
1216 ctrl_panel.get("cl-frmsize-val"),
1217 ctrl_panel.get("cl-tsttype-val"), )):
1218 ctrl_panel.set({"btn-add-dis": False})
1220 ctrl_panel.set({"btn-add-dis": True})
1221 elif trigger.type == "ctrl-btn":
1223 if trigger.idx == "add-test":
1224 rls = ctrl_panel.get("dd-rls-val")
1225 dut = ctrl_panel.get("dd-dut-val")
1226 dutver = ctrl_panel.get("dd-dutver-val")
1227 phy = ctrl_panel.get("dd-phy-val")
1228 area = ctrl_panel.get("dd-area-val")
1229 test = ctrl_panel.get("dd-test-val")
1230 # Add selected test to the list of tests in store:
1231 if store_sel is None:
1233 for core in ctrl_panel.get("cl-core-val"):
1234 for framesize in ctrl_panel.get("cl-frmsize-val"):
1235 for ttype in ctrl_panel.get("cl-tsttype-val"):
1242 phy.replace("af_xdp", "af-xdp"),
1249 if tid not in [i["id"] for i in store_sel]:
1258 "framesize": framesize.lower(),
1259 "core": core.lower(),
1260 "testtype": ttype.lower()
1262 store_sel = sorted(store_sel, key=lambda d: d["id"])
1263 if C.CLEAR_ALL_INPUTS:
1264 ctrl_panel.set(ctrl_panel.defaults)
1265 elif trigger.idx == "rm-test" and lst_sel:
1266 new_store_sel = list()
1267 for idx, item in enumerate(store_sel):
1268 if not lst_sel[idx]:
1269 new_store_sel.append(item)
1270 store_sel = new_store_sel
1271 elif trigger.idx == "rm-test-all":
1276 lg_selected = get_list_group_items(
1277 store_sel, "sel-cl", add_index=True
1279 plotting_area = self._get_plotting_area(
1284 {"store_sel": store_sel, "norm": normalize}
1287 row_card_sel_tests = C.STYLE_ENABLED
1288 row_btns_sel_tests = C.STYLE_ENABLED
1290 plotting_area = C.PLACEHOLDER
1291 row_card_sel_tests = C.STYLE_DISABLED
1292 row_btns_sel_tests = C.STYLE_DISABLED
1303 ret_val.extend(ctrl_panel.values)
1307 Output("plot-mod-url", "is_open"),
1308 [Input("plot-btn-url", "n_clicks")],
1309 [State("plot-mod-url", "is_open")],
1311 def toggle_plot_mod_url(n, is_open):
1312 """Toggle the modal window with url.
1319 Output("download-iterative-data", "data"),
1320 State("store-selected-tests", "data"),
1321 Input("plot-btn-download", "n_clicks"),
1322 prevent_initial_call=True
1324 def _download_iterative_data(store_sel, _):
1325 """Download the data
1327 :param store_sel: List of tests selected by user stored in the
1329 :type store_sel: list
1330 :returns: dict of data frame content (base64 encoded) and meta data
1331 used by the Download component.
1339 for itm in store_sel:
1340 sel_data = select_iterative_data(self._data, itm)
1341 if sel_data is None:
1343 df = pd.concat([df, sel_data], ignore_index=True)
1345 return dcc.send_data_frame(df.to_csv, C.REPORT_DOWNLOAD_FILE_NAME)
1348 Output("metadata-tput-lat", "children"),
1349 Output("metadata-hdrh-graph", "children"),
1350 Output("offcanvas-metadata", "is_open"),
1351 Input({"type": "graph", "index": ALL}, "clickData"),
1352 prevent_initial_call=True
1354 def _show_metadata_from_graphs(graph_data: dict) -> tuple:
1355 """Generates the data for the offcanvas displayed when a particular
1356 point in a graph is clicked on.
1358 :param graph_data: The data from the clicked point in the graph.
1359 :type graph_data: dict
1360 :returns: The data to be displayed on the offcanvas and the
1361 information to show the offcanvas.
1362 :rtype: tuple(list, list, bool)
1365 trigger = Trigger(callback_context.triggered)
1368 idx = 0 if trigger.idx == "tput" else 1
1369 graph_data = graph_data[idx]["points"]
1370 except (IndexError, KeyError, ValueError, TypeError):
1373 def _process_stats(data: list, param: str) -> list:
1374 """Process statistical data provided by plot.ly box graph.
1376 :param data: Statistical data provided by plot.ly box graph.
1377 :param param: Parameter saying if the data come from "tput" or
1381 :returns: Listo of tuples where the first value is the
1382 statistic's name and the secont one it's value.
1386 stats = ("max", "upper fence", "q3", "median", "q1",
1387 "lower fence", "min")
1388 elif len(data) == 9:
1389 stats = ("outlier", "max", "upper fence", "q3", "median",
1390 "q1", "lower fence", "min", "outlier")
1391 elif len(data) == 1:
1393 stats = ("average latency at 50% PDR", )
1395 stats = ("throughput", )
1398 unit = " [us]" if param == "lat" else str()
1399 return [(f"{stat}{unit}", f"{value['y']:,.0f}")
1400 for stat, value in zip(stats, data)]
1402 customdata = graph_data[0].get("customdata", dict())
1403 datapoint = customdata.get("metadata", dict())
1404 hdrh_data = customdata.get("hdrh", dict())
1406 list_group_items = list()
1407 for k, v in datapoint.items():
1409 if len(graph_data) > 1:
1411 list_group_item = dbc.ListGroupItem([
1413 html.A(v, href=f"{C.URL_JENKINS}{v}", target="_blank")
1416 list_group_item = dbc.ListGroupItem([dbc.Badge(k), v])
1417 list_group_items.append(list_group_item)
1420 if trigger.idx == "tput":
1421 title = "Throughput"
1422 elif trigger.idx == "lat":
1424 if len(graph_data) == 1:
1427 class_name="gy-2 p-0",
1429 dbc.CardHeader(hdrh_data.pop("name")),
1430 dbc.CardBody(dcc.Graph(
1431 id="hdrh-latency-graph",
1432 figure=graph_hdrh_latency(
1433 hdrh_data, self._graph_layout
1441 for k, v in _process_stats(graph_data, trigger.idx):
1442 list_group_items.append(dbc.ListGroupItem([dbc.Badge(k), v]))
1446 class_name="gy-2 p-0",
1448 dbc.CardHeader(children=[
1450 target_id="tput-lat-metadata",
1452 style={"display": "inline-block"}
1457 dbc.ListGroup(list_group_items, flush=True),
1458 id="tput-lat-metadata",
1465 return metadata, graph, True
1468 Output("offcanvas-documentation", "is_open"),
1469 Input("btn-documentation", "n_clicks"),
1470 State("offcanvas-documentation", "is_open")
1472 def toggle_offcanvas_documentation(n_clicks, is_open):