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"),
248 dcc.Location(id="url", refresh=False),
260 self._add_ctrl_col(),
261 self._add_plotting_col()
267 id="offcanvas-metadata",
268 title="Throughput And Latency",
272 dbc.Row(id="metadata-tput-lat"),
273 dbc.Row(id="metadata-hdrh-graph")
276 delay_show=C.SPINNER_DELAY
280 id="offcanvas-documentation",
281 title="Documentation",
284 children=html.Iframe(
285 src=C.URL_DOC_TRENDING,
294 dbc.Alert("An Error Occured", color="danger"),
298 def _add_navbar(self):
299 """Add nav element with navigation panel. It is placed on the top.
301 :returns: Navigation bar.
302 :rtype: dbc.NavbarSimple
304 return dbc.NavbarSimple(
306 dbc.NavItem(dbc.NavLink(
312 dbc.NavItem(dbc.NavLink(
317 dbc.NavItem(dbc.NavLink(
322 dbc.NavItem(dbc.NavLink(
324 id="btn-documentation",
327 id="navbarsimple-main",
330 brand_external_link=True,
335 def _add_ctrl_col(self) -> dbc.Col:
336 """Add column with controls. It is placed on the left side.
338 :returns: Column with the control panel.
341 return dbc.Col(html.Div(self._add_ctrl_panel(), className="sticky-top"))
343 def _add_ctrl_panel(self) -> list:
344 """Add control panel.
346 :returns: Control panel.
354 show_tooltip(self._tooltips, "help-dut", "DUT")
357 id={"type": "ctrl-dd", "index": "dut"},
358 placeholder="Select a Device under Test...",
361 {"label": k, "value": k} \
362 for k in self._spec_tbs.keys()
364 key=lambda d: d["label"]
376 show_tooltip(self._tooltips, "help-infra", "Infra")
379 id={"type": "ctrl-dd", "index": "phy"},
380 placeholder="Select a Physical Test Bed Topology..."
391 show_tooltip(self._tooltips, "help-area", "Area")
394 id={"type": "ctrl-dd", "index": "area"},
395 placeholder="Select an Area..."
406 show_tooltip(self._tooltips, "help-test", "Test")
409 id={"type": "ctrl-dd", "index": "test"},
410 placeholder="Select a Test..."
420 dbc.InputGroupText(show_tooltip(
427 id={"type": "ctrl-cl", "index": "frmsize-all"},
428 options=C.CL_ALL_DISABLED,
436 id={"type": "ctrl-cl", "index": "frmsize"},
441 style={"align-items": "center"},
449 dbc.InputGroupText(show_tooltip(
456 id={"type": "ctrl-cl", "index": "core-all"},
457 options=C.CL_ALL_DISABLED,
465 id={"type": "ctrl-cl", "index": "core"},
470 style={"align-items": "center"},
478 dbc.InputGroupText(show_tooltip(
485 id={"type": "ctrl-cl", "index": "tsttype-all"},
486 options=C.CL_ALL_DISABLED,
494 id={"type": "ctrl-cl", "index": "tsttype"},
499 style={"align-items": "center"},
507 dbc.InputGroupText(show_tooltip(
512 dbc.Col(dbc.Checklist(
515 "value": "normalize",
516 "label": "Normalize to CPU frequency 2GHz"
523 style={"align-items": "center"},
530 id={"type": "ctrl-btn", "index": "add-test"},
531 children="Add Selected",
538 class_name="overflow-auto p-0",
541 style={"max-height": "20em"},
544 id="row-card-sel-tests",
545 class_name="g-0 p-1",
546 style=C.STYLE_DISABLED,
552 id={"type": "ctrl-btn", "index": "rm-test"},
559 id={"type": "ctrl-btn", "index": "rm-test-all"},
565 id="row-btns-sel-tests",
566 class_name="g-0 p-1",
567 style=C.STYLE_DISABLED,
572 "Add Telemetry Panel",
573 id={"type": "telemetry-btn", "index": "open"},
576 dbc.Button("Show URL", id="plot-btn-url", color="info"),
579 dbc.ModalHeader(dbc.ModalTitle("URL")),
580 dbc.ModalBody(id="mod-url")
588 id="row-btns-add-tm",
589 class_name="g-0 p-1",
590 style=C.STYLE_DISABLED,
595 def _add_plotting_col(self) -> dbc.Col:
596 """Add column with plots. It is placed on the right side.
598 :returns: Column with plots.
602 id="col-plotting-area",
605 id="plotting-area-trending",
606 class_name="g-0 p-0",
607 children=C.PLACEHOLDER
610 id="plotting-area-telemetry",
611 class_name="g-0 p-0",
612 children=C.PLACEHOLDER
616 style=C.STYLE_DISABLED,
620 def _plotting_area_trending(graphs: list) -> dbc.Col:
621 """Generate the plotting area with all its content.
623 :param graphs: A list of graphs to be displayed in the trending page.
625 :returns: A collumn with trending graphs (tput and latency) in tabs.
637 id={"type": "graph", "index": "tput"},
649 id={"type": "graph", "index": "lat"},
662 active_tab="tab-tput",
671 id="plot-btn-download",
674 style={"padding": "0rem 1rem"}
676 dcc.Download(id="download-trending-data")
678 className="d-grid gap-0 d-md-flex justify-content-md-end"
687 dbc.AccordionItem(trending, title="Trending"),
688 class_name="g-0 p-1",
689 start_collapsed=False,
691 active_item=["item-0", ]
696 dbc.ModalTitle("Select a Metric"),
700 dbc.ModalBody(Layout._get_telemetry_step_1()),
701 delay_show=2 * C.SPINNER_DELAY
706 id={"type": "telemetry-btn", "index": "select"},
712 id={"type": "telemetry-btn", "index": "cancel"},
718 id={"type": "telemetry-btn", "index": "rm-all"},
724 id={"type": "plot-mod-telemetry", "index": 0},
734 dbc.ModalTitle("Select Labels"),
738 dbc.ModalBody(Layout._get_telemetry_step_2()),
739 delay_show=2 * C.SPINNER_DELAY
744 id={"type": "telemetry-btn", "index": "back"},
749 "Add Telemetry Panel",
750 id={"type": "telemetry-btn", "index": "add"},
756 id={"type": "telemetry-btn", "index": "cancel"},
762 id={"type": "plot-mod-telemetry", "index": 1},
773 def _plotting_area_telemetry(graphs: list) -> dbc.Col:
774 """Generate the plotting area with telemetry.
776 :param graphs: A list of graphs to be displayed in the telemetry page.
778 :returns: A collumn with telemetry trending graphs.
784 def _plural(iterative):
785 return "s" if len(iterative) > 1 else str()
788 for idx, graph_set in enumerate(graphs):
790 for graph in graph_set[0]:
791 graph_name = ", ".join(graph[1])
795 id={"type": "graph-telemetry", "index": graph_name},
798 title=(f"Test{_plural(graph[1])}: {graph_name}"),
808 class_name="g-0 p-0",
809 start_collapsed=True,
821 "type": "tm-btn-remove",
826 style={"padding": "0rem 1rem"}
831 "type": "tm-btn-download",
836 style={"padding": "0rem 1rem"}
840 "d-grid gap-0 d-md-flex justify-content-md-end"
845 class_name="g-0 p-0",
847 f"Metric{_plural(graph_set[1])}: ",
848 ", ".join(graph_set[1])
856 class_name="g-0 p-1",
857 start_collapsed=True,
863 def _get_telemetry_step_1() -> list:
864 """Return the content of the modal window used in the step 1 of metrics
867 :returns: A list of dbc rows with 'input' and 'search output'.
872 class_name="g-0 p-1",
875 id={"type": "telemetry-search-in", "index": 0},
876 placeholder="Start typing a metric name...",
882 class_name="g-0 p-1",
885 class_name="overflow-auto p-0",
886 id={"type": "telemetry-search-out", "index": 0},
888 style={"max-height": "14em"},
896 def _get_telemetry_step_2() -> list:
897 """Return the content of the modal window used in the step 2 of metrics
900 :returns: A list of dbc rows with 'container with dynamic dropdowns' and
907 id={"type": "tm-container", "index": 0},
914 id={"type": "cb-all-in-one", "index": 0},
915 label="All Metrics in one Graph"
921 id={"type": "cb-ignore-host", "index": 0},
931 id={"type": "tm-list-metrics", "index": 0},
941 def callbacks(self, app):
942 """Callbacks for the whole application.
944 :param app: The application.
949 Output("store", "data"),
950 Output("plotting-area-trending", "children"),
951 Output("plotting-area-telemetry", "children"),
952 Output("col-plotting-area", "style"),
953 Output("row-card-sel-tests", "style"),
954 Output("row-btns-sel-tests", "style"),
955 Output("row-btns-add-tm", "style"),
956 Output("lg-selected", "children"),
957 Output({"type": "telemetry-search-out", "index": ALL}, "children"),
958 Output({"type": "plot-mod-telemetry", "index": ALL}, "is_open"),
959 Output({"type": "telemetry-btn", "index": ALL}, "disabled"),
960 Output({"type": "tm-container", "index": ALL}, "children"),
961 Output({"type": "tm-list-metrics", "index": ALL}, "value"),
962 Output({"type": "ctrl-dd", "index": "dut"}, "value"),
963 Output({"type": "ctrl-dd", "index": "phy"}, "options"),
964 Output({"type": "ctrl-dd", "index": "phy"}, "disabled"),
965 Output({"type": "ctrl-dd", "index": "phy"}, "value"),
966 Output({"type": "ctrl-dd", "index": "area"}, "options"),
967 Output({"type": "ctrl-dd", "index": "area"}, "disabled"),
968 Output({"type": "ctrl-dd", "index": "area"}, "value"),
969 Output({"type": "ctrl-dd", "index": "test"}, "options"),
970 Output({"type": "ctrl-dd", "index": "test"}, "disabled"),
971 Output({"type": "ctrl-dd", "index": "test"}, "value"),
972 Output({"type": "ctrl-cl", "index": "core"}, "options"),
973 Output({"type": "ctrl-cl", "index": "core"}, "value"),
974 Output({"type": "ctrl-cl", "index": "core-all"}, "value"),
975 Output({"type": "ctrl-cl", "index": "core-all"}, "options"),
976 Output({"type": "ctrl-cl", "index": "frmsize"}, "options"),
977 Output({"type": "ctrl-cl", "index": "frmsize"}, "value"),
978 Output({"type": "ctrl-cl", "index": "frmsize-all"}, "value"),
979 Output({"type": "ctrl-cl", "index": "frmsize-all"}, "options"),
980 Output({"type": "ctrl-cl", "index": "tsttype"}, "options"),
981 Output({"type": "ctrl-cl", "index": "tsttype"}, "value"),
982 Output({"type": "ctrl-cl", "index": "tsttype-all"}, "value"),
983 Output({"type": "ctrl-cl", "index": "tsttype-all"}, "options"),
984 Output({"type": "ctrl-btn", "index": "add-test"}, "disabled"),
985 Output("normalize", "value"),
987 State("store", "data"),
988 State({"type": "sel-cl", "index": ALL}, "value"),
989 State({"type": "cb-all-in-one", "index": ALL}, "value"),
990 State({"type": "cb-ignore-host", "index": ALL}, "value"),
991 State({"type": "telemetry-search-out", "index": ALL}, "children"),
992 State({"type": "plot-mod-telemetry", "index": ALL}, "is_open"),
993 State({"type": "telemetry-btn", "index": ALL}, "disabled"),
994 State({"type": "tm-container", "index": ALL}, "children"),
995 State({"type": "tm-list-metrics", "index": ALL}, "value"),
996 State({"type": "tele-cl", "index": ALL}, "value"),
998 Input("url", "href"),
999 Input({"type": "tm-dd", "index": ALL}, "value"),
1001 Input("normalize", "value"),
1002 Input({"type": "telemetry-search-in", "index": ALL}, "value"),
1003 Input({"type": "telemetry-btn", "index": ALL}, "n_clicks"),
1004 Input({"type": "tm-btn-remove", "index": ALL}, "n_clicks"),
1005 Input({"type": "ctrl-dd", "index": ALL}, "value"),
1006 Input({"type": "ctrl-cl", "index": ALL}, "value"),
1007 Input({"type": "ctrl-btn", "index": ALL}, "n_clicks"),
1009 prevent_initial_call=True
1011 def _update_application(
1018 tm_btns_disabled: list,
1026 """Update the application when the event is detected.
1031 "control-panel": dict(),
1032 "selected-tests": list(),
1033 "trending-graphs": None,
1034 "telemetry-data": dict(),
1035 "selected-metrics": dict(),
1036 "telemetry-panels": list(),
1037 "telemetry-all-in-one": list(),
1038 "telemetry-ignore-host": list(),
1039 "telemetry-graphs": list(),
1043 ctrl_panel = ControlPanel(
1045 store.get("control-panel", dict())
1047 store_sel = store["selected-tests"]
1048 tm_data = store["telemetry-data"]
1049 tm_user = store["selected-metrics"]
1050 tm_panels = store["telemetry-panels"]
1051 tm_all_in_one = store["telemetry-all-in-one"]
1052 tm_ignore_host = store["telemetry-ignore-host"]
1054 plotting_area_telemetry = no_update
1055 on_draw = [False, False] # 0 --> trending, 1 --> telemetry
1058 parsed_url = url_decode(href)
1060 url_params = parsed_url["params"]
1065 # Telemetry user data
1066 # The data provided by user or result of user action
1068 # List of unique metrics:
1069 "unique_metrics": list(),
1070 # List of metrics selected by user:
1071 "selected_metrics": list(),
1072 # Labels from metrics selected by user (key: label name,
1073 # value: list of all possible values):
1074 "unique_labels": dict(),
1075 # Labels selected by the user (subset of 'unique_labels'):
1076 "selected_labels": dict(),
1077 # All unique metrics with labels (output from the step 1)
1078 # converted from pandas dataframe to dictionary.
1079 "unique_metrics_with_labels": dict(),
1080 # Metrics with labels selected by the user using dropdowns.
1081 "selected_metrics_with_labels": dict()
1083 tm = TelemetryData(store_sel) if store_sel else TelemetryData()
1085 trigger = Trigger(callback_context.triggered)
1086 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 telemetry = literal_eval(url_params["telemetry"][0])
1092 url_p = url_params.get("all-in-one", ["[[None]]"])
1093 tm_all_in_one = literal_eval(url_p[0])
1094 url_p = url_params.get("ignore-host", ["[[None]]"])
1095 tm_ignore_host = literal_eval(url_p[0])
1096 if not isinstance(telemetry, list):
1097 telemetry = [telemetry, ]
1098 except (KeyError, IndexError, AttributeError, ValueError):
1101 last_test = store_sel[-1]
1102 test = self._spec_tbs[last_test["dut"]][last_test["phy"]]\
1103 [last_test["area"]][last_test["test"]]
1105 "dd-dut-val": last_test["dut"],
1106 "dd-phy-val": last_test["phy"],
1107 "dd-phy-opt": generate_options(
1108 self._spec_tbs[last_test["dut"]].keys()
1110 "dd-phy-dis": False,
1111 "dd-area-val": last_test["area"],
1113 {"label": label(v), "value": v} for v in sorted(
1114 self._spec_tbs[last_test["dut"]]\
1115 [last_test["phy"]].keys()
1118 "dd-area-dis": False,
1119 "dd-test-val": last_test["test"],
1120 "dd-test-opt": generate_options(
1121 self._spec_tbs[last_test["dut"]][last_test["phy"]]\
1122 [last_test["area"]].keys()
1124 "dd-test-dis": False,
1125 "cl-core-opt": generate_options(test["core"]),
1126 "cl-core-val": [last_test["core"].upper(), ],
1127 "cl-core-all-val": list(),
1128 "cl-core-all-opt": C.CL_ALL_ENABLED,
1129 "cl-frmsize-opt": generate_options(test["frame-size"]),
1130 "cl-frmsize-val": [last_test["framesize"].upper(), ],
1131 "cl-frmsize-all-val": list(),
1132 "cl-frmsize-all-opt": C.CL_ALL_ENABLED,
1133 "cl-tsttype-opt": generate_options(test["test-type"]),
1134 "cl-tsttype-val": [last_test["testtype"].upper(), ],
1135 "cl-tsttype-all-val": list(),
1136 "cl-tsttype-all-opt": C.CL_ALL_ENABLED,
1137 "cl-normalize-val": normalize,
1138 "btn-add-dis": False
1140 store["trending-graphs"] = None
1141 store["telemetry-graphs"] = list()
1144 tm = TelemetryData(store_sel)
1145 tm.from_dataframe(self._data)
1146 tm_data = tm.to_json()
1147 tm.from_json(tm_data)
1148 tm_panels = telemetry
1150 elif trigger.type == "normalize":
1151 ctrl_panel.set({"cl-normalize-val": trigger.value})
1152 store["trending-graphs"] = None
1154 elif trigger.type == "ctrl-dd":
1155 if trigger.idx == "dut":
1157 options = generate_options(
1158 self._spec_tbs[trigger.value].keys()
1165 "dd-dut-val": trigger.value,
1166 "dd-phy-val": str(),
1167 "dd-phy-opt": options,
1168 "dd-phy-dis": disabled,
1169 "dd-area-val": str(),
1170 "dd-area-opt": list(),
1171 "dd-area-dis": True,
1172 "dd-test-val": str(),
1173 "dd-test-opt": list(),
1174 "dd-test-dis": True,
1175 "cl-core-opt": list(),
1176 "cl-core-val": list(),
1177 "cl-core-all-val": list(),
1178 "cl-core-all-opt": C.CL_ALL_DISABLED,
1179 "cl-frmsize-opt": list(),
1180 "cl-frmsize-val": list(),
1181 "cl-frmsize-all-val": list(),
1182 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1183 "cl-tsttype-opt": list(),
1184 "cl-tsttype-val": list(),
1185 "cl-tsttype-all-val": list(),
1186 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1189 elif trigger.idx == "phy":
1191 dut = ctrl_panel.get("dd-dut-val")
1192 phy = self._spec_tbs[dut][trigger.value]
1193 options = [{"label": label(v), "value": v} \
1194 for v in sorted(phy.keys())]
1200 "dd-phy-val": trigger.value,
1201 "dd-area-val": str(),
1202 "dd-area-opt": options,
1203 "dd-area-dis": disabled,
1204 "dd-test-val": str(),
1205 "dd-test-opt": list(),
1206 "dd-test-dis": True,
1207 "cl-core-opt": list(),
1208 "cl-core-val": list(),
1209 "cl-core-all-val": list(),
1210 "cl-core-all-opt": C.CL_ALL_DISABLED,
1211 "cl-frmsize-opt": list(),
1212 "cl-frmsize-val": list(),
1213 "cl-frmsize-all-val": list(),
1214 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1215 "cl-tsttype-opt": list(),
1216 "cl-tsttype-val": list(),
1217 "cl-tsttype-all-val": list(),
1218 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1221 elif trigger.idx == "area":
1223 dut = ctrl_panel.get("dd-dut-val")
1224 phy = ctrl_panel.get("dd-phy-val")
1225 area = self._spec_tbs[dut][phy][trigger.value]
1226 options = generate_options(area.keys())
1232 "dd-area-val": trigger.value,
1233 "dd-test-val": str(),
1234 "dd-test-opt": options,
1235 "dd-test-dis": disabled,
1236 "cl-core-opt": list(),
1237 "cl-core-val": list(),
1238 "cl-core-all-val": list(),
1239 "cl-core-all-opt": C.CL_ALL_DISABLED,
1240 "cl-frmsize-opt": list(),
1241 "cl-frmsize-val": list(),
1242 "cl-frmsize-all-val": list(),
1243 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1244 "cl-tsttype-opt": list(),
1245 "cl-tsttype-val": list(),
1246 "cl-tsttype-all-val": list(),
1247 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1250 elif trigger.idx == "test":
1251 dut = ctrl_panel.get("dd-dut-val")
1252 phy = ctrl_panel.get("dd-phy-val")
1253 area = ctrl_panel.get("dd-area-val")
1254 if all((dut, phy, area, trigger.value, )):
1255 test = self._spec_tbs[dut][phy][area][trigger.value]
1257 "dd-test-val": trigger.value,
1258 "cl-core-opt": generate_options(test["core"]),
1259 "cl-core-val": list(),
1260 "cl-core-all-val": list(),
1261 "cl-core-all-opt": C.CL_ALL_ENABLED,
1263 generate_options(test["frame-size"]),
1264 "cl-frmsize-val": list(),
1265 "cl-frmsize-all-val": list(),
1266 "cl-frmsize-all-opt": C.CL_ALL_ENABLED,
1268 generate_options(test["test-type"]),
1269 "cl-tsttype-val": list(),
1270 "cl-tsttype-all-val": list(),
1271 "cl-tsttype-all-opt": C.CL_ALL_ENABLED,
1274 elif trigger.type == "ctrl-cl":
1275 param = trigger.idx.split("-")[0]
1276 if "-all" in trigger.idx:
1277 c_sel, c_all, c_id = list(), trigger.value, "all"
1279 c_sel, c_all, c_id = trigger.value, list(), str()
1280 val_sel, val_all = sync_checklists(
1281 options=ctrl_panel.get(f"cl-{param}-opt"),
1287 f"cl-{param}-val": val_sel,
1288 f"cl-{param}-all-val": val_all,
1290 if all((ctrl_panel.get("cl-core-val"),
1291 ctrl_panel.get("cl-frmsize-val"),
1292 ctrl_panel.get("cl-tsttype-val"), )):
1293 ctrl_panel.set({"btn-add-dis": False})
1295 ctrl_panel.set({"btn-add-dis": True})
1296 elif trigger.type == "ctrl-btn":
1298 tm_all_in_one = list()
1299 tm_ignore_host = list()
1300 store["trending-graphs"] = None
1301 store["telemetry-graphs"] = list()
1303 on_draw = [True, True]
1304 if trigger.idx == "add-test":
1305 dut = ctrl_panel.get("dd-dut-val")
1306 phy = ctrl_panel.get("dd-phy-val")
1307 area = ctrl_panel.get("dd-area-val")
1308 test = ctrl_panel.get("dd-test-val")
1309 # Add selected test(s) to the list of tests in store:
1310 if store_sel is None:
1312 for core in ctrl_panel.get("cl-core-val"):
1313 for framesize in ctrl_panel.get("cl-frmsize-val"):
1314 for ttype in ctrl_panel.get("cl-tsttype-val"):
1319 phy.replace('af_xdp', 'af-xdp'),
1326 if tid not in [i["id"] for i in store_sel]:
1333 "framesize": framesize.lower(),
1334 "core": core.lower(),
1335 "testtype": ttype.lower()
1337 store_sel = sorted(store_sel, key=lambda d: d["id"])
1338 if C.CLEAR_ALL_INPUTS:
1339 ctrl_panel.set(ctrl_panel.defaults)
1340 elif trigger.idx == "rm-test" and lst_sel:
1341 new_store_sel = list()
1342 for idx, item in enumerate(store_sel):
1343 if not lst_sel[idx]:
1344 new_store_sel.append(item)
1345 store_sel = new_store_sel
1346 elif trigger.idx == "rm-test-all":
1348 elif trigger.type == "telemetry-btn":
1349 if trigger.idx in ("open", "back"):
1350 tm.from_dataframe(self._data)
1351 tm_data = tm.to_json()
1352 tm_user["unique_metrics"] = tm.unique_metrics
1353 tm_user["selected_metrics"] = list()
1354 tm_user["unique_labels"] = dict()
1355 tm_user["selected_labels"] = dict()
1357 get_list_group_items(tm_user["unique_metrics"],
1360 is_open = (True, False)
1361 tm_btns_disabled[1], tm_btns_disabled[5] = False, True
1362 elif trigger.idx == "select":
1364 tm.from_json(tm_data)
1365 if not tm_user["selected_metrics"]:
1366 tm_user["selected_metrics"] = \
1367 tm_user["unique_metrics"]
1368 metrics = [a for a, b in \
1369 zip(tm_user["selected_metrics"], cl_metrics) if b]
1370 tm_user["selected_metrics"] = metrics
1371 tm_user["unique_labels"] = \
1372 tm.get_selected_labels(metrics)
1373 tm_user["unique_metrics_with_labels"] = \
1374 tm.unique_metrics_with_labels
1375 list_metrics[0] = tm.str_metrics
1376 tm_dd[0] = _get_dd_container(tm_user["unique_labels"])
1378 tm_btns_disabled[1] = True
1379 tm_btns_disabled[4] = False
1380 is_open = (False, True)
1382 is_open = (True, False)
1383 elif trigger.idx == "add":
1384 tm.from_json(tm_data)
1385 tm_panels.append(tm_user["selected_metrics_with_labels"])
1386 tm_all_in_one.append(all_in_one)
1387 tm_ignore_host.append(ignore_host)
1388 is_open = (False, False)
1389 tm_btns_disabled[1], tm_btns_disabled[5] = True, True
1390 on_draw = [True, True]
1391 elif trigger.idx == "cancel":
1392 is_open = (False, False)
1393 tm_btns_disabled[1], tm_btns_disabled[5] = True, True
1394 elif trigger.idx == "rm-all":
1396 tm_all_in_one = list()
1397 tm_ignore_host = list()
1399 is_open = (False, False)
1400 tm_btns_disabled[1], tm_btns_disabled[5] = True, True
1401 plotting_area_telemetry = C.PLACEHOLDER
1402 elif trigger.type == "telemetry-search-in":
1403 tm.from_metrics(tm_user["unique_metrics"])
1404 tm_user["selected_metrics"] = \
1405 tm.search_unique_metrics(trigger.value)
1406 search_out = (get_list_group_items(
1407 tm_user["selected_metrics"],
1411 is_open = (True, False)
1412 elif trigger.type == "tm-dd":
1413 tm.from_metrics_with_labels(
1414 tm_user["unique_metrics_with_labels"]
1418 for itm in tm_dd_in:
1421 elif isinstance(itm, str):
1423 selected[itm] = list()
1424 elif isinstance(itm, list):
1425 if previous_itm is not None:
1426 selected[previous_itm] = itm
1429 tm_dd[0] = _get_dd_container(
1430 tm_user["unique_labels"],
1434 sel_metrics = tm.filter_selected_metrics_by_labels(selected)
1435 tm_user["selected_metrics_with_labels"] = sel_metrics.to_dict()
1436 if not sel_metrics.empty:
1437 list_metrics[0] = tm.metrics_to_str(sel_metrics)
1438 tm_btns_disabled[5] = False
1440 list_metrics[0] = str()
1441 elif trigger.type == "tm-btn-remove":
1442 del tm_panels[trigger.idx]
1443 del tm_all_in_one[trigger.idx]
1444 del tm_ignore_host[trigger.idx]
1445 del store["telemetry-graphs"][trigger.idx]
1446 tm.from_json(tm_data)
1447 on_draw = [True, True]
1450 "store_sel": store_sel,
1451 "norm": ctrl_panel.get("cl-normalize-val")
1454 new_url_params["telemetry"] = tm_panels
1455 new_url_params["all-in-one"] = tm_all_in_one
1456 new_url_params["ignore-host"] = tm_ignore_host
1458 if on_draw[0]: # Trending
1460 lg_selected = get_list_group_items(store_sel, "sel-cl")
1461 if store["trending-graphs"]:
1462 graphs = store["trending-graphs"]
1464 graphs = graph_trending(
1468 bool(ctrl_panel.get("cl-normalize-val"))
1470 if graphs and graphs[0]:
1471 store["trending-graphs"] = graphs
1472 plotting_area_trending = \
1473 Layout._plotting_area_trending(graphs)
1476 start_idx = len(store["telemetry-graphs"])
1477 end_idx = len(tm_panels)
1479 plotting_area_telemetry = C.PLACEHOLDER
1480 elif on_draw[1] and (end_idx >= start_idx):
1481 if len(tm_all_in_one) != end_idx:
1482 tm_all_in_one = [[None], ] * end_idx
1483 if len(tm_ignore_host) != end_idx:
1484 tm_ignore_host = [[None], ] * end_idx
1485 for idx in range(start_idx, end_idx):
1486 store["telemetry-graphs"].append(graph_tm_trending(
1487 tm.select_tm_trending_data(
1489 ignore_host=bool(tm_ignore_host[idx][0])
1492 bool(tm_all_in_one[idx][0])
1494 plotting_area_telemetry = \
1495 Layout._plotting_area_telemetry(
1496 store["telemetry-graphs"]
1498 col_plotting_area = C.STYLE_ENABLED
1499 row_card_sel_tests = C.STYLE_ENABLED
1500 row_btns_sel_tests = C.STYLE_ENABLED
1501 row_btns_add_tm = C.STYLE_ENABLED
1503 plotting_area_trending = no_update
1504 plotting_area_telemetry = C.PLACEHOLDER
1505 col_plotting_area = C.STYLE_DISABLED
1506 row_card_sel_tests = C.STYLE_DISABLED
1507 row_btns_sel_tests = C.STYLE_DISABLED
1508 row_btns_add_tm = C.STYLE_DISABLED
1509 lg_selected = no_update
1512 tm_all_in_one = list()
1513 tm_ignore_host = list()
1516 plotting_area_trending = no_update
1517 col_plotting_area = no_update
1518 row_card_sel_tests = no_update
1519 row_btns_sel_tests = no_update
1520 row_btns_add_tm = no_update
1521 lg_selected = no_update
1523 store["url"] = gen_new_url(parsed_url, new_url_params)
1524 store["control-panel"] = ctrl_panel.panel
1525 store["selected-tests"] = store_sel
1526 store["telemetry-data"] = tm_data
1527 store["selected-metrics"] = tm_user
1528 store["telemetry-panels"] = tm_panels
1529 store["telemetry-all-in-one"] = tm_all_in_one
1530 store["telemetry-ignore-host"] = tm_ignore_host
1533 plotting_area_trending,
1534 plotting_area_telemetry,
1546 ret_val.extend(ctrl_panel.values)
1550 Output("plot-mod-url", "is_open"),
1551 Output("mod-url", "children"),
1552 State("store", "data"),
1553 State("plot-mod-url", "is_open"),
1554 Input("plot-btn-url", "n_clicks")
1556 def toggle_plot_mod_url(store, is_open, n_clicks):
1557 """Toggle the modal window with url.
1563 return not is_open, store.get("url", str())
1564 return is_open, store["url"]
1566 def _get_dd_container(
1568 selected_labels: dict=dict(),
1571 """Generate a container with dropdown selection boxes depenting on
1574 :param all_labels: A dictionary with unique labels and their
1576 :param selected_labels: A dictionalry with user selected lables and
1578 :param show_new: If True, a dropdown selection box to add a new
1580 :type all_labels: dict
1581 :type selected_labels: dict
1582 :type show_new: bool
1583 :returns: A list of dbc rows with dropdown selection boxes.
1594 """Generates a dbc row with dropdown boxes.
1596 :param id: A string added to the dropdown ID.
1597 :param lopts: A list of options for 'label' dropdown.
1598 :param lval: Value of 'label' dropdown.
1599 :param vopts: A list of options for 'value' dropdown.
1600 :param vvals: A list of values for 'value' dropdown.
1606 :returns: dbc row with dropdown boxes.
1618 "index": f"label-{id}"
1620 placeholder="Select a label...",
1624 value=lval if lval else None
1637 "index": f"value-{id}"
1639 placeholder="Select a value...",
1643 value=vvals if vvals else None
1649 return dbc.Row(class_name="g-0 p-1", children=children)
1653 # Display rows with items in 'selected_labels'; label on the left,
1654 # values on the right:
1655 keys_left = list(all_labels.keys())
1656 for idx, label in enumerate(selected_labels.keys()):
1657 container.append(_row(
1659 lopts=deepcopy(keys_left),
1661 vopts=all_labels[label],
1662 vvals=selected_labels[label]
1664 keys_left.remove(label)
1666 # Display row with dd with labels on the left, right side is empty:
1667 if show_new and keys_left:
1668 container.append(_row(id="new", lopts=keys_left))
1673 Output("metadata-tput-lat", "children"),
1674 Output("metadata-hdrh-graph", "children"),
1675 Output("offcanvas-metadata", "is_open"),
1676 Input({"type": "graph", "index": ALL}, "clickData"),
1677 prevent_initial_call=True
1679 def _show_metadata_from_graphs(graph_data: dict) -> tuple:
1680 """Generates the data for the offcanvas displayed when a particular
1681 point in a graph is clicked on.
1683 :param graph_data: The data from the clicked point in the graph.
1684 :type graph_data: dict
1685 :returns: The data to be displayed on the offcanvas and the
1686 information to show the offcanvas.
1687 :rtype: tuple(list, list, bool)
1690 trigger = Trigger(callback_context.triggered)
1693 idx = 0 if trigger.idx == "tput" else 1
1694 graph_data = graph_data[idx]["points"][0]
1695 except (IndexError, KeyError, ValueError, TypeError):
1698 metadata = no_update
1703 [dbc.Badge(x.split(":")[0]), x.split(": ")[1]]
1704 ) for x in graph_data.get("text", "").split("<br>")
1706 if trigger.idx == "tput":
1707 title = "Throughput"
1708 elif trigger.idx == "lat":
1710 hdrh_data = graph_data.get("customdata", None)
1713 class_name="gy-2 p-0",
1715 dbc.CardHeader(hdrh_data.pop("name")),
1716 dbc.CardBody(children=[
1718 id="hdrh-latency-graph",
1719 figure=graph_hdrh_latency(
1720 hdrh_data, self._graph_layout
1731 class_name="gy-2 p-0",
1733 dbc.CardHeader(children=[
1735 target_id="tput-lat-metadata",
1737 style={"display": "inline-block"}
1742 id="tput-lat-metadata",
1744 children=[dbc.ListGroup(children, flush=True), ]
1750 return metadata, graph, True
1753 Output("download-trending-data", "data"),
1754 State("store", "data"),
1755 Input("plot-btn-download", "n_clicks"),
1756 Input({"type": "tm-btn-download", "index": ALL}, "n_clicks"),
1757 prevent_initial_call=True
1759 def _download_data(store: list, *_) -> dict:
1760 """Download the data
1762 :param store_sel: List of tests selected by user stored in the
1764 :type store_sel: list
1765 :returns: dict of data frame content (base64 encoded) and meta data
1766 used by the Download component.
1772 if not store["selected-tests"]:
1777 trigger = Trigger(callback_context.triggered)
1778 if not trigger.value:
1781 if trigger.type == "plot-btn-download":
1783 for itm in store["selected-tests"]:
1784 sel_data = select_trending_data(self._data, itm)
1785 if sel_data is None:
1787 data.append(sel_data)
1788 df = pd.concat(data, ignore_index=True, copy=False)
1789 file_name = C.TREND_DOWNLOAD_FILE_NAME
1790 elif trigger.type == "tm-btn-download":
1791 tm = TelemetryData(store["selected-tests"])
1792 tm.from_json(store["telemetry-data"])
1793 df = tm.select_tm_trending_data(
1794 store["telemetry-panels"][trigger.idx]
1796 file_name = C.TELEMETRY_DOWNLOAD_FILE_NAME
1800 return dcc.send_data_frame(df.to_csv, file_name)
1803 Output("offcanvas-documentation", "is_open"),
1804 Input("btn-documentation", "n_clicks"),
1805 State("offcanvas-documentation", "is_open")
1807 def toggle_offcanvas_documentation(n_clicks, is_open):