1 # Copyright (c) 2022 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
17 import plotly.graph_objects as go
20 from datetime import datetime, timedelta
22 def select_data(data: pd.DataFrame, itm:str) -> pd.DataFrame:
26 df = data.loc[(data["job"] == itm)].sort_values(
27 by="start_time", ignore_index=True)
32 def graph_statistics(df: pd.DataFrame, job:str, layout: dict,
33 start: datetime=datetime.utcnow()-timedelta(days=180),
34 end: datetime=datetime.utcnow()) -> tuple:
38 data = select_data(df, job)
39 data = data.dropna(subset=["duration", ])
44 (data["start_time"] >= start) & (data["start_time"] <= end)
50 for _, row in data.iterrows():
52 f"date: {row['start_time'].strftime('%d-%m-%Y %H:%M:%S')}<br>"
54 f"{(int(row['duration']) // 3600):02d}:"
55 f"{((int(row['duration']) % 3600) // 60):02d}<br>"
56 f"passed: {row['passed']}<br>"
57 f"failed: {row['failed']}<br>"
58 f"{row['dut_type']}-ref: {row['dut_version']}<br>"
59 f"csit-ref: {row['job']}/{row['build']}<br>"
60 f"hosts: {', '.join(row['hosts'])}"
62 hover.append(hover_itm)
65 fig_duration = go.Figure(
76 step = max(data["duration"]) / 5
78 tickvals.append(int(step * (i + 1)))
79 layout_duration = layout.get("plot-stats-duration", dict())
81 layout_duration["yaxis"]["tickvals"] = tickvals
82 layout_duration["yaxis"]["ticktext"] = [
83 f"{(val // 3600):02d}:{((val % 3600) // 60):02d}" \
86 fig_duration.update_layout(layout_duration)
89 fig_passed = go.Figure(
107 layout_pf = layout.get("plot-stats-passed", dict())
109 fig_passed.update_layout(layout_pf)
111 return fig_passed, fig_duration