Update VPP_STABLE_VER files
[csit.git] / resources / tools / dash / app / pal / trending / layout.py
index 2be19f8..eac02ce 100644 (file)
@@ -25,14 +25,14 @@ from dash import callback_context, no_update, ALL
 from dash import Input, Output, State
 from dash.exceptions import PreventUpdate
 from yaml import load, FullLoader, YAMLError
 from dash import Input, Output, State
 from dash.exceptions import PreventUpdate
 from yaml import load, FullLoader, YAMLError
-from datetime import datetime, timedelta
+from datetime import datetime
 from copy import deepcopy
 from json import loads, JSONDecodeError
 from ast import literal_eval
 
 from ..utils.constants import Constants as C
 from ..utils.utils import show_tooltip, label, sync_checklists, list_tests, \
 from copy import deepcopy
 from json import loads, JSONDecodeError
 from ast import literal_eval
 
 from ..utils.constants import Constants as C
 from ..utils.utils import show_tooltip, label, sync_checklists, list_tests, \
-    get_date, gen_new_url
+    gen_new_url, generate_options
 from ..utils.url_processing import url_decode
 from ..data.data import Data
 from .graphs import graph_trending, graph_hdrh_latency, \
 from ..utils.url_processing import url_decode
 from ..data.data import Data
 from .graphs import graph_trending, graph_hdrh_latency, \
@@ -239,6 +239,7 @@ class Layout:
         if self.html_layout and self.spec_tbs:
             return html.Div(
                 id="div-main",
         if self.html_layout and self.spec_tbs:
             return html.Div(
                 id="div-main",
+                className="small",
                 children=[
                     dbc.Row(
                         id="row-navbar",
                 children=[
                     dbc.Row(
                         id="row-navbar",
@@ -594,32 +595,7 @@ class Layout:
                                     class_name="me-1",
                                     color="info"
                                 )
                                     class_name="me-1",
                                     color="info"
                                 )
-                            ],
-                            size="md",
-                        )
-                    ]
-                ),
-                dbc.Row(
-                    class_name="gy-1",
-                    children=[
-                        dbc.Label(
-                            class_name="gy-1",
-                            children=show_tooltip(self._tooltips,
-                                "help-time-period", "Time Period"),
-                        ),
-                        dcc.DatePickerRange(
-                            id="dpr-period",
-                            className="d-flex justify-content-center",
-                            min_date_allowed=\
-                                datetime.utcnow() - timedelta(
-                                    days=self.time_period),
-                            max_date_allowed=datetime.utcnow(),
-                            initial_visible_month=datetime.utcnow(),
-                            start_date=\
-                                datetime.utcnow() - timedelta(
-                                    days=self.time_period),
-                            end_date=datetime.utcnow(),
-                            display_format="D MMM YY"
+                            ]
                         )
                     ]
                 ),
                         )
                     ]
                 ),
@@ -662,8 +638,7 @@ class Layout:
                                     color="info",
                                     disabled=False
                                 ),
                                     color="info",
                                     disabled=False
                                 ),
-                            ],
-                            size="md",
+                            ]
                         )
                     ]
                 ),
                         )
                     ]
                 ),
@@ -711,7 +686,7 @@ class Layout:
                 "cl-ctrl-testtype-all-options": C.CL_ALL_DISABLED,
                 "btn-ctrl-add-disabled": True,
                 "cl-normalize-value": list(),
                 "cl-ctrl-testtype-all-options": C.CL_ALL_DISABLED,
                 "btn-ctrl-add-disabled": True,
                 "cl-normalize-value": list(),
-                "cl-selected-options": list(),
+                "cl-selected-options": list()
             }
 
             self._panel = deepcopy(self._defaults)
             }
 
             self._panel = deepcopy(self._defaults)
@@ -890,8 +865,6 @@ class Layout:
             Input("cl-ctrl-testtype-all", "value"),
             Input("cl-ctrl-normalize", "value"),
             Input("btn-ctrl-add", "n_clicks"),
             Input("cl-ctrl-testtype-all", "value"),
             Input("cl-ctrl-normalize", "value"),
             Input("btn-ctrl-add", "n_clicks"),
-            Input("dpr-period", "start_date"),
-            Input("dpr-period", "end_date"),
             Input("btn-sel-remove", "n_clicks"),
             Input("btn-sel-remove-all", "n_clicks"),
             Input("url", "href")
             Input("btn-sel-remove", "n_clicks"),
             Input("btn-sel-remove-all", "n_clicks"),
             Input("url", "href")
@@ -900,7 +873,7 @@ class Layout:
             dd_dut: str, dd_phy: str, dd_area: str, dd_test: str, cl_core: list,
             cl_core_all: list, cl_framesize: list, cl_framesize_all: list,
             cl_testtype: list, cl_testtype_all: list, cl_normalize: list,
             dd_dut: str, dd_phy: str, dd_area: str, dd_test: str, cl_core: list,
             cl_core_all: list, cl_framesize: list, cl_framesize_all: list,
             cl_testtype: list, cl_testtype_all: list, cl_normalize: list,
-            btn_add: int, d_start: str, d_end: str, btn_remove: int,
+            btn_add: int, btn_remove: int,
             btn_remove_all: int, href: str) -> tuple:
             """Update the application when the event is detected.
 
             btn_remove_all: int, href: str) -> tuple:
             """Update the application when the event is detected.
 
@@ -922,8 +895,6 @@ class Layout:
             :param cl_testtype_all: Input - All test types.
             :param cl_normalize: Input - Normalize the results.
             :param btn_add: Input - Button "Add Selected" tests.
             :param cl_testtype_all: Input - All test types.
             :param cl_normalize: Input - Normalize the results.
             :param btn_add: Input - Button "Add Selected" tests.
-            :param d_start: Date and time where the data processing starts.
-            :param d_end: Date and time where the data processing ends.
             :param btn_remove: Input - Button "Remove selected" tests.
             :param btn_remove_all: Input - Button "Remove All" tests.
             :param href: Input - The URL provided by the browser.
             :param btn_remove: Input - Button "Remove selected" tests.
             :param btn_remove_all: Input - Button "Remove All" tests.
             :param href: Input - The URL provided by the browser.
@@ -942,8 +913,6 @@ class Layout:
             :type cl_testtype_all: list
             :type cl_normalize: list
             :type btn_add: int
             :type cl_testtype_all: list
             :type cl_normalize: list
             :type btn_add: int
-            :type d_start: str
-            :type d_end: str
             :type btn_remove: int
             :type btn_remove_all: int
             :type href: str
             :type btn_remove: int
             :type btn_remove_all: int
             :type href: str
@@ -952,12 +921,14 @@ class Layout:
             """
 
             ctrl_panel = self.ControlPanel(cp_data)
             """
 
             ctrl_panel = self.ControlPanel(cp_data)
-
-            d_start = get_date(d_start)
-            d_end = get_date(d_end)
+            norm = cl_normalize
 
             # Parse the url:
             parsed_url = url_decode(href)
 
             # Parse the url:
             parsed_url = url_decode(href)
+            if parsed_url:
+                url_params = parsed_url["params"]
+            else:
+                url_params = None
 
             row_fig_tput = no_update
             row_fig_lat = no_update
 
             row_fig_tput = no_update
             row_fig_lat = no_update
@@ -969,11 +940,8 @@ class Layout:
 
             if trigger_id == "dd-ctrl-dut":
                 try:
 
             if trigger_id == "dd-ctrl-dut":
                 try:
-                    dut = self.spec_tbs[dd_dut]
-                    options = sorted(
-                        [{"label": v, "value": v}for v in dut.keys()],
-                        key=lambda d: d["label"]
-                    )
+                    options = \
+                        generate_options(sorted(self.spec_tbs[dd_dut].keys()))
                     disabled = False
                 except KeyError:
                     options = list()
                     disabled = False
                 except KeyError:
                     options = list()
@@ -1006,10 +974,8 @@ class Layout:
                 try:
                     dut = ctrl_panel.get("dd-ctrl-dut-value")
                     phy = self.spec_tbs[dut][dd_phy]
                 try:
                     dut = ctrl_panel.get("dd-ctrl-dut-value")
                     phy = self.spec_tbs[dut][dd_phy]
-                    options = sorted(
-                        [{"label": label(v), "value": v} for v in phy.keys()],
-                        key=lambda d: d["label"]
-                    )
+                    options = [{"label": label(v), "value": v} \
+                        for v in sorted(phy.keys())]
                     disabled = False
                 except KeyError:
                     options = list()
                     disabled = False
                 except KeyError:
                     options = list()
@@ -1040,10 +1006,7 @@ class Layout:
                     dut = ctrl_panel.get("dd-ctrl-dut-value")
                     phy = ctrl_panel.get("dd-ctrl-phy-value")
                     area = self.spec_tbs[dut][phy][dd_area]
                     dut = ctrl_panel.get("dd-ctrl-dut-value")
                     phy = ctrl_panel.get("dd-ctrl-phy-value")
                     area = self.spec_tbs[dut][phy][dd_area]
-                    options = sorted(
-                        [{"label": v, "value": v} for v in area.keys()],
-                        key=lambda d: d["label"]
-                    )
+                    options = generate_options(sorted(area.keys()))
                     disabled = False
                 except KeyError:
                     options = list()
                     disabled = False
                 except KeyError:
                     options = list()
@@ -1067,34 +1030,25 @@ class Layout:
                     "cl-ctrl-testtype-all-options": C.CL_ALL_DISABLED,
                 })
             elif trigger_id == "dd-ctrl-test":
                     "cl-ctrl-testtype-all-options": C.CL_ALL_DISABLED,
                 })
             elif trigger_id == "dd-ctrl-test":
-                core_opts = list()
-                framesize_opts = list()
-                testtype_opts = list()
                 dut = ctrl_panel.get("dd-ctrl-dut-value")
                 phy = ctrl_panel.get("dd-ctrl-phy-value")
                 area = ctrl_panel.get("dd-ctrl-area-value")
                 dut = ctrl_panel.get("dd-ctrl-dut-value")
                 phy = ctrl_panel.get("dd-ctrl-phy-value")
                 area = ctrl_panel.get("dd-ctrl-area-value")
-                test = self.spec_tbs[dut][phy][area][dd_test]
-                cores = test["core"]
-                fsizes = test["frame-size"]
-                ttypes = test["test-type"]
-                if dut and phy and area and dd_test:
-                    core_opts = [{"label": v, "value": v}
-                        for v in sorted(cores)]
-                    framesize_opts = [{"label": v, "value": v}
-                        for v in sorted(fsizes)]
-                    testtype_opts = [{"label": v, "value": v}
-                        for v in sorted(ttypes)]
+                if all((dut, phy, area, dd_test, )):
+                    test = self.spec_tbs[dut][phy][area][dd_test]
                     ctrl_panel.set({
                         "dd-ctrl-test-value": dd_test,
                     ctrl_panel.set({
                         "dd-ctrl-test-value": dd_test,
-                        "cl-ctrl-core-options": core_opts,
+                        "cl-ctrl-core-options": \
+                            generate_options(sorted(test["core"])),
                         "cl-ctrl-core-value": list(),
                         "cl-ctrl-core-all-value": list(),
                         "cl-ctrl-core-all-options": C.CL_ALL_ENABLED,
                         "cl-ctrl-core-value": list(),
                         "cl-ctrl-core-all-value": list(),
                         "cl-ctrl-core-all-options": C.CL_ALL_ENABLED,
-                        "cl-ctrl-framesize-options": framesize_opts,
+                        "cl-ctrl-framesize-options": \
+                            generate_options(sorted(test["frame-size"])),
                         "cl-ctrl-framesize-value": list(),
                         "cl-ctrl-framesize-all-value": list(),
                         "cl-ctrl-framesize-all-options": C.CL_ALL_ENABLED,
                         "cl-ctrl-framesize-value": list(),
                         "cl-ctrl-framesize-all-value": list(),
                         "cl-ctrl-framesize-all-options": C.CL_ALL_ENABLED,
-                        "cl-ctrl-testtype-options": testtype_opts,
+                        "cl-ctrl-testtype-options": \
+                            generate_options(sorted(test["test-type"])),
                         "cl-ctrl-testtype-value": list(),
                         "cl-ctrl-testtype-all-value": list(),
                         "cl-ctrl-testtype-all-options": C.CL_ALL_ENABLED,
                         "cl-ctrl-testtype-value": list(),
                         "cl-ctrl-testtype-all-value": list(),
                         "cl-ctrl-testtype-all-options": C.CL_ALL_ENABLED,
@@ -1222,30 +1176,70 @@ class Layout:
                             new_store_sel.append(item)
                     store_sel = new_store_sel
             elif trigger_id == "url":
                             new_store_sel.append(item)
                     store_sel = new_store_sel
             elif trigger_id == "url":
-                # TODO: Add verification
-                url_params = parsed_url["params"]
                 if url_params:
                 if url_params:
-                    store_sel = literal_eval(
-                        url_params.get("store_sel", list())[0])
-                    d_start = get_date(url_params.get("start", list())[0])
-                    d_end = get_date(url_params.get("end", list())[0])
+                    try:
+                        store_sel = literal_eval(url_params["store_sel"][0])
+                        norm = literal_eval(url_params["norm"][0])
+                    except (KeyError, IndexError):
+                        pass
                     if store_sel:
                         row_card_sel_tests = C.STYLE_ENABLED
                         row_btns_sel_tests = C.STYLE_ENABLED
                     if store_sel:
                         row_card_sel_tests = C.STYLE_ENABLED
                         row_btns_sel_tests = C.STYLE_ENABLED
-
-            if trigger_id in ("btn-ctrl-add", "url", "dpr-period",
-                    "btn-sel-remove", "cl-ctrl-normalize"):
+                        last_test = store_sel[-1]
+                        test = self.spec_tbs[last_test["dut"]]\
+                            [last_test["phy"]][last_test["area"]]\
+                                [last_test["test"]]
+                        ctrl_panel.set({
+                            "dd-ctrl-dut-value": last_test["dut"],
+                            "dd-ctrl-phy-value": last_test["phy"],
+                            "dd-ctrl-phy-options": generate_options(sorted(
+                                self.spec_tbs[last_test["dut"]].keys())),
+                            "dd-ctrl-phy-disabled": False,
+                            "dd-ctrl-area-value": last_test["area"],
+                            "dd-ctrl-area-options": [
+                                {"label": label(v), "value": v} \
+                                    for v in sorted(
+                                        self.spec_tbs[last_test["dut"]]\
+                                            [last_test["phy"]].keys())
+                            ],
+                            "dd-ctrl-area-disabled": False,
+                            "dd-ctrl-test-value": last_test["test"],
+                            "dd-ctrl-test-options": generate_options(sorted(
+                                self.spec_tbs[last_test["dut"]]\
+                                    [last_test["phy"]]\
+                                        [last_test["area"]].keys())),
+                            "dd-ctrl-test-disabled": False,
+                            "cl-ctrl-core-options": generate_options(sorted(
+                                test["core"])),
+                            "cl-ctrl-core-value": [last_test["core"].upper(), ],
+                            "cl-ctrl-core-all-value": list(),
+                            "cl-ctrl-core-all-options": C.CL_ALL_ENABLED,
+                            "cl-ctrl-framesize-options": generate_options(
+                                sorted(test["frame-size"])),
+                            "cl-ctrl-framesize-value": \
+                                [last_test["framesize"].upper(), ],
+                            "cl-ctrl-framesize-all-value": list(),
+                            "cl-ctrl-framesize-all-options": C.CL_ALL_ENABLED,
+                            "cl-ctrl-testtype-options": generate_options(sorted(
+                                test["test-type"])),
+                            "cl-ctrl-testtype-value": \
+                                [last_test["testtype"].upper(), ],
+                            "cl-ctrl-testtype-all-value": list(),
+                            "cl-ctrl-testtype-all-options": C.CL_ALL_ENABLED
+                        })
+
+            if trigger_id in ("btn-ctrl-add", "url", "btn-sel-remove",
+                    "cl-ctrl-normalize"):
                 if store_sel:
                     row_fig_tput, row_fig_lat, row_btn_dwnld = \
                         _generate_plotting_area(
                             graph_trending(self.data, store_sel, self.layout,
                 if store_sel:
                     row_fig_tput, row_fig_lat, row_btn_dwnld = \
                         _generate_plotting_area(
                             graph_trending(self.data, store_sel, self.layout,
-                                d_start, d_end, bool(cl_normalize)),
+                                bool(norm)),
                             gen_new_url(
                                 parsed_url,
                                 {
                                     "store_sel": store_sel,
                             gen_new_url(
                                 parsed_url,
                                 {
                                     "store_sel": store_sel,
-                                    "start": d_start,
-                                    "end": d_end
+                                    "norm": norm
                                 }
                             )
                         )
                                 }
                             )
                         )
@@ -1269,7 +1263,7 @@ class Layout:
                 disabled = True
             ctrl_panel.set({
                 "btn-ctrl-add-disabled": disabled,
                 disabled = True
             ctrl_panel.set({
                 "btn-ctrl-add-disabled": disabled,
-                "cl-normalize-value": cl_normalize
+                "cl-normalize-value": norm
             })
 
             ret_val = [
             })
 
             ret_val = [