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.
19 import dash_bootstrap_components as dbc
21 from flask import Flask
24 from dash import callback_context, no_update, ALL
25 from dash import Input, Output, State
26 from dash.exceptions import PreventUpdate
27 from yaml import load, FullLoader, YAMLError
28 from ast import literal_eval
30 from ..utils.constants import Constants as C
31 from ..utils.control_panel import ControlPanel
32 from ..utils.trigger import Trigger
33 from ..utils.utils import show_tooltip, label, sync_checklists, gen_new_url, \
34 generate_options, get_list_group_items, graph_hdrh_latency
35 from ..utils.url_processing import url_decode
36 from .graphs import graph_iterative, select_iterative_data
39 # Control panel partameters and their default values.
45 "dd-dutver-opt": list(),
46 "dd-dutver-dis": True,
47 "dd-dutver-val": str(),
51 "dd-area-opt": list(),
54 "dd-test-opt": list(),
57 "cl-core-opt": list(),
58 "cl-core-val": list(),
59 "cl-core-all-val": list(),
60 "cl-core-all-opt": C.CL_ALL_DISABLED,
61 "cl-frmsize-opt": list(),
62 "cl-frmsize-val": list(),
63 "cl-frmsize-all-val": list(),
64 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
65 "cl-tsttype-opt": list(),
66 "cl-tsttype-val": list(),
67 "cl-tsttype-all-val": list(),
68 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
70 "cl-normalize-val": list()
75 """The layout of the dash app and the callbacks.
81 data_iterative: pd.DataFrame,
82 html_layout_file: str,
83 graph_layout_file: str,
87 - save the input parameters,
88 - read and pre-process the data,
89 - prepare data for the control panel,
90 - read HTML layout file,
91 - read tooltips from the tooltip file.
93 :param app: Flask application running the dash application.
94 :param html_layout_file: Path and name of the file specifying the HTML
95 layout of the dash application.
96 :param graph_layout_file: Path and name of the file with layout of
98 :param tooltip_file: Path and name of the yaml file specifying the
101 :type html_layout_file: str
102 :type graph_layout_file: str
103 :type tooltip_file: str
108 self._html_layout_file = html_layout_file
109 self._graph_layout_file = graph_layout_file
110 self._tooltip_file = tooltip_file
111 self._data = data_iterative
113 # Get structure of tests:
116 "job", "test_id", "test_type", "dut_version", "tg_type", "release"
118 for _, row in self._data[cols].drop_duplicates().iterrows():
120 lst_job = row["job"].split("-")
122 d_ver = row["dut_version"]
123 tbed = "-".join(lst_job[-2:])
124 lst_test_id = row["test_id"].split(".")
128 area = "-".join(lst_test_id[3:-2])
129 suite = lst_test_id[-2].replace("2n1l-", "").replace("1n1l-", "").\
131 test = lst_test_id[-1]
132 nic = suite.split("-")[0]
133 for drv in C.DRIVERS:
135 driver = drv.replace("-", "_")
136 test = test.replace(f"{drv}-", "")
140 infra = "-".join((tbed, nic, driver))
141 lst_test = test.split("-")
142 framesize = lst_test[0]
143 core = lst_test[1] if lst_test[1] else "8C"
144 test = "-".join(lst_test[2: -1])
146 if tbs.get(rls, None) is None:
148 if tbs[rls].get(dut, None) is None:
149 tbs[rls][dut] = dict()
150 if tbs[rls][dut].get(d_ver, None) is None:
151 tbs[rls][dut][d_ver] = dict()
152 if tbs[rls][dut][d_ver].get(infra, None) is None:
153 tbs[rls][dut][d_ver][infra] = dict()
154 if tbs[rls][dut][d_ver][infra].get(area, None) is None:
155 tbs[rls][dut][d_ver][infra][area] = dict()
156 if tbs[rls][dut][d_ver][infra][area].get(test, None) is None:
157 tbs[rls][dut][d_ver][infra][area][test] = dict()
158 tbs[rls][dut][d_ver][infra][area][test]["core"] = list()
159 tbs[rls][dut][d_ver][infra][area][test]["frame-size"] = list()
160 tbs[rls][dut][d_ver][infra][area][test]["test-type"] = list()
161 if core.upper() not in \
162 tbs[rls][dut][d_ver][infra][area][test]["core"]:
163 tbs[rls][dut][d_ver][infra][area][test]["core"].append(
166 if framesize.upper() not in \
167 tbs[rls][dut][d_ver][infra][area][test]["frame-size"]:
168 tbs[rls][dut][d_ver][infra][area][test]["frame-size"].append(
171 if row["test_type"] == "mrr":
173 tbs[rls][dut][d_ver][infra][area][test]["test-type"]:
174 tbs[rls][dut][d_ver][infra][area][test]["test-type"].append(
177 elif row["test_type"] == "ndrpdr":
179 tbs[rls][dut][d_ver][infra][area][test]["test-type"]:
180 tbs[rls][dut][d_ver][infra][area][test]["test-type"].extend(
183 elif row["test_type"] == "hoststack" and \
184 row["tg_type"] in ("iperf", "vpp"):
186 tbs[rls][dut][d_ver][infra][area][test]["test-type"]:
187 tbs[rls][dut][d_ver][infra][area][test]["test-type"].append(
190 elif row["test_type"] == "hoststack" and row["tg_type"] == "ab":
192 tbs[rls][dut][d_ver][infra][area][test]["test-type"]:
193 tbs[rls][dut][d_ver][infra][area][test]["test-type"].extend(
199 self._html_layout = str()
200 self._graph_layout = None
201 self._tooltips = dict()
204 with open(self._html_layout_file, "r") as file_read:
205 self._html_layout = file_read.read()
206 except IOError as err:
208 f"Not possible to open the file {self._html_layout_file}\n{err}"
212 with open(self._graph_layout_file, "r") as file_read:
213 self._graph_layout = load(file_read, Loader=FullLoader)
214 except IOError as err:
216 f"Not possible to open the file {self._graph_layout_file}\n"
219 except YAMLError as err:
221 f"An error occurred while parsing the specification file "
222 f"{self._graph_layout_file}\n{err}"
226 with open(self._tooltip_file, "r") as file_read:
227 self._tooltips = load(file_read, Loader=FullLoader)
228 except IOError as err:
230 f"Not possible to open the file {self._tooltip_file}\n{err}"
232 except YAMLError as err:
234 f"An error occurred while parsing the specification file "
235 f"{self._tooltip_file}\n{err}"
239 if self._app is not None and hasattr(self, "callbacks"):
240 self.callbacks(self._app)
243 def html_layout(self):
244 return self._html_layout
246 def add_content(self):
247 """Top level method which generated the web page.
250 - Store for user input data,
252 - Main area with control panel and ploting area.
254 If no HTML layout is provided, an error message is displayed instead.
256 :returns: The HTML div with the whole page.
260 if self.html_layout and self._spec_tbs:
276 dcc.Store(id="store-selected-tests"),
277 dcc.Store(id="store-control-panel"),
278 dcc.Location(id="url", refresh=False),
279 self._add_ctrl_col(),
280 self._add_plotting_col()
286 id="offcanvas-metadata",
287 title="Throughput And Latency",
291 dbc.Row(id="metadata-tput-lat"),
292 dbc.Row(id="metadata-hdrh-graph")
295 delay_show=C.SPINNER_DELAY
312 def _add_navbar(self):
313 """Add nav element with navigation panel. It is placed on the top.
315 :returns: Navigation bar.
316 :rtype: dbc.NavbarSimple
318 return dbc.NavbarSimple(
319 id="navbarsimple-main",
332 brand_external_link=True,
337 def _add_ctrl_col(self) -> dbc.Col:
338 """Add column with controls. It is placed on the left side.
340 :returns: Column with the control panel.
345 children=self._add_ctrl_panel(),
346 className="sticky-top"
350 def _add_plotting_col(self) -> dbc.Col:
351 """Add column with plots. It is placed on the right side.
353 :returns: Column with plots.
357 id="col-plotting-area",
363 class_name="g-0 p-0",
374 def _add_ctrl_panel(self) -> list:
375 """Add control panel.
377 :returns: Control panel.
382 class_name="g-0 p-1",
387 children=show_tooltip(
394 id={"type": "ctrl-dd", "index": "rls"},
395 placeholder="Select a Release...",
398 {"label": k, "value": k} \
399 for k in self._spec_tbs.keys()
401 key=lambda d: d["label"]
410 class_name="g-0 p-1",
415 children=show_tooltip(
422 id={"type": "ctrl-dd", "index": "dut"},
423 placeholder="Select a Device under Test..."
431 class_name="g-0 p-1",
436 children=show_tooltip(
443 id={"type": "ctrl-dd", "index": "dutver"},
445 "Select a Version of Device under Test..."
453 class_name="g-0 p-1",
458 children=show_tooltip(
465 id={"type": "ctrl-dd", "index": "phy"},
467 "Select a Physical Test Bed Topology..."
475 class_name="g-0 p-1",
480 children=show_tooltip(
487 id={"type": "ctrl-dd", "index": "area"},
488 placeholder="Select an Area..."
496 class_name="g-0 p-1",
501 children=show_tooltip(
508 id={"type": "ctrl-dd", "index": "test"},
509 placeholder="Select a Test..."
517 class_name="g-0 p-1",
522 children=show_tooltip(
533 "index": "frmsize-all"
535 options=C.CL_ALL_DISABLED,
554 style={"align-items": "center"},
560 class_name="g-0 p-1",
565 children=show_tooltip(
578 options=C.CL_ALL_DISABLED,
597 style={"align-items": "center"},
603 class_name="g-0 p-1",
608 children=show_tooltip(
619 "index": "tsttype-all"
621 options=C.CL_ALL_DISABLED,
640 style={"align-items": "center"},
646 class_name="g-0 p-1",
651 children=show_tooltip(
662 "value": "normalize",
664 "Normalize to CPU frequency "
675 style={"align-items": "center"},
681 class_name="g-0 p-1",
684 id={"type": "ctrl-btn", "index": "add-test"},
685 children="Add Selected",
691 id="row-card-sel-tests",
692 class_name="g-0 p-1",
693 style=C.STYLE_DISABLED,
696 class_name="overflow-auto p-0",
699 style={"max-height": "20em"},
705 id="row-btns-sel-tests",
706 class_name="g-0 p-1",
707 style=C.STYLE_DISABLED,
712 id={"type": "ctrl-btn", "index": "rm-test"},
713 children="Remove Selected",
719 id={"type": "ctrl-btn", "index": "rm-test-all"},
720 children="Remove All",
731 def _get_plotting_area(
737 """Generate the plotting area with all its content.
739 :param tests: List of tests to be displayed in the graphs.
740 :param normalize: If true, the values in graphs are normalized.
741 :param url: URL to be displayed in the modal window.
743 :type normalize: bool
745 :returns: List of rows with elements to be displayed in the plotting
752 figs = graph_iterative(self._data, tests, self._graph_layout, normalize)
760 id={"type": "graph", "index": "tput"},
763 class_name="g-0 p-1",
772 id={"type": "graph", "index": "lat"},
775 class_name="g-0 p-1",
783 class_name="g-0 p-0",
795 "text-transform": "none",
796 "padding": "0rem 1rem"
801 dbc.ModalHeader(dbc.ModalTitle("URL")),
810 id="plot-btn-download",
811 children="Download Data",
815 "text-transform": "none",
816 "padding": "0rem 1rem"
819 dcc.Download(id="download-iterative-data")
822 "d-grid gap-0 d-md-flex justify-content-md-end"
829 def callbacks(self, app):
830 """Callbacks for the whole application.
832 :param app: The application.
838 Output("store-control-panel", "data"),
839 Output("store-selected-tests", "data"),
840 Output("plotting-area", "children"),
841 Output("row-card-sel-tests", "style"),
842 Output("row-btns-sel-tests", "style"),
843 Output("lg-selected", "children"),
845 Output({"type": "ctrl-dd", "index": "rls"}, "value"),
846 Output({"type": "ctrl-dd", "index": "dut"}, "options"),
847 Output({"type": "ctrl-dd", "index": "dut"}, "disabled"),
848 Output({"type": "ctrl-dd", "index": "dut"}, "value"),
849 Output({"type": "ctrl-dd", "index": "dutver"}, "options"),
850 Output({"type": "ctrl-dd", "index": "dutver"}, "disabled"),
851 Output({"type": "ctrl-dd", "index": "dutver"}, "value"),
852 Output({"type": "ctrl-dd", "index": "phy"}, "options"),
853 Output({"type": "ctrl-dd", "index": "phy"}, "disabled"),
854 Output({"type": "ctrl-dd", "index": "phy"}, "value"),
855 Output({"type": "ctrl-dd", "index": "area"}, "options"),
856 Output({"type": "ctrl-dd", "index": "area"}, "disabled"),
857 Output({"type": "ctrl-dd", "index": "area"}, "value"),
858 Output({"type": "ctrl-dd", "index": "test"}, "options"),
859 Output({"type": "ctrl-dd", "index": "test"}, "disabled"),
860 Output({"type": "ctrl-dd", "index": "test"}, "value"),
861 Output({"type": "ctrl-cl", "index": "core"}, "options"),
862 Output({"type": "ctrl-cl", "index": "core"}, "value"),
863 Output({"type": "ctrl-cl", "index": "core-all"}, "value"),
864 Output({"type": "ctrl-cl", "index": "core-all"}, "options"),
865 Output({"type": "ctrl-cl", "index": "frmsize"}, "options"),
866 Output({"type": "ctrl-cl", "index": "frmsize"}, "value"),
867 Output({"type": "ctrl-cl", "index": "frmsize-all"}, "value"),
868 Output({"type": "ctrl-cl", "index": "frmsize-all"}, "options"),
869 Output({"type": "ctrl-cl", "index": "tsttype"}, "options"),
870 Output({"type": "ctrl-cl", "index": "tsttype"}, "value"),
871 Output({"type": "ctrl-cl", "index": "tsttype-all"}, "value"),
872 Output({"type": "ctrl-cl", "index": "tsttype-all"}, "options"),
873 Output({"type": "ctrl-btn", "index": "add-test"}, "disabled"),
874 Output("normalize", "value")
877 State("store-control-panel", "data"),
878 State("store-selected-tests", "data"),
879 State({"type": "sel-cl", "index": ALL}, "value")
882 Input("url", "href"),
883 Input("normalize", "value"),
885 Input({"type": "ctrl-dd", "index": ALL}, "value"),
886 Input({"type": "ctrl-cl", "index": ALL}, "value"),
887 Input({"type": "ctrl-btn", "index": ALL}, "n_clicks")
890 def _update_application(
898 """Update the application when the event is detected.
901 ctrl_panel = ControlPanel(CP_PARAMS, control_panel)
905 parsed_url = url_decode(href)
907 url_params = parsed_url["params"]
911 plotting_area = no_update
912 row_card_sel_tests = no_update
913 row_btns_sel_tests = no_update
914 lg_selected = no_update
916 trigger = Trigger(callback_context.triggered)
918 if trigger.type == "url" and url_params:
920 store_sel = literal_eval(url_params["store_sel"][0])
921 normalize = literal_eval(url_params["norm"][0])
922 except (KeyError, IndexError):
925 row_card_sel_tests = C.STYLE_ENABLED
926 row_btns_sel_tests = C.STYLE_ENABLED
927 last_test = store_sel[-1]
928 test = self._spec_tbs[last_test["rls"]][last_test["dut"]]\
929 [last_test["dutver"]][last_test["phy"]]\
930 [last_test["area"]][last_test["test"]]
932 "dd-rls-val": last_test["rls"],
933 "dd-dut-val": last_test["dut"],
934 "dd-dut-opt": generate_options(
935 self._spec_tbs[last_test["rls"]].keys()
938 "dd-dutver-val": last_test["dutver"],
939 "dd-dutver-opt": generate_options(
940 self._spec_tbs[last_test["rls"]]\
941 [last_test["dut"]].keys()
943 "dd-dutver-dis": False,
944 "dd-phy-val": last_test["phy"],
945 "dd-phy-opt": generate_options(
946 self._spec_tbs[last_test["rls"]][last_test["dut"]]\
947 [last_test["dutver"]].keys()
950 "dd-area-val": last_test["area"],
952 {"label": label(v), "value": v} for v in \
953 sorted(self._spec_tbs[last_test["rls"]]\
954 [last_test["dut"]][last_test["dutver"]]\
955 [last_test["phy"]].keys())
957 "dd-area-dis": False,
958 "dd-test-val": last_test["test"],
959 "dd-test-opt": generate_options(
960 self._spec_tbs[last_test["rls"]][last_test["dut"]]\
961 [last_test["dutver"]][last_test["phy"]]\
962 [last_test["area"]].keys()
964 "dd-test-dis": False,
965 "cl-core-opt": generate_options(test["core"]),
966 "cl-core-val": [last_test["core"].upper(), ],
967 "cl-core-all-val": list(),
968 "cl-core-all-opt": C.CL_ALL_ENABLED,
969 "cl-frmsize-opt": generate_options(test["frame-size"]),
970 "cl-frmsize-val": [last_test["framesize"].upper(), ],
971 "cl-frmsize-all-val": list(),
972 "cl-frmsize-all-opt": C.CL_ALL_ENABLED,
973 "cl-tsttype-opt": generate_options(test["test-type"]),
974 "cl-tsttype-val": [last_test["testtype"].upper(), ],
975 "cl-tsttype-all-val": list(),
976 "cl-tsttype-all-opt": C.CL_ALL_ENABLED,
977 "cl-normalize-val": normalize,
981 elif trigger.type == "normalize":
982 ctrl_panel.set({"cl-normalize-val": normalize})
984 elif trigger.type == "ctrl-dd":
985 if trigger.idx == "rls":
987 options = generate_options(
988 self._spec_tbs[trigger.value].keys()
995 "dd-rls-val": trigger.value,
997 "dd-dut-opt": options,
998 "dd-dut-dis": disabled,
999 "dd-dutver-val": str(),
1000 "dd-dutver-opt": list(),
1001 "dd-dutver-dis": True,
1002 "dd-phy-val": str(),
1003 "dd-phy-opt": list(),
1005 "dd-area-val": str(),
1006 "dd-area-opt": list(),
1007 "dd-area-dis": True,
1008 "dd-test-val": str(),
1009 "dd-test-opt": list(),
1010 "dd-test-dis": True,
1011 "cl-core-opt": list(),
1012 "cl-core-val": list(),
1013 "cl-core-all-val": list(),
1014 "cl-core-all-opt": C.CL_ALL_DISABLED,
1015 "cl-frmsize-opt": list(),
1016 "cl-frmsize-val": list(),
1017 "cl-frmsize-all-val": list(),
1018 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1019 "cl-tsttype-opt": list(),
1020 "cl-tsttype-val": list(),
1021 "cl-tsttype-all-val": list(),
1022 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1025 elif trigger.idx == "dut":
1027 rls = ctrl_panel.get("dd-rls-val")
1028 dut = self._spec_tbs[rls][trigger.value]
1029 options = generate_options(dut.keys())
1035 "dd-dut-val": trigger.value,
1036 "dd-dutver-val": str(),
1037 "dd-dutver-opt": options,
1038 "dd-dutver-dis": disabled,
1039 "dd-phy-val": str(),
1040 "dd-phy-opt": list(),
1042 "dd-area-val": str(),
1043 "dd-area-opt": list(),
1044 "dd-area-dis": True,
1045 "dd-test-val": str(),
1046 "dd-test-opt": list(),
1047 "dd-test-dis": True,
1048 "cl-core-opt": list(),
1049 "cl-core-val": list(),
1050 "cl-core-all-val": list(),
1051 "cl-core-all-opt": C.CL_ALL_DISABLED,
1052 "cl-frmsize-opt": list(),
1053 "cl-frmsize-val": list(),
1054 "cl-frmsize-all-val": list(),
1055 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1056 "cl-tsttype-opt": list(),
1057 "cl-tsttype-val": list(),
1058 "cl-tsttype-all-val": list(),
1059 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1062 elif trigger.idx == "dutver":
1064 rls = ctrl_panel.get("dd-rls-val")
1065 dut = ctrl_panel.get("dd-dut-val")
1066 dutver = self._spec_tbs[rls][dut][trigger.value]
1067 options = generate_options(dutver.keys())
1073 "dd-dutver-val": trigger.value,
1074 "dd-phy-val": str(),
1075 "dd-phy-opt": options,
1076 "dd-phy-dis": disabled,
1077 "dd-area-val": str(),
1078 "dd-area-opt": list(),
1079 "dd-area-dis": True,
1080 "dd-test-val": str(),
1081 "dd-test-opt": list(),
1082 "dd-test-dis": True,
1083 "cl-core-opt": list(),
1084 "cl-core-val": list(),
1085 "cl-core-all-val": list(),
1086 "cl-core-all-opt": C.CL_ALL_DISABLED,
1087 "cl-frmsize-opt": list(),
1088 "cl-frmsize-val": list(),
1089 "cl-frmsize-all-val": list(),
1090 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1091 "cl-tsttype-opt": list(),
1092 "cl-tsttype-val": list(),
1093 "cl-tsttype-all-val": list(),
1094 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1097 elif trigger.idx == "phy":
1099 rls = ctrl_panel.get("dd-rls-val")
1100 dut = ctrl_panel.get("dd-dut-val")
1101 dutver = ctrl_panel.get("dd-dutver-val")
1102 phy = self._spec_tbs[rls][dut][dutver][trigger.value]
1103 options = [{"label": label(v), "value": v} \
1104 for v in sorted(phy.keys())]
1110 "dd-phy-val": trigger.value,
1111 "dd-area-val": str(),
1112 "dd-area-opt": options,
1113 "dd-area-dis": disabled,
1114 "dd-test-val": str(),
1115 "dd-test-opt": list(),
1116 "dd-test-dis": True,
1117 "cl-core-opt": list(),
1118 "cl-core-val": list(),
1119 "cl-core-all-val": list(),
1120 "cl-core-all-opt": C.CL_ALL_DISABLED,
1121 "cl-frmsize-opt": list(),
1122 "cl-frmsize-val": list(),
1123 "cl-frmsize-all-val": list(),
1124 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1125 "cl-tsttype-opt": list(),
1126 "cl-tsttype-val": list(),
1127 "cl-tsttype-all-val": list(),
1128 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1131 elif trigger.idx == "area":
1133 rls = ctrl_panel.get("dd-rls-val")
1134 dut = ctrl_panel.get("dd-dut-val")
1135 dutver = ctrl_panel.get("dd-dutver-val")
1136 phy = ctrl_panel.get("dd-phy-val")
1138 self._spec_tbs[rls][dut][dutver][phy][trigger.value]
1139 options = generate_options(area.keys())
1145 "dd-area-val": trigger.value,
1146 "dd-test-val": str(),
1147 "dd-test-opt": options,
1148 "dd-test-dis": disabled,
1149 "cl-core-opt": list(),
1150 "cl-core-val": list(),
1151 "cl-core-all-val": list(),
1152 "cl-core-all-opt": C.CL_ALL_DISABLED,
1153 "cl-frmsize-opt": list(),
1154 "cl-frmsize-val": list(),
1155 "cl-frmsize-all-val": list(),
1156 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1157 "cl-tsttype-opt": list(),
1158 "cl-tsttype-val": list(),
1159 "cl-tsttype-all-val": list(),
1160 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1163 elif trigger.idx == "test":
1164 rls = ctrl_panel.get("dd-rls-val")
1165 dut = ctrl_panel.get("dd-dut-val")
1166 dutver = ctrl_panel.get("dd-dutver-val")
1167 phy = ctrl_panel.get("dd-phy-val")
1168 area = ctrl_panel.get("dd-area-val")
1169 if all((rls, dut, dutver, phy, area, trigger.value, )):
1170 test = self._spec_tbs[rls][dut][dutver][phy][area]\
1173 "dd-test-val": trigger.value,
1174 "cl-core-opt": generate_options(test["core"]),
1175 "cl-core-val": list(),
1176 "cl-core-all-val": list(),
1177 "cl-core-all-opt": C.CL_ALL_ENABLED,
1179 generate_options(test["frame-size"]),
1180 "cl-frmsize-val": list(),
1181 "cl-frmsize-all-val": list(),
1182 "cl-frmsize-all-opt": C.CL_ALL_ENABLED,
1184 generate_options(test["test-type"]),
1185 "cl-tsttype-val": list(),
1186 "cl-tsttype-all-val": list(),
1187 "cl-tsttype-all-opt": C.CL_ALL_ENABLED,
1190 elif trigger.type == "ctrl-cl":
1191 param = trigger.idx.split("-")[0]
1192 if "-all" in trigger.idx:
1193 c_sel, c_all, c_id = list(), trigger.value, "all"
1195 c_sel, c_all, c_id = trigger.value, list(), str()
1196 val_sel, val_all = sync_checklists(
1197 options=ctrl_panel.get(f"cl-{param}-opt"),
1203 f"cl-{param}-val": val_sel,
1204 f"cl-{param}-all-val": val_all,
1206 if all((ctrl_panel.get("cl-core-val"),
1207 ctrl_panel.get("cl-frmsize-val"),
1208 ctrl_panel.get("cl-tsttype-val"), )):
1209 ctrl_panel.set({"btn-add-dis": False})
1211 ctrl_panel.set({"btn-add-dis": True})
1212 elif trigger.type == "ctrl-btn":
1214 if trigger.idx == "add-test":
1215 rls = ctrl_panel.get("dd-rls-val")
1216 dut = ctrl_panel.get("dd-dut-val")
1217 dutver = ctrl_panel.get("dd-dutver-val")
1218 phy = ctrl_panel.get("dd-phy-val")
1219 area = ctrl_panel.get("dd-area-val")
1220 test = ctrl_panel.get("dd-test-val")
1221 # Add selected test to the list of tests in store:
1222 if store_sel is None:
1224 for core in ctrl_panel.get("cl-core-val"):
1225 for framesize in ctrl_panel.get("cl-frmsize-val"):
1226 for ttype in ctrl_panel.get("cl-tsttype-val"):
1233 phy.replace("af_xdp", "af-xdp"),
1240 if tid not in [i["id"] for i in store_sel]:
1249 "framesize": framesize.lower(),
1250 "core": core.lower(),
1251 "testtype": ttype.lower()
1253 store_sel = sorted(store_sel, key=lambda d: d["id"])
1254 if C.CLEAR_ALL_INPUTS:
1255 ctrl_panel.set(ctrl_panel.defaults)
1256 elif trigger.idx == "rm-test" and lst_sel:
1257 new_store_sel = list()
1258 for idx, item in enumerate(store_sel):
1259 if not lst_sel[idx]:
1260 new_store_sel.append(item)
1261 store_sel = new_store_sel
1262 elif trigger.idx == "rm-test-all":
1267 lg_selected = get_list_group_items(
1268 store_sel, "sel-cl", add_index=True
1270 plotting_area = self._get_plotting_area(
1275 {"store_sel": store_sel, "norm": normalize}
1278 row_card_sel_tests = C.STYLE_ENABLED
1279 row_btns_sel_tests = C.STYLE_ENABLED
1281 plotting_area = C.PLACEHOLDER
1282 row_card_sel_tests = C.STYLE_DISABLED
1283 row_btns_sel_tests = C.STYLE_DISABLED
1294 ret_val.extend(ctrl_panel.values)
1298 Output("plot-mod-url", "is_open"),
1299 [Input("plot-btn-url", "n_clicks")],
1300 [State("plot-mod-url", "is_open")],
1302 def toggle_plot_mod_url(n, is_open):
1303 """Toggle the modal window with url.
1310 Output("download-iterative-data", "data"),
1311 State("store-selected-tests", "data"),
1312 Input("plot-btn-download", "n_clicks"),
1313 prevent_initial_call=True
1315 def _download_trending_data(store_sel, _):
1316 """Download the data
1318 :param store_sel: List of tests selected by user stored in the
1320 :type store_sel: list
1321 :returns: dict of data frame content (base64 encoded) and meta data
1322 used by the Download component.
1330 for itm in store_sel:
1331 sel_data = select_iterative_data(self._data, itm)
1332 if sel_data is None:
1334 df = pd.concat([df, sel_data], ignore_index=True)
1336 return dcc.send_data_frame(df.to_csv, C.REPORT_DOWNLOAD_FILE_NAME)
1339 Output("metadata-tput-lat", "children"),
1340 Output("metadata-hdrh-graph", "children"),
1341 Output("offcanvas-metadata", "is_open"),
1342 Input({"type": "graph", "index": ALL}, "clickData"),
1343 prevent_initial_call=True
1345 def _show_metadata_from_graphs(graph_data: dict) -> tuple:
1346 """Generates the data for the offcanvas displayed when a particular
1347 point in a graph is clicked on.
1349 :param graph_data: The data from the clicked point in the graph.
1350 :type graph_data: dict
1351 :returns: The data to be displayed on the offcanvas and the
1352 information to show the offcanvas.
1353 :rtype: tuple(list, list, bool)
1356 trigger = Trigger(callback_context.triggered)
1359 idx = 0 if trigger.idx == "tput" else 1
1360 graph_data = graph_data[idx]["points"]
1361 except (IndexError, KeyError, ValueError, TypeError):
1364 def _process_stats(data: list, param: str) -> list:
1365 """Process statistical data provided by plot.ly box graph.
1367 :param data: Statistical data provided by plot.ly box graph.
1368 :param param: Parameter saying if the data come from "tput" or
1372 :returns: Listo of tuples where the first value is the
1373 statistic's name and the secont one it's value.
1377 stats = ("max", "upper fence", "q3", "median", "q1",
1378 "lower fence", "min")
1379 elif len(data) == 9:
1380 stats = ("outlier", "max", "upper fence", "q3", "median",
1381 "q1", "lower fence", "min", "outlier")
1382 elif len(data) == 1:
1384 stats = ("Average Latency at 50% PDR", )
1386 stats = ("Throughput", )
1389 unit = " [us]" if param == "lat" else str()
1390 return [(f"{stat}{unit}", f"{value['y']:,.0f}")
1391 for stat, value in zip(stats, data)]
1394 if trigger.idx == "tput":
1395 title = "Throughput"
1396 elif trigger.idx == "lat":
1398 if len(graph_data) == 1:
1399 hdrh_data = graph_data[0].get("customdata", None)
1402 class_name="gy-2 p-0",
1404 dbc.CardHeader(hdrh_data.pop("name")),
1405 dbc.CardBody(children=[
1407 id="hdrh-latency-graph",
1408 figure=graph_hdrh_latency(
1409 hdrh_data, self._graph_layout
1419 class_name="gy-2 p-0",
1421 dbc.CardHeader(children=[
1423 target_id="tput-lat-metadata",
1425 style={"display": "inline-block"}
1430 id="tput-lat-metadata",
1432 children=[dbc.ListGroup(
1434 dbc.ListGroupItem([dbc.Badge(k), v])
1435 for k, v in _process_stats(
1436 graph_data, trigger.idx)
1445 return metadata, graph, True