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="Detailed Information",
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": "bandwidth"},
653 tab_id="tab-bandwidth"
661 id={"type": "graph", "index": "lat"},
674 active_tab="tab-tput",
683 id="plot-btn-download",
686 style={"padding": "0rem 1rem"}
688 dcc.Download(id="download-trending-data")
690 className="d-grid gap-0 d-md-flex justify-content-md-end"
699 dbc.AccordionItem(trending, title="Trending"),
700 class_name="g-0 p-1",
701 start_collapsed=False,
703 active_item=["item-0", ]
708 dbc.ModalTitle("Select a Metric"),
712 dbc.ModalBody(Layout._get_telemetry_step_1()),
713 delay_show=2 * C.SPINNER_DELAY
718 id={"type": "telemetry-btn", "index": "select"},
724 id={"type": "telemetry-btn", "index": "cancel"},
730 id={"type": "telemetry-btn", "index": "rm-all"},
736 id={"type": "plot-mod-telemetry", "index": 0},
746 dbc.ModalTitle("Select Labels"),
750 dbc.ModalBody(Layout._get_telemetry_step_2()),
751 delay_show=2 * C.SPINNER_DELAY
756 id={"type": "telemetry-btn", "index": "back"},
761 "Add Telemetry Panel",
762 id={"type": "telemetry-btn", "index": "add"},
768 id={"type": "telemetry-btn", "index": "cancel"},
774 id={"type": "plot-mod-telemetry", "index": 1},
785 def _plotting_area_telemetry(graphs: list) -> dbc.Col:
786 """Generate the plotting area with telemetry.
788 :param graphs: A list of graphs to be displayed in the telemetry page.
790 :returns: A collumn with telemetry trending graphs.
796 def _plural(iterative):
797 return "s" if len(iterative) > 1 else str()
800 for idx, graph_set in enumerate(graphs):
802 for graph in graph_set[0]:
803 graph_name = ", ".join(graph[1])
807 id={"type": "graph-telemetry", "index": graph_name},
810 title=(f"Test{_plural(graph[1])}: {graph_name}"),
820 class_name="g-0 p-0",
821 start_collapsed=True,
833 "type": "tm-btn-remove",
838 style={"padding": "0rem 1rem"}
843 "type": "tm-btn-download",
848 style={"padding": "0rem 1rem"}
852 "d-grid gap-0 d-md-flex justify-content-md-end"
857 class_name="g-0 p-0",
859 f"Metric{_plural(graph_set[1])}: ",
860 ", ".join(graph_set[1])
868 class_name="g-0 p-1",
869 start_collapsed=True,
875 def _get_telemetry_step_1() -> list:
876 """Return the content of the modal window used in the step 1 of metrics
879 :returns: A list of dbc rows with 'input' and 'search output'.
884 class_name="g-0 p-1",
887 id={"type": "telemetry-search-in", "index": 0},
888 placeholder="Start typing a metric name...",
894 class_name="g-0 p-1",
897 class_name="overflow-auto p-0",
898 id={"type": "telemetry-search-out", "index": 0},
900 style={"max-height": "14em"},
908 def _get_telemetry_step_2() -> list:
909 """Return the content of the modal window used in the step 2 of metrics
912 :returns: A list of dbc rows with 'container with dynamic dropdowns' and
919 id={"type": "tm-container", "index": 0},
926 id={"type": "cb-all-in-one", "index": 0},
927 label="All Metrics in one Graph"
933 id={"type": "cb-ignore-host", "index": 0},
943 id={"type": "tm-list-metrics", "index": 0},
953 def callbacks(self, app):
954 """Callbacks for the whole application.
956 :param app: The application.
961 Output("store", "data"),
962 Output("plotting-area-trending", "children"),
963 Output("plotting-area-telemetry", "children"),
964 Output("col-plotting-area", "style"),
965 Output("row-card-sel-tests", "style"),
966 Output("row-btns-sel-tests", "style"),
967 Output("row-btns-add-tm", "style"),
968 Output("lg-selected", "children"),
969 Output({"type": "telemetry-search-out", "index": ALL}, "children"),
970 Output({"type": "plot-mod-telemetry", "index": ALL}, "is_open"),
971 Output({"type": "telemetry-btn", "index": ALL}, "disabled"),
972 Output({"type": "tm-container", "index": ALL}, "children"),
973 Output({"type": "tm-list-metrics", "index": ALL}, "value"),
974 Output({"type": "ctrl-dd", "index": "dut"}, "value"),
975 Output({"type": "ctrl-dd", "index": "phy"}, "options"),
976 Output({"type": "ctrl-dd", "index": "phy"}, "disabled"),
977 Output({"type": "ctrl-dd", "index": "phy"}, "value"),
978 Output({"type": "ctrl-dd", "index": "area"}, "options"),
979 Output({"type": "ctrl-dd", "index": "area"}, "disabled"),
980 Output({"type": "ctrl-dd", "index": "area"}, "value"),
981 Output({"type": "ctrl-dd", "index": "test"}, "options"),
982 Output({"type": "ctrl-dd", "index": "test"}, "disabled"),
983 Output({"type": "ctrl-dd", "index": "test"}, "value"),
984 Output({"type": "ctrl-cl", "index": "core"}, "options"),
985 Output({"type": "ctrl-cl", "index": "core"}, "value"),
986 Output({"type": "ctrl-cl", "index": "core-all"}, "value"),
987 Output({"type": "ctrl-cl", "index": "core-all"}, "options"),
988 Output({"type": "ctrl-cl", "index": "frmsize"}, "options"),
989 Output({"type": "ctrl-cl", "index": "frmsize"}, "value"),
990 Output({"type": "ctrl-cl", "index": "frmsize-all"}, "value"),
991 Output({"type": "ctrl-cl", "index": "frmsize-all"}, "options"),
992 Output({"type": "ctrl-cl", "index": "tsttype"}, "options"),
993 Output({"type": "ctrl-cl", "index": "tsttype"}, "value"),
994 Output({"type": "ctrl-cl", "index": "tsttype-all"}, "value"),
995 Output({"type": "ctrl-cl", "index": "tsttype-all"}, "options"),
996 Output({"type": "ctrl-btn", "index": "add-test"}, "disabled"),
997 Output("normalize", "value"),
999 State("store", "data"),
1000 State({"type": "sel-cl", "index": ALL}, "value"),
1001 State({"type": "cb-all-in-one", "index": ALL}, "value"),
1002 State({"type": "cb-ignore-host", "index": ALL}, "value"),
1003 State({"type": "telemetry-search-out", "index": ALL}, "children"),
1004 State({"type": "plot-mod-telemetry", "index": ALL}, "is_open"),
1005 State({"type": "telemetry-btn", "index": ALL}, "disabled"),
1006 State({"type": "tm-container", "index": ALL}, "children"),
1007 State({"type": "tm-list-metrics", "index": ALL}, "value"),
1008 State({"type": "tele-cl", "index": ALL}, "value"),
1010 Input("url", "href"),
1011 Input({"type": "tm-dd", "index": ALL}, "value"),
1013 Input("normalize", "value"),
1014 Input({"type": "telemetry-search-in", "index": ALL}, "value"),
1015 Input({"type": "telemetry-btn", "index": ALL}, "n_clicks"),
1016 Input({"type": "tm-btn-remove", "index": ALL}, "n_clicks"),
1017 Input({"type": "ctrl-dd", "index": ALL}, "value"),
1018 Input({"type": "ctrl-cl", "index": ALL}, "value"),
1019 Input({"type": "ctrl-btn", "index": ALL}, "n_clicks"),
1021 prevent_initial_call=True
1023 def _update_application(
1030 tm_btns_disabled: list,
1038 """Update the application when the event is detected.
1043 "control-panel": dict(),
1044 "selected-tests": list(),
1045 "trending-graphs": None,
1046 "telemetry-data": dict(),
1047 "selected-metrics": dict(),
1048 "telemetry-panels": list(),
1049 "telemetry-all-in-one": list(),
1050 "telemetry-ignore-host": list(),
1051 "telemetry-graphs": list(),
1055 ctrl_panel = ControlPanel(
1057 store.get("control-panel", dict())
1059 store_sel = store["selected-tests"]
1060 tm_data = store["telemetry-data"]
1061 tm_user = store["selected-metrics"]
1062 tm_panels = store["telemetry-panels"]
1063 tm_all_in_one = store["telemetry-all-in-one"]
1064 tm_ignore_host = store["telemetry-ignore-host"]
1066 plotting_area_telemetry = no_update
1067 on_draw = [False, False] # 0 --> trending, 1 --> telemetry
1070 parsed_url = url_decode(href)
1072 url_params = parsed_url["params"]
1077 # Telemetry user data
1078 # The data provided by user or result of user action
1080 # List of unique metrics:
1081 "unique_metrics": list(),
1082 # List of metrics selected by user:
1083 "selected_metrics": list(),
1084 # Labels from metrics selected by user (key: label name,
1085 # value: list of all possible values):
1086 "unique_labels": dict(),
1087 # Labels selected by the user (subset of 'unique_labels'):
1088 "selected_labels": dict(),
1089 # All unique metrics with labels (output from the step 1)
1090 # converted from pandas dataframe to dictionary.
1091 "unique_metrics_with_labels": dict(),
1092 # Metrics with labels selected by the user using dropdowns.
1093 "selected_metrics_with_labels": dict()
1095 tm = TelemetryData(store_sel) if store_sel else TelemetryData()
1097 trigger = Trigger(callback_context.triggered)
1098 if trigger.type == "url" and url_params:
1101 store_sel = literal_eval(url_params["store_sel"][0])
1102 normalize = literal_eval(url_params["norm"][0])
1103 telemetry = literal_eval(url_params["telemetry"][0])
1104 url_p = url_params.get("all-in-one", ["[[None]]"])
1105 tm_all_in_one = literal_eval(url_p[0])
1106 url_p = url_params.get("ignore-host", ["[[None]]"])
1107 tm_ignore_host = literal_eval(url_p[0])
1108 if not isinstance(telemetry, list):
1109 telemetry = [telemetry, ]
1110 except (KeyError, IndexError, AttributeError, ValueError):
1113 last_test = store_sel[-1]
1114 test = self._spec_tbs[last_test["dut"]][last_test["phy"]]\
1115 [last_test["area"]][last_test["test"]]
1117 "dd-dut-val": last_test["dut"],
1118 "dd-phy-val": last_test["phy"],
1119 "dd-phy-opt": generate_options(
1120 self._spec_tbs[last_test["dut"]].keys()
1122 "dd-phy-dis": False,
1123 "dd-area-val": last_test["area"],
1125 {"label": label(v), "value": v} for v in sorted(
1126 self._spec_tbs[last_test["dut"]]\
1127 [last_test["phy"]].keys()
1130 "dd-area-dis": False,
1131 "dd-test-val": last_test["test"],
1132 "dd-test-opt": generate_options(
1133 self._spec_tbs[last_test["dut"]][last_test["phy"]]\
1134 [last_test["area"]].keys()
1136 "dd-test-dis": False,
1137 "cl-core-opt": generate_options(test["core"]),
1138 "cl-core-val": [last_test["core"].upper(), ],
1139 "cl-core-all-val": list(),
1140 "cl-core-all-opt": C.CL_ALL_ENABLED,
1141 "cl-frmsize-opt": generate_options(test["frame-size"]),
1142 "cl-frmsize-val": [last_test["framesize"].upper(), ],
1143 "cl-frmsize-all-val": list(),
1144 "cl-frmsize-all-opt": C.CL_ALL_ENABLED,
1145 "cl-tsttype-opt": generate_options(test["test-type"]),
1146 "cl-tsttype-val": [last_test["testtype"].upper(), ],
1147 "cl-tsttype-all-val": list(),
1148 "cl-tsttype-all-opt": C.CL_ALL_ENABLED,
1149 "cl-normalize-val": normalize,
1150 "btn-add-dis": False
1152 store["trending-graphs"] = None
1153 store["telemetry-graphs"] = list()
1156 tm = TelemetryData(store_sel)
1157 tm.from_dataframe(self._data)
1158 tm_data = tm.to_json()
1159 tm.from_json(tm_data)
1160 tm_panels = telemetry
1162 elif trigger.type == "normalize":
1163 ctrl_panel.set({"cl-normalize-val": trigger.value})
1164 store["trending-graphs"] = None
1166 elif trigger.type == "ctrl-dd":
1167 if trigger.idx == "dut":
1169 options = generate_options(
1170 self._spec_tbs[trigger.value].keys()
1177 "dd-dut-val": trigger.value,
1178 "dd-phy-val": str(),
1179 "dd-phy-opt": options,
1180 "dd-phy-dis": disabled,
1181 "dd-area-val": str(),
1182 "dd-area-opt": list(),
1183 "dd-area-dis": True,
1184 "dd-test-val": str(),
1185 "dd-test-opt": list(),
1186 "dd-test-dis": True,
1187 "cl-core-opt": list(),
1188 "cl-core-val": list(),
1189 "cl-core-all-val": list(),
1190 "cl-core-all-opt": C.CL_ALL_DISABLED,
1191 "cl-frmsize-opt": list(),
1192 "cl-frmsize-val": list(),
1193 "cl-frmsize-all-val": list(),
1194 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1195 "cl-tsttype-opt": list(),
1196 "cl-tsttype-val": list(),
1197 "cl-tsttype-all-val": list(),
1198 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1201 elif trigger.idx == "phy":
1203 dut = ctrl_panel.get("dd-dut-val")
1204 phy = self._spec_tbs[dut][trigger.value]
1205 options = [{"label": label(v), "value": v} \
1206 for v in sorted(phy.keys())]
1212 "dd-phy-val": trigger.value,
1213 "dd-area-val": str(),
1214 "dd-area-opt": options,
1215 "dd-area-dis": disabled,
1216 "dd-test-val": str(),
1217 "dd-test-opt": list(),
1218 "dd-test-dis": True,
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 == "area":
1235 dut = ctrl_panel.get("dd-dut-val")
1236 phy = ctrl_panel.get("dd-phy-val")
1237 area = self._spec_tbs[dut][phy][trigger.value]
1238 options = generate_options(area.keys())
1244 "dd-area-val": trigger.value,
1245 "dd-test-val": str(),
1246 "dd-test-opt": options,
1247 "dd-test-dis": disabled,
1248 "cl-core-opt": list(),
1249 "cl-core-val": list(),
1250 "cl-core-all-val": list(),
1251 "cl-core-all-opt": C.CL_ALL_DISABLED,
1252 "cl-frmsize-opt": list(),
1253 "cl-frmsize-val": list(),
1254 "cl-frmsize-all-val": list(),
1255 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1256 "cl-tsttype-opt": list(),
1257 "cl-tsttype-val": list(),
1258 "cl-tsttype-all-val": list(),
1259 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1262 elif trigger.idx == "test":
1263 dut = ctrl_panel.get("dd-dut-val")
1264 phy = ctrl_panel.get("dd-phy-val")
1265 area = ctrl_panel.get("dd-area-val")
1266 if all((dut, phy, area, trigger.value, )):
1267 test = self._spec_tbs[dut][phy][area][trigger.value]
1269 "dd-test-val": trigger.value,
1270 "cl-core-opt": generate_options(test["core"]),
1271 "cl-core-val": list(),
1272 "cl-core-all-val": list(),
1273 "cl-core-all-opt": C.CL_ALL_ENABLED,
1275 generate_options(test["frame-size"]),
1276 "cl-frmsize-val": list(),
1277 "cl-frmsize-all-val": list(),
1278 "cl-frmsize-all-opt": C.CL_ALL_ENABLED,
1280 generate_options(test["test-type"]),
1281 "cl-tsttype-val": list(),
1282 "cl-tsttype-all-val": list(),
1283 "cl-tsttype-all-opt": C.CL_ALL_ENABLED,
1286 elif trigger.type == "ctrl-cl":
1287 param = trigger.idx.split("-")[0]
1288 if "-all" in trigger.idx:
1289 c_sel, c_all, c_id = list(), trigger.value, "all"
1291 c_sel, c_all, c_id = trigger.value, list(), str()
1292 val_sel, val_all = sync_checklists(
1293 options=ctrl_panel.get(f"cl-{param}-opt"),
1299 f"cl-{param}-val": val_sel,
1300 f"cl-{param}-all-val": val_all,
1302 if all((ctrl_panel.get("cl-core-val"),
1303 ctrl_panel.get("cl-frmsize-val"),
1304 ctrl_panel.get("cl-tsttype-val"), )):
1305 ctrl_panel.set({"btn-add-dis": False})
1307 ctrl_panel.set({"btn-add-dis": True})
1308 elif trigger.type == "ctrl-btn":
1310 tm_all_in_one = list()
1311 tm_ignore_host = list()
1312 store["trending-graphs"] = None
1313 store["telemetry-graphs"] = list()
1315 on_draw = [True, True]
1316 if trigger.idx == "add-test":
1317 dut = ctrl_panel.get("dd-dut-val")
1318 phy = ctrl_panel.get("dd-phy-val")
1319 area = ctrl_panel.get("dd-area-val")
1320 test = ctrl_panel.get("dd-test-val")
1321 # Add selected test(s) to the list of tests in store:
1322 if store_sel is None:
1324 for core in ctrl_panel.get("cl-core-val"):
1325 for framesize in ctrl_panel.get("cl-frmsize-val"):
1326 for ttype in ctrl_panel.get("cl-tsttype-val"):
1331 phy.replace('af_xdp', 'af-xdp'),
1338 if tid not in [i["id"] for i in store_sel]:
1345 "framesize": framesize.lower(),
1346 "core": core.lower(),
1347 "testtype": ttype.lower()
1349 store_sel = sorted(store_sel, key=lambda d: d["id"])
1350 if C.CLEAR_ALL_INPUTS:
1351 ctrl_panel.set(ctrl_panel.defaults)
1352 elif trigger.idx == "rm-test" and lst_sel:
1353 new_store_sel = list()
1354 for idx, item in enumerate(store_sel):
1355 if not lst_sel[idx]:
1356 new_store_sel.append(item)
1357 store_sel = new_store_sel
1358 elif trigger.idx == "rm-test-all":
1360 elif trigger.type == "telemetry-btn":
1361 if trigger.idx in ("open", "back"):
1362 tm.from_dataframe(self._data)
1363 tm_data = tm.to_json()
1364 tm_user["unique_metrics"] = tm.unique_metrics
1365 tm_user["selected_metrics"] = list()
1366 tm_user["unique_labels"] = dict()
1367 tm_user["selected_labels"] = dict()
1369 get_list_group_items(tm_user["unique_metrics"],
1372 is_open = (True, False)
1373 tm_btns_disabled[1], tm_btns_disabled[5] = False, True
1374 elif trigger.idx == "select":
1376 tm.from_json(tm_data)
1377 if not tm_user["selected_metrics"]:
1378 tm_user["selected_metrics"] = \
1379 tm_user["unique_metrics"]
1380 metrics = [a for a, b in \
1381 zip(tm_user["selected_metrics"], cl_metrics) if b]
1382 tm_user["selected_metrics"] = metrics
1383 tm_user["unique_labels"] = \
1384 tm.get_selected_labels(metrics)
1385 tm_user["unique_metrics_with_labels"] = \
1386 tm.unique_metrics_with_labels
1387 list_metrics[0] = tm.str_metrics
1388 tm_dd[0] = _get_dd_container(tm_user["unique_labels"])
1390 tm_btns_disabled[1] = True
1391 tm_btns_disabled[4] = False
1392 is_open = (False, True)
1394 is_open = (True, False)
1395 elif trigger.idx == "add":
1396 tm.from_json(tm_data)
1397 tm_panels.append(tm_user["selected_metrics_with_labels"])
1398 tm_all_in_one.append(all_in_one)
1399 tm_ignore_host.append(ignore_host)
1400 is_open = (False, False)
1401 tm_btns_disabled[1], tm_btns_disabled[5] = True, True
1402 on_draw = [True, True]
1403 elif trigger.idx == "cancel":
1404 is_open = (False, False)
1405 tm_btns_disabled[1], tm_btns_disabled[5] = True, True
1406 elif trigger.idx == "rm-all":
1408 tm_all_in_one = list()
1409 tm_ignore_host = list()
1411 is_open = (False, False)
1412 tm_btns_disabled[1], tm_btns_disabled[5] = True, True
1413 plotting_area_telemetry = C.PLACEHOLDER
1414 elif trigger.type == "telemetry-search-in":
1415 tm.from_metrics(tm_user["unique_metrics"])
1416 tm_user["selected_metrics"] = \
1417 tm.search_unique_metrics(trigger.value)
1418 search_out = (get_list_group_items(
1419 tm_user["selected_metrics"],
1423 is_open = (True, False)
1424 elif trigger.type == "tm-dd":
1425 tm.from_metrics_with_labels(
1426 tm_user["unique_metrics_with_labels"]
1430 for itm in tm_dd_in:
1433 elif isinstance(itm, str):
1435 selected[itm] = list()
1436 elif isinstance(itm, list):
1437 if previous_itm is not None:
1438 selected[previous_itm] = itm
1441 tm_dd[0] = _get_dd_container(
1442 tm_user["unique_labels"],
1446 sel_metrics = tm.filter_selected_metrics_by_labels(selected)
1447 tm_user["selected_metrics_with_labels"] = sel_metrics.to_dict()
1448 if not sel_metrics.empty:
1449 list_metrics[0] = tm.metrics_to_str(sel_metrics)
1450 tm_btns_disabled[5] = False
1452 list_metrics[0] = str()
1453 elif trigger.type == "tm-btn-remove":
1454 del tm_panels[trigger.idx]
1455 del tm_all_in_one[trigger.idx]
1456 del tm_ignore_host[trigger.idx]
1457 del store["telemetry-graphs"][trigger.idx]
1458 tm.from_json(tm_data)
1459 on_draw = [True, True]
1462 "store_sel": store_sel,
1463 "norm": ctrl_panel.get("cl-normalize-val")
1466 new_url_params["telemetry"] = tm_panels
1467 new_url_params["all-in-one"] = tm_all_in_one
1468 new_url_params["ignore-host"] = tm_ignore_host
1470 if on_draw[0]: # Trending
1472 lg_selected = get_list_group_items(store_sel, "sel-cl")
1473 if store["trending-graphs"]:
1474 graphs = store["trending-graphs"]
1476 graphs = graph_trending(
1480 bool(ctrl_panel.get("cl-normalize-val"))
1482 if graphs and graphs[0]:
1483 store["trending-graphs"] = graphs
1484 plotting_area_trending = \
1485 Layout._plotting_area_trending(graphs)
1488 start_idx = len(store["telemetry-graphs"])
1489 end_idx = len(tm_panels)
1491 plotting_area_telemetry = C.PLACEHOLDER
1492 elif on_draw[1] and (end_idx >= start_idx):
1493 if len(tm_all_in_one) != end_idx:
1494 tm_all_in_one = [[None], ] * end_idx
1495 if len(tm_ignore_host) != end_idx:
1496 tm_ignore_host = [[None], ] * end_idx
1497 for idx in range(start_idx, end_idx):
1498 store["telemetry-graphs"].append(graph_tm_trending(
1499 tm.select_tm_trending_data(
1501 ignore_host=bool(tm_ignore_host[idx][0])
1504 bool(tm_all_in_one[idx][0])
1506 plotting_area_telemetry = \
1507 Layout._plotting_area_telemetry(
1508 store["telemetry-graphs"]
1510 col_plotting_area = C.STYLE_ENABLED
1511 row_card_sel_tests = C.STYLE_ENABLED
1512 row_btns_sel_tests = C.STYLE_ENABLED
1513 row_btns_add_tm = C.STYLE_ENABLED
1515 plotting_area_trending = no_update
1516 plotting_area_telemetry = C.PLACEHOLDER
1517 col_plotting_area = C.STYLE_DISABLED
1518 row_card_sel_tests = C.STYLE_DISABLED
1519 row_btns_sel_tests = C.STYLE_DISABLED
1520 row_btns_add_tm = C.STYLE_DISABLED
1521 lg_selected = no_update
1524 tm_all_in_one = list()
1525 tm_ignore_host = list()
1528 plotting_area_trending = no_update
1529 col_plotting_area = no_update
1530 row_card_sel_tests = no_update
1531 row_btns_sel_tests = no_update
1532 row_btns_add_tm = no_update
1533 lg_selected = no_update
1535 store["url"] = gen_new_url(parsed_url, new_url_params)
1536 store["control-panel"] = ctrl_panel.panel
1537 store["selected-tests"] = store_sel
1538 store["telemetry-data"] = tm_data
1539 store["selected-metrics"] = tm_user
1540 store["telemetry-panels"] = tm_panels
1541 store["telemetry-all-in-one"] = tm_all_in_one
1542 store["telemetry-ignore-host"] = tm_ignore_host
1545 plotting_area_trending,
1546 plotting_area_telemetry,
1558 ret_val.extend(ctrl_panel.values)
1562 Output("plot-mod-url", "is_open"),
1563 Output("mod-url", "children"),
1564 State("store", "data"),
1565 State("plot-mod-url", "is_open"),
1566 Input("plot-btn-url", "n_clicks")
1568 def toggle_plot_mod_url(store, is_open, n_clicks):
1569 """Toggle the modal window with url.
1575 return not is_open, store.get("url", str())
1576 return is_open, store["url"]
1578 def _get_dd_container(
1580 selected_labels: dict=dict(),
1583 """Generate a container with dropdown selection boxes depenting on
1586 :param all_labels: A dictionary with unique labels and their
1588 :param selected_labels: A dictionalry with user selected lables and
1590 :param show_new: If True, a dropdown selection box to add a new
1592 :type all_labels: dict
1593 :type selected_labels: dict
1594 :type show_new: bool
1595 :returns: A list of dbc rows with dropdown selection boxes.
1606 """Generates a dbc row with dropdown boxes.
1608 :param id: A string added to the dropdown ID.
1609 :param lopts: A list of options for 'label' dropdown.
1610 :param lval: Value of 'label' dropdown.
1611 :param vopts: A list of options for 'value' dropdown.
1612 :param vvals: A list of values for 'value' dropdown.
1618 :returns: dbc row with dropdown boxes.
1630 "index": f"label-{id}"
1632 placeholder="Select a label...",
1636 value=lval if lval else None
1649 "index": f"value-{id}"
1651 placeholder="Select a value...",
1655 value=vvals if vvals else None
1661 return dbc.Row(class_name="g-0 p-1", children=children)
1665 # Display rows with items in 'selected_labels'; label on the left,
1666 # values on the right:
1667 keys_left = list(all_labels.keys())
1668 for idx, label in enumerate(selected_labels.keys()):
1669 container.append(_row(
1671 lopts=deepcopy(keys_left),
1673 vopts=all_labels[label],
1674 vvals=selected_labels[label]
1676 keys_left.remove(label)
1678 # Display row with dd with labels on the left, right side is empty:
1679 if show_new and keys_left:
1680 container.append(_row(id="new", lopts=keys_left))
1685 Output("metadata-tput-lat", "children"),
1686 Output("metadata-hdrh-graph", "children"),
1687 Output("offcanvas-metadata", "is_open"),
1688 Input({"type": "graph", "index": ALL}, "clickData"),
1689 prevent_initial_call=True
1691 def _show_metadata_from_graphs(graph_data: dict) -> tuple:
1692 """Generates the data for the offcanvas displayed when a particular
1693 point in a graph is clicked on.
1695 :param graph_data: The data from the clicked point in the graph.
1696 :type graph_data: dict
1697 :returns: The data to be displayed on the offcanvas and the
1698 information to show the offcanvas.
1699 :rtype: tuple(list, list, bool)
1702 trigger = Trigger(callback_context.triggered)
1705 if trigger.idx == "tput":
1707 elif trigger.idx == "bandwidth":
1709 elif trigger.idx == "lat":
1713 graph_data = graph_data[idx]["points"][0]
1714 except (IndexError, KeyError, ValueError, TypeError):
1717 metadata = no_update
1720 list_group_items = list()
1721 for itm in graph_data.get("text", None).split("<br>"):
1724 lst_itm = itm.split(": ")
1725 if lst_itm[0] == "csit-ref":
1726 list_group_item = dbc.ListGroupItem([
1727 dbc.Badge(lst_itm[0]),
1730 href=f"{C.URL_JENKINS}{lst_itm[1]}",
1735 list_group_item = dbc.ListGroupItem([
1736 dbc.Badge(lst_itm[0]),
1739 list_group_items.append(list_group_item)
1741 if trigger.idx == "tput":
1742 title = "Throughput"
1743 elif trigger.idx == "bandwidth":
1745 elif trigger.idx == "lat":
1747 hdrh_data = graph_data.get("customdata", None)
1750 class_name="gy-2 p-0",
1752 dbc.CardHeader(hdrh_data.pop("name")),
1755 id="hdrh-latency-graph",
1756 figure=graph_hdrh_latency(
1757 hdrh_data, self._graph_layout
1768 class_name="gy-2 p-0",
1770 dbc.CardHeader(children=[
1772 target_id="tput-lat-metadata",
1774 style={"display": "inline-block"}
1779 dbc.ListGroup(list_group_items, flush=True),
1780 id="tput-lat-metadata",
1787 return metadata, graph, True
1790 Output("download-trending-data", "data"),
1791 State("store", "data"),
1792 Input("plot-btn-download", "n_clicks"),
1793 Input({"type": "tm-btn-download", "index": ALL}, "n_clicks"),
1794 prevent_initial_call=True
1796 def _download_data(store: list, *_) -> dict:
1797 """Download the data
1799 :param store_sel: List of tests selected by user stored in the
1801 :type store_sel: list
1802 :returns: dict of data frame content (base64 encoded) and meta data
1803 used by the Download component.
1809 if not store["selected-tests"]:
1814 trigger = Trigger(callback_context.triggered)
1815 if not trigger.value:
1818 if trigger.type == "plot-btn-download":
1820 for itm in store["selected-tests"]:
1821 sel_data = select_trending_data(self._data, itm)
1822 if sel_data is None:
1824 data.append(sel_data)
1825 df = pd.concat(data, ignore_index=True, copy=False)
1826 file_name = C.TREND_DOWNLOAD_FILE_NAME
1827 elif trigger.type == "tm-btn-download":
1828 tm = TelemetryData(store["selected-tests"])
1829 tm.from_json(store["telemetry-data"])
1830 df = tm.select_tm_trending_data(
1831 store["telemetry-panels"][trigger.idx]
1833 file_name = C.TELEMETRY_DOWNLOAD_FILE_NAME
1837 return dcc.send_data_frame(df.to_csv, file_name)
1840 Output("offcanvas-documentation", "is_open"),
1841 Input("btn-documentation", "n_clicks"),
1842 State("offcanvas-documentation", "is_open")
1844 def toggle_offcanvas_documentation(n_clicks, is_open):