From 430c577e8e8a737cb46e67cbe802e038b8ffd25a Mon Sep 17 00:00:00 2001 From: Tibor Frank Date: Mon, 19 Sep 2022 11:39:26 +0200 Subject: C-Dash: Prepare layout for telemetry in trending Signed-off-by: Tibor Frank Change-Id: I6bd248922d7e6c61ab17eee580af2937022f8371 --- csit.infra.dash/app/cdash/utils/constants.py | 15 ++-- csit.infra.dash/app/cdash/utils/control_panel.py | 87 ++++++++++++++++++++++++ csit.infra.dash/app/cdash/utils/trigger.py | 63 +++++++++++++++++ csit.infra.dash/app/cdash/utils/utils.py | 32 ++++++++- 4 files changed, 189 insertions(+), 8 deletions(-) create mode 100644 csit.infra.dash/app/cdash/utils/control_panel.py create mode 100644 csit.infra.dash/app/cdash/utils/trigger.py (limited to 'csit.infra.dash/app/cdash/utils') diff --git a/csit.infra.dash/app/cdash/utils/constants.py b/csit.infra.dash/app/cdash/utils/constants.py index 6e973b81a8..cf16491d6b 100644 --- a/csit.infra.dash/app/cdash/utils/constants.py +++ b/csit.infra.dash/app/cdash/utils/constants.py @@ -39,7 +39,7 @@ class Constants: BRAND = "CSIT-Dash" # The application description. - DESCRIPTION = 'Performance Dashboard "CSIT-Dash"' + DESCRIPTION = "Performance Dashboard" # External stylesheets. EXTERNAL_STYLESHEETS = ["/static/dist/css/bootstrap.css", ] @@ -101,7 +101,7 @@ class Constants: } ] - # Checklist "All" is enable, visible and unchecked. + # Checklist "All" is enabled, visible and unchecked. CL_ALL_ENABLED = [ { "label": "All", @@ -158,7 +158,8 @@ class Constants: "3n-dnv": 2.000, "3n-icx": 2.600, "3n-skx": 2.500, - "3n-tsh": 2.200 + "3n-tsh": 2.200, + "3n-snr": 2.200 } ############################################################################ @@ -253,7 +254,7 @@ class Constants: # News. # The title. - NEWS_TITLE = "CI TEST FAILURE AND ANOMALY STATISTICS" + NEWS_TITLE = "Failures and Anomalies" # The pathname prefix for the application. NEWS_ROUTES_PATHNAME_PREFIX = "/news/" @@ -270,7 +271,7 @@ class Constants: # Report. # The title. - REPORT_TITLE = "PER RELEASE PERFORMANCE RESULTS" + REPORT_TITLE = "Per Release Performance" # The pathname prefix for the application. REPORT_ROUTES_PATHNAME_PREFIX = "/report/" @@ -285,7 +286,7 @@ class Constants: # Statistics. # The title. - STATS_TITLE = "CI JOB EXECUTION STATISTICS" + STATS_TITLE = "Test Job Statistics" # The pathname prefix for the application. STATS_ROUTES_PATHNAME_PREFIX = "/stats/" @@ -303,7 +304,7 @@ class Constants: # Trending. # The title. - TREND_TITLE = "PERFORMANCE TRENDING (DAILY, WEEKLY)" + TREND_TITLE = "Performance Trending" # The pathname prefix for the application. TREND_ROUTES_PATHNAME_PREFIX = "/trending/" diff --git a/csit.infra.dash/app/cdash/utils/control_panel.py b/csit.infra.dash/app/cdash/utils/control_panel.py new file mode 100644 index 0000000000..d892dfa4c1 --- /dev/null +++ b/csit.infra.dash/app/cdash/utils/control_panel.py @@ -0,0 +1,87 @@ +# Copyright (c) 2022 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. + +"""A module implementing the control panel data structure. +""" + +from copy import deepcopy + + +class ControlPanel: + """A class representing the control panel. + """ + + def __init__(self, params: dict, panel: dict) -> None: + """Initialisation of the control pannel by default values. If + particular values are provided (parameter "panel") they are set + afterwards. + + :param params: Default values to be set to the control panel. This + dictionary also defines the full set of the control panel's + parameters and their order. + :param panel: Custom values to be set to the control panel. + :type params: dict + :type panel: dict + """ + + if not params: + raise ValueError("The params must be defined.") + self._panel = deepcopy(params) + if panel: + for key in panel: + if key in self._panel: + self._panel[key] = panel[key] + else: + raise AttributeError( + f"The parameter {key} is not defined in the list of " + f"parameters." + ) + + @property + def panel(self) -> dict: + return self._panel + + @property + def values(self) -> tuple: + """Returns the values from the Control panel as a tuple. + + :returns: The values from the Control panel. + :rtype: tuple + """ + return tuple(self._panel.values()) + + def set(self, kwargs: dict=dict()) -> None: + """Set the values of the Control panel. + + :param kwargs: key - value pairs to be set. + :type kwargs: dict + :raises KeyError: If the key in kwargs is not present in the Control + panel. + """ + for key, val in kwargs.items(): + if key in self._panel: + self._panel[key] = val + else: + raise KeyError(f"The key {key} is not defined.") + + def get(self, key: str) -> any: + """Returns the value of a key from the Control panel. + + :param key: The key which value should be returned. + :type key: str + :returns: The value of the key. + :rtype: any + :raises KeyError: If the key in kwargs is not present in the Control + panel. + """ + return self._panel[key] diff --git a/csit.infra.dash/app/cdash/utils/trigger.py b/csit.infra.dash/app/cdash/utils/trigger.py new file mode 100644 index 0000000000..53f7a2076a --- /dev/null +++ b/csit.infra.dash/app/cdash/utils/trigger.py @@ -0,0 +1,63 @@ +# Copyright (c) 2022 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. + +"""A module implementing the processing of a trigger. +""" + +from json import loads, JSONDecodeError + + +class Trigger: + """ + """ + def __init__(self, trigger) -> None: + """ + """ + self._id = trigger[0]["prop_id"].split(".") + self._param = self._id[1] + try: + self._id = loads(self._id[0]) + except (JSONDecodeError, TypeError): + # It is a string + self._id = {"type": self._id[0], "index": None} + self._val = trigger[0]["value"] + + def __str__(self) -> str: + return ( + f"\nTrigger:\n" + f" ID: {self._id}\n" + f" Type: {self._id['type']}\n" + f" Index: {self._id['index']}\n" + f" Parameter: {self._param}\n" + f" Value: {self._val}\n" + ) + + @property + def id(self) -> dict: + return self._id + + @property + def type(self) -> str: + return self._id["type"] + + @property + def idx(self) -> any: + return self._id["index"] + + @property + def parameter(self) -> str: + return self._param + + @property + def value(self) -> any: + return self._val diff --git a/csit.infra.dash/app/cdash/utils/utils.py b/csit.infra.dash/app/cdash/utils/utils.py index 9e4eeeb892..461821d28b 100644 --- a/csit.infra.dash/app/cdash/utils/utils.py +++ b/csit.infra.dash/app/cdash/utils/utils.py @@ -303,7 +303,7 @@ def get_job(df: pd.DataFrame, dut, ttype, cadence, testbed): )]["job"].item() -def generate_options(opts: list) -> list: +def generate_options(opts: list, sort: bool=True) -> list: """Return list of options for radio items in control panel. The items in the list are dictionaries with keys "label" and "value". @@ -312,6 +312,8 @@ def generate_options(opts: list) -> list: :returns: List of options (dict). :rtype: list """ + if sort: + opts = sorted(opts) return [{"label": i, "value": i} for i in opts] @@ -342,3 +344,31 @@ def set_job_params(df: pd.DataFrame, job: str) -> dict: "tbeds": generate_options( get_test_beds(df, l_job[1], l_job[3], l_job[4])) } + + +def get_list_group_items(tests: list) -> list: + """Generate list of ListGroupItems with checkboxes with selected tests. + + :param tests: List of tests to be displayed in the ListGroup. + :type tests: list + :returns: List of ListGroupItems with checkboxes with selected tests. + :rtype: list + """ + return [ + dbc.ListGroupItem( + children=[ + dbc.Checkbox( + id={"type": "sel-cl", "index": i}, + label=l["id"], + value=False, + label_class_name="m-0 p-0", + label_style={ + "font-size": ".875em", + "color": get_color(i) + }, + input_class_name="border-danger bg-danger" + ) + ], + class_name="p-0" + ) for i, l in enumerate(tests) + ] -- cgit 1.2.3-korg