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
282 dbc.Alert("An Error Occured", color="danger"),
286 def _add_navbar(self):
287 """Add nav element with navigation panel. It is placed on the top.
289 :returns: Navigation bar.
290 :rtype: dbc.NavbarSimple
292 return dbc.NavbarSimple(
301 id="navbarsimple-main",
304 brand_external_link=True,
309 def _add_ctrl_col(self) -> dbc.Col:
310 """Add column with controls. It is placed on the left side.
312 :returns: Column with the control panel.
315 return dbc.Col(html.Div(self._add_ctrl_panel(), className="sticky-top"))
317 def _add_ctrl_panel(self) -> list:
318 """Add control panel.
320 :returns: Control panel.
328 show_tooltip(self._tooltips, "help-dut", "DUT")
331 id={"type": "ctrl-dd", "index": "dut"},
332 placeholder="Select a Device under Test...",
335 {"label": k, "value": k} \
336 for k in self._spec_tbs.keys()
338 key=lambda d: d["label"]
350 show_tooltip(self._tooltips, "help-infra", "Infra")
353 id={"type": "ctrl-dd", "index": "phy"},
354 placeholder="Select a Physical Test Bed Topology..."
365 show_tooltip(self._tooltips, "help-area", "Area")
368 id={"type": "ctrl-dd", "index": "area"},
369 placeholder="Select an Area..."
380 show_tooltip(self._tooltips, "help-test", "Test")
383 id={"type": "ctrl-dd", "index": "test"},
384 placeholder="Select a Test..."
394 dbc.InputGroupText(show_tooltip(
401 id={"type": "ctrl-cl", "index": "frmsize-all"},
402 options=C.CL_ALL_DISABLED,
410 id={"type": "ctrl-cl", "index": "frmsize"},
415 style={"align-items": "center"},
423 dbc.InputGroupText(show_tooltip(
430 id={"type": "ctrl-cl", "index": "core-all"},
431 options=C.CL_ALL_DISABLED,
439 id={"type": "ctrl-cl", "index": "core"},
444 style={"align-items": "center"},
452 dbc.InputGroupText(show_tooltip(
459 id={"type": "ctrl-cl", "index": "tsttype-all"},
460 options=C.CL_ALL_DISABLED,
468 id={"type": "ctrl-cl", "index": "tsttype"},
473 style={"align-items": "center"},
481 dbc.InputGroupText(show_tooltip(
486 dbc.Col(dbc.Checklist(
489 "value": "normalize",
490 "label": "Normalize to CPU frequency 2GHz"
497 style={"align-items": "center"},
504 id={"type": "ctrl-btn", "index": "add-test"},
505 children="Add Selected",
512 class_name="overflow-auto p-0",
515 style={"max-height": "20em"},
518 id="row-card-sel-tests",
519 class_name="g-0 p-1",
520 style=C.STYLE_DISABLED,
526 id={"type": "ctrl-btn", "index": "rm-test"},
533 id={"type": "ctrl-btn", "index": "rm-test-all"},
539 id="row-btns-sel-tests",
540 class_name="g-0 p-1",
541 style=C.STYLE_DISABLED,
546 "Add Telemetry Panel",
547 id={"type": "telemetry-btn", "index": "open"},
550 dbc.Button("Show URL", id="plot-btn-url", color="info"),
553 dbc.ModalHeader(dbc.ModalTitle("URL")),
554 dbc.ModalBody(id="mod-url")
562 id="row-btns-add-tm",
563 class_name="g-0 p-1",
564 style=C.STYLE_DISABLED,
569 def _add_plotting_col(self) -> dbc.Col:
570 """Add column with plots. It is placed on the right side.
572 :returns: Column with plots.
576 id="col-plotting-area",
579 id="plotting-area-trending",
580 class_name="g-0 p-0",
581 children=C.PLACEHOLDER
584 id="plotting-area-telemetry",
585 class_name="g-0 p-0",
586 children=C.PLACEHOLDER
590 style=C.STYLE_DISABLED,
594 def _plotting_area_trending(graphs: list) -> dbc.Col:
595 """Generate the plotting area with all its content.
597 :param graphs: A list of graphs to be displayed in the trending page.
599 :returns: A collumn with trending graphs (tput and latency) in tabs.
611 id={"type": "graph", "index": "tput"},
623 id={"type": "graph", "index": "lat"},
636 active_tab="tab-tput",
645 id="plot-btn-download",
648 style={"padding": "0rem 1rem"}
650 dcc.Download(id="download-trending-data")
652 className="d-grid gap-0 d-md-flex justify-content-md-end"
661 dbc.AccordionItem(trending, title="Trending"),
662 class_name="g-0 p-1",
663 start_collapsed=False,
665 active_item=["item-0", ]
670 dbc.ModalTitle("Select a Metric"),
674 dbc.ModalBody(Layout._get_telemetry_step_1()),
675 delay_show=2 * C.SPINNER_DELAY
680 id={"type": "telemetry-btn", "index": "select"},
686 id={"type": "telemetry-btn", "index": "cancel"},
692 id={"type": "telemetry-btn", "index": "rm-all"},
698 id={"type": "plot-mod-telemetry", "index": 0},
708 dbc.ModalTitle("Select Labels"),
712 dbc.ModalBody(Layout._get_telemetry_step_2()),
713 delay_show=2 * C.SPINNER_DELAY
718 id={"type": "telemetry-btn", "index": "back"},
723 "Add Telemetry Panel",
724 id={"type": "telemetry-btn", "index": "add"},
730 id={"type": "telemetry-btn", "index": "cancel"},
736 id={"type": "plot-mod-telemetry", "index": 1},
747 def _plotting_area_telemetry(graphs: list) -> dbc.Col:
748 """Generate the plotting area with telemetry.
750 :param graphs: A list of graphs to be displayed in the telemetry page.
752 :returns: A collumn with telemetry trending graphs.
758 def _plural(iterative):
759 return "s" if len(iterative) > 1 else str()
762 for idx, graph_set in enumerate(graphs):
764 for graph in graph_set[0]:
765 graph_name = ", ".join(graph[1])
769 id={"type": "graph-telemetry", "index": graph_name},
772 title=(f"Test{_plural(graph[1])}: {graph_name}"),
782 class_name="g-0 p-0",
783 start_collapsed=True,
795 "type": "tm-btn-remove",
800 style={"padding": "0rem 1rem"}
805 "type": "tm-btn-download",
810 style={"padding": "0rem 1rem"}
814 "d-grid gap-0 d-md-flex justify-content-md-end"
819 class_name="g-0 p-0",
821 f"Metric{_plural(graph_set[1])}: ",
822 ", ".join(graph_set[1])
830 class_name="g-0 p-1",
831 start_collapsed=True,
837 def _get_telemetry_step_1() -> list:
838 """Return the content of the modal window used in the step 1 of metrics
841 :returns: A list of dbc rows with 'input' and 'search output'.
846 class_name="g-0 p-1",
849 id={"type": "telemetry-search-in", "index": 0},
850 placeholder="Start typing a metric name...",
856 class_name="g-0 p-1",
859 class_name="overflow-auto p-0",
860 id={"type": "telemetry-search-out", "index": 0},
862 style={"max-height": "14em"},
870 def _get_telemetry_step_2() -> list:
871 """Return the content of the modal window used in the step 2 of metrics
874 :returns: A list of dbc rows with 'container with dynamic dropdowns' and
881 id={"type": "tm-container", "index": 0},
888 id={"type": "cb-all-in-one", "index": 0},
889 label="All Metrics in one Graph"
895 id={"type": "cb-ignore-host", "index": 0},
905 id={"type": "tm-list-metrics", "index": 0},
915 def callbacks(self, app):
916 """Callbacks for the whole application.
918 :param app: The application.
923 Output("store", "data"),
924 Output("plotting-area-trending", "children"),
925 Output("plotting-area-telemetry", "children"),
926 Output("col-plotting-area", "style"),
927 Output("row-card-sel-tests", "style"),
928 Output("row-btns-sel-tests", "style"),
929 Output("row-btns-add-tm", "style"),
930 Output("lg-selected", "children"),
931 Output({"type": "telemetry-search-out", "index": ALL}, "children"),
932 Output({"type": "plot-mod-telemetry", "index": ALL}, "is_open"),
933 Output({"type": "telemetry-btn", "index": ALL}, "disabled"),
934 Output({"type": "tm-container", "index": ALL}, "children"),
935 Output({"type": "tm-list-metrics", "index": ALL}, "value"),
936 Output({"type": "ctrl-dd", "index": "dut"}, "value"),
937 Output({"type": "ctrl-dd", "index": "phy"}, "options"),
938 Output({"type": "ctrl-dd", "index": "phy"}, "disabled"),
939 Output({"type": "ctrl-dd", "index": "phy"}, "value"),
940 Output({"type": "ctrl-dd", "index": "area"}, "options"),
941 Output({"type": "ctrl-dd", "index": "area"}, "disabled"),
942 Output({"type": "ctrl-dd", "index": "area"}, "value"),
943 Output({"type": "ctrl-dd", "index": "test"}, "options"),
944 Output({"type": "ctrl-dd", "index": "test"}, "disabled"),
945 Output({"type": "ctrl-dd", "index": "test"}, "value"),
946 Output({"type": "ctrl-cl", "index": "core"}, "options"),
947 Output({"type": "ctrl-cl", "index": "core"}, "value"),
948 Output({"type": "ctrl-cl", "index": "core-all"}, "value"),
949 Output({"type": "ctrl-cl", "index": "core-all"}, "options"),
950 Output({"type": "ctrl-cl", "index": "frmsize"}, "options"),
951 Output({"type": "ctrl-cl", "index": "frmsize"}, "value"),
952 Output({"type": "ctrl-cl", "index": "frmsize-all"}, "value"),
953 Output({"type": "ctrl-cl", "index": "frmsize-all"}, "options"),
954 Output({"type": "ctrl-cl", "index": "tsttype"}, "options"),
955 Output({"type": "ctrl-cl", "index": "tsttype"}, "value"),
956 Output({"type": "ctrl-cl", "index": "tsttype-all"}, "value"),
957 Output({"type": "ctrl-cl", "index": "tsttype-all"}, "options"),
958 Output({"type": "ctrl-btn", "index": "add-test"}, "disabled"),
959 Output("normalize", "value"),
961 State("store", "data"),
962 State({"type": "sel-cl", "index": ALL}, "value"),
963 State({"type": "cb-all-in-one", "index": ALL}, "value"),
964 State({"type": "cb-ignore-host", "index": ALL}, "value"),
965 State({"type": "telemetry-search-out", "index": ALL}, "children"),
966 State({"type": "plot-mod-telemetry", "index": ALL}, "is_open"),
967 State({"type": "telemetry-btn", "index": ALL}, "disabled"),
968 State({"type": "tm-container", "index": ALL}, "children"),
969 State({"type": "tm-list-metrics", "index": ALL}, "value"),
970 State({"type": "tele-cl", "index": ALL}, "value"),
972 Input("url", "href"),
973 Input({"type": "tm-dd", "index": ALL}, "value"),
975 Input("normalize", "value"),
976 Input({"type": "telemetry-search-in", "index": ALL}, "value"),
977 Input({"type": "telemetry-btn", "index": ALL}, "n_clicks"),
978 Input({"type": "tm-btn-remove", "index": ALL}, "n_clicks"),
979 Input({"type": "ctrl-dd", "index": ALL}, "value"),
980 Input({"type": "ctrl-cl", "index": ALL}, "value"),
981 Input({"type": "ctrl-btn", "index": ALL}, "n_clicks"),
983 prevent_initial_call=True
985 def _update_application(
992 tm_btns_disabled: list,
1000 """Update the application when the event is detected.
1005 "control-panel": dict(),
1006 "selected-tests": list(),
1007 "trending-graphs": None,
1008 "telemetry-data": dict(),
1009 "selected-metrics": dict(),
1010 "telemetry-panels": list(),
1011 "telemetry-all-in-one": list(),
1012 "telemetry-ignore-host": list(),
1013 "telemetry-graphs": list(),
1017 ctrl_panel = ControlPanel(
1019 store.get("control-panel", dict())
1021 store_sel = store["selected-tests"]
1022 tm_data = store["telemetry-data"]
1023 tm_user = store["selected-metrics"]
1024 tm_panels = store["telemetry-panels"]
1025 tm_all_in_one = store["telemetry-all-in-one"]
1026 tm_ignore_host = store["telemetry-ignore-host"]
1028 plotting_area_telemetry = no_update
1029 on_draw = [False, False] # 0 --> trending, 1 --> telemetry
1032 parsed_url = url_decode(href)
1034 url_params = parsed_url["params"]
1039 # Telemetry user data
1040 # The data provided by user or result of user action
1042 # List of unique metrics:
1043 "unique_metrics": list(),
1044 # List of metrics selected by user:
1045 "selected_metrics": list(),
1046 # Labels from metrics selected by user (key: label name,
1047 # value: list of all possible values):
1048 "unique_labels": dict(),
1049 # Labels selected by the user (subset of 'unique_labels'):
1050 "selected_labels": dict(),
1051 # All unique metrics with labels (output from the step 1)
1052 # converted from pandas dataframe to dictionary.
1053 "unique_metrics_with_labels": dict(),
1054 # Metrics with labels selected by the user using dropdowns.
1055 "selected_metrics_with_labels": dict()
1057 tm = TelemetryData(store_sel) if store_sel else TelemetryData()
1059 trigger = Trigger(callback_context.triggered)
1060 if trigger.type == "url" and url_params:
1063 store_sel = literal_eval(url_params["store_sel"][0])
1064 normalize = literal_eval(url_params["norm"][0])
1065 telemetry = literal_eval(url_params["telemetry"][0])
1066 url_p = url_params.get("all-in-one", ["[[None]]"])
1067 tm_all_in_one = literal_eval(url_p[0])
1068 url_p = url_params.get("ignore-host", ["[[None]]"])
1069 tm_ignore_host = literal_eval(url_p[0])
1070 if not isinstance(telemetry, list):
1071 telemetry = [telemetry, ]
1072 except (KeyError, IndexError, AttributeError, ValueError):
1075 last_test = store_sel[-1]
1076 test = self._spec_tbs[last_test["dut"]][last_test["phy"]]\
1077 [last_test["area"]][last_test["test"]]
1079 "dd-dut-val": last_test["dut"],
1080 "dd-phy-val": last_test["phy"],
1081 "dd-phy-opt": generate_options(
1082 self._spec_tbs[last_test["dut"]].keys()
1084 "dd-phy-dis": False,
1085 "dd-area-val": last_test["area"],
1087 {"label": label(v), "value": v} for v in sorted(
1088 self._spec_tbs[last_test["dut"]]\
1089 [last_test["phy"]].keys()
1092 "dd-area-dis": False,
1093 "dd-test-val": last_test["test"],
1094 "dd-test-opt": generate_options(
1095 self._spec_tbs[last_test["dut"]][last_test["phy"]]\
1096 [last_test["area"]].keys()
1098 "dd-test-dis": False,
1099 "cl-core-opt": generate_options(test["core"]),
1100 "cl-core-val": [last_test["core"].upper(), ],
1101 "cl-core-all-val": list(),
1102 "cl-core-all-opt": C.CL_ALL_ENABLED,
1103 "cl-frmsize-opt": generate_options(test["frame-size"]),
1104 "cl-frmsize-val": [last_test["framesize"].upper(), ],
1105 "cl-frmsize-all-val": list(),
1106 "cl-frmsize-all-opt": C.CL_ALL_ENABLED,
1107 "cl-tsttype-opt": generate_options(test["test-type"]),
1108 "cl-tsttype-val": [last_test["testtype"].upper(), ],
1109 "cl-tsttype-all-val": list(),
1110 "cl-tsttype-all-opt": C.CL_ALL_ENABLED,
1111 "cl-normalize-val": normalize,
1112 "btn-add-dis": False
1114 store["trending-graphs"] = None
1115 store["telemetry-graphs"] = list()
1118 tm = TelemetryData(store_sel)
1119 tm.from_dataframe(self._data)
1120 tm_data = tm.to_json()
1121 tm.from_json(tm_data)
1122 tm_panels = telemetry
1124 elif trigger.type == "normalize":
1125 ctrl_panel.set({"cl-normalize-val": trigger.value})
1126 store["trending-graphs"] = None
1128 elif trigger.type == "ctrl-dd":
1129 if trigger.idx == "dut":
1131 options = generate_options(
1132 self._spec_tbs[trigger.value].keys()
1139 "dd-dut-val": trigger.value,
1140 "dd-phy-val": str(),
1141 "dd-phy-opt": options,
1142 "dd-phy-dis": disabled,
1143 "dd-area-val": str(),
1144 "dd-area-opt": list(),
1145 "dd-area-dis": True,
1146 "dd-test-val": str(),
1147 "dd-test-opt": list(),
1148 "dd-test-dis": True,
1149 "cl-core-opt": list(),
1150 "cl-core-val": list(),
1151 "cl-core-all-val": list(),
1152 "cl-core-all-opt": C.CL_ALL_DISABLED,
1153 "cl-frmsize-opt": list(),
1154 "cl-frmsize-val": list(),
1155 "cl-frmsize-all-val": list(),
1156 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1157 "cl-tsttype-opt": list(),
1158 "cl-tsttype-val": list(),
1159 "cl-tsttype-all-val": list(),
1160 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1163 elif trigger.idx == "phy":
1165 dut = ctrl_panel.get("dd-dut-val")
1166 phy = self._spec_tbs[dut][trigger.value]
1167 options = [{"label": label(v), "value": v} \
1168 for v in sorted(phy.keys())]
1174 "dd-phy-val": trigger.value,
1175 "dd-area-val": str(),
1176 "dd-area-opt": options,
1177 "dd-area-dis": disabled,
1178 "dd-test-val": str(),
1179 "dd-test-opt": list(),
1180 "dd-test-dis": True,
1181 "cl-core-opt": list(),
1182 "cl-core-val": list(),
1183 "cl-core-all-val": list(),
1184 "cl-core-all-opt": C.CL_ALL_DISABLED,
1185 "cl-frmsize-opt": list(),
1186 "cl-frmsize-val": list(),
1187 "cl-frmsize-all-val": list(),
1188 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1189 "cl-tsttype-opt": list(),
1190 "cl-tsttype-val": list(),
1191 "cl-tsttype-all-val": list(),
1192 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1195 elif trigger.idx == "area":
1197 dut = ctrl_panel.get("dd-dut-val")
1198 phy = ctrl_panel.get("dd-phy-val")
1199 area = self._spec_tbs[dut][phy][trigger.value]
1200 options = generate_options(area.keys())
1206 "dd-area-val": trigger.value,
1207 "dd-test-val": str(),
1208 "dd-test-opt": options,
1209 "dd-test-dis": disabled,
1210 "cl-core-opt": list(),
1211 "cl-core-val": list(),
1212 "cl-core-all-val": list(),
1213 "cl-core-all-opt": C.CL_ALL_DISABLED,
1214 "cl-frmsize-opt": list(),
1215 "cl-frmsize-val": list(),
1216 "cl-frmsize-all-val": list(),
1217 "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1218 "cl-tsttype-opt": list(),
1219 "cl-tsttype-val": list(),
1220 "cl-tsttype-all-val": list(),
1221 "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1224 elif trigger.idx == "test":
1225 dut = ctrl_panel.get("dd-dut-val")
1226 phy = ctrl_panel.get("dd-phy-val")
1227 area = ctrl_panel.get("dd-area-val")
1228 if all((dut, phy, area, trigger.value, )):
1229 test = self._spec_tbs[dut][phy][area][trigger.value]
1231 "dd-test-val": trigger.value,
1232 "cl-core-opt": generate_options(test["core"]),
1233 "cl-core-val": list(),
1234 "cl-core-all-val": list(),
1235 "cl-core-all-opt": C.CL_ALL_ENABLED,
1237 generate_options(test["frame-size"]),
1238 "cl-frmsize-val": list(),
1239 "cl-frmsize-all-val": list(),
1240 "cl-frmsize-all-opt": C.CL_ALL_ENABLED,
1242 generate_options(test["test-type"]),
1243 "cl-tsttype-val": list(),
1244 "cl-tsttype-all-val": list(),
1245 "cl-tsttype-all-opt": C.CL_ALL_ENABLED,
1248 elif trigger.type == "ctrl-cl":
1249 param = trigger.idx.split("-")[0]
1250 if "-all" in trigger.idx:
1251 c_sel, c_all, c_id = list(), trigger.value, "all"
1253 c_sel, c_all, c_id = trigger.value, list(), str()
1254 val_sel, val_all = sync_checklists(
1255 options=ctrl_panel.get(f"cl-{param}-opt"),
1261 f"cl-{param}-val": val_sel,
1262 f"cl-{param}-all-val": val_all,
1264 if all((ctrl_panel.get("cl-core-val"),
1265 ctrl_panel.get("cl-frmsize-val"),
1266 ctrl_panel.get("cl-tsttype-val"), )):
1267 ctrl_panel.set({"btn-add-dis": False})
1269 ctrl_panel.set({"btn-add-dis": True})
1270 elif trigger.type == "ctrl-btn":
1272 tm_all_in_one = list()
1273 tm_ignore_host = list()
1274 store["trending-graphs"] = None
1275 store["telemetry-graphs"] = list()
1277 on_draw = [True, True]
1278 if trigger.idx == "add-test":
1279 dut = ctrl_panel.get("dd-dut-val")
1280 phy = ctrl_panel.get("dd-phy-val")
1281 area = ctrl_panel.get("dd-area-val")
1282 test = ctrl_panel.get("dd-test-val")
1283 # Add selected test(s) to the list of tests in store:
1284 if store_sel is None:
1286 for core in ctrl_panel.get("cl-core-val"):
1287 for framesize in ctrl_panel.get("cl-frmsize-val"):
1288 for ttype in ctrl_panel.get("cl-tsttype-val"):
1293 phy.replace('af_xdp', 'af-xdp'),
1300 if tid not in [i["id"] for i in store_sel]:
1307 "framesize": framesize.lower(),
1308 "core": core.lower(),
1309 "testtype": ttype.lower()
1311 store_sel = sorted(store_sel, key=lambda d: d["id"])
1312 if C.CLEAR_ALL_INPUTS:
1313 ctrl_panel.set(ctrl_panel.defaults)
1314 elif trigger.idx == "rm-test" and lst_sel:
1315 new_store_sel = list()
1316 for idx, item in enumerate(store_sel):
1317 if not lst_sel[idx]:
1318 new_store_sel.append(item)
1319 store_sel = new_store_sel
1320 elif trigger.idx == "rm-test-all":
1322 elif trigger.type == "telemetry-btn":
1323 if trigger.idx in ("open", "back"):
1324 tm.from_dataframe(self._data)
1325 tm_data = tm.to_json()
1326 tm_user["unique_metrics"] = tm.unique_metrics
1327 tm_user["selected_metrics"] = list()
1328 tm_user["unique_labels"] = dict()
1329 tm_user["selected_labels"] = dict()
1331 get_list_group_items(tm_user["unique_metrics"],
1334 is_open = (True, False)
1335 tm_btns_disabled[1], tm_btns_disabled[5] = False, True
1336 elif trigger.idx == "select":
1338 tm.from_json(tm_data)
1339 if not tm_user["selected_metrics"]:
1340 tm_user["selected_metrics"] = \
1341 tm_user["unique_metrics"]
1342 metrics = [a for a, b in \
1343 zip(tm_user["selected_metrics"], cl_metrics) if b]
1344 tm_user["selected_metrics"] = metrics
1345 tm_user["unique_labels"] = \
1346 tm.get_selected_labels(metrics)
1347 tm_user["unique_metrics_with_labels"] = \
1348 tm.unique_metrics_with_labels
1349 list_metrics[0] = tm.str_metrics
1350 tm_dd[0] = _get_dd_container(tm_user["unique_labels"])
1352 tm_btns_disabled[1] = True
1353 tm_btns_disabled[4] = False
1354 is_open = (False, True)
1356 is_open = (True, False)
1357 elif trigger.idx == "add":
1358 tm.from_json(tm_data)
1359 tm_panels.append(tm_user["selected_metrics_with_labels"])
1360 tm_all_in_one.append(all_in_one)
1361 tm_ignore_host.append(ignore_host)
1362 is_open = (False, False)
1363 tm_btns_disabled[1], tm_btns_disabled[5] = True, True
1364 on_draw = [True, True]
1365 elif trigger.idx == "cancel":
1366 is_open = (False, False)
1367 tm_btns_disabled[1], tm_btns_disabled[5] = True, True
1368 elif trigger.idx == "rm-all":
1370 tm_all_in_one = list()
1371 tm_ignore_host = list()
1373 is_open = (False, False)
1374 tm_btns_disabled[1], tm_btns_disabled[5] = True, True
1375 plotting_area_telemetry = C.PLACEHOLDER
1376 elif trigger.type == "telemetry-search-in":
1377 tm.from_metrics(tm_user["unique_metrics"])
1378 tm_user["selected_metrics"] = \
1379 tm.search_unique_metrics(trigger.value)
1380 search_out = (get_list_group_items(
1381 tm_user["selected_metrics"],
1385 is_open = (True, False)
1386 elif trigger.type == "tm-dd":
1387 tm.from_metrics_with_labels(
1388 tm_user["unique_metrics_with_labels"]
1392 for itm in tm_dd_in:
1395 elif isinstance(itm, str):
1397 selected[itm] = list()
1398 elif isinstance(itm, list):
1399 if previous_itm is not None:
1400 selected[previous_itm] = itm
1403 tm_dd[0] = _get_dd_container(
1404 tm_user["unique_labels"],
1408 sel_metrics = tm.filter_selected_metrics_by_labels(selected)
1409 tm_user["selected_metrics_with_labels"] = sel_metrics.to_dict()
1410 if not sel_metrics.empty:
1411 list_metrics[0] = tm.metrics_to_str(sel_metrics)
1412 tm_btns_disabled[5] = False
1414 list_metrics[0] = str()
1415 elif trigger.type == "tm-btn-remove":
1416 del tm_panels[trigger.idx]
1417 del tm_all_in_one[trigger.idx]
1418 del tm_ignore_host[trigger.idx]
1419 del store["telemetry-graphs"][trigger.idx]
1420 tm.from_json(tm_data)
1421 on_draw = [True, True]
1424 "store_sel": store_sel,
1425 "norm": ctrl_panel.get("cl-normalize-val")
1428 new_url_params["telemetry"] = tm_panels
1429 new_url_params["all-in-one"] = tm_all_in_one
1430 new_url_params["ignore-host"] = tm_ignore_host
1432 if on_draw[0]: # Trending
1434 lg_selected = get_list_group_items(store_sel, "sel-cl")
1435 if store["trending-graphs"]:
1436 graphs = store["trending-graphs"]
1438 graphs = graph_trending(
1442 bool(ctrl_panel.get("cl-normalize-val"))
1444 if graphs and graphs[0]:
1445 store["trending-graphs"] = graphs
1446 plotting_area_trending = \
1447 Layout._plotting_area_trending(graphs)
1450 start_idx = len(store["telemetry-graphs"])
1451 end_idx = len(tm_panels)
1453 plotting_area_telemetry = C.PLACEHOLDER
1454 elif on_draw[1] and (end_idx >= start_idx):
1455 if len(tm_all_in_one) != end_idx:
1456 tm_all_in_one = [[None], ] * end_idx
1457 if len(tm_ignore_host) != end_idx:
1458 tm_ignore_host = [[None], ] * end_idx
1459 for idx in range(start_idx, end_idx):
1460 store["telemetry-graphs"].append(graph_tm_trending(
1461 tm.select_tm_trending_data(
1463 ignore_host=bool(tm_ignore_host[idx][0])
1466 bool(tm_all_in_one[idx][0])
1468 plotting_area_telemetry = \
1469 Layout._plotting_area_telemetry(
1470 store["telemetry-graphs"]
1472 col_plotting_area = C.STYLE_ENABLED
1473 row_card_sel_tests = C.STYLE_ENABLED
1474 row_btns_sel_tests = C.STYLE_ENABLED
1475 row_btns_add_tm = C.STYLE_ENABLED
1477 plotting_area_trending = no_update
1478 plotting_area_telemetry = C.PLACEHOLDER
1479 col_plotting_area = C.STYLE_DISABLED
1480 row_card_sel_tests = C.STYLE_DISABLED
1481 row_btns_sel_tests = C.STYLE_DISABLED
1482 row_btns_add_tm = C.STYLE_DISABLED
1483 lg_selected = no_update
1486 tm_all_in_one = list()
1487 tm_ignore_host = list()
1490 plotting_area_trending = no_update
1491 col_plotting_area = no_update
1492 row_card_sel_tests = no_update
1493 row_btns_sel_tests = no_update
1494 row_btns_add_tm = no_update
1495 lg_selected = no_update
1497 store["url"] = gen_new_url(parsed_url, new_url_params)
1498 store["control-panel"] = ctrl_panel.panel
1499 store["selected-tests"] = store_sel
1500 store["telemetry-data"] = tm_data
1501 store["selected-metrics"] = tm_user
1502 store["telemetry-panels"] = tm_panels
1503 store["telemetry-all-in-one"] = tm_all_in_one
1504 store["telemetry-ignore-host"] = tm_ignore_host
1507 plotting_area_trending,
1508 plotting_area_telemetry,
1520 ret_val.extend(ctrl_panel.values)
1524 Output("plot-mod-url", "is_open"),
1525 Output("mod-url", "children"),
1526 State("store", "data"),
1527 State("plot-mod-url", "is_open"),
1528 Input("plot-btn-url", "n_clicks")
1530 def toggle_plot_mod_url(store, is_open, n_clicks):
1531 """Toggle the modal window with url.
1537 return not is_open, store.get("url", str())
1538 return is_open, store["url"]
1540 def _get_dd_container(
1542 selected_labels: dict=dict(),
1545 """Generate a container with dropdown selection boxes depenting on
1548 :param all_labels: A dictionary with unique labels and their
1550 :param selected_labels: A dictionalry with user selected lables and
1552 :param show_new: If True, a dropdown selection box to add a new
1554 :type all_labels: dict
1555 :type selected_labels: dict
1556 :type show_new: bool
1557 :returns: A list of dbc rows with dropdown selection boxes.
1568 """Generates a dbc row with dropdown boxes.
1570 :param id: A string added to the dropdown ID.
1571 :param lopts: A list of options for 'label' dropdown.
1572 :param lval: Value of 'label' dropdown.
1573 :param vopts: A list of options for 'value' dropdown.
1574 :param vvals: A list of values for 'value' dropdown.
1580 :returns: dbc row with dropdown boxes.
1592 "index": f"label-{id}"
1594 placeholder="Select a label...",
1598 value=lval if lval else None
1611 "index": f"value-{id}"
1613 placeholder="Select a value...",
1617 value=vvals if vvals else None
1623 return dbc.Row(class_name="g-0 p-1", children=children)
1627 # Display rows with items in 'selected_labels'; label on the left,
1628 # values on the right:
1629 keys_left = list(all_labels.keys())
1630 for idx, label in enumerate(selected_labels.keys()):
1631 container.append(_row(
1633 lopts=deepcopy(keys_left),
1635 vopts=all_labels[label],
1636 vvals=selected_labels[label]
1638 keys_left.remove(label)
1640 # Display row with dd with labels on the left, right side is empty:
1641 if show_new and keys_left:
1642 container.append(_row(id="new", lopts=keys_left))
1647 Output("metadata-tput-lat", "children"),
1648 Output("metadata-hdrh-graph", "children"),
1649 Output("offcanvas-metadata", "is_open"),
1650 Input({"type": "graph", "index": ALL}, "clickData"),
1651 prevent_initial_call=True
1653 def _show_metadata_from_graphs(graph_data: dict) -> tuple:
1654 """Generates the data for the offcanvas displayed when a particular
1655 point in a graph is clicked on.
1657 :param graph_data: The data from the clicked point in the graph.
1658 :type graph_data: dict
1659 :returns: The data to be displayed on the offcanvas and the
1660 information to show the offcanvas.
1661 :rtype: tuple(list, list, bool)
1664 trigger = Trigger(callback_context.triggered)
1667 idx = 0 if trigger.idx == "tput" else 1
1668 graph_data = graph_data[idx]["points"][0]
1669 except (IndexError, KeyError, ValueError, TypeError):
1672 metadata = no_update
1677 [dbc.Badge(x.split(":")[0]), x.split(": ")[1]]
1678 ) for x in graph_data.get("text", "").split("<br>")
1680 if trigger.idx == "tput":
1681 title = "Throughput"
1682 elif trigger.idx == "lat":
1684 hdrh_data = graph_data.get("customdata", None)
1687 class_name="gy-2 p-0",
1689 dbc.CardHeader(hdrh_data.pop("name")),
1690 dbc.CardBody(children=[
1692 id="hdrh-latency-graph",
1693 figure=graph_hdrh_latency(
1694 hdrh_data, self._graph_layout
1705 class_name="gy-2 p-0",
1707 dbc.CardHeader(children=[
1709 target_id="tput-lat-metadata",
1711 style={"display": "inline-block"}
1716 id="tput-lat-metadata",
1718 children=[dbc.ListGroup(children, flush=True), ]
1724 return metadata, graph, True
1727 Output("download-trending-data", "data"),
1728 State("store", "data"),
1729 Input("plot-btn-download", "n_clicks"),
1730 Input({"type": "tm-btn-download", "index": ALL}, "n_clicks"),
1731 prevent_initial_call=True
1733 def _download_data(store: list, *_) -> dict:
1734 """Download the data
1736 :param store_sel: List of tests selected by user stored in the
1738 :type store_sel: list
1739 :returns: dict of data frame content (base64 encoded) and meta data
1740 used by the Download component.
1746 if not store["selected-tests"]:
1751 trigger = Trigger(callback_context.triggered)
1752 if not trigger.value:
1755 if trigger.type == "plot-btn-download":
1757 for itm in store["selected-tests"]:
1758 sel_data = select_trending_data(self._data, itm)
1759 if sel_data is None:
1761 data.append(sel_data)
1762 df = pd.concat(data, ignore_index=True, copy=False)
1763 file_name = C.TREND_DOWNLOAD_FILE_NAME
1764 elif trigger.type == "tm-btn-download":
1765 tm = TelemetryData(store["selected-tests"])
1766 tm.from_json(store["telemetry-data"])
1767 df = tm.select_tm_trending_data(
1768 store["telemetry-panels"][trigger.idx]
1770 file_name = C.TELEMETRY_DOWNLOAD_FILE_NAME
1774 return dcc.send_data_frame(df.to_csv, file_name)