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, start: datetime,
23 end: datetime) -> pd.DataFrame:
28 (data["job"] == itm) &
29 (data["start_time"] >= start) & (data["start_time"] <= end)
30 ].sort_values(by="start_time", ignore_index=True)
31 df = df.dropna(subset=["duration", ])
36 def graph_statistics(df: pd.DataFrame, job:str, layout: dict,
37 start: datetime=datetime.utcnow()-timedelta(days=180),
38 end: datetime=datetime.utcnow()) -> tuple:
42 data = select_data(df, job, start, end)
47 for _, row in data.iterrows():
49 f"date: {row['start_time'].strftime('%d-%m-%Y %H:%M:%S')}<br>"
51 f"{(int(row['duration']) // 3600):02d}:"
52 f"{((int(row['duration']) % 3600) // 60):02d}<br>"
53 f"passed: {row['passed']}<br>"
54 f"failed: {row['failed']}<br>"
55 f"{row['dut_type']}-ref: {row['dut_version']}<br>"
56 f"csit-ref: {row['job']}/{row['build']}<br>"
57 f"hosts: {', '.join(row['hosts'])}"
59 hover.append(hover_itm)
62 fig_duration = go.Figure(
73 step = max(data["duration"]) / 5
75 tickvals.append(int(step * (i + 1)))
76 layout_duration = layout.get("plot-stats-duration", dict())
78 layout_duration["yaxis"]["tickvals"] = tickvals
79 layout_duration["yaxis"]["ticktext"] = [
80 f"{(val // 3600):02d}:{((val % 3600) // 60):02d}" \
83 fig_duration.update_layout(layout_duration)
86 fig_passed = go.Figure(
104 layout_pf = layout.get("plot-stats-passed", dict())
106 fig_passed.update_layout(layout_pf)
108 return fig_passed, fig_duration