aboutsummaryrefslogtreecommitdiffstats
path: root/resources/tools
diff options
context:
space:
mode:
authorTibor Frank <tifrank@cisco.com>2022-07-21 13:40:50 +0200
committerTibor Frank <tifrank@cisco.com>2022-07-21 13:40:50 +0200
commitaa9f6d2b4d417b439e2953a9c82c31b0d561f632 (patch)
tree39e7ec4ed6199b332ae7ab5ac59510e677e1e144 /resources/tools
parentae1fe880286d7b0414664bce2b2c7c91c3f543f3 (diff)
UTI: Move common functions to utils.
Change-Id: Ic390359afcea7855a964f8f9793f6d17a5b9b616 Signed-off-by: Tibor Frank <tifrank@cisco.com>
Diffstat (limited to 'resources/tools')
-rw-r--r--resources/tools/dash/app/pal/news/layout.py47
-rw-r--r--resources/tools/dash/app/pal/report/graphs.py11
-rw-r--r--resources/tools/dash/app/pal/report/layout.py122
-rw-r--r--resources/tools/dash/app/pal/stats/layout.py68
-rw-r--r--resources/tools/dash/app/pal/trending/graphs.py14
-rw-r--r--resources/tools/dash/app/pal/trending/layout.py141
-rw-r--r--resources/tools/dash/app/pal/utils/utils.py141
7 files changed, 244 insertions, 300 deletions
diff --git a/resources/tools/dash/app/pal/news/layout.py b/resources/tools/dash/app/pal/news/layout.py
index c9f2808a14..6743b5a33c 100644
--- a/resources/tools/dash/app/pal/news/layout.py
+++ b/resources/tools/dash/app/pal/news/layout.py
@@ -28,7 +28,7 @@ from copy import deepcopy
from ..data.data import Data
from ..utils.constants import Constants as C
-from ..utils.utils import classify_anomalies
+from ..utils.utils import classify_anomalies, show_tooltip
from ..data.data import Data
from .tables import table_news
@@ -389,43 +389,6 @@ class Layout:
lst_job[1], lst_job[3], lst_job[4]))
}
- def _show_tooltip(self, id: str, title: str,
- clipboard_id: str=None) -> list:
- """Generate list of elements to display a text (e.g. a title) with a
- tooltip and optionaly with Copy&Paste icon and the clipboard
- functionality enabled.
-
- :param id: Tooltip ID.
- :param title: A text for which the tooltip will be displayed.
- :param clipboard_id: If defined, a Copy&Paste icon is displayed and the
- clipboard functionality is enabled.
- :type id: str
- :type title: str
- :type clipboard_id: str
- :returns: List of elements to display a text with a tooltip and
- optionaly with Copy&Paste icon.
- :rtype: list
- """
-
- return [
- dcc.Clipboard(target_id=clipboard_id, title="Copy URL") \
- if clipboard_id else str(),
- f"{title} ",
- dbc.Badge(
- id=id,
- children="?",
- pill=True,
- color="white",
- text_color="info",
- class_name="border ms-1",
- ),
- dbc.Tooltip(
- children=self._tooltips.get(id, str()),
- target=id,
- placement="auto"
- )
- ]
-
def add_content(self):
"""Top level method which generated the web page.
@@ -552,7 +515,7 @@ class Layout:
children=[
dbc.Label(
class_name="p-0",
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-dut", "Device under Test")
),
dbc.Row(
@@ -570,7 +533,7 @@ class Layout:
children=[
dbc.Label(
class_name="p-0",
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-ttype", "Test Type"),
),
dbc.RadioItems(
@@ -586,7 +549,7 @@ class Layout:
children=[
dbc.Label(
class_name="p-0",
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-cadence", "Cadence"),
),
dbc.RadioItems(
@@ -602,7 +565,7 @@ class Layout:
children=[
dbc.Label(
class_name="p-0",
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-tbed", "Test Bed"),
),
dbc.Select(
diff --git a/resources/tools/dash/app/pal/report/graphs.py b/resources/tools/dash/app/pal/report/graphs.py
index c5d8f8f2d7..4cd9287f0f 100644
--- a/resources/tools/dash/app/pal/report/graphs.py
+++ b/resources/tools/dash/app/pal/report/graphs.py
@@ -21,12 +21,7 @@ import pandas as pd
from copy import deepcopy
from ..utils.constants import Constants as C
-
-
-def _get_color(idx: int) -> str:
- """
- """
- return C.PLOT_COLORS[idx % len(C.PLOT_COLORS)]
+from ..utils.utils import get_color
def get_short_version(version: str, dut_type: str="vpp") -> str:
@@ -146,7 +141,7 @@ def graph_iterative(data: pd.DataFrame, sel:dict, layout: dict,
hoverinfo=u"y+name",
boxpoints="all",
jitter=0.3,
- marker=dict(color=_get_color(idx))
+ marker=dict(color=get_color(idx))
)
tput_traces.append(go.Box(**tput_kwargs))
show_tput = True
@@ -168,7 +163,7 @@ def graph_iterative(data: pd.DataFrame, sel:dict, layout: dict,
hoverinfo="all",
boxpoints="all",
jitter=0.3,
- marker=dict(color=_get_color(idx))
+ marker=dict(color=get_color(idx))
)
x_lat.append(idx + 1)
lat_traces.append(go.Box(**lat_kwargs))
diff --git a/resources/tools/dash/app/pal/report/layout.py b/resources/tools/dash/app/pal/report/layout.py
index 164f2d48d9..7afa0ea0c5 100644
--- a/resources/tools/dash/app/pal/report/layout.py
+++ b/resources/tools/dash/app/pal/report/layout.py
@@ -28,7 +28,9 @@ from copy import deepcopy
from ast import literal_eval
from ..utils.constants import Constants as C
-from ..utils.url_processing import url_decode, url_encode
+from ..utils.utils import show_tooltip, label, sync_checklists, list_tests, \
+ gen_new_url
+from ..utils.url_processing import url_decode
from ..data.data import Data
from .graphs import graph_iterative, table_comparison, get_short_version
@@ -189,32 +191,6 @@ class Layout:
def layout(self):
return self._graph_layout
- def label(self, key: str) -> str:
- return C.LABELS.get(key, key)
-
- def _show_tooltip(self, id: str, title: str,
- clipboard_id: str=None) -> list:
- """
- """
- return [
- dcc.Clipboard(target_id=clipboard_id, title="Copy URL") \
- if clipboard_id else str(),
- f"{title} ",
- dbc.Badge(
- id=id,
- children="?",
- pill=True,
- color="white",
- text_color="info",
- class_name="border ms-1",
- ),
- dbc.Tooltip(
- children=self._tooltips.get(id, str()),
- target=id,
- placement="auto"
- )
- ]
-
def add_content(self):
"""
"""
@@ -358,7 +334,7 @@ class Layout:
dbc.InputGroup(
[
dbc.InputGroupText(
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-release", "CSIT Release")
),
dbc.Select(
@@ -384,7 +360,7 @@ class Layout:
dbc.InputGroup(
[
dbc.InputGroupText(
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-dut", "DUT")
),
dbc.Select(
@@ -405,7 +381,7 @@ class Layout:
dbc.InputGroup(
[
dbc.InputGroupText(
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-dut-ver", "DUT Version")
),
dbc.Select(
@@ -427,7 +403,7 @@ class Layout:
dbc.InputGroup(
[
dbc.InputGroupText(
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-infra", "Infra")
),
dbc.Select(
@@ -449,7 +425,7 @@ class Layout:
dbc.InputGroup(
[
dbc.InputGroupText(
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-area", "Area")
),
dbc.Select(
@@ -469,7 +445,7 @@ class Layout:
dbc.InputGroup(
[
dbc.InputGroupText(
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-test", "Test")
),
dbc.Select(
@@ -488,7 +464,7 @@ class Layout:
class_name="gy-1",
children=[
dbc.Label(
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-framesize", "Frame Size"),
class_name="p-0"
),
@@ -519,7 +495,7 @@ class Layout:
class_name="gy-1",
children=[
dbc.Label(
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-cores", "Number of Cores"),
class_name="p-0"
),
@@ -550,7 +526,7 @@ class Layout:
class_name="gy-1",
children=[
dbc.Label(
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-ttype", "Test Type"),
class_name="p-0"
),
@@ -581,7 +557,7 @@ class Layout:
class_name="gy-1",
children=[
dbc.Label(
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-normalize", "Normalize"),
class_name="p-0"
),
@@ -731,26 +707,6 @@ class Layout:
def values(self) -> tuple:
return tuple(self._panel.values())
- @staticmethod
- def _sync_checklists(opt: list, sel: list, all: list, id: str) -> tuple:
- """
- """
- options = {v["value"] for v in opt}
- if id =="all":
- sel = list(options) if all else list()
- else:
- all = ["all", ] if set(sel) == options else list()
- return sel, all
-
- @staticmethod
- def _list_tests(selection: dict) -> list:
- """Display selected tests with checkboxes
- """
- if selection:
- return [{"label": v["id"], "value": v["id"]} for v in selection]
- else:
- return list()
-
def callbacks(self, app):
def _generate_plotting_area(figs: tuple, table: pd.DataFrame,
@@ -779,7 +735,7 @@ class Layout:
dcc.Loading(children=[
dbc.Button(
id="btn-download-data",
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-download", "Download Data"),
class_name="me-1",
color="info"
@@ -796,7 +752,7 @@ class Layout:
children=[
dbc.InputGroupText(
style=C.URL_STYLE,
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-url", "URL", "input-url")
),
dbc.Input(
@@ -901,21 +857,6 @@ class Layout:
"""
"""
- def _gen_new_url(parsed_url: dict, store_sel: list) -> str:
-
- if parsed_url:
- new_url = url_encode({
- "scheme": parsed_url["scheme"],
- "netloc": parsed_url["netloc"],
- "path": parsed_url["path"],
- "params": {
- "store_sel": store_sel,
- }
- })
- else:
- new_url = str()
- return new_url
-
ctrl_panel = self.ControlPanel(cp_data)
# Parse the url:
@@ -1054,8 +995,7 @@ class Layout:
dutver = ctrl_panel.get("dd-dutver-value")
phy = self.spec_tbs[rls][dut][dutver][dd_phy]
options = sorted(
- [{"label": self.label(v), "value": v}
- for v in phy.keys()],
+ [{"label": label(v), "value": v} for v in phy.keys()],
key=lambda d: d["label"]
)
disabled = False
@@ -1143,8 +1083,8 @@ class Layout:
"cl-testtype-all-options": C.CL_ALL_ENABLED,
})
elif trigger_id == "cl-ctrl-core":
- val_sel, val_all = self._sync_checklists(
- opt=ctrl_panel.get("cl-core-options"),
+ val_sel, val_all = sync_checklists(
+ options=ctrl_panel.get("cl-core-options"),
sel=cl_core,
all=list(),
id=""
@@ -1154,8 +1094,8 @@ class Layout:
"cl-core-all-value": val_all,
})
elif trigger_id == "cl-ctrl-core-all":
- val_sel, val_all = self._sync_checklists(
- opt = ctrl_panel.get("cl-core-options"),
+ val_sel, val_all = sync_checklists(
+ options = ctrl_panel.get("cl-core-options"),
sel=list(),
all=cl_core_all,
id="all"
@@ -1165,8 +1105,8 @@ class Layout:
"cl-core-all-value": val_all,
})
elif trigger_id == "cl-ctrl-framesize":
- val_sel, val_all = self._sync_checklists(
- opt = ctrl_panel.get("cl-framesize-options"),
+ val_sel, val_all = sync_checklists(
+ options = ctrl_panel.get("cl-framesize-options"),
sel=cl_framesize,
all=list(),
id=""
@@ -1176,8 +1116,8 @@ class Layout:
"cl-framesize-all-value": val_all,
})
elif trigger_id == "cl-ctrl-framesize-all":
- val_sel, val_all = self._sync_checklists(
- opt = ctrl_panel.get("cl-framesize-options"),
+ val_sel, val_all = sync_checklists(
+ options = ctrl_panel.get("cl-framesize-options"),
sel=list(),
all=cl_framesize_all,
id="all"
@@ -1187,8 +1127,8 @@ class Layout:
"cl-framesize-all-value": val_all,
})
elif trigger_id == "cl-ctrl-testtype":
- val_sel, val_all = self._sync_checklists(
- opt = ctrl_panel.get("cl-testtype-options"),
+ val_sel, val_all = sync_checklists(
+ options = ctrl_panel.get("cl-testtype-options"),
sel=cl_testtype,
all=list(),
id=""
@@ -1198,8 +1138,8 @@ class Layout:
"cl-testtype-all-value": val_all,
})
elif trigger_id == "cl-ctrl-testtype-all":
- val_sel, val_all = self._sync_checklists(
- opt = ctrl_panel.get("cl-testtype-options"),
+ val_sel, val_all = sync_checklists(
+ options = ctrl_panel.get("cl-testtype-options"),
sel=list(),
all=cl_testtype_all,
id="all"
@@ -1252,7 +1192,7 @@ class Layout:
if C.CLEAR_ALL_INPUTS:
ctrl_panel.set(ctrl_panel.defaults)
ctrl_panel.set({
- "cl-selected-options": self._list_tests(store_sel)
+ "cl-selected-options": list_tests(store_sel)
})
elif trigger_id == "btn-sel-remove-all":
_ = btn_remove_all
@@ -1294,10 +1234,10 @@ class Layout:
table_comparison(
self.data, store_sel, bool(cl_normalize)
),
- _gen_new_url(parsed_url, store_sel)
+ gen_new_url(parsed_url, {"store_sel": store_sel})
)
ctrl_panel.set({
- "cl-selected-options": self._list_tests(store_sel)
+ "cl-selected-options": list_tests(store_sel)
})
else:
row_fig_tput = C.PLACEHOLDER
diff --git a/resources/tools/dash/app/pal/stats/layout.py b/resources/tools/dash/app/pal/stats/layout.py
index 03707c0394..a0920a4ec0 100644
--- a/resources/tools/dash/app/pal/stats/layout.py
+++ b/resources/tools/dash/app/pal/stats/layout.py
@@ -29,7 +29,8 @@ from datetime import datetime, timedelta
from copy import deepcopy
from ..utils.constants import Constants as C
-from ..utils.url_processing import url_decode, url_encode
+from ..utils.utils import show_tooltip, gen_new_url
+from ..utils.url_processing import url_decode
from ..data.data import Data
from .graphs import graph_statistics, select_data
@@ -261,29 +262,6 @@ class Layout:
lst_job[1], lst_job[3], lst_job[4]))
}
- def _show_tooltip(self, id: str, title: str,
- clipboard_id: str=None) -> list:
- """
- """
- return [
- dcc.Clipboard(target_id=clipboard_id, title="Copy URL") \
- if clipboard_id else str(),
- f"{title} ",
- dbc.Badge(
- id=id,
- children="?",
- pill=True,
- color="white",
- text_color="info",
- class_name="border ms-1",
- ),
- dbc.Tooltip(
- children=self._tooltips.get(id, str()),
- target=id,
- placement="auto"
- )
- ]
-
def add_content(self):
"""
"""
@@ -408,7 +386,7 @@ class Layout:
dcc.Loading(children=[
dbc.Button(
id="btn-download-data",
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-download", "Download Data"),
class_name="me-1",
color="info"
@@ -425,8 +403,11 @@ class Layout:
children=[
dbc.InputGroupText(
style=C.URL_STYLE,
- children=self._show_tooltip(
- "help-url", "URL", "input-url")
+ children=show_tooltip(
+ self._tooltips,
+ "help-url", "URL",
+ "input-url"
+ )
),
dbc.Input(
id="input-url",
@@ -460,7 +441,7 @@ class Layout:
children=[
dbc.Label(
class_name="p-0",
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-dut", "Device under Test")
),
dbc.Row(
@@ -478,7 +459,7 @@ class Layout:
children=[
dbc.Label(
class_name="p-0",
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-ttype", "Test Type"),
),
dbc.RadioItems(
@@ -494,7 +475,7 @@ class Layout:
children=[
dbc.Label(
class_name="p-0",
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-cadence", "Cadence"),
),
dbc.RadioItems(
@@ -510,7 +491,7 @@ class Layout:
children=[
dbc.Label(
class_name="p-0",
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-tbed", "Test Bed"),
),
dbc.Select(
@@ -536,7 +517,7 @@ class Layout:
children=[
dbc.Label(
class_name="gy-1",
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-time-period", "Time Period"),
),
dcc.DatePickerRange(
@@ -729,25 +710,18 @@ class Layout:
fig_passed, fig_duration = graph_statistics(self.data, job,
self.layout, start, end)
- if parsed_url:
- new_url = url_encode({
- "scheme": parsed_url["scheme"],
- "netloc": parsed_url["netloc"],
- "path": parsed_url["path"],
- "params": {
- "job": job,
- "start": start,
- "end": end
- }
- })
- else:
- new_url = str()
-
ret_val = [
ctrl_panel.panel,
fig_passed,
fig_duration,
- new_url
+ gen_new_url(
+ parsed_url,
+ {
+ "job": job,
+ "start": start,
+ "end": end
+ }
+ )
]
ret_val.extend(ctrl_panel.values())
return ret_val
diff --git a/resources/tools/dash/app/pal/trending/graphs.py b/resources/tools/dash/app/pal/trending/graphs.py
index 0b4968082f..4cd8285f72 100644
--- a/resources/tools/dash/app/pal/trending/graphs.py
+++ b/resources/tools/dash/app/pal/trending/graphs.py
@@ -23,13 +23,7 @@ import hdrh.codec
from datetime import datetime
from ..utils.constants import Constants as C
-from ..utils.utils import classify_anomalies
-
-
-def _get_color(idx: int) -> str:
- """
- """
- return C.PLOT_COLORS[idx % len(C.PLOT_COLORS)]
+from ..utils.utils import classify_anomalies, get_color
def _get_hdrh_latencies(row: pd.Series, name: str) -> dict:
@@ -272,7 +266,7 @@ def graph_trending(data: pd.DataFrame, sel:dict, layout: dict,
else:
norm_factor = 1.0
traces = _generate_trending_traces(
- itm["testtype"], name, df, start, end, _get_color(idx), norm_factor
+ itm["testtype"], name, df, start, end, get_color(idx), norm_factor
)
if traces:
if not fig_tput:
@@ -281,7 +275,7 @@ def graph_trending(data: pd.DataFrame, sel:dict, layout: dict,
if itm["testtype"] == "pdr":
traces = _generate_trending_traces(
- "pdr-lat", name, df, start, end, _get_color(idx), norm_factor
+ "pdr-lat", name, df, start, end, get_color(idx), norm_factor
)
if traces:
if not fig_lat:
@@ -348,7 +342,7 @@ def graph_hdrh_latency(data: dict, layout: dict) -> go.Figure:
legendgroup=C.GRAPH_LAT_HDRH_DESC[lat_name],
showlegend=bool(idx % 2),
line=dict(
- color=_get_color(int(idx/2)),
+ color=get_color(int(idx/2)),
dash="solid",
width=1 if idx % 2 else 2
),
diff --git a/resources/tools/dash/app/pal/trending/layout.py b/resources/tools/dash/app/pal/trending/layout.py
index 48a8e5481e..0fe28ebed5 100644
--- a/resources/tools/dash/app/pal/trending/layout.py
+++ b/resources/tools/dash/app/pal/trending/layout.py
@@ -31,7 +31,9 @@ from json import loads, JSONDecodeError
from ast import literal_eval
from ..utils.constants import Constants as C
-from ..utils.url_processing import url_decode, url_encode
+from ..utils.utils import show_tooltip, label, sync_checklists, list_tests, \
+ get_date, gen_new_url
+from ..utils.url_processing import url_decode
from ..data.data import Data
from .graphs import graph_trending, graph_hdrh_latency, \
select_trending_data
@@ -197,32 +199,6 @@ class Layout:
def time_period(self):
return self._time_period
- def label(self, key: str) -> str:
- return C.LABELS.get(key, key)
-
- def _show_tooltip(self, id: str, title: str,
- clipboard_id: str=None) -> list:
- """
- """
- return [
- dcc.Clipboard(target_id=clipboard_id, title="Copy URL") \
- if clipboard_id else str(),
- f"{title} ",
- dbc.Badge(
- id=id,
- children="?",
- pill=True,
- color="white",
- text_color="info",
- class_name="border ms-1",
- ),
- dbc.Tooltip(
- children=self._tooltips.get(id, str()),
- target=id,
- placement="auto"
- )
- ]
-
def add_content(self):
"""
"""
@@ -356,7 +332,7 @@ class Layout:
dbc.InputGroup(
[
dbc.InputGroupText(
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-dut", "DUT")
),
dbc.Select(
@@ -384,7 +360,7 @@ class Layout:
dbc.InputGroup(
[
dbc.InputGroupText(
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-infra", "Infra")
),
dbc.Select(
@@ -406,7 +382,7 @@ class Layout:
dbc.InputGroup(
[
dbc.InputGroupText(
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-area", "Area")
),
dbc.Select(
@@ -426,7 +402,7 @@ class Layout:
dbc.InputGroup(
[
dbc.InputGroupText(
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-test", "Test")
),
dbc.Select(
@@ -445,7 +421,7 @@ class Layout:
class_name="gy-1",
children=[
dbc.Label(
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-framesize", "Frame Size"),
class_name="p-0"
),
@@ -476,7 +452,7 @@ class Layout:
class_name="gy-1",
children=[
dbc.Label(
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-cores", "Number of Cores"),
class_name="p-0"
),
@@ -507,7 +483,7 @@ class Layout:
class_name="gy-1",
children=[
dbc.Label(
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-ttype", "Test Type"),
class_name="p-0"
),
@@ -538,7 +514,7 @@ class Layout:
class_name="gy-1",
children=[
dbc.Label(
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-normalize", "Normalize"),
class_name="p-0"
),
@@ -582,7 +558,7 @@ class Layout:
children=[
dbc.Label(
class_name="gy-1",
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-time-period", "Time Period"),
),
dcc.DatePickerRange(
@@ -706,30 +682,6 @@ class Layout:
def values(self) -> tuple:
return tuple(self._panel.values())
- @staticmethod
- def _sync_checklists(opt: list, sel: list, all: list, id: str) -> tuple:
- """
- """
- options = {v["value"] for v in opt}
- if id =="all":
- sel = list(options) if all else list()
- else:
- all = ["all", ] if set(sel) == options else list()
- return sel, all
-
- @staticmethod
- def _list_tests(selection: dict) -> list:
- """Display selected tests with checkboxes
- """
- if selection:
- return [{"label": v["id"], "value": v["id"]} for v in selection]
- else:
- return list()
-
- @staticmethod
- def _get_date(s_date: str) -> datetime:
- return datetime(int(s_date[0:4]), int(s_date[5:7]), int(s_date[8:10]))
-
def callbacks(self, app):
def _generate_plotting_area(figs: tuple, url: str) -> tuple:
@@ -756,7 +708,7 @@ class Layout:
dcc.Loading(children=[
dbc.Button(
id="btn-download-data",
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-download", "Download Data"),
class_name="me-1",
color="info"
@@ -773,7 +725,7 @@ class Layout:
children=[
dbc.InputGroupText(
style=C.URL_STYLE,
- children=self._show_tooltip(
+ children=show_tooltip(self._tooltips,
"help-url", "URL", "input-url")
),
dbc.Input(
@@ -861,29 +813,10 @@ class Layout:
"""
"""
- def _gen_new_url(parsed_url: dict, store_sel: list,
- start: datetime, end: datetime) -> str:
-
- if parsed_url:
- new_url = url_encode({
- "scheme": parsed_url["scheme"],
- "netloc": parsed_url["netloc"],
- "path": parsed_url["path"],
- "params": {
- "store_sel": store_sel,
- "start": start,
- "end": end
- }
- })
- else:
- new_url = str()
- return new_url
-
-
ctrl_panel = self.ControlPanel(cp_data)
- d_start = self._get_date(d_start)
- d_end = self._get_date(d_end)
+ d_start = get_date(d_start)
+ d_end = get_date(d_end)
# Parse the url:
parsed_url = url_decode(href)
@@ -936,8 +869,7 @@ class Layout:
dut = ctrl_panel.get("dd-ctrl-dut-value")
phy = self.spec_tbs[dut][dd_phy]
options = sorted(
- [{"label": self.label(v), "value": v}
- for v in phy.keys()],
+ [{"label": label(v), "value": v} for v in phy.keys()],
key=lambda d: d["label"]
)
disabled = False
@@ -1030,8 +962,8 @@ class Layout:
"cl-ctrl-testtype-all-options": C.CL_ALL_ENABLED,
})
elif trigger_id == "cl-ctrl-core":
- val_sel, val_all = self._sync_checklists(
- opt=ctrl_panel.get("cl-ctrl-core-options"),
+ val_sel, val_all = sync_checklists(
+ options=ctrl_panel.get("cl-ctrl-core-options"),
sel=cl_core,
all=list(),
id=""
@@ -1041,8 +973,8 @@ class Layout:
"cl-ctrl-core-all-value": val_all,
})
elif trigger_id == "cl-ctrl-core-all":
- val_sel, val_all = self._sync_checklists(
- opt = ctrl_panel.get("cl-ctrl-core-options"),
+ val_sel, val_all = sync_checklists(
+ options = ctrl_panel.get("cl-ctrl-core-options"),
sel=list(),
all=cl_core_all,
id="all"
@@ -1052,8 +984,8 @@ class Layout:
"cl-ctrl-core-all-value": val_all,
})
elif trigger_id == "cl-ctrl-framesize":
- val_sel, val_all = self._sync_checklists(
- opt = ctrl_panel.get("cl-ctrl-framesize-options"),
+ val_sel, val_all = sync_checklists(
+ options = ctrl_panel.get("cl-ctrl-framesize-options"),
sel=cl_framesize,
all=list(),
id=""
@@ -1063,8 +995,8 @@ class Layout:
"cl-ctrl-framesize-all-value": val_all,
})
elif trigger_id == "cl-ctrl-framesize-all":
- val_sel, val_all = self._sync_checklists(
- opt = ctrl_panel.get("cl-ctrl-framesize-options"),
+ val_sel, val_all = sync_checklists(
+ options = ctrl_panel.get("cl-ctrl-framesize-options"),
sel=list(),
all=cl_framesize_all,
id="all"
@@ -1074,8 +1006,8 @@ class Layout:
"cl-ctrl-framesize-all-value": val_all,
})
elif trigger_id == "cl-ctrl-testtype":
- val_sel, val_all = self._sync_checklists(
- opt = ctrl_panel.get("cl-ctrl-testtype-options"),
+ val_sel, val_all = sync_checklists(
+ options = ctrl_panel.get("cl-ctrl-testtype-options"),
sel=cl_testtype,
all=list(),
id=""
@@ -1085,8 +1017,8 @@ class Layout:
"cl-ctrl-testtype-all-value": val_all,
})
elif trigger_id == "cl-ctrl-testtype-all":
- val_sel, val_all = self._sync_checklists(
- opt = ctrl_panel.get("cl-ctrl-testtype-options"),
+ val_sel, val_all = sync_checklists(
+ options = ctrl_panel.get("cl-ctrl-testtype-options"),
sel=list(),
all=cl_testtype_all,
id="all"
@@ -1157,8 +1089,8 @@ class Layout:
if url_params:
store_sel = literal_eval(
url_params.get("store_sel", list())[0])
- d_start = self._get_date(url_params.get("start", list())[0])
- d_end = self._get_date(url_params.get("end", list())[0])
+ d_start = get_date(url_params.get("start", list())[0])
+ d_end = get_date(url_params.get("end", list())[0])
if store_sel:
row_card_sel_tests = C.STYLE_ENABLED
row_btns_sel_tests = C.STYLE_ENABLED
@@ -1170,10 +1102,17 @@ class Layout:
_generate_plotting_area(
graph_trending(self.data, store_sel, self.layout,
d_start, d_end, bool(cl_normalize)),
- _gen_new_url(parsed_url, store_sel, d_start, d_end)
+ gen_new_url(
+ parsed_url,
+ {
+ "store_sel": store_sel,
+ "start": d_start,
+ "end": d_end
+ }
+ )
)
ctrl_panel.set({
- "cl-selected-options": self._list_tests(store_sel)
+ "cl-selected-options": list_tests(store_sel)
})
else:
row_fig_tput = C.PLACEHOLDER
diff --git a/resources/tools/dash/app/pal/utils/utils.py b/resources/tools/dash/app/pal/utils/utils.py
index 63c9c1aaa4..70fb02e189 100644
--- a/resources/tools/dash/app/pal/utils/utils.py
+++ b/resources/tools/dash/app/pal/utils/utils.py
@@ -11,12 +11,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+"""Function used by Dash applications.
"""
-"""
+
+import dash_bootstrap_components as dbc
from numpy import isnan
+from dash import dcc
+from datetime import datetime
from ..jumpavg import classify
+from ..utils.constants import Constants as C
+from ..utils.url_processing import url_encode
def classify_anomalies(data):
@@ -67,3 +73,136 @@ def classify_anomalies(data):
stdevs.append(stdv)
values_left -= 1
return classification, avgs, stdevs
+
+
+def get_color(idx: int) -> str:
+ """Returns a color from the list defined in Constants.PLOT_COLORS defined by
+ its index.
+
+ :param idx: Index of the color.
+ :type idex: int
+ :returns: Color defined by hex code.
+ :trype: str
+ """
+ return C.PLOT_COLORS[idx % len(C.PLOT_COLORS)]
+
+
+def show_tooltip(tooltips:dict, id: str, title: str,
+ clipboard_id: str=None) -> list:
+ """Generate list of elements to display a text (e.g. a title) with a
+ tooltip and optionaly with Copy&Paste icon and the clipboard
+ functionality enabled.
+
+ :param tooltips: Dictionary with tooltips.
+ :param id: Tooltip ID.
+ :param title: A text for which the tooltip will be displayed.
+ :param clipboard_id: If defined, a Copy&Paste icon is displayed and the
+ clipboard functionality is enabled.
+ :type tooltips: dict
+ :type id: str
+ :type title: str
+ :type clipboard_id: str
+ :returns: List of elements to display a text with a tooltip and
+ optionaly with Copy&Paste icon.
+ :rtype: list
+ """
+
+ return [
+ dcc.Clipboard(target_id=clipboard_id, title="Copy URL") \
+ if clipboard_id else str(),
+ f"{title} ",
+ dbc.Badge(
+ id=id,
+ children="?",
+ pill=True,
+ color="white",
+ text_color="info",
+ class_name="border ms-1",
+ ),
+ dbc.Tooltip(
+ children=tooltips.get(id, str()),
+ target=id,
+ placement="auto"
+ )
+ ]
+
+
+def label(key: str) -> str:
+ """Returns a label for input elements (dropdowns, ...).
+
+ If the label is not defined, the function returns the provided key.
+
+ :param key: The key to the label defined in Constants.LABELS.
+ :type key: str
+ :returns: Label.
+ :rtype: str
+ """
+ return C.LABELS.get(key, key)
+
+
+def sync_checklists(options: list, sel: list, all: list, id: str) -> tuple:
+ """Synchronize a checklist with defined "options" with its "All" checklist.
+
+ :param options: List of options for the cheklist.
+ :param sel: List of selected options.
+ :param all: List of selected option from "All" checklist.
+ :param id: ID of a checklist to be used for synchronization.
+ :returns: Tuple of lists with otions for both checklists.
+ :rtype: tuple of lists
+ """
+ opts = {v["value"] for v in options}
+ if id =="all":
+ sel = list(opts) if all else list()
+ else:
+ all = ["all", ] if set(sel) == opts else list()
+ return sel, all
+
+
+def list_tests(selection: dict) -> list:
+ """Transform list of tests to a list of dictionaries usable by checkboxes.
+
+ :param selection: List of tests to be displayed in "Selected tests" window.
+ :type selection: list
+ :returns: List of dictionaries with "label", "value" pairs for a checkbox.
+ :rtype: list
+ """
+ if selection:
+ return [{"label": v["id"], "value": v["id"]} for v in selection]
+ else:
+ return list()
+
+
+def get_date(s_date: str) -> datetime:
+ """Transform string reprezentation of date to datetime.datetime data type.
+
+ :param s_date: String reprezentation of date.
+ :type s_date: str
+ :returns: Date as datetime.datetime.
+ :rtype: datetime.datetime
+ """
+ return datetime(int(s_date[0:4]), int(s_date[5:7]), int(s_date[8:10]))
+
+
+def gen_new_url(parsed_url: dict, params: dict) -> str:
+ """Generate a new URL with encoded parameters.
+
+ :param parsed_url: Dictionary with URL elements. It should contain "scheme",
+ "netloc" and "path".
+ :param params: URL parameters to be encoded to the URL.
+ :type parsed_url: dict
+ :type params: dict
+ :returns Encoded URL with parameters.
+ :rtype: str
+ """
+
+ if parsed_url:
+ return url_encode(
+ {
+ "scheme": parsed_url.get("scheme", ""),
+ "netloc": parsed_url.get("netloc", ""),
+ "path": parsed_url.get("path", ""),
+ "params": params
+ }
+ )
+ else:
+ return str()