aboutsummaryrefslogtreecommitdiffstats
path: root/resources/tools/dash/app/pal/stats/layout.py
diff options
context:
space:
mode:
authorTibor Frank <tifrank@cisco.com>2022-05-06 14:29:55 +0200
committerTibor Frank <tifrank@cisco.com>2022-05-09 12:47:05 +0200
commitd3f16c6ceaa5b475a9c8dc13d21817735e087869 (patch)
tree2d59e5495cbaffb37d992f5a10a7069fa0d74608 /resources/tools/dash/app/pal/stats/layout.py
parente11de9bb083712650425284e0824e1d635c4c895 (diff)
feat(uti): tooltips
Change-Id: I615affce80f1e6af9ea0a5d581b84e17ee88e458 Signed-off-by: Tibor Frank <tifrank@cisco.com>
Diffstat (limited to 'resources/tools/dash/app/pal/stats/layout.py')
-rw-r--r--resources/tools/dash/app/pal/stats/layout.py120
1 files changed, 83 insertions, 37 deletions
diff --git a/resources/tools/dash/app/pal/stats/layout.py b/resources/tools/dash/app/pal/stats/layout.py
index dedb265684..7ac379ae01 100644
--- a/resources/tools/dash/app/pal/stats/layout.py
+++ b/resources/tools/dash/app/pal/stats/layout.py
@@ -14,6 +14,7 @@
"""Plotly Dash HTML layout override.
"""
+import logging
import pandas as pd
import dash_bootstrap_components as dbc
@@ -38,7 +39,7 @@ class Layout:
DEFAULT_JOB = "csit-vpp-perf-mrr-daily-master-2n-icx"
def __init__(self, app: Flask, html_layout_file: str, spec_file: str,
- graph_layout_file: str, data_spec_file: str,
+ graph_layout_file: str, data_spec_file: str, tooltip_file: str,
time_period: int=None) -> None:
"""
"""
@@ -49,6 +50,7 @@ class Layout:
self._spec_file = spec_file
self._graph_layout_file = graph_layout_file
self._data_spec_file = data_spec_file
+ self._tooltip_file = tooltip_file
self._time_period = time_period
# Read the data:
@@ -138,6 +140,7 @@ class Layout:
# Read from files:
self._html_layout = ""
self._graph_layout = None
+ self._tooltips = dict()
try:
with open(self._html_layout_file, "r") as file_read:
@@ -158,10 +161,23 @@ class Layout:
except YAMLError as err:
raise RuntimeError(
f"An error occurred while parsing the specification file "
- f"{self._graph_layout_file}\n"
- f"{err}"
+ f"{self._graph_layout_file}\n{err}"
+ )
+
+ try:
+ with open(self._tooltip_file, "r") as file_read:
+ self._tooltips = load(file_read, Loader=FullLoader)
+ except IOError as err:
+ logging.warning(
+ f"Not possible to open the file {self._tooltip_file}\n{err}"
+ )
+ except YAMLError as err:
+ logging.warning(
+ f"An error occurred while parsing the specification file "
+ f"{self._tooltip_file}\n{err}"
)
+
self._default_fig_passed, self._default_fig_duration = graph_statistics(
self.data, self._default["job"], self.layout
)
@@ -231,6 +247,25 @@ class Layout:
(self.df_job_info["tbed"] == testbed)
)]["job"].item()
+ def _show_tooltip(self, id: str, title: str) -> list:
+ """
+ """
+ return [
+ 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):
"""
@@ -353,7 +388,8 @@ class Layout:
dcc.Loading(children=[
dbc.Button(
id="btn-download-data",
- children=["Download Data"],
+ children=self._show_tooltip(
+ "help-download", "Download"),
class_name="me-1",
color="info"
),
@@ -379,14 +415,17 @@ class Layout:
class_name="gy-1",
children=[
dbc.Label(
- "Device under Test",
- class_name="p-0"
+ class_name="p-0",
+ children=self._show_tooltip(
+ "help-dut", "Device under Test")
),
- dbc.RadioItems(
- id="ri-duts",
- inline=True,
- value=self.default["dut"],
- options=self.default["duts"]
+ dbc.Row(
+ dbc.RadioItems(
+ id="ri-duts",
+ inline=True,
+ value=self.default["dut"],
+ options=self.default["duts"]
+ )
)
]
),
@@ -394,8 +433,9 @@ class Layout:
class_name="gy-1",
children=[
dbc.Label(
- "Test Type",
- class_name="p-0"
+ class_name="p-0",
+ children=self._show_tooltip(
+ "help-ttype", "Test Type"),
),
dbc.RadioItems(
id="ri-ttypes",
@@ -409,8 +449,9 @@ class Layout:
class_name="gy-1",
children=[
dbc.Label(
- "Cadence",
- class_name="p-0"
+ class_name="p-0",
+ children=self._show_tooltip(
+ "help-cadence", "Cadence"),
),
dbc.RadioItems(
id="ri-cadences",
@@ -424,8 +465,9 @@ class Layout:
class_name="gy-1",
children=[
dbc.Label(
- "Test Bed",
- class_name="p-0"
+ class_name="p-0",
+ children=self._show_tooltip(
+ "help-tbed", "Test Bed"),
),
dbc.Select(
id="dd-tbeds",
@@ -444,29 +486,33 @@ class Layout:
children=self.default["job"]
)
]
+ ),
+ dbc.Row(
+ class_name="g-0 p-2",
+ children=[
+ dbc.Label(
+ class_name="gy-1",
+ children=self._show_tooltip(
+ "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"
+ )
+ ]
)
]
),
- dbc.Row(
- class_name="g-0 p-2",
- children=[
- dbc.Label("Choose the 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 MMMM YY"
- )
- ]
- )
]
)