diff options
author | Tibor Frank <tifrank@cisco.com> | 2022-08-03 15:00:51 +0200 |
---|---|---|
committer | Tibor Frank <tifrank@cisco.com> | 2022-08-03 13:57:50 +0000 |
commit | 808797d2d913eac7581a4e4cba3fb826ddbff775 (patch) | |
tree | 450d088ff8231635b2f498adc682aa07372a9e64 /resources/tools/dash/app/pal/report/layout.py | |
parent | 1f0d4ffc8d3fabe2bd7452760425e005c2970ff6 (diff) |
UTI: Add Download for iterative data.
Change-Id: I79bcfc2449310d4d186146ce79b2143a33ed2d1f
Signed-off-by: Tibor Frank <tifrank@cisco.com>
Diffstat (limited to 'resources/tools/dash/app/pal/report/layout.py')
-rw-r--r-- | resources/tools/dash/app/pal/report/layout.py | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/resources/tools/dash/app/pal/report/layout.py b/resources/tools/dash/app/pal/report/layout.py index 0e8f32405c..978ab0de6c 100644 --- a/resources/tools/dash/app/pal/report/layout.py +++ b/resources/tools/dash/app/pal/report/layout.py @@ -23,6 +23,7 @@ from dash import dcc from dash import html 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 copy import deepcopy from ast import literal_eval @@ -32,7 +33,8 @@ 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 +from .graphs import graph_iterative, table_comparison, get_short_version, \ + select_iterative_data class Layout: @@ -1408,3 +1410,37 @@ class Layout: ] ret_val.extend(ctrl_panel.values()) return ret_val + + @app.callback( + Output("download-data", "data"), + State("selected-tests", "data"), + Input("btn-download-data", "n_clicks"), + prevent_initial_call=True + ) + def _download_data(store_sel, n_clicks): + """Download the data + + :param store_sel: List of tests selected by user stored in the + browser. + :param n_clicks: Number of clicks on the button "Download". + :type store_sel: list + :type n_clicks: int + :returns: dict of data frame content (base64 encoded) and meta data + used by the Download component. + :rtype: dict + """ + + if not n_clicks: + raise PreventUpdate + + if not store_sel: + raise PreventUpdate + + df = pd.DataFrame() + for itm in store_sel: + sel_data = select_iterative_data(self.data, itm) + if sel_data is None: + continue + df = pd.concat([df, sel_data], ignore_index=True) + + return dcc.send_data_frame(df.to_csv, C.REPORT_DOWNLOAD_FILE_NAME) |