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, graph_hdrh_latency
38 from ..utils.url_processing import url_decode
39 from .graphs import graph_trending, select_trending_data, graph_tm_trending
42 # Control panel partameters and their default values.
48 "dd-area-opt": list(),
51 "dd-test-opt": list(),
54 "cl-core-opt": list(),
55 "cl-core-val": list(),
56 "cl-core-all-val": list(),
57 "cl-core-all-opt": C.CL_ALL_DISABLED,
58 "cl-frmsize-opt": list(),
59 "cl-frmsize-val": list(),
60 "cl-frmsize-all-val": list(),
61 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
62 "cl-tsttype-opt": list(),
63 "cl-tsttype-val": list(),
64 "cl-tsttype-all-val": list(),
65 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
67 "cl-normalize-val": list()
72 """The layout of the dash app and the callbacks.
77 data_trending: pd.DataFrame,
78 html_layout_file: str,
79 graph_layout_file: str,
83 - save the input parameters,
84 - read and pre-process the data,
85 - prepare data for the control panel,
86 - read HTML layout file,
87 - read tooltips from the tooltip file.
89 :param app: Flask application running the dash application.
90 :param data_trending: Pandas dataframe with trending data.
91 :param html_layout_file: Path and name of the file specifying the HTML
92 layout of the dash application.
93 :param graph_layout_file: Path and name of the file with layout of
95 :param tooltip_file: Path and name of the yaml file specifying the
98 :type data_trending: pandas.DataFrame
99 :type html_layout_file: str
100 :type graph_layout_file: str
101 :type tooltip_file: str
106 self._data = data_trending
107 self._html_layout_file = html_layout_file
108 self._graph_layout_file = graph_layout_file
109 self._tooltip_file = tooltip_file
111 # Get structure of tests:
113 cols = ["job", "test_id", "test_type", "tg_type"]
114 for _, row in self._data[cols].drop_duplicates().iterrows():
115 lst_job = row["job"].split("-")
117 tbed = "-".join(lst_job[-2:])
118 lst_test = row["test_id"].split(".")
122 area = "-".join(lst_test[3:-2])
123 suite = lst_test[-2].replace("2n1l-", "").replace("1n1l-", "").\
126 nic = suite.split("-")[0]
127 for drv in C.DRIVERS:
133 test = test.replace(f"{drv}-", "")
137 infra = "-".join((tbed, nic, driver))
138 lst_test = test.split("-")
139 framesize = lst_test[0]
140 core = lst_test[1] if lst_test[1] else "8C"
141 test = "-".join(lst_test[2: -1])
143 if tbs.get(dut, None) is None:
145 if tbs[dut].get(infra, None) is None:
146 tbs[dut][infra] = dict()
147 if tbs[dut][infra].get(area, None) is None:
148 tbs[dut][infra][area] = dict()
149 if tbs[dut][infra][area].get(test, None) is None:
150 tbs[dut][infra][area][test] = dict()
151 tbs[dut][infra][area][test]["core"] = list()
152 tbs[dut][infra][area][test]["frame-size"] = list()
153 tbs[dut][infra][area][test]["test-type"] = list()
154 if core.upper() not in tbs[dut][infra][area][test]["core"]:
155 tbs[dut][infra][area][test]["core"].append(core.upper())
156 if framesize.upper() not in \
157 tbs[dut][infra][area][test]["frame-size"]:
158 tbs[dut][infra][area][test]["frame-size"].append(
161 if row["test_type"] == "mrr":
162 if "MRR" not in tbs[dut][infra][area][test]["test-type"]:
163 tbs[dut][infra][area][test]["test-type"].append("MRR")
164 elif row["test_type"] == "ndrpdr":
165 if "NDR" not in tbs[dut][infra][area][test]["test-type"]:
166 tbs[dut][infra][area][test]["test-type"].extend(
169 elif row["test_type"] == "hoststack":
170 if row["tg_type"] in ("iperf", "vpp"):
171 if "BPS" not in tbs[dut][infra][area][test]["test-type"]:
172 tbs[dut][infra][area][test]["test-type"].append("BPS")
173 elif row["tg_type"] == "ab":
174 if "CPS" not in tbs[dut][infra][area][test]["test-type"]:
175 tbs[dut][infra][area][test]["test-type"].extend(
181 self._html_layout = str()
182 self._graph_layout = None
183 self._tooltips = dict()
186 with open(self._html_layout_file, "r") as file_read:
187 self._html_layout = file_read.read()
188 except IOError as err:
190 f"Not possible to open the file {self._html_layout_file}\n{err}"
194 with open(self._graph_layout_file, "r") as file_read:
195 self._graph_layout = load(file_read, Loader=FullLoader)
196 except IOError as err:
198 f"Not possible to open the file {self._graph_layout_file}\n"
201 except YAMLError as err:
203 f"An error occurred while parsing the specification file "
204 f"{self._graph_layout_file}\n{err}"
208 with open(self._tooltip_file, "r") as file_read:
209 self._tooltips = load(file_read, Loader=FullLoader)
210 except IOError as err:
212 f"Not possible to open the file {self._tooltip_file}\n{err}"
214 except YAMLError as err:
216 f"An error occurred while parsing the specification file "
217 f"{self._tooltip_file}\n{err}"
221 if self._app is not None and hasattr(self, "callbacks"):
222 self.callbacks(self._app)
225 def html_layout(self):
226 return self._html_layout
228 def add_content(self):
229 """Top level method which generated the web page.
232 - Store for user input data,
234 - Main area with control panel and ploting area.
236 If no HTML layout is provided, an error message is displayed instead.
238 :returns: The HTML div with the whole page.
242 if self.html_layout and self._spec_tbs:
247 dcc.Store(id="store-selected-tests"),
248 dcc.Store(id="store-control-panel"),
249 dcc.Store(id="store-telemetry-data"),
250 dcc.Store(id="store-telemetry-user"),
251 dcc.Location(id="url", refresh=False),
263 self._add_ctrl_col(),
264 self._add_plotting_col()
270 id="offcanvas-metadata",
271 title="Throughput And Latency",
275 dbc.Row(id="metadata-tput-lat"),
276 dbc.Row(id="metadata-hdrh-graph")
279 delay_show=C.SPINNER_DELAY
296 def _add_navbar(self):
297 """Add nav element with navigation panel. It is placed on the top.
299 :returns: Navigation bar.
300 :rtype: dbc.NavbarSimple
302 return dbc.NavbarSimple(
303 id="navbarsimple-main",
316 brand_external_link=True,
321 def _add_ctrl_col(self) -> dbc.Col:
322 """Add column with controls. It is placed on the left side.
324 :returns: Column with the control panel.
329 children=self._add_ctrl_panel(),
330 className="sticky-top"
334 def _add_ctrl_panel(self) -> list:
335 """Add control panel.
337 :returns: Control panel.
342 class_name="g-0 p-1",
347 children=show_tooltip(
354 id={"type": "ctrl-dd", "index": "dut"},
355 placeholder="Select a Device under Test...",
358 {"label": k, "value": k} \
359 for k in self._spec_tbs.keys()
361 key=lambda d: d["label"]
370 class_name="g-0 p-1",
375 children=show_tooltip(
382 id={"type": "ctrl-dd", "index": "phy"},
384 "Select a Physical Test Bed Topology..."
392 class_name="g-0 p-1",
397 children=show_tooltip(
404 id={"type": "ctrl-dd", "index": "area"},
405 placeholder="Select an Area..."
413 class_name="g-0 p-1",
418 children=show_tooltip(
425 id={"type": "ctrl-dd", "index": "test"},
426 placeholder="Select a Test..."
434 class_name="g-0 p-1",
439 children=show_tooltip(
450 "index": "frmsize-all"
452 options=C.CL_ALL_DISABLED,
471 style={"align-items": "center"},
477 class_name="g-0 p-1",
482 children=show_tooltip(
495 options=C.CL_ALL_DISABLED,
514 style={"align-items": "center"},
520 class_name="g-0 p-1",
525 children=show_tooltip(
536 "index": "tsttype-all"
538 options=C.CL_ALL_DISABLED,
557 style={"align-items": "center"},
563 class_name="g-0 p-1",
568 children=show_tooltip(
579 "value": "normalize",
581 "Normalize to CPU frequency "
592 style={"align-items": "center"},
598 class_name="g-0 p-1",
601 id={"type": "ctrl-btn", "index": "add-test"},
602 children="Add Selected",
608 id="row-card-sel-tests",
609 class_name="g-0 p-1",
610 style=C.STYLE_DISABLED,
613 class_name="overflow-auto p-0",
616 style={"max-height": "20em"},
622 id="row-btns-sel-tests",
623 class_name="g-0 p-1",
624 style=C.STYLE_DISABLED,
629 id={"type": "ctrl-btn", "index": "rm-test"},
630 children="Remove Selected",
636 id={"type": "ctrl-btn", "index": "rm-test-all"},
637 children="Remove All",
648 def _add_plotting_col(self) -> dbc.Col:
649 """Add column with plots. It is placed on the right side.
651 :returns: Column with plots.
655 id="col-plotting-area",
659 id="plotting-area-trending",
660 class_name="g-0 p-0",
661 children=C.PLACEHOLDER
663 delay_show=C.SPINNER_DELAY
666 id="plotting-area-telemetry",
667 class_name="g-0 p-0",
668 children=C.PLACEHOLDER
671 id="plotting-area-buttons",
672 class_name="g-0 p-0",
673 children=C.PLACEHOLDER
679 def _get_plotting_area_buttons(self) -> dbc.Col:
680 """Add buttons and modals to the plotting area.
682 :returns: A column with buttons and modals for telemetry.
689 id={"type": "telemetry-btn", "index": "open"},
690 children="Add Panel with Telemetry",
694 "text-transform": "none",
695 "padding": "0rem 1rem"
708 id="plot-mod-telemetry-body-1",
709 children=self._get_telemetry_step_1()
711 delay_show=2*C.SPINNER_DELAY
717 "type": "telemetry-btn",
725 "type": "telemetry-btn",
732 id="plot-mod-telemetry-1",
749 id="plot-mod-telemetry-body-2",
750 children=self._get_telemetry_step_2()
752 delay_show=2*C.SPINNER_DELAY
758 "type": "telemetry-btn",
766 "type": "telemetry-btn",
774 "type": "telemetry-btn",
781 id="plot-mod-telemetry-2",
789 className="d-grid gap-0 d-md-flex justify-content-md-end"
793 def _get_plotting_area_trending(
799 """Generate the plotting area with all its content.
801 :param tests: A list of tests to be displayed in the trending graphs.
802 :param normalize: If True, the data in graphs is normalized.
803 :param url: An URL to be displayed in the modal window.
805 :type normalize: bool
807 :returns: A collumn with trending graphs (tput and latency) in tabs.
813 figs = graph_trending(self._data, tests, self._graph_layout, normalize)
821 id={"type": "graph", "index": "tput"},
833 id={"type": "graph", "index": "lat"},
846 active_tab="tab-tput",
859 "text-transform": "none",
860 "padding": "0rem 1rem"
865 dbc.ModalHeader(dbc.ModalTitle("URL")),
874 id="plot-btn-download",
875 children="Download Data",
879 "text-transform": "none",
880 "padding": "0rem 1rem"
883 dcc.Download(id="download-trending-data")
886 "d-grid gap-0 d-md-flex justify-content-md-end"
903 class_name="g-0 p-1",
904 start_collapsed=False,
906 active_item=["item-0", ]
908 class_name="g-0 p-0",
913 def _get_plotting_area_telemetry(self, graphs: list) -> dbc.Col:
914 """Generate the plotting area with telemetry.
923 title=f"Telemetry: {graph[1]}",
925 id={"type": "graph-telemetry", "index": graph[1]},
936 class_name="g-0 p-1",
937 start_collapsed=False,
939 active_item=[f"item-{i}" for i in range(len(acc_items))]
941 class_name="g-0 p-0",
947 def _get_telemetry_step_1() -> list:
948 """Return the content of the modal window used in the step 1 of metrics
951 :returns: A list of dbc rows with 'input' and 'search output'.
956 class_name="g-0 p-1",
959 id="telemetry-search-in",
960 placeholder="Start typing a metric name...",
966 class_name="g-0 p-1",
969 class_name="overflow-auto p-0",
970 id="telemetry-search-out",
972 style={"max-height": "14em"},
980 def _get_telemetry_step_2() -> list:
981 """Return the content of the modal window used in the step 2 of metrics
984 :returns: A list of dbc rows with 'container with dynamic dropdowns' and
991 class_name="g-0 p-1",
992 children=["Add content here."]
995 class_name="g-0 p-1",
998 id="telemetry-list-metrics",
1008 def callbacks(self, app):
1009 """Callbacks for the whole application.
1011 :param app: The application.
1017 Output("store-control-panel", "data"),
1018 Output("store-selected-tests", "data"),
1019 Output("plotting-area-trending", "children"),
1020 Output("plotting-area-buttons", "children"),
1021 Output("row-card-sel-tests", "style"),
1022 Output("row-btns-sel-tests", "style"),
1023 Output("lg-selected", "children"),
1024 Output({"type": "ctrl-dd", "index": "dut"}, "value"),
1025 Output({"type": "ctrl-dd", "index": "phy"}, "options"),
1026 Output({"type": "ctrl-dd", "index": "phy"}, "disabled"),
1027 Output({"type": "ctrl-dd", "index": "phy"}, "value"),
1028 Output({"type": "ctrl-dd", "index": "area"}, "options"),
1029 Output({"type": "ctrl-dd", "index": "area"}, "disabled"),
1030 Output({"type": "ctrl-dd", "index": "area"}, "value"),
1031 Output({"type": "ctrl-dd", "index": "test"}, "options"),
1032 Output({"type": "ctrl-dd", "index": "test"}, "disabled"),
1033 Output({"type": "ctrl-dd", "index": "test"}, "value"),
1034 Output({"type": "ctrl-cl", "index": "core"}, "options"),
1035 Output({"type": "ctrl-cl", "index": "core"}, "value"),
1036 Output({"type": "ctrl-cl", "index": "core-all"}, "value"),
1037 Output({"type": "ctrl-cl", "index": "core-all"}, "options"),
1038 Output({"type": "ctrl-cl", "index": "frmsize"}, "options"),
1039 Output({"type": "ctrl-cl", "index": "frmsize"}, "value"),
1040 Output({"type": "ctrl-cl", "index": "frmsize-all"}, "value"),
1041 Output({"type": "ctrl-cl", "index": "frmsize-all"}, "options"),
1042 Output({"type": "ctrl-cl", "index": "tsttype"}, "options"),
1043 Output({"type": "ctrl-cl", "index": "tsttype"}, "value"),
1044 Output({"type": "ctrl-cl", "index": "tsttype-all"}, "value"),
1045 Output({"type": "ctrl-cl", "index": "tsttype-all"}, "options"),
1046 Output({"type": "ctrl-btn", "index": "add-test"}, "disabled"),
1047 Output("normalize", "value")
1050 State("store-control-panel", "data"),
1051 State("store-selected-tests", "data"),
1052 State({"type": "sel-cl", "index": ALL}, "value")
1055 Input("url", "href"),
1056 Input("normalize", "value"),
1057 Input({"type": "ctrl-dd", "index": ALL}, "value"),
1058 Input({"type": "ctrl-cl", "index": ALL}, "value"),
1059 Input({"type": "ctrl-btn", "index": ALL}, "n_clicks")
1061 prevent_initial_call=True
1063 def _update_application(
1064 control_panel: dict,
1071 """Update the application when the event is detected.
1074 ctrl_panel = ControlPanel(CP_PARAMS, control_panel)
1078 parsed_url = url_decode(href)
1080 url_params = parsed_url["params"]
1084 trigger = Trigger(callback_context.triggered)
1086 if trigger.type == "url" and url_params:
1088 store_sel = literal_eval(url_params["store_sel"][0])
1089 normalize = literal_eval(url_params["norm"][0])
1090 except (KeyError, IndexError):
1093 last_test = store_sel[-1]
1094 test = self._spec_tbs[last_test["dut"]][last_test["phy"]]\
1095 [last_test["area"]][last_test["test"]]
1097 "dd-dut-val": last_test["dut"],
1098 "dd-phy-val": last_test["phy"],
1099 "dd-phy-opt": generate_options(
1100 self._spec_tbs[last_test["dut"]].keys()
1102 "dd-phy-dis": False,
1103 "dd-area-val": last_test["area"],
1105 {"label": label(v), "value": v} for v in sorted(
1106 self._spec_tbs[last_test["dut"]]\
1107 [last_test["phy"]].keys()
1110 "dd-area-dis": False,
1111 "dd-test-val": last_test["test"],
1112 "dd-test-opt": generate_options(
1113 self._spec_tbs[last_test["dut"]][last_test["phy"]]\
1114 [last_test["area"]].keys()
1116 "dd-test-dis": False,
1117 "cl-core-opt": generate_options(test["core"]),
1118 "cl-core-val": [last_test["core"].upper(), ],
1119 "cl-core-all-val": list(),
1120 "cl-core-all-opt": C.CL_ALL_ENABLED,
1121 "cl-frmsize-opt": generate_options(test["frame-size"]),
1122 "cl-frmsize-val": [last_test["framesize"].upper(), ],
1123 "cl-frmsize-all-val": list(),
1124 "cl-frmsize-all-opt": C.CL_ALL_ENABLED,
1125 "cl-tsttype-opt": generate_options(test["test-type"]),
1126 "cl-tsttype-val": [last_test["testtype"].upper(), ],
1127 "cl-tsttype-all-val": list(),
1128 "cl-tsttype-all-opt": C.CL_ALL_ENABLED,
1129 "cl-normalize-val": normalize,
1130 "btn-add-dis": False
1133 elif trigger.type == "normalize":
1134 ctrl_panel.set({"cl-normalize-val": normalize})
1136 elif trigger.type == "ctrl-dd":
1137 if trigger.idx == "dut":
1139 options = generate_options(
1140 self._spec_tbs[trigger.value].keys()
1147 "dd-dut-val": trigger.value,
1148 "dd-phy-val": str(),
1149 "dd-phy-opt": options,
1150 "dd-phy-dis": disabled,
1151 "dd-area-val": str(),
1152 "dd-area-opt": list(),
1153 "dd-area-dis": True,
1154 "dd-test-val": str(),
1155 "dd-test-opt": list(),
1156 "dd-test-dis": True,
1157 "cl-core-opt": list(),
1158 "cl-core-val": list(),
1159 "cl-core-all-val": list(),
1160 "cl-core-all-opt": C.CL_ALL_DISABLED,
1161 "cl-frmsize-opt": list(),
1162 "cl-frmsize-val": list(),
1163 "cl-frmsize-all-val": list(),
1164 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1165 "cl-tsttype-opt": list(),
1166 "cl-tsttype-val": list(),
1167 "cl-tsttype-all-val": list(),
1168 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1171 elif trigger.idx == "phy":
1173 dut = ctrl_panel.get("dd-dut-val")
1174 phy = self._spec_tbs[dut][trigger.value]
1175 options = [{"label": label(v), "value": v} \
1176 for v in sorted(phy.keys())]
1182 "dd-phy-val": trigger.value,
1183 "dd-area-val": str(),
1184 "dd-area-opt": options,
1185 "dd-area-dis": disabled,
1186 "dd-test-val": str(),
1187 "dd-test-opt": list(),
1188 "dd-test-dis": True,
1189 "cl-core-opt": list(),
1190 "cl-core-val": list(),
1191 "cl-core-all-val": list(),
1192 "cl-core-all-opt": C.CL_ALL_DISABLED,
1193 "cl-frmsize-opt": list(),
1194 "cl-frmsize-val": list(),
1195 "cl-frmsize-all-val": list(),
1196 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1197 "cl-tsttype-opt": list(),
1198 "cl-tsttype-val": list(),
1199 "cl-tsttype-all-val": list(),
1200 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1203 elif trigger.idx == "area":
1205 dut = ctrl_panel.get("dd-dut-val")
1206 phy = ctrl_panel.get("dd-phy-val")
1207 area = self._spec_tbs[dut][phy][trigger.value]
1208 options = generate_options(area.keys())
1214 "dd-area-val": trigger.value,
1215 "dd-test-val": str(),
1216 "dd-test-opt": options,
1217 "dd-test-dis": disabled,
1218 "cl-core-opt": list(),
1219 "cl-core-val": list(),
1220 "cl-core-all-val": list(),
1221 "cl-core-all-opt": C.CL_ALL_DISABLED,
1222 "cl-frmsize-opt": list(),
1223 "cl-frmsize-val": list(),
1224 "cl-frmsize-all-val": list(),
1225 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1226 "cl-tsttype-opt": list(),
1227 "cl-tsttype-val": list(),
1228 "cl-tsttype-all-val": list(),
1229 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1232 elif trigger.idx == "test":
1233 dut = ctrl_panel.get("dd-dut-val")
1234 phy = ctrl_panel.get("dd-phy-val")
1235 area = ctrl_panel.get("dd-area-val")
1236 if all((dut, phy, area, trigger.value, )):
1237 test = self._spec_tbs[dut][phy][area][trigger.value]
1239 "dd-test-val": trigger.value,
1240 "cl-core-opt": generate_options(test["core"]),
1241 "cl-core-val": list(),
1242 "cl-core-all-val": list(),
1243 "cl-core-all-opt": C.CL_ALL_ENABLED,
1245 generate_options(test["frame-size"]),
1246 "cl-frmsize-val": list(),
1247 "cl-frmsize-all-val": list(),
1248 "cl-frmsize-all-opt": C.CL_ALL_ENABLED,
1250 generate_options(test["test-type"]),
1251 "cl-tsttype-val": list(),
1252 "cl-tsttype-all-val": list(),
1253 "cl-tsttype-all-opt": C.CL_ALL_ENABLED,
1256 elif trigger.type == "ctrl-cl":
1257 param = trigger.idx.split("-")[0]
1258 if "-all" in trigger.idx:
1259 c_sel, c_all, c_id = list(), trigger.value, "all"
1261 c_sel, c_all, c_id = trigger.value, list(), str()
1262 val_sel, val_all = sync_checklists(
1263 options=ctrl_panel.get(f"cl-{param}-opt"),
1269 f"cl-{param}-val": val_sel,
1270 f"cl-{param}-all-val": val_all,
1272 if all((ctrl_panel.get("cl-core-val"),
1273 ctrl_panel.get("cl-frmsize-val"),
1274 ctrl_panel.get("cl-tsttype-val"), )):
1275 ctrl_panel.set({"btn-add-dis": False})
1277 ctrl_panel.set({"btn-add-dis": True})
1278 elif trigger.type == "ctrl-btn":
1280 if trigger.idx == "add-test":
1281 dut = ctrl_panel.get("dd-dut-val")
1282 phy = ctrl_panel.get("dd-phy-val")
1283 area = ctrl_panel.get("dd-area-val")
1284 test = ctrl_panel.get("dd-test-val")
1285 # Add selected test(s) to the list of tests in store:
1286 if store_sel is None:
1288 for core in ctrl_panel.get("cl-core-val"):
1289 for framesize in ctrl_panel.get("cl-frmsize-val"):
1290 for ttype in ctrl_panel.get("cl-tsttype-val"):
1295 phy.replace('af_xdp', 'af-xdp'),
1302 if tid not in [i["id"] for i in store_sel]:
1309 "framesize": framesize.lower(),
1310 "core": core.lower(),
1311 "testtype": ttype.lower()
1313 store_sel = sorted(store_sel, key=lambda d: d["id"])
1314 if C.CLEAR_ALL_INPUTS:
1315 ctrl_panel.set(ctrl_panel.defaults)
1316 elif trigger.idx == "rm-test" and lst_sel:
1317 new_store_sel = list()
1318 for idx, item in enumerate(store_sel):
1319 if not lst_sel[idx]:
1320 new_store_sel.append(item)
1321 store_sel = new_store_sel
1322 elif trigger.idx == "rm-test-all":
1327 lg_selected = get_list_group_items(store_sel, "sel-cl")
1328 plotting_area_trending = self._get_plotting_area_trending(
1333 {"store_sel": store_sel, "norm": normalize}
1336 plotting_area_buttons = self._get_plotting_area_buttons()
1337 row_card_sel_tests = C.STYLE_ENABLED
1338 row_btns_sel_tests = C.STYLE_ENABLED
1340 plotting_area_trending = C.PLACEHOLDER
1341 plotting_area_buttons = C.PLACEHOLDER
1342 row_card_sel_tests = C.STYLE_DISABLED
1343 row_btns_sel_tests = C.STYLE_DISABLED
1344 lg_selected = no_update
1347 plotting_area_trending = no_update
1348 plotting_area_buttons = no_update
1349 row_card_sel_tests = no_update
1350 row_btns_sel_tests = no_update
1351 lg_selected = no_update
1356 plotting_area_trending,
1357 plotting_area_buttons,
1362 ret_val.extend(ctrl_panel.values)
1366 Output("plot-mod-url", "is_open"),
1367 Input("plot-btn-url", "n_clicks"),
1368 State("plot-mod-url", "is_open")
1370 def toggle_plot_mod_url(n, is_open):
1371 """Toggle the modal window with url.
1378 Output("store-telemetry-data", "data"),
1379 Output("store-telemetry-user", "data"),
1380 Output("telemetry-search-in", "value"),
1381 Output("telemetry-search-out", "children"),
1382 Output("telemetry-list-metrics", "value"),
1383 Output("telemetry-dd", "children"),
1384 Output("plotting-area-telemetry", "children"),
1385 Output("plot-mod-telemetry-1", "is_open"),
1386 Output("plot-mod-telemetry-2", "is_open"),
1387 Output({"type": "telemetry-btn", "index": "select"}, "disabled"),
1388 Output({"type": "telemetry-btn", "index": "add"}, "disabled"),
1389 State("store-telemetry-data", "data"),
1390 State("store-telemetry-user", "data"),
1391 State("store-selected-tests", "data"),
1392 Input({"type": "tele-cl", "index": ALL}, "value"),
1393 Input("telemetry-search-in", "value"),
1394 Input({"type": "telemetry-btn", "index": ALL}, "n_clicks"),
1395 Input({"type": "tm-dd", "index": ALL}, "value"),
1396 prevent_initial_call=True
1398 def _update_plot_mod_telemetry(
1407 """Toggle the modal window with telemetry.
1410 if not any(n_clicks):
1414 # Telemetry user data
1415 # The data provided by user or result of user action
1417 # List of unique metrics:
1418 "unique_metrics": list(),
1419 # List of metrics selected by user:
1420 "selected_metrics": list(),
1421 # Labels from metrics selected by user (key: label name,
1422 # value: list of all possible values):
1423 "unique_labels": dict(),
1424 # Labels selected by the user (subset of 'unique_labels'):
1425 "selected_labels": dict(),
1426 # All unique metrics with labels (output from the step 1)
1427 # converted from pandas dataframe to dictionary.
1428 "unique_metrics_with_labels": dict(),
1429 # Metrics with labels selected by the user using dropdowns.
1430 "selected_metrics_with_labels": dict()
1433 tm = TelemetryData(tests=store_sel)
1435 search_out = no_update
1436 list_metrics = no_update
1438 plotting_area_telemetry = no_update
1439 is_open = (False, False)
1440 is_btn_disabled = (True, True)
1442 trigger = Trigger(callback_context.triggered)
1443 if trigger.type == "telemetry-btn":
1444 if trigger.idx in ("open", "back"):
1445 tm.from_dataframe(self._data)
1446 tm_json = tm.to_json()
1447 tm_user["unique_metrics"] = tm.unique_metrics
1448 tm_user["selected_metrics"] = list()
1449 tm_user["unique_labels"] = dict()
1450 tm_user["selected_labels"] = dict()
1452 search_out = get_list_group_items(
1453 tm_user["unique_metrics"],
1457 is_open = (True, False)
1458 elif trigger.idx == "select":
1459 tm.from_json(tm_data)
1461 if not tm_user["selected_metrics"]:
1462 tm_user["selected_metrics"] = \
1463 tm_user["unique_metrics"]
1464 metrics = [a for a, b in \
1465 zip(tm_user["selected_metrics"], cl_metrics) if b]
1466 tm_user["selected_metrics"] = metrics
1467 tm_user["unique_labels"] = \
1468 tm.get_selected_labels(metrics)
1469 tm_user["unique_metrics_with_labels"] = \
1470 tm.unique_metrics_with_labels
1471 list_metrics = tm.str_metrics
1472 tm_dd = _get_dd_container(tm_user["unique_labels"])
1474 is_btn_disabled = (True, False)
1475 is_open = (False, True)
1478 is_open = (False, False)
1479 elif trigger.idx == "add":
1480 tm.from_json(tm_data)
1481 plotting_area_telemetry = self._get_plotting_area_telemetry(
1483 tm.select_tm_trending_data(
1484 tm_user["selected_metrics_with_labels"]
1489 is_open = (False, False)
1490 elif trigger.idx == "cancel":
1492 is_open = (False, False)
1493 elif trigger.type == "telemetry-search-in":
1494 tm.from_metrics(tm_user["unique_metrics"])
1495 tm_user["selected_metrics"] = \
1496 tm.search_unique_metrics(search_in)
1497 search_out = get_list_group_items(
1498 tm_user["selected_metrics"],
1502 is_open = (True, False)
1503 elif trigger.type == "tele-cl":
1505 is_btn_disabled = (False, True)
1506 is_open = (True, False)
1507 elif trigger.type == "tm-dd":
1508 tm.from_metrics_with_labels(
1509 tm_user["unique_metrics_with_labels"]
1513 for itm in tm_dd_in:
1516 elif isinstance(itm, str):
1518 selected[itm] = list()
1519 elif isinstance(itm, list):
1520 if previous_itm is not None:
1521 selected[previous_itm] = itm
1525 tm_dd = _get_dd_container(
1526 tm_user["unique_labels"],
1530 sel_metrics = tm.filter_selected_metrics_by_labels(selected)
1531 tm_user["selected_metrics_with_labels"] = sel_metrics.to_dict()
1532 if not sel_metrics.empty:
1533 list_metrics = tm.metrics_to_str(sel_metrics)
1535 list_metrics = str()
1537 is_btn_disabled = (True, False)
1538 is_open = (False, True)
1548 plotting_area_telemetry
1550 ret_val.extend(is_open)
1551 ret_val.extend(is_btn_disabled)
1554 def _get_dd_container(
1556 selected_labels: dict=dict(),
1559 """Generate a container with dropdown selection boxes depenting on
1562 :param all_labels: A dictionary with unique labels and their
1564 :param selected_labels: A dictionalry with user selected lables and
1566 :param show_new: If True, a dropdown selection box to add a new
1568 :type all_labels: dict
1569 :type selected_labels: dict
1570 :type show_new: bool
1571 :returns: A list of dbc rows with dropdown selection boxes.
1582 """Generates a dbc row with dropdown boxes.
1584 :param id: A string added to the dropdown ID.
1585 :param lopts: A list of options for 'label' dropdown.
1586 :param lval: Value of 'label' dropdown.
1587 :param vopts: A list of options for 'value' dropdown.
1588 :param vvals: A list of values for 'value' dropdown.
1594 :returns: dbc row with dropdown boxes.
1606 "index": f"label-{id}"
1608 placeholder="Select a label...",
1612 value=lval if lval else None
1625 "index": f"value-{id}"
1627 placeholder="Select a value...",
1631 value=vvals if vvals else None
1637 return dbc.Row(class_name="g-0 p-1", children=children)
1641 # Display rows with items in 'selected_labels'; label on the left,
1642 # values on the right:
1643 keys_left = list(all_labels.keys())
1644 for idx, label in enumerate(selected_labels.keys()):
1645 container.append(_row(
1647 lopts=deepcopy(keys_left),
1649 vopts=all_labels[label],
1650 vvals=selected_labels[label]
1652 keys_left.remove(label)
1654 # Display row with dd with labels on the left, right side is empty:
1655 if show_new and keys_left:
1656 container.append(_row(id="new", lopts=keys_left))
1661 Output("metadata-tput-lat", "children"),
1662 Output("metadata-hdrh-graph", "children"),
1663 Output("offcanvas-metadata", "is_open"),
1664 Input({"type": "graph", "index": ALL}, "clickData"),
1665 prevent_initial_call=True
1667 def _show_metadata_from_graphs(graph_data: dict) -> tuple:
1668 """Generates the data for the offcanvas displayed when a particular
1669 point in a graph is clicked on.
1671 :param graph_data: The data from the clicked point in the graph.
1672 :type graph_data: dict
1673 :returns: The data to be displayed on the offcanvas and the
1674 information to show the offcanvas.
1675 :rtype: tuple(list, list, bool)
1678 trigger = Trigger(callback_context.triggered)
1681 idx = 0 if trigger.idx == "tput" else 1
1682 graph_data = graph_data[idx]["points"][0]
1683 except (IndexError, KeyError, ValueError, TypeError):
1686 metadata = no_update
1691 [dbc.Badge(x.split(":")[0]), x.split(": ")[1]]
1692 ) for x in graph_data.get("text", "").split("<br>")
1694 if trigger.idx == "tput":
1695 title = "Throughput"
1696 elif trigger.idx == "lat":
1698 hdrh_data = graph_data.get("customdata", None)
1701 class_name="gy-2 p-0",
1703 dbc.CardHeader(hdrh_data.pop("name")),
1704 dbc.CardBody(children=[
1706 id="hdrh-latency-graph",
1707 figure=graph_hdrh_latency(
1708 hdrh_data, self._graph_layout
1719 class_name="gy-2 p-0",
1721 dbc.CardHeader(children=[
1723 target_id="tput-lat-metadata",
1725 style={"display": "inline-block"}
1730 id="tput-lat-metadata",
1732 children=[dbc.ListGroup(children, flush=True), ]
1738 return metadata, graph, True
1741 Output("download-trending-data", "data"),
1742 State("store-selected-tests", "data"),
1743 Input("plot-btn-download", "n_clicks"),
1744 prevent_initial_call=True
1746 def _download_trending_data(store_sel: list, _) -> dict:
1747 """Download the data
1749 :param store_sel: List of tests selected by user stored in the
1751 :type store_sel: list
1752 :returns: dict of data frame content (base64 encoded) and meta data
1753 used by the Download component.
1761 for itm in store_sel:
1762 sel_data = select_trending_data(self._data, itm)
1763 if sel_data is None:
1765 df = pd.concat([df, sel_data], ignore_index=True, copy=False)
1767 return dcc.send_data_frame(df.to_csv, C.TREND_DOWNLOAD_FILE_NAME)