1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
|
# Copyright (c) 2024 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.
"""Plotly Dash HTML layout override.
"""
import logging
import pandas as pd
import dash_bootstrap_components as dbc
from flask import Flask
from dash import dcc
from dash import html, dash_table
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 ast import literal_eval
from ..utils.constants import Constants as C
from ..utils.control_panel import ControlPanel
from ..utils.trigger import Trigger
from ..utils.utils import gen_new_url, generate_options, navbar_trending, \
filter_table_data, sort_table_data, show_trending_graph_data, \
show_iterative_graph_data, show_tooltip
from ..utils.url_processing import url_decode
from .tables import search_table
from ..coverage.tables import coverage_tables
from ..report.graphs import graph_iterative
from ..trending.graphs import graph_trending
# Control panel partameters and their default values.
CP_PARAMS = {
"datatype-val": str(),
"dut-opt": list(),
"dut-dis": C.STYLE_DONT_DISPLAY,
"dut-val": str(),
"release-opt": list(),
"release-dis": C.STYLE_DONT_DISPLAY,
"release-val": str(),
"help-dis": C.STYLE_DONT_DISPLAY,
"help-val": str(),
"search-dis": C.STYLE_DONT_DISPLAY,
"search-val": str()
}
class Layout:
"""The layout of the dash app and the callbacks.
"""
def __init__(self,
app: Flask,
data: dict,
html_layout_file: str,
graph_layout_file: str,
tooltip_file: str
) -> None:
"""Initialization:
- save the input parameters,
- read and pre-process the data,
- prepare data for the control panel,
- read HTML layout file,
- read graph layout file,
- read tooltips from the tooltip file.
:param app: Flask application running the dash application.
:param data_trending: Pandas dataframe with trending data.
:param html_layout_file: Path and name of the file specifying the HTML
layout of the dash application.
:param graph_layout_file: Path and name of the file with layout of
plot.ly graphs.
:param tooltip_file: Path and name of the yaml file specifying the
tooltips.
:type app: Flask
:type data_trending: pandas.DataFrame
:type html_layout_file: str
:type graph_layout_file: str
:type tooltip_file: str
"""
# Inputs
self._app = app
self._html_layout_file = html_layout_file
self._graph_layout_file = graph_layout_file
self._tooltip_file = tooltip_file
# Inputs - Data
self._data = {
k: v for k, v in data.items() if not v.empty and k != "statistics"
}
for data_type, pd in self._data.items():
if pd.empty:
continue
full_id = list()
for _, row in pd.iterrows():
l_id = row["test_id"].split(".")
suite = l_id[-2].replace("2n1l-", "").replace("1n1l-", "").\
replace("2n-", "")
tb = "-".join(row["job"].split("-")[-2:])
nic = suite.split("-")[0]
for driver in C.DRIVERS:
if driver in suite:
drv = driver
break
else:
drv = "dpdk"
test = l_id[-1]
if data_type in ("iterative", "coverage", ):
full_id.append(
"_".join((row["release"], row["dut_type"],
row["dut_version"], tb, nic, drv, test))
)
else: # Trending
full_id.append(
"_".join((row["dut_type"], tb, nic, drv, test))
)
pd["full_id"] = full_id
# Get structure of tests:
self._duts = dict()
for data_type, pd in self._data.items():
if pd.empty:
continue
self._duts[data_type] = dict()
if data_type in ("iterative", "coverage", ):
cols = ["job", "dut_type", "dut_version", "release", "test_id"]
for _, row in pd[cols].drop_duplicates().iterrows():
dut = row["dut_type"]
if self._duts[data_type].get(dut, None) is None:
self._duts[data_type][dut] = list()
if row["release"] not in self._duts[data_type][dut]:
self._duts[data_type][dut].append(row["release"])
else:
for dut in pd["dut_type"].unique():
if self._duts[data_type].get(dut, None) is None:
self._duts[data_type][dut] = list()
# Read from files:
self._html_layout = str()
self._graph_layout = None
self._tooltips = dict()
try:
with open(self._html_layout_file, "r") as file_read:
self._html_layout = file_read.read()
except IOError as err:
raise RuntimeError(
f"Not possible to open the file {self._html_layout_file}\n{err}"
)
try:
with open(self._graph_layout_file, "r") as file_read:
self._graph_layout = load(file_read, Loader=FullLoader)
except IOError as err:
raise RuntimeError(
f"Not possible to open the file {self._graph_layout_file}\n"
f"{err}"
)
except YAMLError as err:
raise RuntimeError(
f"An error occurred while parsing the specification file "
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}"
)
# Callbacks:
if self._app is not None and hasattr(self, "callbacks"):
self.callbacks(self._app)
@property
def html_layout(self):
return self._html_layout
def add_content(self):
"""Top level method which generated the web page.
It generates:
- Store for user input data,
- Navigation bar,
- Main area with control panel and ploting area.
If no HTML layout is provided, an error message is displayed instead.
:returns: The HTML div with the whole page.
:rtype: html.Div
"""
if self.html_layout and self._duts:
return html.Div(
id="div-main",
className="small",
children=[
dcc.Store(id="store"),
dcc.Store(id="store-table-data"),
dcc.Store(id="store-filtered-table-data"),
dcc.Location(id="url", refresh=False),
dbc.Row(
id="row-navbar",
class_name="g-0",
children=[navbar_trending((False, False, False, True))]
),
dbc.Row(
id="row-main",
class_name="g-0",
children=[
self._add_ctrl_col(),
self._add_plotting_col()
]
),
dbc.Spinner(
dbc.Offcanvas(
class_name="w-75",
id="offcanvas-details",
title="Test Details",
placement="end",
is_open=False,
children=[]
),
delay_show=C.SPINNER_DELAY
),
dbc.Spinner(
dbc.Offcanvas(
class_name="w-50",
id="offcanvas-metadata",
title="Detailed Information",
placement="end",
is_open=False,
children=[
dbc.Row(id="metadata-tput-lat"),
dbc.Row(id="metadata-hdrh-graph")
]
),
delay_show=C.SPINNER_DELAY
),
dbc.Offcanvas(
class_name="w-75",
id="offcanvas-documentation",
title="Documentation",
placement="end",
is_open=False,
children=html.Iframe(
src=C.URL_DOC_TRENDING,
width="100%",
height="100%"
)
)
]
)
else:
return html.Div(
dbc.Alert("An Error Occured", color="danger"),
id="div-main-error"
)
def _add_ctrl_col(self) -> dbc.Col:
"""Add column with controls. It is placed on the left side.
:returns: Column with the control panel.
:rtype: dbc.Col
"""
return dbc.Col(html.Div(self._add_ctrl_panel(), className="sticky-top"))
def _add_ctrl_panel(self) -> list:
"""Add control panel.
:returns: Control panel.
:rtype: list
"""
return [
dbc.Row(
class_name="g-0 p-1",
children=[
dbc.InputGroup(
[
dbc.InputGroupText(show_tooltip(
self._tooltips,
"help-data-type",
"Data Type"
)),
dbc.Select(
id={"type": "ctrl-dd", "index": "datatype"},
placeholder="Select a Data Type...",
options=sorted(
[
{"label": k, "value": k} \
for k in self._data.keys()
],
key=lambda d: d["label"]
)
)
],
size="sm"
)
],
style=C.STYLE_DISPLAY
),
dbc.Row(
class_name="g-0 p-1",
id={"type": "ctrl-row", "index": "dut"},
children=[
dbc.InputGroup(
[
dbc.InputGroupText(show_tooltip(
self._tooltips,
"help-dut",
"DUT"
)),
dbc.Select(
id={"type": "ctrl-dd", "index": "dut"},
placeholder="Select a Device under Test..."
)
],
size="sm"
)
],
style=C.STYLE_DONT_DISPLAY
),
dbc.Row(
class_name="g-0 p-1",
id={"type": "ctrl-row", "index": "release"},
children=[
dbc.InputGroup(
[
dbc.InputGroupText(show_tooltip(
self._tooltips,
"help-release",
"CSIT Release"
)),
dbc.Select(
id={"type": "ctrl-dd", "index": "release"},
placeholder="Select a Release..."
)
],
size="sm"
)
],
style=C.STYLE_DONT_DISPLAY
),
dbc.Row(
class_name="g-0 p-1",
id={"type": "ctrl-row", "index": "help"},
children=[
dbc.Input(
id={"type": "ctrl-dd", "index": "help"},
readonly=True,
debounce=True,
size="sm"
)
],
style=C.STYLE_DONT_DISPLAY
),
dbc.Row(
class_name="g-0 p-1",
id={"type": "ctrl-row", "index": "search"},
children=[
dbc.Input(
id={"type": "ctrl-dd", "index": "search"},
placeholder="Type a Regular Expression...",
debounce=True,
size="sm"
)
],
style=C.STYLE_DONT_DISPLAY
)
]
def _add_plotting_col(self) -> dbc.Col:
"""Add column with tables. It is placed on the right side.
:returns: Column with tables.
:rtype: dbc.Col
"""
return dbc.Col(
id="col-plotting-area",
children=[
dbc.Spinner(
children=[
dbc.Row(
id="plotting-area",
class_name="g-0 p-0",
children=[C.PLACEHOLDER, ]
)
]
)
],
width=9
)
@staticmethod
def _get_plotting_area(table: pd.DataFrame, url: str) -> list:
"""Generate the plotting area with all its content.
:param table: Search table to be displayed.
:param url: URL to be displayed in a modal window.
:type table: pandas.DataFrame
:type url: str
:returns: List of rows with elements to be displayed in the plotting
area.
:rtype: list
"""
if table.empty:
return dbc.Row(
dbc.Col(
children=dbc.Alert(
"No data found.",
color="danger"
),
class_name="g-0 p-1",
),
class_name="g-0 p-0"
)
columns = [{"name": col, "id": col} for col in table.columns]
return [
dbc.Row(
children=[
dbc.Col(
children=dash_table.DataTable(
id={"type": "table", "index": "search"},
columns=columns,
data=table.to_dict("records"),
filter_action="custom",
sort_action="custom",
sort_mode="multi",
selected_columns=[],
selected_rows=[],
page_action="none",
style_cell={"textAlign": "left"}
),
class_name="g-0 p-1"
)
],
class_name="g-0 p-0"
),
dbc.Row(
[
dbc.Col([html.Div(
[
dbc.Button(
id="plot-btn-url",
children="Show URL",
class_name="me-1",
color="info",
style={
"text-transform": "none",
"padding": "0rem 1rem"
}
),
dbc.Modal(
[
dbc.ModalHeader(dbc.ModalTitle("URL")),
dbc.ModalBody(url)
],
id="plot-mod-url",
size="xl",
is_open=False,
scrollable=True
),
dbc.Button(
id="plot-btn-download",
children="Download Data",
class_name="me-1",
color="info",
style={
"text-transform": "none",
"padding": "0rem 1rem"
}
),
dcc.Download(id="download-data")
],
className=\
"d-grid gap-0 d-md-flex justify-content-md-end"
)])
],
class_name="g-0 p-0"
),
dbc.Row(
children=C.PLACEHOLDER,
class_name="g-0 p-1"
)
]
def callbacks(self, app):
"""Callbacks for the whole application.
:param app: The application.
:type app: Flask
"""
@app.callback(
Output("store", "data"),
Output("store-table-data", "data"),
Output("store-filtered-table-data", "data"),
Output("plotting-area", "children"),
Output({"type": "table", "index": ALL}, "data"),
Output({"type": "ctrl-dd", "index": "datatype"}, "value"),
Output({"type": "ctrl-dd", "index": "dut"}, "options"),
Output({"type": "ctrl-row", "index": "dut"}, "style"),
Output({"type": "ctrl-dd", "index": "dut"}, "value"),
Output({"type": "ctrl-dd", "index": "release"}, "options"),
Output({"type": "ctrl-row", "index": "release"}, "style"),
Output({"type": "ctrl-dd", "index": "release"}, "value"),
Output({"type": "ctrl-row", "index": "help"}, "style"),
Output({"type": "ctrl-dd", "index": "help"}, "value"),
Output({"type": "ctrl-row", "index": "search"}, "style"),
Output({"type": "ctrl-dd", "index": "search"}, "value"),
State("store", "data"),
State("store-table-data", "data"),
State("store-filtered-table-data", "data"),
State({"type": "table", "index": ALL}, "data"),
Input("url", "href"),
Input({"type": "table", "index": ALL}, "filter_query"),
Input({"type": "table", "index": ALL}, "sort_by"),
Input({"type": "ctrl-dd", "index": ALL}, "value"),
prevent_initial_call=True
)
def _update_application(
store: dict,
store_table_data: list,
filtered_data: list,
table_data: list,
href: str,
*_
) -> tuple:
"""Update the application when the event is detected.
"""
if store is None:
store = {
"control-panel": dict(),
"selection": dict()
}
ctrl_panel = ControlPanel(
CP_PARAMS,
store.get("control-panel", dict())
)
selection = store["selection"]
plotting_area = no_update
on_draw = False
# Parse the url:
parsed_url = url_decode(href)
if parsed_url:
url_params = parsed_url["params"]
else:
url_params = None
trigger = Trigger(callback_context.triggered)
if trigger.type == "url" and url_params:
try:
selection = literal_eval(url_params["selection"][0])
if selection:
dtype = selection["datatype"]
dut = selection["dut"]
if dtype == "trending":
rls_opts = list()
rls_dis = C.STYLE_DONT_DISPLAY
else:
rls_opts = generate_options(self._duts[dtype][dut])
rls_dis = C.STYLE_DISPLAY
ctrl_panel.set({
"datatype-val": dtype,
"dut-opt": \
generate_options(self._duts[dtype].keys()),
"dut-dis": C.STYLE_DISPLAY,
"dut-val": dut,
"release-opt": rls_opts,
"release-dis": rls_dis,
"release-val": selection["release"],
"help-dis": C.STYLE_DISPLAY,
"help-val": selection["help"],
"search-dis": C.STYLE_DISPLAY,
"search-val": selection["regexp"]
})
on_draw = True
except (KeyError, IndexError, AttributeError, ValueError):
pass
elif trigger.type == "ctrl-dd":
if trigger.idx == "datatype":
try:
data_type = self._duts[trigger.value]
options = generate_options(data_type.keys())
disabled = C.STYLE_DISPLAY
except KeyError:
options = list()
disabled = C.STYLE_DONT_DISPLAY
ctrl_panel.set({
"datatype-val": trigger.value,
"dut-opt": options,
"dut-dis": disabled,
"dut-val": str(),
"release-opt": list(),
"release-dis": C.STYLE_DONT_DISPLAY,
"release-val": str(),
"help-dis": C.STYLE_DONT_DISPLAY,
"help-val": str(),
"search-dis": C.STYLE_DONT_DISPLAY,
"search-val": str()
})
elif trigger.idx == "dut":
try:
data_type = ctrl_panel.get("datatype-val")
dut = self._duts[data_type][trigger.value]
if data_type != "trending":
options = generate_options(dut)
disabled = C.STYLE_DISPLAY
except KeyError:
options = list()
disabled = C.STYLE_DONT_DISPLAY
if data_type == "trending":
ctrl_panel.set({
"dut-val": trigger.value,
"release-opt": list(),
"release-dis": C.STYLE_DONT_DISPLAY,
"release-val": str(),
"help-dis": disabled,
"help-val": "<testbed> <nic> <driver> " + \
"<framesize> <cores> <test>",
"search-dis": disabled,
"search-val": str()
})
else:
ctrl_panel.set({
"dut-val": trigger.value,
"release-opt": options,
"release-dis": disabled,
"release-val": str(),
"help-dis": C.STYLE_DONT_DISPLAY,
"help-val": str(),
"search-dis": C.STYLE_DONT_DISPLAY,
"search-val": str()
})
elif trigger.idx == "release":
ctrl_panel.set({
"release-val": trigger.value,
"help-dis": C.STYLE_DISPLAY,
"help-val": "<DUT version> <testbed> <nic> " + \
"<driver> <framesize> <core> <test>",
"search-dis": C.STYLE_DISPLAY,
"search-val": str()
})
elif trigger.idx == "search":
ctrl_panel.set({"search-val": trigger.value})
selection = {
"datatype": ctrl_panel.get("datatype-val"),
"dut": ctrl_panel.get("dut-val"),
"release": ctrl_panel.get("release-val"),
"help": ctrl_panel.get("help-val"),
"regexp": ctrl_panel.get("search-val"),
}
on_draw = True
elif trigger.type == "table" and trigger.idx == "search":
if trigger.parameter == "filter_query":
filtered_data = filter_table_data(
store_table_data,
trigger.value
)
elif trigger.parameter == "sort_by":
filtered_data = sort_table_data(
store_table_data,
trigger.value
)
table_data = [filtered_data, ]
if on_draw:
table = search_table(data=self._data, selection=selection)
plotting_area = Layout._get_plotting_area(
table,
gen_new_url(parsed_url, {"selection": selection})
)
store_table_data = table.to_dict("records")
filtered_data = store_table_data
if table_data:
table_data = [store_table_data, ]
else:
plotting_area = no_update
store["control-panel"] = ctrl_panel.panel
store["selection"] = selection
ret_val = [
store,
store_table_data,
filtered_data,
plotting_area,
table_data
]
ret_val.extend(ctrl_panel.values)
return ret_val
@app.callback(
Output("offcanvas-details", "is_open"),
Output("offcanvas-details", "children"),
State("store", "data"),
State("store-filtered-table-data", "data"),
Input({"type": "table", "index": ALL}, "active_cell"),
prevent_initial_call=True
)
def show_test_data(store, table, *_):
"""Show offcanvas with graphs and tables based on selected test(s).
"""
trigger = Trigger(callback_context.triggered)
if not trigger.value:
raise PreventUpdate
try:
row = pd.DataFrame.from_records(table).\
iloc[[trigger.value["row"]]]
datatype = store["selection"]["datatype"]
dut = store["selection"]["dut"]
rls = store["selection"]["release"]
tb = row["Test Bed"].iloc[0]
nic = row["NIC"].iloc[0]
driver = row["Driver"].iloc[0]
test_name = row["Test"].iloc[0]
dutver = str()
except(KeyError, IndexError, AttributeError, ValueError):
raise PreventUpdate
data = self._data[datatype]
if datatype == "trending":
df = pd.DataFrame(data.loc[data["dut_type"] == dut])
else:
dutver = row["DUT Version"].iloc[0]
df = pd.DataFrame(data.loc[(
(data["dut_type"] == dut) &
(data["dut_version"] == dutver) &
(data["release"] == rls)
)])
df = df[df.full_id.str.contains(
f".*{tb}.*{nic}.*{test_name}",
regex=True
)]
if datatype in ("trending", "iterative"):
l_test_id = df["test_id"].iloc[0].split(".")
if dut == "dpdk":
area = "dpdk"
else:
area = ".".join(l_test_id[3:-2])
for drv in C.DRIVERS:
if drv in test_name:
test = test_name.replace(f"{drv}-", "")
break
else:
test = test_name
l_test = test.split("-")
testtype = l_test[-1]
if testtype == "ndrpdr":
testtype = ["ndr", "pdr"]
else:
testtype = [testtype, ]
core = l_test[1] if l_test[1] else "8c"
test = "-".join(l_test[2: -1])
test_id = f"{tb}-{nic}-{driver}-{l_test[0]}-{core}-{test}"
title = dbc.Row(
class_name="g-0 p-0",
children=dbc.Alert(test_id, color="info"),
)
selected = list()
indexes = ("tput", "bandwidth", "lat")
if datatype == "trending":
for ttype in testtype:
selected.append({
"id": f"{dut}-{test_id}-{ttype}",
"dut": dut,
"phy": f"{tb}-{nic}-{driver}",
"area": area,
"test": test,
"framesize": l_test[0],
"core": core,
"testtype": ttype
})
graphs = graph_trending(df, selected, self._graph_layout)
labels = ("Throughput", "Bandwidth", "Latency")
tabs = list()
for graph, label, idx in zip(graphs, labels, indexes):
if graph:
tabs.append(dbc.Tab(
children=dcc.Graph(
figure=graph,
id={"type": "graph-trend", "index": idx},
),
label=label
))
if tabs:
ret_val = [
title,
dbc.Row(dbc.Tabs(tabs), class_name="g-0 p-0")
]
else:
ret_val = [
title,
dbc.Row("No data.", class_name="g-0 p-0")
]
else: # Iterative
for ttype in testtype:
selected.append({
"id": f"{test_id}-{ttype}",
"rls": rls,
"dut": dut,
"dutver": dutver,
"phy": f"{tb}-{nic}-{driver}",
"area": area,
"test": test,
"framesize": l_test[0],
"core": core,
"testtype": ttype
})
graphs = graph_iterative(df, selected, self._graph_layout)
cols = list()
for graph, idx in zip(graphs, indexes):
if graph:
cols.append(dbc.Col(dcc.Graph(
figure=graph,
id={"type": "graph-iter", "index": idx},
)))
if not cols:
cols="No data."
ret_val = [
title,
dbc.Row(class_name="g-0 p-0", children=cols)
]
elif datatype == "coverage":
ret_val = coverage_tables(
data=df,
selected={
"rls": rls,
"dut": dut,
"dutver": dutver,
"phy": f"{tb}-{nic}-{driver}",
"area": ".*",
},
start_collapsed=False
)
else:
raise PreventUpdate
return True, ret_val
@app.callback(
Output("metadata-tput-lat", "children"),
Output("metadata-hdrh-graph", "children"),
Output("offcanvas-metadata", "is_open"),
Input({"type": "graph-trend", "index": ALL}, "clickData"),
Input({"type": "graph-iter", "index": ALL}, "clickData"),
prevent_initial_call=True
)
def _show_metadata_from_graph(
trend_data: dict,
iter_data: dict
) -> tuple:
"""Generates the data for the offcanvas displayed when a particular
point in a graph is clicked on.
"""
trigger = Trigger(callback_context.triggered)
if not trigger.value:
raise PreventUpdate
if trigger.type == "graph-trend":
return show_trending_graph_data(
trigger, trend_data, self._graph_layout)
elif trigger.type == "graph-iter":
return show_iterative_graph_data(
trigger, iter_data, self._graph_layout)
else:
raise PreventUpdate
@app.callback(
Output("plot-mod-url", "is_open"),
Input("plot-btn-url", "n_clicks"),
State("plot-mod-url", "is_open")
)
def toggle_plot_mod_url(n, is_open):
"""Toggle the modal window with url.
"""
if n:
return not is_open
return is_open
@app.callback(
Output("download-data", "data"),
State("store-filtered-table-data", "data"),
Input("plot-btn-download", "n_clicks"),
prevent_initial_call=True
)
def _download_search_data(selection, _):
"""Download the data.
:param selection: Selected data in table format (records).
:type selection: dict
:returns: dict of data frame content (base64 encoded) and meta data
used by the Download component.
:rtype: dict
"""
if not selection:
raise PreventUpdate
return dcc.send_data_frame(
pd.DataFrame.from_records(selection).to_csv,
C.SEARCH_DOWNLOAD_FILE_NAME
)
@app.callback(
Output("offcanvas-documentation", "is_open"),
Input("btn-documentation", "n_clicks"),
State("offcanvas-documentation", "is_open")
)
def toggle_offcanvas_documentation(n_clicks, is_open):
if n_clicks:
return not is_open
return is_open
|