aboutsummaryrefslogtreecommitdiffstats
path: root/csit.infra.dash/app/pal/stats/graphs.py
diff options
context:
space:
mode:
authorpmikus <peter.mikus@protonmail.ch>2022-09-19 08:49:01 +0200
committerPeter Mikus <peter.mikus@protonmail.ch>2022-09-19 06:54:43 +0000
commitd6a60b5043c6f7c3dfc45853feb68d0aca5a4a5f (patch)
tree022343584d4e00a0da8ef12eb4e713d67344fc95 /csit.infra.dash/app/pal/stats/graphs.py
parentd2ef7bc01df66f6a27f25d061db064cf4a463267 (diff)
feat(uti): Move directory
Signed-off-by: pmikus <peter.mikus@protonmail.ch> Change-Id: I7300ecfe756baaf3fbeedb020070f882cfaca445
Diffstat (limited to 'csit.infra.dash/app/pal/stats/graphs.py')
-rw-r--r--csit.infra.dash/app/pal/stats/graphs.py124
1 files changed, 124 insertions, 0 deletions
diff --git a/csit.infra.dash/app/pal/stats/graphs.py b/csit.infra.dash/app/pal/stats/graphs.py
new file mode 100644
index 0000000000..f533d72aa8
--- /dev/null
+++ b/csit.infra.dash/app/pal/stats/graphs.py
@@ -0,0 +1,124 @@
+# Copyright (c) 2022 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.
+
+"""
+"""
+
+import plotly.graph_objects as go
+import pandas as pd
+
+
+def select_data(data: pd.DataFrame, itm:str) -> pd.DataFrame:
+ """Select the data for graphs from the provided data frame.
+
+ :param data: Data frame with data for graphs.
+ :param itm: Item (in this case job name) which data will be selected from
+ the input data frame.
+ :type data: pandas.DataFrame
+ :type itm: str
+ :returns: A data frame with selected data.
+ :rtype: pandas.DataFrame
+ """
+
+ df = data.loc[(data["job"] == itm)].sort_values(
+ by="start_time", ignore_index=True)
+ df = df.dropna(subset=["duration", ])
+
+ return df
+
+
+def graph_statistics(df: pd.DataFrame, job:str, layout: dict) -> tuple:
+ """Generate graphs:
+ 1. Passed / failed tests,
+ 2. Job durations
+ with additional information shown in hover.
+
+ :param df: Data frame with input data.
+ :param job: The name of job which data will be presented in the graphs.
+ :param layout: Layout of plot.ly graph.
+ :type df: pandas.DataFrame
+ :type job: str
+ :type layout: dict
+ :returns: Tuple with two generated graphs (pased/failed tests and job
+ duration).
+ :rtype: tuple(plotly.graph_objects.Figure, plotly.graph_objects.Figure)
+ """
+
+ data = select_data(df, job)
+ if data.empty:
+ return None, None
+
+ hover = list()
+ for _, row in data.iterrows():
+ d_type = "trex" if row["dut_type"] == "none" else row["dut_type"]
+ hover_itm = (
+ f"date: {row['start_time'].strftime('%Y-%m-%d %H:%M:%S')}<br>"
+ f"duration: "
+ f"{(int(row['duration']) // 3600):02d}:"
+ f"{((int(row['duration']) % 3600) // 60):02d}<br>"
+ f"passed: {row['passed']}<br>"
+ f"failed: {row['failed']}<br>"
+ f"{d_type}-ref: {row['dut_version']}<br>"
+ f"csit-ref: {row['job']}/{row['build']}<br>"
+ f"hosts: {', '.join(row['hosts'])}"
+ )
+ hover.append(hover_itm)
+
+ # Job durations:
+ fig_duration = go.Figure(
+ data=go.Scatter(
+ x=data["start_time"],
+ y=data["duration"],
+ name=u"Duration",
+ text=hover,
+ hoverinfo=u"text"
+ )
+ )
+
+ tickvals = [0, ]
+ step = max(data["duration"]) / 5
+ for i in range(5):
+ tickvals.append(int(step * (i + 1)))
+ layout_duration = layout.get("plot-stats-duration", dict())
+ if layout_duration:
+ layout_duration["yaxis"]["tickvals"] = tickvals
+ layout_duration["yaxis"]["ticktext"] = [
+ f"{(val // 3600):02d}:{((val % 3600) // 60):02d}" \
+ for val in tickvals
+ ]
+ fig_duration.update_layout(layout_duration)
+
+ # Passed / failed:
+ fig_passed = go.Figure(
+ data=[
+ go.Bar(
+ x=data["start_time"],
+ y=data["passed"],
+ name=u"Passed",
+ hovertext=hover,
+ hoverinfo=u"text"
+ ),
+ go.Bar(
+ x=data["start_time"],
+ y=data["failed"],
+ name=u"Failed",
+ hovertext=hover,
+ hoverinfo=u"text"
+ )
+ ]
+ )
+ layout_pf = layout.get("plot-stats-passed", dict())
+ if layout_pf:
+ fig_passed.update_layout(layout_pf)
+
+ return fig_passed, fig_duration