X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=resources%2Ftools%2Fdash%2Fapp%2Fpal%2Ftrending%2Flayout.py;h=470f72ef220c853636bdea11a9c63699ba3b85dd;hb=54b40c5fbfa6102d3e71502ebcb9ca56cb5ef80c;hp=ddc39dc4435f94a6838e4436d88aca2c7d9e9a4e;hpb=65421a4ebc81c4e163b3cb38dd6d095b8e99f2d4;p=csit.git
diff --git a/resources/tools/dash/app/pal/trending/layout.py b/resources/tools/dash/app/pal/trending/layout.py
index ddc39dc443..470f72ef22 100644
--- a/resources/tools/dash/app/pal/trending/layout.py
+++ b/resources/tools/dash/app/pal/trending/layout.py
@@ -17,14 +17,16 @@
import pandas as pd
import dash_bootstrap_components as dbc
+from flask import Flask
from dash import dcc
from dash import html
-from dash import callback_context, no_update
+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 datetime import datetime, timedelta
from copy import deepcopy
+from json import loads, JSONDecodeError
from ..data.data import Data
from .graphs import graph_trending, graph_hdrh_latency, \
@@ -51,8 +53,9 @@ class Layout:
PLACEHOLDER = html.Nobr("")
- def __init__(self, app, html_layout_file, spec_file, graph_layout_file,
- data_spec_file):
+ def __init__(self, app: Flask, html_layout_file: str, spec_file: str,
+ graph_layout_file: str, data_spec_file: str,
+ time_period: str=None) -> None:
"""
"""
@@ -62,20 +65,26 @@ class Layout:
self._spec_file = spec_file
self._graph_layout_file = graph_layout_file
self._data_spec_file = data_spec_file
+ self._time_period = time_period
# Read the data:
data_mrr = Data(
data_spec_file=self._data_spec_file,
debug=True
- ).read_trending_mrr(days=5)
+ ).read_trending_mrr(days=self._time_period)
data_ndrpdr = Data(
data_spec_file=self._data_spec_file,
debug=True
- ).read_trending_ndrpdr(days=14)
+ ).read_trending_ndrpdr(days=self._time_period)
self._data = pd.concat([data_mrr, data_ndrpdr], ignore_index=True)
+ data_time_period = \
+ (datetime.utcnow() - self._data["start_time"].min()).days
+ if self._time_period > data_time_period:
+ self._time_period = data_time_period
+
# Read from files:
self._html_layout = ""
self._spec_tbs = None
@@ -138,6 +147,10 @@ class Layout:
def layout(self):
return self._graph_layout
+ @property
+ def time_period(self):
+ return self._time_period
+
def add_content(self):
"""
"""
@@ -154,6 +167,7 @@ class Layout:
),
dcc.Loading(
dbc.Offcanvas(
+ class_name="w-50",
id="offcanvas-metadata",
title="Throughput And Latency",
placement="end",
@@ -264,48 +278,58 @@ class Layout:
class_name="g-0 p-2",
children=[
dbc.Row(
- class_name="gy-1",
+ class_name="g-0",
children=[
- dbc.Label(
- "Physical Test Bed Topology, NIC and Driver",
- class_name="p-0"
- ),
- dbc.Select(
- id="dd-ctrl-phy",
- placeholder="Select a Physical Test Bed Topology...",
- options=[
- {"label": k, "value": k} for k in self.spec_tbs.keys()
+ dbc.InputGroup(
+ [
+ dbc.InputGroupText("Infra"),
+ dbc.Select(
+ id="dd-ctrl-phy",
+ placeholder=(
+ "Select a Physical Test Bed "
+ "Topology..."
+ ),
+ options=[
+ {"label": k, "value": k} \
+ for k in self.spec_tbs.keys()
+ ],
+ ),
],
+ class_name="mb-3",
size="sm",
),
]
),
dbc.Row(
- class_name="gy-1",
+ class_name="g-0",
children=[
- dbc.Label(
- "Area",
- class_name="p-0"
- ),
- dbc.Select(
- id="dd-ctrl-area",
- placeholder="Select an Area...",
- disabled=True,
+ dbc.InputGroup(
+ [
+ dbc.InputGroupText("Area"),
+ dbc.Select(
+ id="dd-ctrl-area",
+ placeholder="Select an Area...",
+ disabled=True,
+ ),
+ ],
+ class_name="mb-3",
size="sm",
),
]
),
dbc.Row(
- class_name="gy-1",
+ class_name="g-0",
children=[
- dbc.Label(
- "Test",
- class_name="p-0"
- ),
- dbc.Select(
- id="dd-ctrl-test",
- placeholder="Select a Test...",
- disabled=True,
+ dbc.InputGroup(
+ [
+ dbc.InputGroupText("Test"),
+ dbc.Select(
+ id="dd-ctrl-test",
+ placeholder="Select a Test...",
+ disabled=True,
+ ),
+ ],
+ class_name="mb-3",
size="sm",
),
]
@@ -401,14 +425,15 @@ class Layout:
]
),
dbc.Row(
- class_name="gy-1",
+ class_name="gy-1 p-0",
children=[
dbc.ButtonGroup(
[
dbc.Button(
id="btn-ctrl-add",
children="Add Selected",
- color="secondary",
+ class_name="me-1",
+ color="info"
)
],
size="md",
@@ -420,11 +445,15 @@ class Layout:
children=[
dcc.DatePickerRange(
id="dpr-period",
+ className="d-flex justify-content-center",
min_date_allowed=\
- datetime.utcnow()-timedelta(days=180),
+ datetime.utcnow() - timedelta(
+ days=self.time_period),
max_date_allowed=datetime.utcnow(),
initial_visible_month=datetime.utcnow(),
- start_date=datetime.utcnow() - timedelta(days=180),
+ start_date=\
+ datetime.utcnow() - timedelta(
+ days=self.time_period),
end_date=datetime.utcnow(),
display_format="D MMMM YY"
)
@@ -453,28 +482,22 @@ class Layout:
style=self.STYLE_DISABLED,
children=[
dbc.ButtonGroup(
+ class_name="gy-2",
children=[
- dbc.Button(
- id="btn-sel-remove-all",
- children="Remove All",
- class_name="w-100",
- color="secondary",
- disabled=False
- ),
dbc.Button(
id="btn-sel-remove",
children="Remove Selected",
- class_name="w-100",
- color="secondary",
+ class_name="w-100 me-1",
+ color="info",
disabled=False
),
dbc.Button(
- id="btn-sel-display",
- children="Display",
- class_name="w-100",
- color="secondary",
+ id="btn-sel-remove-all",
+ children="Remove All",
+ class_name="w-100 me-1",
+ color="info",
disabled=False
- )
+ ),
],
size="md",
)
@@ -581,7 +604,7 @@ class Layout:
row_fig_tput = [
dcc.Loading(
dcc.Graph(
- id="graph-tput",
+ id={"type": "graph", "index": "tput"},
figure=fig_tput
)
),
@@ -590,7 +613,9 @@ class Layout:
dcc.Loading(children=[
dbc.Button(
id="btn-download-data",
- children=["Download Data"]
+ children=["Download Data"],
+ class_name="me-1",
+ color="info"
),
dcc.Download(id="download-data")
]),
@@ -599,7 +624,7 @@ class Layout:
row_fig_lat = [
dcc.Loading(
dcc.Graph(
- id="graph-latency",
+ id={"type": "graph", "index": "lat"},
figure=fig_lat
)
)
@@ -651,7 +676,6 @@ class Layout:
Input("btn-ctrl-add", "n_clicks"),
Input("dpr-period", "start_date"),
Input("dpr-period", "end_date"),
- Input("btn-sel-display", "n_clicks"),
Input("btn-sel-remove", "n_clicks"),
Input("btn-sel-remove-all", "n_clicks"),
)
@@ -659,7 +683,7 @@ class Layout:
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, btn_add: int,
- d_start: str, d_end: str, btn_display: int, btn_remove: int,
+ d_start: str, d_end: str, btn_remove: int,
btn_remove_all: int) -> tuple:
"""
"""
@@ -879,8 +903,13 @@ class Layout:
ctrl_panel.set({
"cl-selected-options": self._list_tests(store_sel)
})
- elif trigger_id in ("btn-sel-display", "dpr-period"):
- _ = btn_display
+ row_fig_tput, row_fig_lat, row_btn_dwnld = \
+ _generate_plotting_arrea(
+ graph_trending(
+ self.data, store_sel, self.layout, d_start, d_end
+ )
+ )
+ elif trigger_id == "dpr-period":
row_fig_tput, row_fig_lat, row_btn_dwnld = \
_generate_plotting_arrea(
graph_trending(
@@ -939,30 +968,38 @@ class Layout:
Output("metadata-tput-lat", "children"),
Output("metadata-hdrh-graph", "children"),
Output("offcanvas-metadata", "is_open"),
- Input("graph-tput", "clickData"),
- Input("graph-latency", "clickData")
+ Input({"type": "graph", "index": ALL}, "clickData"),
+ prevent_initial_call=True
)
- def _show_metadata_from_graphs(
- tput_data: dict, lat_data: dict) -> tuple:
+ def _show_metadata_from_graphs(graph_data: dict) -> tuple:
"""
"""
- if not (tput_data or lat_data):
+ try:
+ trigger_id = loads(
+ callback_context.triggered[0]["prop_id"].split(".")[0]
+ )["index"]
+ idx = 0 if trigger_id == "tput" else 1
+ graph_data = graph_data[idx]["points"][0]
+ except (JSONDecodeError, IndexError, KeyError, ValueError,
+ TypeError):
raise PreventUpdate
metadata = no_update
graph = list()
- trigger_id = callback_context.triggered[0]["prop_id"].split(".")[0]
- if trigger_id == "graph-tput":
+ children = [
+ dbc.ListGroupItem(
+ [dbc.Badge(x.split(":")[0]), x.split(": ")[1]]
+ ) for x in graph_data.get("text", "").split("
")
+ ]
+ if trigger_id == "tput":
title = "Throughput"
- txt = tput_data["points"][0]["text"].replace("
", "\n")
- elif trigger_id == "graph-latency":
+ elif trigger_id == "lat":
title = "Latency"
- txt = lat_data["points"][0]["text"].replace("
", "\n")
- hdrh_data = lat_data["points"][0].get("customdata", None)
+ hdrh_data = graph_data.get("customdata", None)
if hdrh_data:
graph = [dbc.Card(
- class_name="g-0",
+ class_name="gy-2 p-0",
children=[
dbc.CardHeader(hdrh_data.pop("name")),
dbc.CardBody(children=[
@@ -977,7 +1014,7 @@ class Layout:
]
metadata = [
dbc.Card(
- class_name="g-0",
+ class_name="gy-2 p-0",
children=[
dbc.CardHeader(children=[
dcc.Clipboard(
@@ -989,7 +1026,8 @@ class Layout:
]),
dbc.CardBody(
id="tput-lat-metadata",
- children=[txt]
+ class_name="p-0",
+ children=[dbc.ListGroup(children, flush=True), ]
)
]
)