aboutsummaryrefslogtreecommitdiffstats
path: root/resources/tools/dash/app
diff options
context:
space:
mode:
authorTibor Frank <tifrank@cisco.com>2022-05-09 15:57:01 +0200
committerTibor Frank <tifrank@cisco.com>2022-05-09 15:57:01 +0200
commit36850dfb1d3ff689cbaf683669e2e55c6db84596 (patch)
tree36366c9cb4c3003d88811f8c10ab3fb2a5323472 /resources/tools/dash/app
parentd3f16c6ceaa5b475a9c8dc13d21817735e087869 (diff)
feat(uti): data to csv
Change-Id: Iebc24dae2b76408f07c145b2638c346193cf8e1e Signed-off-by: Tibor Frank <tifrank@cisco.com>
Diffstat (limited to 'resources/tools/dash/app')
-rw-r--r--resources/tools/dash/app/pal/stats/graphs.py19
-rw-r--r--resources/tools/dash/app/pal/stats/layout.py25
2 files changed, 29 insertions, 15 deletions
diff --git a/resources/tools/dash/app/pal/stats/graphs.py b/resources/tools/dash/app/pal/stats/graphs.py
index 37fc1b2e73..d9f49407d9 100644
--- a/resources/tools/dash/app/pal/stats/graphs.py
+++ b/resources/tools/dash/app/pal/stats/graphs.py
@@ -19,12 +19,16 @@ import pandas as pd
from datetime import datetime, timedelta
-def select_data(data: pd.DataFrame, itm:str) -> pd.DataFrame:
+def select_data(data: pd.DataFrame, itm:str, start: datetime,
+ end: datetime) -> pd.DataFrame:
"""
"""
- df = data.loc[(data["job"] == itm)].sort_values(
- by="start_time", ignore_index=True)
+ df = data.loc[
+ (data["job"] == itm) &
+ (data["start_time"] >= start) & (data["start_time"] <= end)
+ ].sort_values(by="start_time", ignore_index=True)
+ df = df.dropna(subset=["duration", ])
return df
@@ -35,14 +39,7 @@ def graph_statistics(df: pd.DataFrame, job:str, layout: dict,
"""
"""
- data = select_data(df, job)
- data = data.dropna(subset=["duration", ])
- if data.empty:
- return None, None
-
- data = data.loc[(
- (data["start_time"] >= start) & (data["start_time"] <= end)
- )]
+ data = select_data(df, job, start, end)
if data.empty:
return None, None
diff --git a/resources/tools/dash/app/pal/stats/layout.py b/resources/tools/dash/app/pal/stats/layout.py
index 7ac379ae01..1b2aebe332 100644
--- a/resources/tools/dash/app/pal/stats/layout.py
+++ b/resources/tools/dash/app/pal/stats/layout.py
@@ -29,7 +29,7 @@ from datetime import datetime, timedelta
from copy import deepcopy
from ..data.data import Data
-from .graphs import graph_statistics
+from .graphs import graph_statistics, select_data
class Layout:
@@ -661,16 +661,33 @@ class Layout:
@app.callback(
Output("download-data", "data"),
+ State("control-panel", "data"), # Store
+ State("dpr-period", "start_date"),
+ State("dpr-period", "end_date"),
Input("btn-download-data", "n_clicks"),
prevent_initial_call=True
)
- def _download_data(n_clicks):
+ def _download_data(cp_data: dict, start: str, end: str, n_clicks: int):
"""
"""
- if not n_clicks:
+ if not (n_clicks):
raise PreventUpdate
- return dcc.send_data_frame(self.data.to_csv, "statistics.csv")
+ ctrl_panel = self.ControlPanel(cp_data, self.default)
+
+ job = self._get_job(
+ ctrl_panel.get("ri-duts-value"),
+ ctrl_panel.get("ri-ttypes-value"),
+ ctrl_panel.get("ri-cadences-value"),
+ ctrl_panel.get("dd-tbeds-value")
+ )
+
+ start = datetime(int(start[0:4]), int(start[5:7]), int(start[8:10]))
+ end = datetime(int(end[0:4]), int(end[5:7]), int(end[8:10]))
+ data = select_data(self.data, job, start, end)
+ data = data.drop(columns=["job", ])
+
+ return dcc.send_data_frame(data.T.to_csv, f"{job}-stats.csv")
@app.callback(
Output("row-metadata", "children"),