aboutsummaryrefslogtreecommitdiffstats
path: root/csit.infra.dash/app/cdash/comparisons/layout.py
blob: a16277c0f123886d4f2345c9ca8566ba62b9badf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
# Copyright (c) 2023 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Plotly Dash HTML layout override.
"""

import pandas as pd
import dash_bootstrap_components as dbc

from flask import Flask
from dash import dcc, html, dash_table, callback_context, no_update, ALL
from dash import Input, Output, State
from dash.exceptions import PreventUpdate
from dash.dash_table.Format import Format, Scheme
from ast import literal_eval

from ..utils.constants import Constants as C
from ..utils.control_panel import ControlPanel
from ..utils.trigger import Trigger
from ..utils.url_processing import url_decode
from ..utils.utils import generate_options, gen_new_url
from .tables import comparison_table, filter_table_data


# Control panel partameters and their default values.
CP_PARAMS = {
    "dut-val": str(),
    "dutver-opt": list(),
    "dutver-dis": True,
    "dutver-val": str(),
    "infra-opt": list(),
    "infra-dis": True,
    "infra-val": str(),
    "core-opt": list(),
    "core-val": list(),
    "frmsize-opt": list(),
    "frmsize-val": list(),
    "ttype-opt": list(),
    "ttype-val": list(),
    "cmp-par-opt": list(),
    "cmp-par-dis": True,
    "cmp-par-val": str(),
    "cmp-val-opt": list(),
    "cmp-val-dis": True,
    "cmp-val-val": str(),
    "normalize-val": list()
}

# List of comparable parameters.
CMP_PARAMS = {
    "dutver": "Release and Version",
    "infra": "Infrastructure",
    "frmsize": "Frame Size",
    "core": "Number of Cores",
    "ttype": "Measurement"
}


class Layout:
    """The layout of the dash app and the callbacks.
    """

    def __init__(
            self,
            app: Flask,
            data_iterative: pd.DataFrame,
            html_layout_file: str
        ) -> None:
        """Initialization:
        - save the input parameters,
        - prepare data for the control panel,
        - read HTML layout file,

        :param app: Flask application running the dash application.
        :param data_iterative: Iterative data to be used in comparison tables.
        :param html_layout_file: Path and name of the file specifying the HTML
            layout of the dash application.
        :type app: Flask
        :type data_iterative: pandas.DataFrame
        :type html_layout_file: str
        """

        # Inputs
        self._app = app
        self._html_layout_file = html_layout_file
        self._data = data_iterative

        # Get structure of tests:
        tbs = dict()
        cols = [
            "job", "test_id", "test_type", "dut_type", "dut_version", "tg_type",
            "release", "passed"
        ]
        for _, row in self._data[cols].drop_duplicates().iterrows():
            lst_job = row["job"].split("-")
            dut = lst_job[1]
            dver = f"{row['release']}-{row['dut_version']}"
            tbed = "-".join(lst_job[-2:])
            lst_test_id = row["test_id"].split(".")

            suite = lst_test_id[-2].replace("2n1l-", "").replace("1n1l-", "").\
                replace("2n-", "")
            test = lst_test_id[-1]
            nic = suite.split("-")[0]
            for driver in C.DRIVERS:
                if driver in test:
                    drv = driver.replace("-", "_")
                    test = test.replace(f"{driver}-", "")
                    break
            else:
                drv = "dpdk"
            infra = "-".join((tbed, nic, drv))
            lst_test = test.split("-")
            fsize = lst_test[0]
            core = lst_test[1] if lst_test[1] else "8C"

            if tbs.get(dut, None) is None:
                tbs[dut] = dict()
            if tbs[dut].get(dver, None) is None:
                tbs[dut][dver] = dict()
            if tbs[dut][dver].get(infra, None) is None:
                tbs[dut][dver][infra] = dict()
                tbs[dut][dver][infra]["core"] = list()
                tbs[dut][dver][infra]["fsize"] = list()
                tbs[dut][dver][infra]["ttype"] = list()
            if core.upper() not in tbs[dut][dver][infra]["core"]:
                tbs[dut][dver][infra]["core"].append(core.upper())
            if fsize.upper() not in tbs[dut][dver][infra]["fsize"]:
                tbs[dut][dver][infra]["fsize"].append(fsize.upper())
            if row["test_type"] == "mrr":
                if "MRR" not in tbs[dut][dver][infra]["ttype"]:
                    tbs[dut][dver][infra]["ttype"].append("MRR")
            elif row["test_type"] == "ndrpdr":
                if "NDR" not in tbs[dut][dver][infra]["ttype"]:
                    tbs[dut][dver][infra]["ttype"].extend(
                        ("NDR", "PDR", "Latency")
                    )
            elif row["test_type"] == "hoststack" and \
                    row["tg_type"] in ("iperf", "vpp"):
                if "BPS" not in tbs[dut][dver][infra]["ttype"]:
                    tbs[dut][dver][infra]["ttype"].append("BPS")
            elif row["test_type"] == "hoststack" and row["tg_type"] == "ab":
                if "CPS" not in tbs[dut][dver][infra]["ttype"]:
                    tbs[dut][dver][infra]["ttype"].extend(("CPS", "RPS", ))
        self._tbs = tbs

        # Read from files:
        self._html_layout = str()
        try:
            with open(self._html_layout_file, "r") as file_read:
                self._html_layout = file_read.read()
        except IOError as err:
            raise RuntimeError(
                f"Not possible to open the file {self._html_layout_file}\n{err}"
            )

        # Callbacks:
        if self._app is not None and hasattr(self, "callbacks"):
            self.callbacks(self._app)

    @property
    def html_layout(self):
        return self._html_layout

    def add_content(self):
        """Top level method which generated the web page.

        It generates:
        - Store for user input data,
        - Navigation bar,
        - Main area with control panel and ploting area.

        If no HTML layout is provided, an error message is displayed instead.

        :returns: The HTML div with the whole page.
        :rtype: html.Div
        """

        if self.html_layout and self._tbs:
            return html.Div(
                id="div-main",
                className="small",
                children=[
                    dbc.Row(
                        id="row-navbar",
                        class_name="g-0",
                        children=[
                            self._add_navbar()
                        ]
                    ),
                    dbc.Row(
                        id="row-main",
                        class_name="g-0",
                        children=[
                            dcc.Store(id="store-control-panel"),
                            dcc.Store(id="store-selected"),
                            dcc.Store(id="store-table-data"),
                            dcc.Store(id="store-filtered-table-data"),
                            dcc.Location(id="url", refresh=False),
                            self._add_ctrl_col(),
                            self._add_plotting_col()
                        ]
                    )
                ]
            )
        else:
            return html.Div(
                id="div-main-error",
                children=[
                    dbc.Alert(
                        [
                            "An Error Occured"
                        ],
                        color="danger"
                    )
                ]
            )

    def _add_navbar(self):
        """Add nav element with navigation panel. It is placed on the top.

        :returns: Navigation bar.
        :rtype: dbc.NavbarSimple
        """
        return dbc.NavbarSimple(
            id="navbarsimple-main",
            children=[
                dbc.NavItem(
                    dbc.NavLink(
                        C.COMP_TITLE,
                        disabled=True,
                        external_link=True,
                        href="#"
                    )
                )
            ],
            brand=C.BRAND,
            brand_href="/",
            brand_external_link=True,
            class_name="p-2",
            fluid=True
        )

    def _add_ctrl_col(self) -> dbc.Col:
        """Add column with controls. It is placed on the left side.

        :returns: Column with the control panel.
        :rtype: dbc.Col
        """
        return dbc.Col([
            html.Div(
                children=self._add_ctrl_panel(),
                className="sticky-top"
            )
        ])

    def _add_plotting_col(self) -> dbc.Col:
        """Add column with plots. It is placed on the right side.

        :returns: Column with plots.
        :rtype: dbc.Col
        """
        return dbc.Col(
            id="col-plotting-area",
            children=[
                dbc.Spinner(
                    children=[
                        dbc.Row(
                            id="plotting-area",
                            class_name="g-0 p-0",
                            children=[
                                C.PLACEHOLDER
                            ]
                        )
                    ]
                )
            ],
            width=9
        )

    def _add_ctrl_panel(self) -> list:
        """Add control panel.

        :returns: Control panel.
        :rtype: list
        """

        reference = [
            dbc.Row(
                class_name="g-0 p-1",
                children=[
                    dbc.InputGroup(
                        [
                            dbc.InputGroupText("DUT"),
                            dbc.Select(
                                id={"type": "ctrl-dd", "index": "dut"},
                                placeholder="Select a Device under Test...",
                                options=sorted(
                                    [
                                        {"label": k, "value": k} \
                                            for k in self._tbs.keys()
                                    ],
                                    key=lambda d: d["label"]
                                )
                            )
                        ],
                        size="sm"
                    )
                ]
            ),
            dbc.Row(
                class_name="g-0 p-1",
                children=[
                    dbc.InputGroup(
                        [
                            dbc.InputGroupText("CSIT and DUT Version"),
                            dbc.Select(
                                id={"type": "ctrl-dd", "index": "dutver"},
                                placeholder="Select a CSIT and DUT Version...")
                        ],
                        size="sm"
                    )
                ]
            ),
            dbc.Row(
                class_name="g-0 p-1",
                children=[
                    dbc.InputGroup(
                        [
                            dbc.InputGroupText("Infra"),
                            dbc.Select(
                                id={"type": "ctrl-dd", "index": "infra"},
                                placeholder=\
                                    "Select a Physical Test Bed Topology..."
                            )
                        ],
                        size="sm"
                    )
                ]
            ),
            dbc.Row(
                class_name="g-0 p-1",
                children=[
                    dbc.InputGroup(
                        [
                            dbc.InputGroupText("Frame Size"),
                            dbc.Checklist(
                                id={"type": "ctrl-cl", "index": "frmsize"},
                                inline=True,
                                class_name="ms-2"
                            )
                        ],
                        style={"align-items": "center"},
                        size="sm"
                    )
                ]
            ),
            dbc.Row(
                class_name="g-0 p-1",
                children=[
                    dbc.InputGroup(
                        [
                            dbc.InputGroupText("Number of Cores"),
                            dbc.Checklist(
                                id={"type": "ctrl-cl", "index": "core"},
                                inline=True,
                                class_name="ms-2"
                            )
                        ],
                        style={"align-items": "center"},
                        size="sm"
                    )
                ]
            ),
            dbc.Row(
                class_name="g-0 p-1",
                children=[
                    dbc.InputGroup(
                        [
                            dbc.InputGroupText("Measurement"),
                            dbc.Checklist(
                                id={"type": "ctrl-cl", "index": "ttype"},
                                inline=True,
                                class_name="ms-2"
                            )
                        ],
                        style={"align-items": "center"},
                        size="sm"
                    )
                ]
            )
        ]

        compare = [
            dbc.Row(
                class_name="g-0 p-1",
                children=[
                    dbc.InputGroup(
                        [
                            dbc.InputGroupText("Parameter"),
                            dbc.Select(
                                id={"type": "ctrl-dd", "index": "cmpprm"},
                                placeholder="Select a Parameter..."
                            )
                        ],
                        size="sm"
                    )
                ]
            ),
            dbc.Row(
                class_name="g-0 p-1",
                children=[
                    dbc.InputGroup(
                        [
                            dbc.InputGroupText("Value"),
                            dbc.Select(
                                id={"type": "ctrl-dd", "index": "cmpval"},
                                placeholder="Select a Value..."
                            )
                        ],
                        size="sm"
                    )
                ]
            )
        ]

        normalize = [
            dbc.Row(
                class_name="g-0 p-1",
                children=[
                    dbc.InputGroup(
                        dbc.Checklist(
                            id="normalize",
                            options=[{
                                "value": "normalize",
                                "label": "Normalize to 2GHz CPU frequency"
                            }],
                            value=[],
                            inline=True,
                            class_name="ms-2"
                        ),
                        style={"align-items": "center"},
                        size="sm"
                    )
                ]
            )
        ]

        return [
            dbc.Row(
                dbc.Card(
                    [
                        dbc.CardHeader(
                            html.H5("Reference Value")
                        ),
                        dbc.CardBody(
                            children=reference,
                            class_name="g-0 p-0"
                        )
                    ],
                    color="secondary",
                    outline=True
                ),
                class_name="g-0 p-1"
            ),
            dbc.Row(
                dbc.Card(
                    [
                        dbc.CardHeader(
                            html.H5("Compared Value")
                        ),
                        dbc.CardBody(
                            children=compare,
                            class_name="g-0 p-0"
                        )
                    ],
                    color="secondary",
                    outline=True
                ),
                class_name="g-0 p-1"
            ),
            dbc.Row(
                dbc.Card(
                    [
                        dbc.CardHeader(
                            html.H5("Normalization")
                        ),
                        dbc.CardBody(
                            children=normalize,
                            class_name="g-0 p-0"
                        )
                    ],
                    color="secondary",
                    outline=True
                ),
                class_name="g-0 p-1"
            )
        ]

    @staticmethod
    def _get_plotting_area(
            title: str,
            table: pd.DataFrame,
            url: str
        ) -> list:
        """Generate the plotting area with all its content.

        :param title: The title of the comparison table..
        :param table: Comparison table to be displayed.
        :param url: URL to be displayed in the modal window.
        :type title: str
        :type table: pandas.DataFrame
        :type url: str
        :returns: List of rows with elements to be displayed in the plotting
            area.
        :rtype: list
        """

        if table.empty:
            return dbc.Row(
                dbc.Col(
                    children=dbc.Alert(
                        "No data for comparison.",
                        color="danger"
                    ),
                    class_name="g-0 p-1",
                ),
                class_name="g-0 p-0"
            )

        cols = list()
        for idx, col in enumerate(table.columns):
            if idx == 0:
                cols.append({
                    "name": ["", col],
                    "id": col,
                    "deletable": False,
                    "selectable": False,
                    "type": "text"
                })
            else:
                l_col = col.rsplit(" ", 2)
                cols.append({
                    "name": [l_col[0], " ".join(l_col[-2:])],
                    "id": col,
                    "deletable": False,
                    "selectable": False,
                    "type": "numeric",
                    "format": Format(precision=2, scheme=Scheme.fixed)
                })

        return [
            dbc.Row(
                children=html.H5(title),
                class_name="g-0 p-1"
            ),
            dbc.Row(
                children=[
                    dbc.Col(
                        children=dash_table.DataTable(
                            id={"type": "table", "index": "comparison"},
                            columns=cols,
                            data=table.to_dict("records"),
                            merge_duplicate_headers=True,
                            editable=False,
                            filter_action="custom",
                            filter_query="",
                            sort_action="native",
                            sort_mode="multi",
                            selected_columns=[],
                            selected_rows=[],
                            page_action="none",
                            style_cell={"textAlign": "right"},
                            style_cell_conditional=[{
                                "if": {"column_id": "Test Name"},
                                "textAlign": "left"
                            }]
                        ),
                        class_name="g-0 p-1"
                    )
                ],
                class_name="g-0 p-0"
            ),
            dbc.Row(
                [
                    dbc.Col([html.Div(
                        [
                            dbc.Button(
                                id="plot-btn-url",
                                children="Show URL",
                                class_name="me-1",
                                color="info",
                                style={
                                    "text-transform": "none",
                                    "padding": "0rem 1rem"
                                }
                            ),
                            dbc.Modal(
                                [
                                    dbc.ModalHeader(dbc.ModalTitle("URL")),
                                    dbc.ModalBody(url)
                                ],
                                id="plot-mod-url",
                                size="xl",
                                is_open=False,
                                scrollable=True
                            ),
                            dbc.Button(
                                id="plot-btn-download",
                                children="Download Data",
                                class_name="me-1",
                                color="info",
                                style={
                                    "text-transform": "none",
                                    "padding": "0rem 1rem"
                                }
                            ),
                            dcc.Download(id="download-iterative-data")
                        ],
                        className=\
                            "d-grid gap-0 d-md-flex justify-content-md-end"
                    )])
                ],
                class_name="g-0 p-0"
            ),
            dbc.Row(
                children=C.PLACEHOLDER,
                class_name="g-0 p-1"
            )
        ]

    def callbacks(self, app):
        """Callbacks for the whole application.

        :param app: The application.
        :type app: Flask
        """

        @app.callback(
            [
                Output("store-control-panel", "data"),
                Output("store-selected", "data"),
                Output("store-table-data", "data"),
                Output("store-filtered-table-data", "data"),
                Output("plotting-area", "children"),
                Output({"type": "table", "index": ALL}, "data"),
                Output({"type": "ctrl-dd", "index": "dut"}, "value"),
                Output({"type": "ctrl-dd", "index": "dutver"}, "options"),
                Output({"type": "ctrl-dd", "index": "dutver"}, "disabled"),
                Output({"type": "ctrl-dd", "index": "dutver"}, "value"),
                Output({"type": "ctrl-dd", "index": "infra"}, "options"),
                Output({"type": "ctrl-dd", "index": "infra"}, "disabled"),
                Output({"type": "ctrl-dd", "index": "infra"}, "value"),
                Output({"type": "ctrl-cl", "index": "core"}, "options"),
                Output({"type": "ctrl-cl", "index": "core"}, "value"),
                Output({"type": "ctrl-cl", "index": "frmsize"}, "options"),
                Output({"type": "ctrl-cl", "index": "frmsize"}, "value"),
                Output({"type": "ctrl-cl", "index": "ttype"}, "options"),
                Output({"type": "ctrl-cl", "index": "ttype"}, "value"),
                Output({"type": "ctrl-dd", "index": "cmpprm"}, "options"),
                Output({"type": "ctrl-dd", "index": "cmpprm"}, "disabled"),
                Output({"type": "ctrl-dd", "index": "cmpprm"}, "value"),
                Output({"type": "ctrl-dd", "index": "cmpval"}, "options"),
                Output({"type": "ctrl-dd", "index": "cmpval"}, "disabled"),
                Output({"type": "ctrl-dd", "index": "cmpval"}, "value"),
                Output("normalize", "value")
            ],
            [
                State("store-control-panel", "data"),
                State("store-selected", "data"),
                State("store-table-data", "data"),
                State("store-filtered-table-data", "data"),
                State({"type": "table", "index": ALL}, "data")
            ],
            [
                Input("url", "href"),
                Input("normalize", "value"),
                Input({"type": "table", "index": ALL}, "filter_query"),
                Input({"type": "ctrl-dd", "index": ALL}, "value"),
                Input({"type": "ctrl-cl", "index": ALL}, "value"),
                Input({"type": "ctrl-btn", "index": ALL}, "n_clicks")
            ]
        )
        def _update_application(
                control_panel: dict,
                selected: dict,
                store_table_data: list,
                filtered_data: list,
                table_data: list,
                href: str,
                normalize: list,
                table_filter: str,
                *_
            ) -> tuple:
            """Update the application when the event is detected.
            """

            ctrl_panel = ControlPanel(CP_PARAMS, control_panel)

            if selected is None:
                selected = {
                    "reference": {
                        "set": False,
                    },
                    "compare": {
                        "set": False,
                    }
                }

            # Parse the url:
            parsed_url = url_decode(href)
            if parsed_url:
                url_params = parsed_url["params"]
            else:
                url_params = None

            on_draw = False
            plotting_area = no_update

            trigger = Trigger(callback_context.triggered)
            if trigger.type == "url" and url_params:
                process_url = False
                try:
                    selected = literal_eval(url_params["selected"][0])
                    r_sel = selected["reference"]["selection"]
                    c_sel = selected["compare"]
                    normalize = literal_eval(url_params["norm"][0])
                    process_url = bool(
                        (selected["reference"]["set"] == True) and
                        (c_sel["set"] == True)
                    )
                except (KeyError, IndexError, AttributeError):
                    pass
                if process_url:
                    ctrl_panel.set({
                        "dut-val": r_sel["dut"],
                        "dutver-opt": generate_options(
                            self._tbs[r_sel["dut"]].keys()
                        ),
                        "dutver-dis": False,
                        "dutver-val": r_sel["dutver"],
                        "infra-opt": generate_options(
                            self._tbs[r_sel["dut"]][r_sel["dutver"]].keys()
                        ),
                        "infra-dis": False,
                        "infra-val": r_sel["infra"],
                        "core-opt": generate_options(
                            self._tbs[r_sel["dut"]][r_sel["dutver"]]\
                                [r_sel["infra"]]["core"]
                        ),
                        "core-val": r_sel["core"],
                        "frmsize-opt": generate_options(
                            self._tbs[r_sel["dut"]][r_sel["dutver"]]\
                                [r_sel["infra"]]["fsize"]
                        ),
                        "frmsize-val": r_sel["frmsize"],
                        "ttype-opt": generate_options(
                            self._tbs[r_sel["dut"]][r_sel["dutver"]]\
                                [r_sel["infra"]]["ttype"]
                        ),
                        "ttype-val": r_sel["ttype"],
                        "normalize-val": normalize
                    })
                    opts = list()
                    for itm, label in CMP_PARAMS.items():
                        if len(ctrl_panel.get(f"{itm}-opt")) > 1:
                            opts.append({"label": label, "value": itm})
                    ctrl_panel.set({
                        "cmp-par-opt": opts,
                        "cmp-par-dis": False,
                        "cmp-par-val": c_sel["parameter"]
                    })
                    opts = list()
                    for itm in ctrl_panel.get(f"{c_sel['parameter']}-opt"):
                        set_val = ctrl_panel.get(f"{c_sel['parameter']}-val")
                        if isinstance(set_val, list):
                            if itm["value"] not in set_val:
                                opts.append(itm)
                        else:
                            if itm["value"] != set_val:
                                opts.append(itm)
                    ctrl_panel.set({
                        "cmp-val-opt": opts,
                        "cmp-val-dis": False,
                        "cmp-val-val": c_sel["value"]
                    })
                    on_draw = True
            elif trigger.type == "normalize":
                ctrl_panel.set({"normalize-val": normalize})
                on_draw = True
            elif trigger.type == "ctrl-dd":
                if trigger.idx == "dut":
                    try:
                        opts = generate_options(self._tbs[trigger.value].keys())
                        disabled = False
                    except KeyError:
                        opts = list()
                        disabled = True
                    ctrl_panel.set({
                        "dut-val": trigger.value,
                        "dutver-opt": opts,
                        "dutver-dis": disabled,
                        "dutver-val": str(),
                        "infra-opt": list(),
                        "infra-dis": True,
                        "infra-val": str(),
                        "core-opt": list(),
                        "core-val": list(),
                        "frmsize-opt": list(),
                        "frmsize-val": list(),
                        "ttype-opt": list(),
                        "ttype-val": list(),
                        "cmp-par-opt": list(),
                        "cmp-par-dis": True,
                        "cmp-par-val": str(),
                        "cmp-val-opt": list(),
                        "cmp-val-dis": True,
                        "cmp-val-val": str()
                    })
                elif trigger.idx == "dutver":
                    try:
                        dut = ctrl_panel.get("dut-val")
                        dver = self._tbs[dut][trigger.value]
                        opts = generate_options(dver.keys())
                        disabled = False
                    except KeyError:
                        opts = list()
                        disabled = True
                    ctrl_panel.set({
                        "dutver-val": trigger.value,
                        "infra-opt": opts,
                        "infra-dis": disabled,
                        "infra-val": str(),
                        "core-opt": list(),
                        "core-val": list(),
                        "frmsize-opt": list(),
                        "frmsize-val": list(),
                        "ttype-opt": list(),
                        "ttype-val": list(),
                        "cmp-par-opt": list(),
                        "cmp-par-dis": True,
                        "cmp-par-val": str(),
                        "cmp-val-opt": list(),
                        "cmp-val-dis": True,
                        "cmp-val-val": str()
                    })
                elif trigger.idx == "infra":
                    dut = ctrl_panel.get("dut-val")
                    dver = ctrl_panel.get("dutver-val")
                    if all((dut, dver, trigger.value, )):
                        driver = self._tbs[dut][dver][trigger.value]
                        ctrl_panel.set({
                            "infra-val": trigger.value,
                            "core-opt": generate_options(driver["core"]),
                            "core-val": list(),
                            "frmsize-opt": generate_options(driver["fsize"]),
                            "frmsize-val": list(),
                            "ttype-opt": generate_options(driver["ttype"]),
                            "ttype-val": list(),
                            "cmp-par-opt": list(),
                            "cmp-par-dis": True,
                            "cmp-par-val": str(),
                            "cmp-val-opt": list(),
                            "cmp-val-dis": True,
                            "cmp-val-val": str()
                        })
                elif trigger.idx == "cmpprm":
                    value = trigger.value
                    opts = list()
                    for itm in ctrl_panel.get(f"{value}-opt"):
                        set_val = ctrl_panel.get(f"{value}-val")
                        if isinstance(set_val, list):
                            if itm["value"] == "Latency":
                                continue
                            if itm["value"] not in set_val:
                                opts.append(itm)
                        else:
                            if itm["value"] != set_val:
                                opts.append(itm)
                    ctrl_panel.set({
                        "cmp-par-val": value,
                        "cmp-val-opt": opts,
                        "cmp-val-dis": False,
                        "cmp-val-val": str()
                    })
                elif trigger.idx == "cmpval":
                    ctrl_panel.set({"cmp-val-val": trigger.value})
                    selected["reference"] = {
                        "set": True,
                        "selection": {
                            "dut": ctrl_panel.get("dut-val"),
                            "dutver": ctrl_panel.get("dutver-val"),
                            "infra": ctrl_panel.get("infra-val"),
                            "core": ctrl_panel.get("core-val"),
                            "frmsize": ctrl_panel.get("frmsize-val"),
                            "ttype": ctrl_panel.get("ttype-val")
                        }
                    }
                    selected["compare"] = {
                        "set": True,
                        "parameter": ctrl_panel.get("cmp-par-val"),
                        "value": trigger.value
                    }
                    on_draw = True
            elif trigger.type == "ctrl-cl":
                ctrl_panel.set({f"{trigger.idx}-val": trigger.value})
                if all((ctrl_panel.get("core-val"),
                        ctrl_panel.get("frmsize-val"),
                        ctrl_panel.get("ttype-val"), )):
                    if "Latency" in ctrl_panel.get("ttype-val"):
                        ctrl_panel.set({"ttype-val": ["Latency", ]})
                    opts = list()
                    for itm, label in CMP_PARAMS.items():
                        if "Latency" in ctrl_panel.get("ttype-val") and \
                                itm == "ttype":
                            continue
                        if len(ctrl_panel.get(f"{itm}-opt")) > 1:
                            if isinstance(ctrl_panel.get(f"{itm}-val"), list):
                                if len(ctrl_panel.get(f"{itm}-opt")) == \
                                        len(ctrl_panel.get(f"{itm}-val")):
                                    continue
                            opts.append({"label": label, "value": itm})
                    ctrl_panel.set({
                        "cmp-par-opt": opts,
                        "cmp-par-dis": False,
                        "cmp-par-val": str(),
                        "cmp-val-opt": list(),
                        "cmp-val-dis": True,
                        "cmp-val-val": str()
                    })
                else:
                    ctrl_panel.set({
                        "cmp-par-opt": list(),
                        "cmp-par-dis": True,
                        "cmp-par-val": str(),
                        "cmp-val-opt": list(),
                        "cmp-val-dis": True,
                        "cmp-val-val": str()
                    })
            elif trigger.type == "table" and trigger.idx == "comparison":
                filtered_data = filter_table_data(
                    store_table_data,
                    table_filter[0]
                )
                table_data = [filtered_data, ]

            if all((on_draw, selected["reference"]["set"],
                    selected["compare"]["set"], )):
                title, table = comparison_table(self._data, selected, normalize)
                plotting_area = self._get_plotting_area(
                    title=title,
                    table=table,
                    url=gen_new_url(
                        parsed_url,
                        params={"selected": selected, "norm": normalize}
                    )
                )
                store_table_data = table.to_dict("records")
                filtered_data = store_table_data
                if table_data:
                    table_data = [store_table_data, ]

            ret_val = [
                ctrl_panel.panel,
                selected,
                store_table_data,
                filtered_data,
                plotting_area,
                table_data
            ]
            ret_val.extend(ctrl_panel.values)
            return ret_val

        @app.callback(
            Output("plot-mod-url", "is_open"),
            Input("plot-btn-url", "n_clicks"),
            State("plot-mod-url", "is_open")
        )
        def toggle_plot_mod_url(n, is_open):
            """Toggle the modal window with url.
            """
            if n:
                return not is_open
            return is_open

        @app.callback(
            Output("download-iterative-data", "data"),
            State("store-table-data", "data"),
            State("store-filtered-table-data", "data"),
            Input("plot-btn-download", "n_clicks"),
            prevent_initial_call=True
        )
        def _download_comparison_data(
                table_data: list,
                filtered_table_data: list,
                _: int
            ) -> dict:
            """Download the data.

            :param table_data: Original unfiltered table data.
            :param filtered_table_data: Filtered table data.
            :type table_data: list
            :type filtered_table_data: list
            :returns: dict of data frame content (base64 encoded) and meta data
                used by the Download component.
            :rtype: dict
            """

            if not table_data:
                raise PreventUpdate
            
            if filtered_table_data:
                table = pd.DataFrame.from_records(filtered_table_data)
            else:
                table = pd.DataFrame.from_records(table_data)

            return dcc.send_data_frame(table.to_csv, C.COMP_DOWNLOAD_FILE_NAME)