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.
15 """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
30 from copy import deepcopy
32 from ..utils.constants import Constants as C
33 from ..utils.control_panel import ControlPanel
34 from ..utils.trigger import Trigger
35 from ..utils.telemetry_data import TelemetryData
36 from ..utils.utils import show_tooltip, label, sync_checklists, gen_new_url, \
37 generate_options, get_list_group_items
38 from ..utils.url_processing import url_decode
39 from .graphs import graph_trending, graph_hdrh_latency, select_trending_data, \
43 # Control panel partameters and their default values.
49 "dd-area-opt": list(),
52 "dd-test-opt": list(),
55 "cl-core-opt": list(),
56 "cl-core-val": list(),
57 "cl-core-all-val": list(),
58 "cl-core-all-opt": C.CL_ALL_DISABLED,
59 "cl-frmsize-opt": list(),
60 "cl-frmsize-val": list(),
61 "cl-frmsize-all-val": list(),
62 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
63 "cl-tsttype-opt": list(),
64 "cl-tsttype-val": list(),
65 "cl-tsttype-all-val": list(),
66 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
68 "cl-normalize-val": list()
73 """The layout of the dash app and the callbacks.
78 data_trending: pd.DataFrame,
79 html_layout_file: str,
80 graph_layout_file: str,
84 - save the input parameters,
85 - read and pre-process the data,
86 - prepare data for the control panel,
87 - read HTML layout file,
88 - read tooltips from the tooltip file.
90 :param app: Flask application running the dash application.
91 :param data_trending: Pandas dataframe with trending data.
92 :param html_layout_file: Path and name of the file specifying the HTML
93 layout of the dash application.
94 :param graph_layout_file: Path and name of the file with layout of
96 :param tooltip_file: Path and name of the yaml file specifying the
99 :type data_trending: pandas.DataFrame
100 :type html_layout_file: str
101 :type graph_layout_file: str
102 :type tooltip_file: str
107 self._data = data_trending
108 self._html_layout_file = html_layout_file
109 self._graph_layout_file = graph_layout_file
110 self._tooltip_file = tooltip_file
112 # Get structure of tests:
114 cols = ["job", "test_id", "test_type", "tg_type"]
115 for _, row in self._data[cols].drop_duplicates().iterrows():
116 lst_job = row["job"].split("-")
118 tbed = "-".join(lst_job[-2:])
119 lst_test = row["test_id"].split(".")
123 area = "-".join(lst_test[3:-2])
124 suite = lst_test[-2].replace("2n1l-", "").replace("1n1l-", "").\
127 nic = suite.split("-")[0]
128 for drv in C.DRIVERS:
134 test = test.replace(f"{drv}-", "")
138 infra = "-".join((tbed, nic, driver))
139 lst_test = test.split("-")
140 framesize = lst_test[0]
141 core = lst_test[1] if lst_test[1] else "8C"
142 test = "-".join(lst_test[2: -1])
144 if tbs.get(dut, None) is None:
146 if tbs[dut].get(infra, None) is None:
147 tbs[dut][infra] = dict()
148 if tbs[dut][infra].get(area, None) is None:
149 tbs[dut][infra][area] = dict()
150 if tbs[dut][infra][area].get(test, None) is None:
151 tbs[dut][infra][area][test] = dict()
152 tbs[dut][infra][area][test]["core"] = list()
153 tbs[dut][infra][area][test]["frame-size"] = list()
154 tbs[dut][infra][area][test]["test-type"] = list()
155 if core.upper() not in tbs[dut][infra][area][test]["core"]:
156 tbs[dut][infra][area][test]["core"].append(core.upper())
157 if framesize.upper() not in \
158 tbs[dut][infra][area][test]["frame-size"]:
159 tbs[dut][infra][area][test]["frame-size"].append(
162 if row["test_type"] == "mrr":
163 if "MRR" not in tbs[dut][infra][area][test]["test-type"]:
164 tbs[dut][infra][area][test]["test-type"].append("MRR")
165 elif row["test_type"] == "ndrpdr":
166 if "NDR" not in tbs[dut][infra][area][test]["test-type"]:
167 tbs[dut][infra][area][test]["test-type"].extend(
170 elif row["test_type"] == "hoststack":
171 if row["tg_type"] in ("iperf", "vpp"):
172 if "BPS" not in tbs[dut][infra][area][test]["test-type"]:
173 tbs[dut][infra][area][test]["test-type"].append("BPS")
174 elif row["tg_type"] == "ab":
175 if "CPS" not in tbs[dut][infra][area][test]["test-type"]:
176 tbs[dut][infra][area][test]["test-type"].extend(
182 self._html_layout = str()
183 self._graph_layout = None
184 self._tooltips = dict()
187 with open(self._html_layout_file, "r") as file_read:
188 self._html_layout = file_read.read()
189 except IOError as err:
191 f"Not possible to open the file {self._html_layout_file}\n{err}"
195 with open(self._graph_layout_file, "r") as file_read:
196 self._graph_layout = load(file_read, Loader=FullLoader)
197 except IOError as err:
199 f"Not possible to open the file {self._graph_layout_file}\n"
202 except YAMLError as err:
204 f"An error occurred while parsing the specification file "
205 f"{self._graph_layout_file}\n{err}"
209 with open(self._tooltip_file, "r") as file_read:
210 self._tooltips = load(file_read, Loader=FullLoader)
211 except IOError as err:
213 f"Not possible to open the file {self._tooltip_file}\n{err}"
215 except YAMLError as err:
217 f"An error occurred while parsing the specification file "
218 f"{self._tooltip_file}\n{err}"
222 if self._app is not None and hasattr(self, "callbacks"):
223 self.callbacks(self._app)
226 def html_layout(self):
227 return self._html_layout
229 def add_content(self):
230 """Top level method which generated the web page.
233 - Store for user input data,
235 - Main area with control panel and ploting area.
237 If no HTML layout is provided, an error message is displayed instead.
239 :returns: The HTML div with the whole page.
243 if self.html_layout and self._spec_tbs:
248 dcc.Store(id="store-selected-tests"),
249 dcc.Store(id="store-control-panel"),
250 dcc.Store(id="store-telemetry-data"),
251 dcc.Store(id="store-telemetry-user"),
252 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
297 def _add_navbar(self):
298 """Add nav element with navigation panel. It is placed on the top.
300 :returns: Navigation bar.
301 :rtype: dbc.NavbarSimple
303 return dbc.NavbarSimple(
304 id="navbarsimple-main",
317 brand_external_link=True,
322 def _add_ctrl_col(self) -> dbc.Col:
323 """Add column with controls. It is placed on the left side.
325 :returns: Column with the control panel.
330 children=self._add_ctrl_panel(),
331 className="sticky-top"
335 def _add_ctrl_panel(self) -> list:
336 """Add control panel.
338 :returns: Control panel.
343 class_name="g-0 p-1",
348 children=show_tooltip(
355 id={"type": "ctrl-dd", "index": "dut"},
356 placeholder="Select a Device under Test...",
359 {"label": k, "value": k} \
360 for k in self._spec_tbs.keys()
362 key=lambda d: d["label"]
371 class_name="g-0 p-1",
376 children=show_tooltip(
383 id={"type": "ctrl-dd", "index": "phy"},
385 "Select a Physical Test Bed Topology..."
393 class_name="g-0 p-1",
398 children=show_tooltip(
405 id={"type": "ctrl-dd", "index": "area"},
406 placeholder="Select an Area..."
414 class_name="g-0 p-1",
419 children=show_tooltip(
426 id={"type": "ctrl-dd", "index": "test"},
427 placeholder="Select a Test..."
435 class_name="g-0 p-1",
440 children=show_tooltip(
451 "index": "frmsize-all"
453 options=C.CL_ALL_DISABLED,
472 style={"align-items": "center"},
478 class_name="g-0 p-1",
483 children=show_tooltip(
496 options=C.CL_ALL_DISABLED,
515 style={"align-items": "center"},
521 class_name="g-0 p-1",
526 children=show_tooltip(
537 "index": "tsttype-all"
539 options=C.CL_ALL_DISABLED,
558 style={"align-items": "center"},
564 class_name="g-0 p-1",
569 children=show_tooltip(
580 "value": "normalize",
582 "Normalize to CPU frequency "
593 style={"align-items": "center"},
599 class_name="g-0 p-1",
602 id={"type": "ctrl-btn", "index": "add-test"},
603 children="Add Selected",
609 id="row-card-sel-tests",
610 class_name="g-0 p-1",
611 style=C.STYLE_DISABLED,
614 class_name="overflow-auto p-0",
617 style={"max-height": "14em"},
623 id="row-btns-sel-tests",
624 class_name="g-0 p-1",
625 style=C.STYLE_DISABLED,
630 id={"type": "ctrl-btn", "index": "rm-test"},
631 children="Remove Selected",
637 id={"type": "ctrl-btn", "index": "rm-test-all"},
638 children="Remove All",
649 def _add_plotting_col(self) -> dbc.Col:
650 """Add column with plots. It is placed on the right side.
652 :returns: Column with plots.
656 id="col-plotting-area",
660 id="plotting-area-trending",
661 class_name="g-0 p-0",
662 children=C.PLACEHOLDER
664 delay_show=C.SPINNER_DELAY
667 id="plotting-area-telemetry",
668 class_name="g-0 p-0",
669 children=C.PLACEHOLDER
672 id="plotting-area-buttons",
673 class_name="g-0 p-0",
674 children=C.PLACEHOLDER
680 def _get_plotting_area_buttons(self) -> dbc.Col:
681 """Add buttons and modals to the plotting area.
683 :returns: A column with buttons and modals for telemetry.
690 id={"type": "telemetry-btn", "index": "open"},
691 children="Add Panel with Telemetry",
695 "text-transform": "none",
696 "padding": "0rem 1rem"
709 id="plot-mod-telemetry-body-1",
710 children=self._get_telemetry_step_1()
712 delay_show=2*C.SPINNER_DELAY
718 "type": "telemetry-btn",
726 "type": "telemetry-btn",
733 id="plot-mod-telemetry-1",
750 id="plot-mod-telemetry-body-2",
751 children=self._get_telemetry_step_2()
753 delay_show=2*C.SPINNER_DELAY
759 "type": "telemetry-btn",
767 "type": "telemetry-btn",
775 "type": "telemetry-btn",
782 id="plot-mod-telemetry-2",
790 className="d-grid gap-0 d-md-flex justify-content-md-end"
794 def _get_plotting_area_trending(
800 """Generate the plotting area with all its content.
802 :param tests: A list of tests to be displayed in the trending graphs.
803 :param normalize: If True, the data in graphs is normalized.
804 :param url: An URL to be displayed in the modal window.
806 :type normalize: bool
808 :returns: A collumn with trending graphs (tput and latency) in tabs.
814 figs = graph_trending(self._data, tests, self._graph_layout, normalize)
822 id={"type": "graph", "index": "tput"},
834 id={"type": "graph", "index": "lat"},
847 active_tab="tab-tput",
860 "text-transform": "none",
861 "padding": "0rem 1rem"
866 dbc.ModalHeader(dbc.ModalTitle("URL")),
875 id="plot-btn-download",
876 children="Download Data",
880 "text-transform": "none",
881 "padding": "0rem 1rem"
884 dcc.Download(id="download-trending-data")
887 "d-grid gap-0 d-md-flex justify-content-md-end"
904 class_name="g-0 p-1",
905 start_collapsed=False,
907 active_item=["item-0", ]
909 class_name="g-0 p-0",
914 def _get_plotting_area_telemetry(self, graphs: list) -> dbc.Col:
915 """Generate the plotting area with telemetry.
924 title=f"Telemetry: {graph[1]}",
926 id={"type": "graph-telemetry", "index": graph[1]},
937 class_name="g-0 p-1",
938 start_collapsed=False,
940 active_item=[f"item-{i}" for i in range(len(acc_items))]
942 class_name="g-0 p-0",
948 def _get_telemetry_step_1() -> list:
949 """Return the content of the modal window used in the step 1 of metrics
952 :returns: A list of dbc rows with 'input' and 'search output'.
957 class_name="g-0 p-1",
960 id="telemetry-search-in",
961 placeholder="Start typing a metric name...",
967 class_name="g-0 p-1",
970 class_name="overflow-auto p-0",
971 id="telemetry-search-out",
973 style={"max-height": "14em"},
981 def _get_telemetry_step_2() -> list:
982 """Return the content of the modal window used in the step 2 of metrics
985 :returns: A list of dbc rows with 'container with dynamic dropdowns' and
992 class_name="g-0 p-1",
993 children=["Add content here."]
996 class_name="g-0 p-1",
999 id="telemetry-list-metrics",
1009 def callbacks(self, app):
1010 """Callbacks for the whole application.
1012 :param app: The application.
1018 Output("store-control-panel", "data"),
1019 Output("store-selected-tests", "data"),
1020 Output("plotting-area-trending", "children"),
1021 Output("plotting-area-buttons", "children"),
1022 Output("row-card-sel-tests", "style"),
1023 Output("row-btns-sel-tests", "style"),
1024 Output("lg-selected", "children"),
1025 Output({"type": "ctrl-dd", "index": "dut"}, "value"),
1026 Output({"type": "ctrl-dd", "index": "phy"}, "options"),
1027 Output({"type": "ctrl-dd", "index": "phy"}, "disabled"),
1028 Output({"type": "ctrl-dd", "index": "phy"}, "value"),
1029 Output({"type": "ctrl-dd", "index": "area"}, "options"),
1030 Output({"type": "ctrl-dd", "index": "area"}, "disabled"),
1031 Output({"type": "ctrl-dd", "index": "area"}, "value"),
1032 Output({"type": "ctrl-dd", "index": "test"}, "options"),
1033 Output({"type": "ctrl-dd", "index": "test"}, "disabled"),
1034 Output({"type": "ctrl-dd", "index": "test"}, "value"),
1035 Output({"type": "ctrl-cl", "index": "core"}, "options"),
1036 Output({"type": "ctrl-cl", "index": "core"}, "value"),
1037 Output({"type": "ctrl-cl", "index": "core-all"}, "value"),
1038 Output({"type": "ctrl-cl", "index": "core-all"}, "options"),
1039 Output({"type": "ctrl-cl", "index": "frmsize"}, "options"),
1040 Output({"type": "ctrl-cl", "index": "frmsize"}, "value"),
1041 Output({"type": "ctrl-cl", "index": "frmsize-all"}, "value"),
1042 Output({"type": "ctrl-cl", "index": "frmsize-all"}, "options"),
1043 Output({"type": "ctrl-cl", "index": "tsttype"}, "options"),
1044 Output({"type": "ctrl-cl", "index": "tsttype"}, "value"),
1045 Output({"type": "ctrl-cl", "index": "tsttype-all"}, "value"),
1046 Output({"type": "ctrl-cl", "index": "tsttype-all"}, "options"),
1047 Output({"type": "ctrl-btn", "index": "add-test"}, "disabled"),
1048 Output("normalize", "value")
1051 State("store-control-panel", "data"),
1052 State("store-selected-tests", "data"),
1053 State({"type": "sel-cl", "index": ALL}, "value")
1056 Input("url", "href"),
1057 Input("normalize", "value"),
1058 Input({"type": "ctrl-dd", "index": ALL}, "value"),
1059 Input({"type": "ctrl-cl", "index": ALL}, "value"),
1060 Input({"type": "ctrl-btn", "index": ALL}, "n_clicks")
1062 prevent_initial_call=True
1064 def _update_application(
1065 control_panel: dict,
1072 """Update the application when the event is detected.
1075 ctrl_panel = ControlPanel(CP_PARAMS, control_panel)
1079 parsed_url = url_decode(href)
1081 url_params = parsed_url["params"]
1085 trigger = Trigger(callback_context.triggered)
1087 if trigger.type == "url" and url_params:
1089 store_sel = literal_eval(url_params["store_sel"][0])
1090 normalize = literal_eval(url_params["norm"][0])
1091 except (KeyError, IndexError):
1094 last_test = store_sel[-1]
1095 test = self._spec_tbs[last_test["dut"]][last_test["phy"]]\
1096 [last_test["area"]][last_test["test"]]
1098 "dd-dut-val": last_test["dut"],
1099 "dd-phy-val": last_test["phy"],
1100 "dd-phy-opt": generate_options(
1101 self._spec_tbs[last_test["dut"]].keys()
1103 "dd-phy-dis": False,
1104 "dd-area-val": last_test["area"],
1106 {"label": label(v), "value": v} for v in sorted(
1107 self._spec_tbs[last_test["dut"]]\
1108 [last_test["phy"]].keys()
1111 "dd-area-dis": False,
1112 "dd-test-val": last_test["test"],
1113 "dd-test-opt": generate_options(
1114 self._spec_tbs[last_test["dut"]][last_test["phy"]]\
1115 [last_test["area"]].keys()
1117 "dd-test-dis": False,
1118 "cl-core-opt": generate_options(test["core"]),
1119 "cl-core-val": [last_test["core"].upper(), ],
1120 "cl-core-all-val": list(),
1121 "cl-core-all-opt": C.CL_ALL_ENABLED,
1122 "cl-frmsize-opt": generate_options(test["frame-size"]),
1123 "cl-frmsize-val": [last_test["framesize"].upper(), ],
1124 "cl-frmsize-all-val": list(),
1125 "cl-frmsize-all-opt": C.CL_ALL_ENABLED,
1126 "cl-tsttype-opt": generate_options(test["test-type"]),
1127 "cl-tsttype-val": [last_test["testtype"].upper(), ],
1128 "cl-tsttype-all-val": list(),
1129 "cl-tsttype-all-opt": C.CL_ALL_ENABLED,
1130 "cl-normalize-val": normalize,
1131 "btn-add-dis": False
1134 elif trigger.type == "normalize":
1135 ctrl_panel.set({"cl-normalize-val": normalize})
1137 elif trigger.type == "ctrl-dd":
1138 if trigger.idx == "dut":
1140 options = generate_options(
1141 self._spec_tbs[trigger.value].keys()
1148 "dd-dut-val": trigger.value,
1149 "dd-phy-val": str(),
1150 "dd-phy-opt": options,
1151 "dd-phy-dis": disabled,
1152 "dd-area-val": str(),
1153 "dd-area-opt": list(),
1154 "dd-area-dis": True,
1155 "dd-test-val": str(),
1156 "dd-test-opt": list(),
1157 "dd-test-dis": True,
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":
1174 dut = ctrl_panel.get("dd-dut-val")
1175 phy = self._spec_tbs[dut][trigger.value]
1176 options = [{"label": label(v), "value": v} \
1177 for v in sorted(phy.keys())]
1183 "dd-phy-val": trigger.value,
1184 "dd-area-val": str(),
1185 "dd-area-opt": options,
1186 "dd-area-dis": disabled,
1187 "dd-test-val": str(),
1188 "dd-test-opt": list(),
1189 "dd-test-dis": True,
1190 "cl-core-opt": list(),
1191 "cl-core-val": list(),
1192 "cl-core-all-val": list(),
1193 "cl-core-all-opt": C.CL_ALL_DISABLED,
1194 "cl-frmsize-opt": list(),
1195 "cl-frmsize-val": list(),
1196 "cl-frmsize-all-val": list(),
1197 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1198 "cl-tsttype-opt": list(),
1199 "cl-tsttype-val": list(),
1200 "cl-tsttype-all-val": list(),
1201 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1204 elif trigger.idx == "area":
1206 dut = ctrl_panel.get("dd-dut-val")
1207 phy = ctrl_panel.get("dd-phy-val")
1208 area = self._spec_tbs[dut][phy][trigger.value]
1209 options = generate_options(area.keys())
1215 "dd-area-val": trigger.value,
1216 "dd-test-val": str(),
1217 "dd-test-opt": options,
1218 "dd-test-dis": disabled,
1219 "cl-core-opt": list(),
1220 "cl-core-val": list(),
1221 "cl-core-all-val": list(),
1222 "cl-core-all-opt": C.CL_ALL_DISABLED,
1223 "cl-frmsize-opt": list(),
1224 "cl-frmsize-val": list(),
1225 "cl-frmsize-all-val": list(),
1226 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1227 "cl-tsttype-opt": list(),
1228 "cl-tsttype-val": list(),
1229 "cl-tsttype-all-val": list(),
1230 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1233 elif trigger.idx == "test":
1234 dut = ctrl_panel.get("dd-dut-val")
1235 phy = ctrl_panel.get("dd-phy-val")
1236 area = ctrl_panel.get("dd-area-val")
1237 if all((dut, phy, area, trigger.value, )):
1238 test = self._spec_tbs[dut][phy][area][trigger.value]
1240 "dd-test-val": trigger.value,
1241 "cl-core-opt": generate_options(test["core"]),
1242 "cl-core-val": list(),
1243 "cl-core-all-val": list(),
1244 "cl-core-all-opt": C.CL_ALL_ENABLED,
1246 generate_options(test["frame-size"]),
1247 "cl-frmsize-val": list(),
1248 "cl-frmsize-all-val": list(),
1249 "cl-frmsize-all-opt": C.CL_ALL_ENABLED,
1251 generate_options(test["test-type"]),
1252 "cl-tsttype-val": list(),
1253 "cl-tsttype-all-val": list(),
1254 "cl-tsttype-all-opt": C.CL_ALL_ENABLED,
1257 elif trigger.type == "ctrl-cl":
1258 param = trigger.idx.split("-")[0]
1259 if "-all" in trigger.idx:
1260 c_sel, c_all, c_id = list(), trigger.value, "all"
1262 c_sel, c_all, c_id = trigger.value, list(), str()
1263 val_sel, val_all = sync_checklists(
1264 options=ctrl_panel.get(f"cl-{param}-opt"),
1270 f"cl-{param}-val": val_sel,
1271 f"cl-{param}-all-val": val_all,
1273 if all((ctrl_panel.get("cl-core-val"),
1274 ctrl_panel.get("cl-frmsize-val"),
1275 ctrl_panel.get("cl-tsttype-val"), )):
1276 ctrl_panel.set({"btn-add-dis": False})
1278 ctrl_panel.set({"btn-add-dis": True})
1279 elif trigger.type == "ctrl-btn":
1281 if trigger.idx == "add-test":
1282 dut = ctrl_panel.get("dd-dut-val")
1283 phy = ctrl_panel.get("dd-phy-val")
1284 area = ctrl_panel.get("dd-area-val")
1285 test = ctrl_panel.get("dd-test-val")
1286 # Add selected test(s) to the list of tests in store:
1287 if store_sel is None:
1289 for core in ctrl_panel.get("cl-core-val"):
1290 for framesize in ctrl_panel.get("cl-frmsize-val"):
1291 for ttype in ctrl_panel.get("cl-tsttype-val"):
1296 phy.replace('af_xdp', 'af-xdp'),
1303 if tid not in [i["id"] for i in store_sel]:
1310 "framesize": framesize.lower(),
1311 "core": core.lower(),
1312 "testtype": ttype.lower()
1314 store_sel = sorted(store_sel, key=lambda d: d["id"])
1315 if C.CLEAR_ALL_INPUTS:
1316 ctrl_panel.set(ctrl_panel.defaults)
1317 elif trigger.idx == "rm-test" and lst_sel:
1318 new_store_sel = list()
1319 for idx, item in enumerate(store_sel):
1320 if not lst_sel[idx]:
1321 new_store_sel.append(item)
1322 store_sel = new_store_sel
1323 elif trigger.idx == "rm-test-all":
1328 lg_selected = get_list_group_items(store_sel, "sel-cl")
1329 plotting_area_trending = self._get_plotting_area_trending(
1334 {"store_sel": store_sel, "norm": normalize}
1337 plotting_area_buttons = self._get_plotting_area_buttons()
1338 row_card_sel_tests = C.STYLE_ENABLED
1339 row_btns_sel_tests = C.STYLE_ENABLED
1341 plotting_area_trending = C.PLACEHOLDER
1342 plotting_area_buttons = C.PLACEHOLDER
1343 row_card_sel_tests = C.STYLE_DISABLED
1344 row_btns_sel_tests = C.STYLE_DISABLED
1345 lg_selected = no_update
1348 plotting_area_trending = no_update
1349 plotting_area_buttons = no_update
1350 row_card_sel_tests = no_update
1351 row_btns_sel_tests = no_update
1352 lg_selected = no_update
1357 plotting_area_trending,
1358 plotting_area_buttons,
1363 ret_val.extend(ctrl_panel.values)
1367 Output("plot-mod-url", "is_open"),
1368 Input("plot-btn-url", "n_clicks"),
1369 State("plot-mod-url", "is_open")
1371 def toggle_plot_mod_url(n, is_open):
1372 """Toggle the modal window with url.
1379 Output("store-telemetry-data", "data"),
1380 Output("store-telemetry-user", "data"),
1381 Output("telemetry-search-in", "value"),
1382 Output("telemetry-search-out", "children"),
1383 Output("telemetry-list-metrics", "value"),
1384 Output("telemetry-dd", "children"),
1385 Output("plotting-area-telemetry", "children"),
1386 Output("plot-mod-telemetry-1", "is_open"),
1387 Output("plot-mod-telemetry-2", "is_open"),
1388 Output({"type": "telemetry-btn", "index": "select"}, "disabled"),
1389 Output({"type": "telemetry-btn", "index": "add"}, "disabled"),
1390 State("store-telemetry-data", "data"),
1391 State("store-telemetry-user", "data"),
1392 State("store-selected-tests", "data"),
1393 Input({"type": "tele-cl", "index": ALL}, "value"),
1394 Input("telemetry-search-in", "value"),
1395 Input({"type": "telemetry-btn", "index": ALL}, "n_clicks"),
1396 Input({"type": "tm-dd", "index": ALL}, "value"),
1397 prevent_initial_call=True
1399 def _update_plot_mod_telemetry(
1408 """Toggle the modal window with telemetry.
1411 if not any(n_clicks):
1415 # Telemetry user data
1416 # The data provided by user or result of user action
1418 # List of unique metrics:
1419 "unique_metrics": list(),
1420 # List of metrics selected by user:
1421 "selected_metrics": list(),
1422 # Labels from metrics selected by user (key: label name,
1423 # value: list of all possible values):
1424 "unique_labels": dict(),
1425 # Labels selected by the user (subset of 'unique_labels'):
1426 "selected_labels": dict(),
1427 # All unique metrics with labels (output from the step 1)
1428 # converted from pandas dataframe to dictionary.
1429 "unique_metrics_with_labels": dict(),
1430 # Metrics with labels selected by the user using dropdowns.
1431 "selected_metrics_with_labels": dict()
1434 tm = TelemetryData(tests=store_sel)
1436 search_out = no_update
1437 list_metrics = no_update
1439 plotting_area_telemetry = no_update
1440 is_open = (False, False)
1441 is_btn_disabled = (True, True)
1443 trigger = Trigger(callback_context.triggered)
1444 if trigger.type == "telemetry-btn":
1445 if trigger.idx in ("open", "back"):
1446 tm.from_dataframe(self._data)
1447 tm_json = tm.to_json()
1448 tm_user["unique_metrics"] = tm.unique_metrics
1449 tm_user["selected_metrics"] = list()
1450 tm_user["unique_labels"] = dict()
1451 tm_user["selected_labels"] = dict()
1453 search_out = get_list_group_items(
1454 tm_user["unique_metrics"],
1458 is_open = (True, False)
1459 elif trigger.idx == "select":
1460 tm.from_json(tm_data)
1462 if not tm_user["selected_metrics"]:
1463 tm_user["selected_metrics"] = \
1464 tm_user["unique_metrics"]
1465 metrics = [a for a, b in \
1466 zip(tm_user["selected_metrics"], cl_metrics) if b]
1467 tm_user["selected_metrics"] = metrics
1468 tm_user["unique_labels"] = \
1469 tm.get_selected_labels(metrics)
1470 tm_user["unique_metrics_with_labels"] = \
1471 tm.unique_metrics_with_labels
1472 list_metrics = tm.str_metrics
1473 tm_dd = _get_dd_container(tm_user["unique_labels"])
1475 is_btn_disabled = (True, False)
1476 is_open = (False, True)
1479 is_open = (False, False)
1480 elif trigger.idx == "add":
1481 tm.from_json(tm_data)
1482 plotting_area_telemetry = self._get_plotting_area_telemetry(
1484 tm.select_tm_trending_data(
1485 tm_user["selected_metrics_with_labels"]
1490 is_open = (False, False)
1491 elif trigger.idx == "cancel":
1493 is_open = (False, False)
1494 elif trigger.type == "telemetry-search-in":
1495 tm.from_metrics(tm_user["unique_metrics"])
1496 tm_user["selected_metrics"] = \
1497 tm.search_unique_metrics(search_in)
1498 search_out = get_list_group_items(
1499 tm_user["selected_metrics"],
1503 is_open = (True, False)
1504 elif trigger.type == "tele-cl":
1506 is_btn_disabled = (False, True)
1507 is_open = (True, False)
1508 elif trigger.type == "tm-dd":
1509 tm.from_metrics_with_labels(
1510 tm_user["unique_metrics_with_labels"]
1514 for itm in tm_dd_in:
1517 elif isinstance(itm, str):
1519 selected[itm] = list()
1520 elif isinstance(itm, list):
1521 if previous_itm is not None:
1522 selected[previous_itm] = itm
1526 tm_dd = _get_dd_container(
1527 tm_user["unique_labels"],
1531 sel_metrics = tm.filter_selected_metrics_by_labels(selected)
1532 tm_user["selected_metrics_with_labels"] = sel_metrics.to_dict()
1533 if not sel_metrics.empty:
1534 list_metrics = tm.metrics_to_str(sel_metrics)
1536 list_metrics = str()
1538 is_btn_disabled = (True, False)
1539 is_open = (False, True)
1549 plotting_area_telemetry
1551 ret_val.extend(is_open)
1552 ret_val.extend(is_btn_disabled)
1555 def _get_dd_container(
1557 selected_labels: dict=dict(),
1560 """Generate a container with dropdown selection boxes depenting on
1563 :param all_labels: A dictionary with unique labels and their
1565 :param selected_labels: A dictionalry with user selected lables and
1567 :param show_new: If True, a dropdown selection box to add a new
1569 :type all_labels: dict
1570 :type selected_labels: dict
1571 :type show_new: bool
1572 :returns: A list of dbc rows with dropdown selection boxes.
1583 """Generates a dbc row with dropdown boxes.
1585 :param id: A string added to the dropdown ID.
1586 :param lopts: A list of options for 'label' dropdown.
1587 :param lval: Value of 'label' dropdown.
1588 :param vopts: A list of options for 'value' dropdown.
1589 :param vvals: A list of values for 'value' dropdown.
1595 :returns: dbc row with dropdown boxes.
1607 "index": f"label-{id}"
1609 placeholder="Select a label...",
1613 value=lval if lval else None
1626 "index": f"value-{id}"
1628 placeholder="Select a value...",
1632 value=vvals if vvals else None
1638 return dbc.Row(class_name="g-0 p-1", children=children)
1642 # Display rows with items in 'selected_labels'; label on the left,
1643 # values on the right:
1644 keys_left = list(all_labels.keys())
1645 for idx, label in enumerate(selected_labels.keys()):
1646 container.append(_row(
1648 lopts=deepcopy(keys_left),
1650 vopts=all_labels[label],
1651 vvals=selected_labels[label]
1653 keys_left.remove(label)
1655 # Display row with dd with labels on the left, right side is empty:
1656 if show_new and keys_left:
1657 container.append(_row(id="new", lopts=keys_left))
1662 Output("metadata-tput-lat", "children"),
1663 Output("metadata-hdrh-graph", "children"),
1664 Output("offcanvas-metadata", "is_open"),
1665 Input({"type": "graph", "index": ALL}, "clickData"),
1666 prevent_initial_call=True
1668 def _show_metadata_from_graphs(graph_data: dict) -> tuple:
1669 """Generates the data for the offcanvas displayed when a particular
1670 point in a graph is clicked on.
1672 :param graph_data: The data from the clicked point in the graph.
1673 :type graph_data: dict
1674 :returns: The data to be displayed on the offcanvas and the
1675 information to show the offcanvas.
1676 :rtype: tuple(list, list, bool)
1679 trigger = Trigger(callback_context.triggered)
1682 idx = 0 if trigger.idx == "tput" else 1
1683 graph_data = graph_data[idx]["points"][0]
1684 except (IndexError, KeyError, ValueError, TypeError):
1687 metadata = no_update
1692 [dbc.Badge(x.split(":")[0]), x.split(": ")[1]]
1693 ) for x in graph_data.get("text", "").split("<br>")
1695 if trigger.idx == "tput":
1696 title = "Throughput"
1697 elif trigger.idx == "lat":
1699 hdrh_data = graph_data.get("customdata", None)
1702 class_name="gy-2 p-0",
1704 dbc.CardHeader(hdrh_data.pop("name")),
1705 dbc.CardBody(children=[
1707 id="hdrh-latency-graph",
1708 figure=graph_hdrh_latency(
1709 hdrh_data, self._graph_layout
1720 class_name="gy-2 p-0",
1722 dbc.CardHeader(children=[
1724 target_id="tput-lat-metadata",
1726 style={"display": "inline-block"}
1731 id="tput-lat-metadata",
1733 children=[dbc.ListGroup(children, flush=True), ]
1739 return metadata, graph, True
1742 Output("download-trending-data", "data"),
1743 State("store-selected-tests", "data"),
1744 Input("plot-btn-download", "n_clicks"),
1745 prevent_initial_call=True
1747 def _download_trending_data(store_sel: list, _) -> dict:
1748 """Download the data
1750 :param store_sel: List of tests selected by user stored in the
1752 :type store_sel: list
1753 :returns: dict of data frame content (base64 encoded) and meta data
1754 used by the Download component.
1762 for itm in store_sel:
1763 sel_data = select_trending_data(self._data, itm)
1764 if sel_data is None:
1766 df = pd.concat([df, sel_data], ignore_index=True, copy=False)
1768 return dcc.send_data_frame(df.to_csv, C.TREND_DOWNLOAD_FILE_NAME)