C-Dash: Add search in tests
[csit.git] / csit.infra.dash / app / cdash / report / layout.py
1 # Copyright (c) 2024 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:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
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.
13
14 """Plotly Dash HTML layout override.
15 """
16
17
18 import logging
19 import pandas as pd
20 import dash_bootstrap_components as dbc
21
22 from flask import Flask
23 from dash import dcc
24 from dash import html
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
31 from ..utils.constants import Constants as C
32 from ..utils.control_panel import ControlPanel
33 from ..utils.trigger import Trigger
34 from ..utils.utils import show_tooltip, label, sync_checklists, gen_new_url, \
35     generate_options, get_list_group_items, navbar_report, \
36     show_iterative_graph_data
37 from ..utils.url_processing import url_decode
38 from .graphs import graph_iterative, select_iterative_data
39
40
41 # Control panel partameters and their default values.
42 CP_PARAMS = {
43     "dd-rls-val": str(),
44     "dd-dut-opt": list(),
45     "dd-dut-dis": True,
46     "dd-dut-val": str(),
47     "dd-dutver-opt": list(),
48     "dd-dutver-dis": True,
49     "dd-dutver-val": str(),
50     "dd-phy-opt": list(),
51     "dd-phy-dis": True,
52     "dd-phy-val": str(),
53     "dd-area-opt": list(),
54     "dd-area-dis": True,
55     "dd-area-val": str(),
56     "dd-test-opt": list(),
57     "dd-test-dis": True,
58     "dd-test-val": str(),
59     "cl-core-opt": list(),
60     "cl-core-val": list(),
61     "cl-core-all-val": list(),
62     "cl-core-all-opt": C.CL_ALL_DISABLED,
63     "cl-frmsize-opt": list(),
64     "cl-frmsize-val": list(),
65     "cl-frmsize-all-val": list(),
66     "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
67     "cl-tsttype-opt": list(),
68     "cl-tsttype-val": list(),
69     "cl-tsttype-all-val": list(),
70     "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
71     "btn-add-dis": True,
72     "cl-normalize-val": list()
73 }
74
75
76 class Layout:
77     """The layout of the dash app and the callbacks.
78     """
79
80     def __init__(
81             self,
82             app: Flask,
83             data_iterative: pd.DataFrame,
84             html_layout_file: str,
85             graph_layout_file: str,
86             tooltip_file: str
87         ) -> None:
88         """Initialization:
89         - save the input parameters,
90         - read and pre-process the data,
91         - prepare data for the control panel,
92         - read HTML layout file,
93         - read tooltips from the tooltip file.
94
95         :param app: Flask application running the dash application.
96         :param html_layout_file: Path and name of the file specifying the HTML
97             layout of the dash application.
98         :param graph_layout_file: Path and name of the file with layout of
99             plot.ly graphs.
100         :param tooltip_file: Path and name of the yaml file specifying the
101             tooltips.
102         :type app: Flask
103         :type html_layout_file: str
104         :type graph_layout_file: str
105         :type tooltip_file: str
106         """
107
108         # Inputs
109         self._app = app
110         self._html_layout_file = html_layout_file
111         self._graph_layout_file = graph_layout_file
112         self._tooltip_file = tooltip_file
113         self._data = data_iterative
114
115         # Get structure of tests:
116         tbs = dict()
117         cols = [
118             "job", "test_id", "test_type", "dut_version", "tg_type", "release"
119         ]
120         for _, row in self._data[cols].drop_duplicates().iterrows():
121             rls = row["release"]
122             lst_job = row["job"].split("-")
123             dut = lst_job[1]
124             d_ver = row["dut_version"]
125             tbed = "-".join(lst_job[-2:])
126             lst_test_id = row["test_id"].split(".")
127             if dut == "dpdk":
128                 area = "dpdk"
129             else:
130                 area = ".".join(lst_test_id[3:-2])
131             suite = lst_test_id[-2].replace("2n1l-", "").replace("1n1l-", "").\
132                 replace("2n-", "")
133             test = lst_test_id[-1]
134             nic = suite.split("-")[0]
135             for drv in C.DRIVERS:
136                 if drv in test:
137                     driver = drv.replace("-", "_")
138                     test = test.replace(f"{drv}-", "")
139                     break
140             else:
141                 driver = "dpdk"
142             infra = "-".join((tbed, nic, driver))
143             lst_test = test.split("-")
144             framesize = lst_test[0]
145             core = lst_test[1] if lst_test[1] else "8C"
146             test = "-".join(lst_test[2: -1])
147
148             if tbs.get(rls, None) is None:
149                 tbs[rls] = dict()
150             if tbs[rls].get(dut, None) is None:
151                 tbs[rls][dut] = dict()
152             if tbs[rls][dut].get(d_ver, None) is None:
153                 tbs[rls][dut][d_ver] = dict()
154             if tbs[rls][dut][d_ver].get(area, None) is None:
155                 tbs[rls][dut][d_ver][area] = dict()
156             if tbs[rls][dut][d_ver][area].get(test, None) is None:
157                 tbs[rls][dut][d_ver][area][test] = dict()
158             if tbs[rls][dut][d_ver][area][test].get(infra, None) is None:
159                 tbs[rls][dut][d_ver][area][test][infra] = {
160                     "core": list(),
161                     "frame-size": list(),
162                     "test-type": list()
163                 }
164             tst_params = tbs[rls][dut][d_ver][area][test][infra]
165             if core.upper() not in tst_params["core"]:
166                 tst_params["core"].append(core.upper())
167             if framesize.upper() not in tst_params["frame-size"]:
168                 tst_params["frame-size"].append(framesize.upper())
169             if row["test_type"] == "mrr":
170                 if "MRR" not in tst_params["test-type"]:
171                     tst_params["test-type"].append("MRR")
172             elif row["test_type"] == "ndrpdr":
173                 if "NDR" not in tst_params["test-type"]:
174                     tst_params["test-type"].extend(("NDR", "PDR", ))
175             elif row["test_type"] == "hoststack" and \
176                     row["tg_type"] in ("iperf", "vpp"):
177                 if "BPS" not in tst_params["test-type"]:
178                     tst_params["test-type"].append("BPS")
179             elif row["test_type"] == "hoststack" and row["tg_type"] == "ab":
180                 if "CPS" not in tst_params["test-type"]:
181                     tst_params["test-type"].extend(("CPS", "RPS"))
182         self._spec_tbs = tbs
183
184         # Read from files:
185         self._html_layout = str()
186         self._graph_layout = None
187         self._tooltips = dict()
188
189         try:
190             with open(self._html_layout_file, "r") as file_read:
191                 self._html_layout = file_read.read()
192         except IOError as err:
193             raise RuntimeError(
194                 f"Not possible to open the file {self._html_layout_file}\n{err}"
195             )
196
197         try:
198             with open(self._graph_layout_file, "r") as file_read:
199                 self._graph_layout = load(file_read, Loader=FullLoader)
200         except IOError as err:
201             raise RuntimeError(
202                 f"Not possible to open the file {self._graph_layout_file}\n"
203                 f"{err}"
204             )
205         except YAMLError as err:
206             raise RuntimeError(
207                 f"An error occurred while parsing the specification file "
208                 f"{self._graph_layout_file}\n{err}"
209             )
210
211         try:
212             with open(self._tooltip_file, "r") as file_read:
213                 self._tooltips = load(file_read, Loader=FullLoader)
214         except IOError as err:
215             logging.warning(
216                 f"Not possible to open the file {self._tooltip_file}\n{err}"
217             )
218         except YAMLError as err:
219             logging.warning(
220                 f"An error occurred while parsing the specification file "
221                 f"{self._tooltip_file}\n{err}"
222             )
223
224         # Callbacks:
225         if self._app is not None and hasattr(self, "callbacks"):
226             self.callbacks(self._app)
227
228     @property
229     def html_layout(self):
230         return self._html_layout
231
232     def add_content(self):
233         """Top level method which generated the web page.
234
235         It generates:
236         - Store for user input data,
237         - Navigation bar,
238         - Main area with control panel and ploting area.
239
240         If no HTML layout is provided, an error message is displayed instead.
241
242         :returns: The HTML div with the whole page.
243         :rtype: html.Div
244         """
245
246         if self.html_layout and self._spec_tbs:
247             return html.Div(
248                 id="div-main",
249                 className="small",
250                 children=[
251                     dbc.Row(
252                         id="row-navbar",
253                         class_name="g-0",
254                         children=[navbar_report((True, False, False, False)), ]
255                     ),
256                     dbc.Row(
257                         id="row-main",
258                         class_name="g-0",
259                         children=[
260                             dcc.Store(id="store-selected-tests"),
261                             dcc.Store(id="store-control-panel"),
262                             dcc.Location(id="url", refresh=False),
263                             self._add_ctrl_col(),
264                             self._add_plotting_col()
265                         ]
266                     ),
267                     dbc.Spinner(
268                         dbc.Offcanvas(
269                             class_name="w-50",
270                             id="offcanvas-metadata",
271                             title="Throughput And Latency",
272                             placement="end",
273                             is_open=False,
274                             children=[
275                                 dbc.Row(id="metadata-tput-lat"),
276                                 dbc.Row(id="metadata-hdrh-graph")
277                             ]
278                         ),
279                         delay_show=C.SPINNER_DELAY
280                     ),
281                     dbc.Offcanvas(
282                         class_name="w-75",
283                         id="offcanvas-documentation",
284                         title="Documentation",
285                         placement="end",
286                         is_open=False,
287                         children=html.Iframe(
288                             src=C.URL_DOC_REL_NOTES,
289                             width="100%",
290                             height="100%"
291                         )
292                     )
293                 ]
294             )
295         else:
296             return html.Div(
297                 id="div-main-error",
298                 children=[
299                     dbc.Alert(
300                         [
301                             "An Error Occured"
302                         ],
303                         color="danger"
304                     )
305                 ]
306             )
307
308     def _add_ctrl_col(self) -> dbc.Col:
309         """Add column with controls. It is placed on the left side.
310
311         :returns: Column with the control panel.
312         :rtype: dbc.Col
313         """
314         return dbc.Col([
315             html.Div(
316                 children=self._add_ctrl_panel(),
317                 className="sticky-top"
318             )
319         ])
320
321     def _add_plotting_col(self) -> dbc.Col:
322         """Add column with plots. It is placed on the right side.
323
324         :returns: Column with plots.
325         :rtype: dbc.Col
326         """
327         return dbc.Col(
328             id="col-plotting-area",
329             children=[
330                 dbc.Spinner(
331                     children=[
332                         dbc.Row(
333                             id="plotting-area",
334                             class_name="g-0 p-0",
335                             children=[
336                                 C.PLACEHOLDER
337                             ]
338                         )
339                     ]
340                 )
341             ],
342             width=9
343         )
344
345     def _add_ctrl_panel(self) -> list:
346         """Add control panel.
347
348         :returns: Control panel.
349         :rtype: list
350         """
351         return [
352             dbc.Row(
353                 class_name="g-0 p-1",
354                 children=[
355                     dbc.InputGroup(
356                         [
357                             dbc.InputGroupText(
358                                 children=show_tooltip(
359                                     self._tooltips,
360                                     "help-release",
361                                     "CSIT Release"
362                                 )
363                             ),
364                             dbc.Select(
365                                 id={"type": "ctrl-dd", "index": "rls"},
366                                 placeholder="Select a Release...",
367                                 options=sorted(
368                                     [
369                                         {"label": k, "value": k} \
370                                             for k in self._spec_tbs.keys()
371                                     ],
372                                     key=lambda d: d["label"]
373                                 )
374                             )
375                         ],
376                         size="sm"
377                     )
378                 ]
379             ),
380             dbc.Row(
381                 class_name="g-0 p-1",
382                 children=[
383                     dbc.InputGroup(
384                         [
385                             dbc.InputGroupText(
386                                 children=show_tooltip(
387                                     self._tooltips,
388                                     "help-dut",
389                                     "DUT"
390                                 )
391                             ),
392                             dbc.Select(
393                                 id={"type": "ctrl-dd", "index": "dut"},
394                                 placeholder="Select a Device under Test..."
395                             )
396                         ],
397                         size="sm"
398                     )
399                 ]
400             ),
401             dbc.Row(
402                 class_name="g-0 p-1",
403                 children=[
404                     dbc.InputGroup(
405                         [
406                             dbc.InputGroupText(
407                                 children=show_tooltip(
408                                     self._tooltips,
409                                     "help-dut-ver",
410                                     "DUT Version"
411                                 )
412                             ),
413                             dbc.Select(
414                                 id={"type": "ctrl-dd", "index": "dutver"},
415                                 placeholder=\
416                                     "Select a Version of Device under Test..."
417                             )
418                         ],
419                         size="sm"
420                     )
421                 ]
422             ),
423             dbc.Row(
424                 class_name="g-0 p-1",
425                 children=[
426                     dbc.InputGroup(
427                         [
428                             dbc.InputGroupText(
429                                 children=show_tooltip(
430                                     self._tooltips,
431                                     "help-area",
432                                     "Area"
433                                 )
434                             ),
435                             dbc.Select(
436                                 id={"type": "ctrl-dd", "index": "area"},
437                                 placeholder="Select an Area..."
438                             )
439                         ],
440                         size="sm"
441                     )
442                 ]
443             ),
444             dbc.Row(
445                 class_name="g-0 p-1",
446                 children=[
447                     dbc.InputGroup(
448                         [
449                             dbc.InputGroupText(
450                                 children=show_tooltip(
451                                     self._tooltips,
452                                     "help-test",
453                                     "Test"
454                                 )
455                             ),
456                             dbc.Select(
457                                 id={"type": "ctrl-dd", "index": "test"},
458                                 placeholder="Select a Test..."
459                             )
460                         ],
461                         size="sm"
462                     )
463                 ]
464             ),
465             dbc.Row(
466                 class_name="g-0 p-1",
467                 children=[
468                     dbc.InputGroup(
469                         [
470                             dbc.InputGroupText(
471                                 children=show_tooltip(
472                                     self._tooltips,
473                                     "help-infra",
474                                     "Infra"
475                                 )
476                             ),
477                             dbc.Select(
478                                 id={"type": "ctrl-dd", "index": "phy"},
479                                 placeholder=\
480                                     "Select a Physical Test Bed Topology..."
481                             )
482                         ],
483                         size="sm"
484                     )
485                 ]
486             ),
487             dbc.Row(
488                 class_name="g-0 p-1",
489                 children=[
490                     dbc.InputGroup(
491                         [
492                             dbc.InputGroupText(
493                                 children=show_tooltip(
494                                     self._tooltips,
495                                     "help-framesize",
496                                     "Frame Size"
497                                 )
498                             ),
499                             dbc.Col(
500                                 children=[
501                                     dbc.Checklist(
502                                         id={
503                                             "type": "ctrl-cl",
504                                             "index": "frmsize-all"
505                                         },
506                                         options=C.CL_ALL_DISABLED,
507                                         inline=True,
508                                         class_name="ms-2"
509                                     )
510                                 ],
511                                 width=2
512                             ),
513                             dbc.Col(
514                                 children=[
515                                     dbc.Checklist(
516                                         id={
517                                             "type": "ctrl-cl",
518                                             "index": "frmsize"
519                                         },
520                                         inline=True
521                                     )
522                                 ]
523                             )
524                         ],
525                         style={"align-items": "center"},
526                         size="sm"
527                     )
528                 ]
529             ),
530             dbc.Row(
531                 class_name="g-0 p-1",
532                 children=[
533                     dbc.InputGroup(
534                         [
535                             dbc.InputGroupText(
536                                 children=show_tooltip(
537                                     self._tooltips,
538                                     "help-cores",
539                                     "Number of Cores"
540                                 )
541                             ),
542                             dbc.Col(
543                                 children=[
544                                     dbc.Checklist(
545                                         id={
546                                             "type": "ctrl-cl",
547                                             "index": "core-all"
548                                         },
549                                         options=C.CL_ALL_DISABLED,
550                                         inline=True,
551                                         class_name="ms-2"
552                                     )
553                                 ],
554                                 width=2
555                             ),
556                             dbc.Col(
557                                 children=[
558                                     dbc.Checklist(
559                                         id={
560                                             "type": "ctrl-cl",
561                                             "index": "core"
562                                         },
563                                         inline=True
564                                     )
565                                 ]
566                             )
567                         ],
568                         style={"align-items": "center"},
569                         size="sm"
570                     )
571                 ]
572             ),
573             dbc.Row(
574                 class_name="g-0 p-1",
575                 children=[
576                     dbc.InputGroup(
577                         [
578                             dbc.InputGroupText(
579                                 children=show_tooltip(
580                                     self._tooltips,
581                                     "help-ttype",
582                                     "Test Type"
583                                 )
584                             ),
585                             dbc.Col(
586                                 children=[
587                                     dbc.Checklist(
588                                         id={
589                                             "type": "ctrl-cl",
590                                             "index": "tsttype-all"
591                                         },
592                                         options=C.CL_ALL_DISABLED,
593                                         inline=True,
594                                         class_name="ms-2"
595                                     )
596                                 ],
597                                 width=2
598                             ),
599                             dbc.Col(
600                                 children=[
601                                     dbc.Checklist(
602                                         id={
603                                             "type": "ctrl-cl",
604                                             "index": "tsttype"
605                                         },
606                                         inline=True
607                                     )
608                                 ]
609                             )
610                         ],
611                         style={"align-items": "center"},
612                         size="sm"
613                     )
614                 ]
615             ),
616             dbc.Row(
617                 class_name="g-0 p-1",
618                 children=[
619                     dbc.InputGroup(
620                         [
621                             dbc.InputGroupText(
622                                 children=show_tooltip(
623                                     self._tooltips,
624                                     "help-normalize",
625                                     "Normalization"
626                                 )
627                             ),
628                             dbc.Col(
629                                 children=[
630                                     dbc.Checklist(
631                                         id="normalize",
632                                         options=[{
633                                             "value": "normalize",
634                                             "label": (
635                                                 "Normalize to CPU frequency "
636                                                 "2GHz"
637                                             )
638                                         }],
639                                         value=[],
640                                         inline=True,
641                                         class_name="ms-2"
642                                     )
643                                 ]
644                             )
645                         ],
646                         style={"align-items": "center"},
647                         size="sm"
648                     )
649                 ]
650             ),
651             dbc.Row(
652                 class_name="g-0 p-1",
653                 children=[
654                     dbc.Button(
655                         id={"type": "ctrl-btn", "index": "add-test"},
656                         children="Add Selected",
657                         color="info"
658                     )
659                 ]
660             ),
661             dbc.Row(
662                 id="row-card-sel-tests",
663                 class_name="g-0 p-1",
664                 style=C.STYLE_DISABLED,
665                 children=[
666                     dbc.ListGroup(
667                         class_name="overflow-auto p-0",
668                         id="lg-selected",
669                         children=[],
670                         style={"max-height": "20em"},
671                         flush=True
672                     )
673                 ]
674             ),
675             dbc.Stack(
676                 id="row-btns-sel-tests",
677                 class_name="g-0 p-1",
678                 style=C.STYLE_DISABLED,
679                 gap=2,
680                 children=[
681                     dbc.ButtonGroup(children=[
682                         dbc.Button(
683                             id={"type": "ctrl-btn", "index": "rm-test"},
684                             children="Remove Selected",
685                             class_name="w-100",
686                             color="info",
687                             disabled=False
688                         ),
689                         dbc.Button(
690                             id={"type": "ctrl-btn", "index": "rm-test-all"},
691                             children="Remove All",
692                             class_name="w-100",
693                             color="info",
694                             disabled=False
695                         )
696                     ]),
697                     dbc.ButtonGroup(children=[
698                         dbc.Button(
699                             id="plot-btn-url",
700                             children="Show URL",
701                             class_name="w-100",
702                             color="info",
703                             disabled=False
704                         ),
705                         dbc.Button(
706                             id="plot-btn-download",
707                             children="Download Data",
708                             class_name="w-100",
709                             color="info",
710                             disabled=False
711                         )
712                     ])
713                 ]
714             )
715         ]
716
717     def _get_plotting_area(
718             self,
719             tests: list,
720             normalize: bool,
721             url: str
722         ) -> list:
723         """Generate the plotting area with all its content.
724
725         :param tests: List of tests to be displayed in the graphs.
726         :param normalize: If true, the values in graphs are normalized.
727         :param url: URL to be displayed in the modal window.
728         :type tests: list
729         :type normalize: bool
730         :type url: str
731         :returns: List of rows with elements to be displayed in the plotting
732             area.
733         :rtype: list
734         """
735         if not tests:
736             return C.PLACEHOLDER
737
738         graphs = \
739             graph_iterative(self._data, tests, self._graph_layout, normalize)
740
741         if not graphs[0]:
742             return C.PLACEHOLDER
743         
744         tab_items = [
745             dbc.Tab(
746                 children=dcc.Graph(
747                     id={"type": "graph", "index": "tput"},
748                     figure=graphs[0]
749                 ),
750                 label="Throughput",
751                 tab_id="tab-tput"
752             )
753         ]
754
755         if graphs[1]:
756             tab_items.append(
757                 dbc.Tab(
758                     children=dcc.Graph(
759                         id={"type": "graph", "index": "bandwidth"},
760                         figure=graphs[1]
761                     ),
762                     label="Bandwidth",
763                     tab_id="tab-bandwidth"
764                 )
765             )
766
767         if graphs[2]:
768             tab_items.append(
769                 dbc.Tab(
770                     children=dcc.Graph(
771                         id={"type": "graph", "index": "lat"},
772                         figure=graphs[2]
773                     ),
774                     label="Latency",
775                     tab_id="tab-lat"
776                 )
777             )
778
779         return [
780             dbc.Row(
781                 dbc.Tabs(
782                     children=tab_items,
783                     id="tabs",
784                     active_tab="tab-tput",
785                 ),
786                 class_name="g-0 p-0"
787             ),
788             dbc.Modal(
789                 [
790                     dbc.ModalHeader(dbc.ModalTitle("URL")),
791                     dbc.ModalBody(url)
792                 ],
793                 id="plot-mod-url",
794                 size="xl",
795                 is_open=False,
796                 scrollable=True
797             ),
798             dcc.Download(id="download-iterative-data")
799         ]
800
801     def callbacks(self, app):
802         """Callbacks for the whole application.
803
804         :param app: The application.
805         :type app: Flask
806         """
807
808         @app.callback(
809             [
810                 Output("store-control-panel", "data"),
811                 Output("store-selected-tests", "data"),
812                 Output("plotting-area", "children"),
813                 Output("row-card-sel-tests", "style"),
814                 Output("row-btns-sel-tests", "style"),
815                 Output("lg-selected", "children"),
816
817                 Output({"type": "ctrl-dd", "index": "rls"}, "value"),
818                 Output({"type": "ctrl-dd", "index": "dut"}, "options"),
819                 Output({"type": "ctrl-dd", "index": "dut"}, "disabled"),
820                 Output({"type": "ctrl-dd", "index": "dut"}, "value"),
821                 Output({"type": "ctrl-dd", "index": "dutver"}, "options"),
822                 Output({"type": "ctrl-dd", "index": "dutver"}, "disabled"),
823                 Output({"type": "ctrl-dd", "index": "dutver"}, "value"),
824                 Output({"type": "ctrl-dd", "index": "phy"}, "options"),
825                 Output({"type": "ctrl-dd", "index": "phy"}, "disabled"),
826                 Output({"type": "ctrl-dd", "index": "phy"}, "value"),
827                 Output({"type": "ctrl-dd", "index": "area"}, "options"),
828                 Output({"type": "ctrl-dd", "index": "area"}, "disabled"),
829                 Output({"type": "ctrl-dd", "index": "area"}, "value"),
830                 Output({"type": "ctrl-dd", "index": "test"}, "options"),
831                 Output({"type": "ctrl-dd", "index": "test"}, "disabled"),
832                 Output({"type": "ctrl-dd", "index": "test"}, "value"),
833                 Output({"type": "ctrl-cl", "index": "core"}, "options"),
834                 Output({"type": "ctrl-cl", "index": "core"}, "value"),
835                 Output({"type": "ctrl-cl", "index": "core-all"}, "value"),
836                 Output({"type": "ctrl-cl", "index": "core-all"}, "options"),
837                 Output({"type": "ctrl-cl", "index": "frmsize"}, "options"),
838                 Output({"type": "ctrl-cl", "index": "frmsize"}, "value"),
839                 Output({"type": "ctrl-cl", "index": "frmsize-all"}, "value"),
840                 Output({"type": "ctrl-cl", "index": "frmsize-all"}, "options"),
841                 Output({"type": "ctrl-cl", "index": "tsttype"}, "options"),
842                 Output({"type": "ctrl-cl", "index": "tsttype"}, "value"),
843                 Output({"type": "ctrl-cl", "index": "tsttype-all"}, "value"),
844                 Output({"type": "ctrl-cl", "index": "tsttype-all"}, "options"),
845                 Output({"type": "ctrl-btn", "index": "add-test"}, "disabled"),
846                 Output("normalize", "value")
847             ],
848             [
849                 State("store-control-panel", "data"),
850                 State("store-selected-tests", "data"),
851                 State({"type": "sel-cl", "index": ALL}, "value")
852             ],
853             [
854                 Input("url", "href"),
855                 Input("normalize", "value"),
856
857                 Input({"type": "ctrl-dd", "index": ALL}, "value"),
858                 Input({"type": "ctrl-cl", "index": ALL}, "value"),
859                 Input({"type": "ctrl-btn", "index": ALL}, "n_clicks")
860             ]
861         )
862         def _update_application(
863                 control_panel: dict,
864                 store_sel: list,
865                 lst_sel: list,
866                 href: str,
867                 normalize: list,
868                 *_
869             ) -> tuple:
870             """Update the application when the event is detected.
871             """
872
873             ctrl_panel = ControlPanel(CP_PARAMS, control_panel)
874             on_draw = False
875
876             # Parse the url:
877             parsed_url = url_decode(href)
878             if parsed_url:
879                 url_params = parsed_url["params"]
880             else:
881                 url_params = None
882
883             plotting_area = no_update
884             row_card_sel_tests = no_update
885             row_btns_sel_tests = no_update
886             lg_selected = no_update
887
888             trigger = Trigger(callback_context.triggered)
889
890             if trigger.type == "url" and url_params:
891                 try:
892                     store_sel = literal_eval(url_params["store_sel"][0])
893                     normalize = literal_eval(url_params["norm"][0])
894                 except (KeyError, IndexError, AttributeError):
895                     pass
896                 if store_sel:
897                     row_card_sel_tests = C.STYLE_ENABLED
898                     row_btns_sel_tests = C.STYLE_ENABLED
899                     last_test = store_sel[-1]
900                     test = self._spec_tbs[last_test["rls"]][last_test["dut"]]\
901                         [last_test["dutver"]][last_test["area"]]\
902                             [last_test["test"]][last_test["phy"]]
903                     ctrl_panel.set({
904                         "dd-rls-val": last_test["rls"],
905                         "dd-dut-val": last_test["dut"],
906                         "dd-dut-opt": generate_options(
907                             self._spec_tbs[last_test["rls"]].keys()
908                         ),
909                         "dd-dut-dis": False,
910                         "dd-dutver-val": last_test["dutver"],
911                         "dd-dutver-opt": generate_options(
912                             self._spec_tbs[last_test["rls"]]\
913                                 [last_test["dut"]].keys()
914                         ),
915                         "dd-dutver-dis": False,
916                         "dd-area-val": last_test["area"],
917                         "dd-area-opt": [
918                             {"label": label(v), "value": v} for v in \
919                                 sorted(self._spec_tbs[last_test["rls"]]\
920                                     [last_test["dut"]]\
921                                         [last_test["dutver"]].keys())
922                         ],
923                         "dd-area-dis": False,
924                         "dd-test-val": last_test["test"],
925                         "dd-test-opt": generate_options(
926                             self._spec_tbs[last_test["rls"]][last_test["dut"]]\
927                                 [last_test["dutver"]][last_test["area"]].keys()
928                         ),
929                         "dd-test-dis": False,
930                         "dd-phy-val": last_test["phy"],
931                         "dd-phy-opt": generate_options(
932                             self._spec_tbs[last_test["rls"]][last_test["dut"]]\
933                                 [last_test["dutver"]][last_test["area"]]\
934                                     [last_test["test"]].keys()
935                         ),
936                         "dd-phy-dis": False,
937                         "cl-core-opt": generate_options(test["core"]),
938                         "cl-core-val": [last_test["core"].upper(), ],
939                         "cl-core-all-val": list(),
940                         "cl-core-all-opt": C.CL_ALL_ENABLED,
941                         "cl-frmsize-opt": generate_options(test["frame-size"]),
942                         "cl-frmsize-val": [last_test["framesize"].upper(), ],
943                         "cl-frmsize-all-val": list(),
944                         "cl-frmsize-all-opt": C.CL_ALL_ENABLED,
945                         "cl-tsttype-opt": generate_options(test["test-type"]),
946                         "cl-tsttype-val": [last_test["testtype"].upper(), ],
947                         "cl-tsttype-all-val": list(),
948                         "cl-tsttype-all-opt": C.CL_ALL_ENABLED,
949                         "cl-normalize-val": normalize,
950                         "btn-add-dis": False
951                     })
952                     on_draw = True
953             elif trigger.type == "normalize":
954                 ctrl_panel.set({"cl-normalize-val": normalize})
955                 on_draw = True
956             elif trigger.type == "ctrl-dd":
957                 if trigger.idx == "rls":
958                     try:
959                         options = generate_options(
960                             self._spec_tbs[trigger.value].keys()
961                         )
962                         disabled = False
963                     except KeyError:
964                         options = list()
965                         disabled = True
966                     ctrl_panel.set({
967                         "dd-rls-val": trigger.value,
968                         "dd-dut-val": str(),
969                         "dd-dut-opt": options,
970                         "dd-dut-dis": disabled,
971                         "dd-dutver-val": str(),
972                         "dd-dutver-opt": list(),
973                         "dd-dutver-dis": True,
974                         "dd-phy-val": str(),
975                         "dd-phy-opt": list(),
976                         "dd-phy-dis": True,
977                         "dd-area-val": str(),
978                         "dd-area-opt": list(),
979                         "dd-area-dis": True,
980                         "dd-test-val": str(),
981                         "dd-test-opt": list(),
982                         "dd-test-dis": True,
983                         "cl-core-opt": list(),
984                         "cl-core-val": list(),
985                         "cl-core-all-val": list(),
986                         "cl-core-all-opt": C.CL_ALL_DISABLED,
987                         "cl-frmsize-opt": list(),
988                         "cl-frmsize-val": list(),
989                         "cl-frmsize-all-val": list(),
990                         "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
991                         "cl-tsttype-opt": list(),
992                         "cl-tsttype-val": list(),
993                         "cl-tsttype-all-val": list(),
994                         "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
995                         "btn-add-dis": True
996                     })
997                 elif trigger.idx == "dut":
998                     try:
999                         rls = ctrl_panel.get("dd-rls-val")
1000                         dut = self._spec_tbs[rls][trigger.value]
1001                         options = generate_options(dut.keys())
1002                         disabled = False
1003                     except KeyError:
1004                         options = list()
1005                         disabled = True
1006                     ctrl_panel.set({
1007                         "dd-dut-val": trigger.value,
1008                         "dd-dutver-val": str(),
1009                         "dd-dutver-opt": options,
1010                         "dd-dutver-dis": disabled,
1011                         "dd-phy-val": str(),
1012                         "dd-phy-opt": list(),
1013                         "dd-phy-dis": True,
1014                         "dd-area-val": str(),
1015                         "dd-area-opt": list(),
1016                         "dd-area-dis": True,
1017                         "dd-test-val": str(),
1018                         "dd-test-opt": list(),
1019                         "dd-test-dis": True,
1020                         "cl-core-opt": list(),
1021                         "cl-core-val": list(),
1022                         "cl-core-all-val": list(),
1023                         "cl-core-all-opt": C.CL_ALL_DISABLED,
1024                         "cl-frmsize-opt": list(),
1025                         "cl-frmsize-val": list(),
1026                         "cl-frmsize-all-val": list(),
1027                         "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1028                         "cl-tsttype-opt": list(),
1029                         "cl-tsttype-val": list(),
1030                         "cl-tsttype-all-val": list(),
1031                         "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1032                         "btn-add-dis": True
1033                     })
1034                 elif trigger.idx == "dutver":
1035                     try:
1036                         rls = ctrl_panel.get("dd-rls-val")
1037                         dut = ctrl_panel.get("dd-dut-val")
1038                         dutver = self._spec_tbs[rls][dut][trigger.value]
1039                         options = [{"label": label(v), "value": v} \
1040                             for v in sorted(dutver.keys())]
1041                         disabled = False
1042                     except KeyError:
1043                         options = list()
1044                         disabled = True
1045                     ctrl_panel.set({
1046                         "dd-dutver-val": trigger.value,
1047                         "dd-area-val": str(),
1048                         "dd-area-opt": options,
1049                         "dd-area-dis": disabled,
1050                         "dd-test-val": str(),
1051                         "dd-test-opt": list(),
1052                         "dd-test-dis": True,
1053                         "dd-phy-val": str(),
1054                         "dd-phy-opt": list(),
1055                         "dd-phy-dis": True,
1056                         "cl-core-opt": list(),
1057                         "cl-core-val": list(),
1058                         "cl-core-all-val": list(),
1059                         "cl-core-all-opt": C.CL_ALL_DISABLED,
1060                         "cl-frmsize-opt": list(),
1061                         "cl-frmsize-val": list(),
1062                         "cl-frmsize-all-val": list(),
1063                         "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1064                         "cl-tsttype-opt": list(),
1065                         "cl-tsttype-val": list(),
1066                         "cl-tsttype-all-val": list(),
1067                         "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1068                         "btn-add-dis": True
1069                     })
1070                 elif trigger.idx == "area":
1071                     try:
1072                         rls = ctrl_panel.get("dd-rls-val")
1073                         dut = ctrl_panel.get("dd-dut-val")
1074                         dutver = ctrl_panel.get("dd-dutver-val")
1075                         area = self._spec_tbs[rls][dut][dutver][trigger.value]
1076                         options = generate_options(area.keys())
1077                         disabled = False
1078                     except KeyError:
1079                         options = list()
1080                         disabled = True
1081                     ctrl_panel.set({
1082                         "dd-area-val": trigger.value,
1083                         "dd-test-val": str(),
1084                         "dd-test-opt": options,
1085                         "dd-test-dis": disabled,
1086                         "dd-phy-val": str(),
1087                         "dd-phy-opt": list(),
1088                         "dd-phy-dis": True,
1089                         "cl-core-opt": list(),
1090                         "cl-core-val": list(),
1091                         "cl-core-all-val": list(),
1092                         "cl-core-all-opt": C.CL_ALL_DISABLED,
1093                         "cl-frmsize-opt": list(),
1094                         "cl-frmsize-val": list(),
1095                         "cl-frmsize-all-val": list(),
1096                         "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1097                         "cl-tsttype-opt": list(),
1098                         "cl-tsttype-val": list(),
1099                         "cl-tsttype-all-val": list(),
1100                         "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1101                         "btn-add-dis": True
1102                     })
1103                 elif trigger.idx == "test":
1104                     try:
1105                         rls = ctrl_panel.get("dd-rls-val")
1106                         dut = ctrl_panel.get("dd-dut-val")
1107                         dutver = ctrl_panel.get("dd-dutver-val")
1108                         area = ctrl_panel.get("dd-area-val")
1109                         test = self._spec_tbs[rls][dut][dutver][area]\
1110                             [trigger.value]
1111                         options = generate_options(test.keys())
1112                         disabled = False
1113                     except KeyError:
1114                         options = list()
1115                         disabled = True
1116                     ctrl_panel.set({
1117                         "dd-test-val": trigger.value,
1118                         "dd-phy-val": str(),
1119                         "dd-phy-opt": options,
1120                         "dd-phy-dis": disabled,
1121                         "cl-core-opt": list(),
1122                         "cl-core-val": list(),
1123                         "cl-core-all-val": list(),
1124                         "cl-core-all-opt": C.CL_ALL_DISABLED,
1125                         "cl-frmsize-opt": list(),
1126                         "cl-frmsize-val": list(),
1127                         "cl-frmsize-all-val": list(),
1128                         "cl-frmsize-all-opt": C.CL_ALL_DISABLED,
1129                         "cl-tsttype-opt": list(),
1130                         "cl-tsttype-val": list(),
1131                         "cl-tsttype-all-val": list(),
1132                         "cl-tsttype-all-opt": C.CL_ALL_DISABLED,
1133                         "btn-add-dis": True
1134                     })
1135                 elif trigger.idx == "phy":
1136                     rls = ctrl_panel.get("dd-rls-val")
1137                     dut = ctrl_panel.get("dd-dut-val")
1138                     dutver = ctrl_panel.get("dd-dutver-val")
1139                     area = ctrl_panel.get("dd-area-val")
1140                     test = ctrl_panel.get("dd-test-val")
1141                     if all((rls, dut, dutver, area, test, trigger.value, )):
1142                         phy = self._spec_tbs[rls][dut][dutver][area][test]\
1143                             [trigger.value]
1144                         ctrl_panel.set({
1145                             "dd-phy-val": trigger.value,
1146                             "cl-core-opt": generate_options(phy["core"]),
1147                             "cl-core-val": list(),
1148                             "cl-core-all-val": list(),
1149                             "cl-core-all-opt": C.CL_ALL_ENABLED,
1150                             "cl-frmsize-opt": \
1151                                 generate_options(phy["frame-size"]),
1152                             "cl-frmsize-val": list(),
1153                             "cl-frmsize-all-val": list(),
1154                             "cl-frmsize-all-opt": C.CL_ALL_ENABLED,
1155                             "cl-tsttype-opt": \
1156                                 generate_options(phy["test-type"]),
1157                             "cl-tsttype-val": list(),
1158                             "cl-tsttype-all-val": list(),
1159                             "cl-tsttype-all-opt": C.CL_ALL_ENABLED,
1160                             "btn-add-dis": True
1161                         })
1162             elif trigger.type == "ctrl-cl":
1163                 param = trigger.idx.split("-")[0]
1164                 if "-all" in trigger.idx:
1165                     c_sel, c_all, c_id = list(), trigger.value, "all"
1166                 else:
1167                     c_sel, c_all, c_id = trigger.value, list(), str()
1168                 val_sel, val_all = sync_checklists(
1169                     options=ctrl_panel.get(f"cl-{param}-opt"),
1170                     sel=c_sel,
1171                     all=c_all,
1172                     id=c_id
1173                 )
1174                 ctrl_panel.set({
1175                     f"cl-{param}-val": val_sel,
1176                     f"cl-{param}-all-val": val_all,
1177                 })
1178                 if all((ctrl_panel.get("cl-core-val"),
1179                         ctrl_panel.get("cl-frmsize-val"),
1180                         ctrl_panel.get("cl-tsttype-val"), )):
1181                     ctrl_panel.set({"btn-add-dis": False})
1182                 else:
1183                     ctrl_panel.set({"btn-add-dis": True})
1184             elif trigger.type == "ctrl-btn":
1185                 on_draw = True
1186                 if trigger.idx == "add-test":
1187                     rls = ctrl_panel.get("dd-rls-val")
1188                     dut = ctrl_panel.get("dd-dut-val")
1189                     dutver = ctrl_panel.get("dd-dutver-val")
1190                     phy = ctrl_panel.get("dd-phy-val")
1191                     area = ctrl_panel.get("dd-area-val")
1192                     test = ctrl_panel.get("dd-test-val")
1193                     # Add selected test to the list of tests in store:
1194                     if store_sel is None:
1195                         store_sel = list()
1196                     for core in ctrl_panel.get("cl-core-val"):
1197                         for framesize in ctrl_panel.get("cl-frmsize-val"):
1198                             for ttype in ctrl_panel.get("cl-tsttype-val"):
1199                                 if dut == "trex":
1200                                     core = str()
1201                                 tid = "-".join((
1202                                     rls,
1203                                     dut,
1204                                     dutver,
1205                                     phy.replace("af_xdp", "af-xdp"),
1206                                     area,
1207                                     framesize.lower(),
1208                                     core.lower(),
1209                                     test,
1210                                     ttype.lower()
1211                                 ))
1212                                 if tid not in [i["id"] for i in store_sel]:
1213                                     store_sel.append({
1214                                         "id": tid,
1215                                         "rls": rls,
1216                                         "dut": dut,
1217                                         "dutver": dutver,
1218                                         "phy": phy,
1219                                         "area": area,
1220                                         "test": test,
1221                                         "framesize": framesize.lower(),
1222                                         "core": core.lower(),
1223                                         "testtype": ttype.lower()
1224                                     })
1225                     store_sel = sorted(store_sel, key=lambda d: d["id"])
1226                     if C.CLEAR_ALL_INPUTS:
1227                         ctrl_panel.set(ctrl_panel.defaults)
1228                 elif trigger.idx == "rm-test" and lst_sel:
1229                     new_store_sel = list()
1230                     for idx, item in enumerate(store_sel):
1231                         if not lst_sel[idx]:
1232                             new_store_sel.append(item)
1233                     store_sel = new_store_sel
1234                 elif trigger.idx == "rm-test-all":
1235                     store_sel = list()
1236
1237             if on_draw:
1238                 if store_sel:
1239                     lg_selected = get_list_group_items(
1240                         store_sel, "sel-cl", add_index=True
1241                     )
1242                     plotting_area = self._get_plotting_area(
1243                         store_sel,
1244                         bool(normalize),
1245                         gen_new_url(
1246                             parsed_url,
1247                             {"store_sel": store_sel, "norm": normalize}
1248                         )
1249                     )
1250                     row_card_sel_tests = C.STYLE_ENABLED
1251                     row_btns_sel_tests = C.STYLE_ENABLED
1252                 else:
1253                     plotting_area = C.PLACEHOLDER
1254                     row_card_sel_tests = C.STYLE_DISABLED
1255                     row_btns_sel_tests = C.STYLE_DISABLED
1256                     store_sel = list()
1257
1258             ret_val = [
1259                 ctrl_panel.panel,
1260                 store_sel,
1261                 plotting_area,
1262                 row_card_sel_tests,
1263                 row_btns_sel_tests,
1264                 lg_selected
1265             ]
1266             ret_val.extend(ctrl_panel.values)
1267             return ret_val
1268
1269         @app.callback(
1270             Output("plot-mod-url", "is_open"),
1271             Output("plot-btn-url", "n_clicks"),
1272             Input("plot-btn-url", "n_clicks"),
1273             State("plot-mod-url", "is_open")
1274         )
1275         def toggle_plot_mod_url(n, is_open):
1276             """Toggle the modal window with url.
1277             """
1278             if n:
1279                 return not is_open, 0
1280             return is_open, 0
1281
1282         @app.callback(
1283             Output("download-iterative-data", "data"),
1284             State("store-selected-tests", "data"),
1285             Input("plot-btn-download", "n_clicks"),
1286             prevent_initial_call=True
1287         )
1288         def _download_iterative_data(store_sel, _):
1289             """Download the data
1290
1291             :param store_sel: List of tests selected by user stored in the
1292                 browser.
1293             :type store_sel: list
1294             :returns: dict of data frame content (base64 encoded) and meta data
1295                 used by the Download component.
1296             :rtype: dict
1297             """
1298
1299             if not store_sel:
1300                 raise PreventUpdate
1301
1302             df = pd.DataFrame()
1303             for itm in store_sel:
1304                 sel_data = select_iterative_data(self._data, itm)
1305                 if sel_data is None:
1306                     continue
1307                 df = pd.concat([df, sel_data], ignore_index=True)
1308
1309             return dcc.send_data_frame(df.to_csv, C.REPORT_DOWNLOAD_FILE_NAME)
1310
1311         @app.callback(
1312             Output("metadata-tput-lat", "children"),
1313             Output("metadata-hdrh-graph", "children"),
1314             Output("offcanvas-metadata", "is_open"),
1315             Input({"type": "graph", "index": ALL}, "clickData"),
1316             prevent_initial_call=True
1317         )
1318         def _show_metadata_from_graphs(graph_data: dict) -> tuple:
1319             """Generates the data for the offcanvas displayed when a particular
1320             point in a graph is clicked on.
1321
1322             :param graph_data: The data from the clicked point in the graph.
1323             :type graph_data: dict
1324             :returns: The data to be displayed on the offcanvas and the
1325                 information to show the offcanvas.
1326             :rtype: tuple(list, list, bool)
1327             """
1328
1329             trigger = Trigger(callback_context.triggered)
1330             if not trigger.value:
1331                 raise PreventUpdate
1332
1333             return show_iterative_graph_data(
1334                     trigger, graph_data, self._graph_layout)
1335
1336         @app.callback(
1337             Output("offcanvas-documentation", "is_open"),
1338             Input("btn-documentation", "n_clicks"),
1339             State("offcanvas-documentation", "is_open")
1340         )
1341         def toggle_offcanvas_documentation(n_clicks, is_open):
1342             if n_clicks:
1343                 return not is_open
1344             return is_open