UTI: Add regressions and progressions
[csit.git] / resources / tools / dash / app / pal / news / tables.py
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:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
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.
13
14 """
15 """
16
17 import pandas as pd
18 import dash_bootstrap_components as dbc
19
20
21 # Time period for regressions and progressions.
22 TIME_PERIOD = 21  # [days]
23
24
25 def table_news(data: pd.DataFrame, job: str) -> list:
26     """
27     """
28
29     job_data = data.loc[(data["job"] == job)]
30     failed = job_data["failed"].to_list()[0]
31     regressions = {"Test Name": list(), "Last Regression": list()}
32     for itm in job_data["regressions"].to_list()[0]:
33         regressions["Test Name"].append(itm[0])
34         regressions["Last Regression"].append(itm[1].strftime('%Y-%m-%d %H:%M'))
35     progressions = {"Test Name": list(), "Last Progression": list()}
36     for itm in job_data["progressions"].to_list()[0]:
37         progressions["Test Name"].append(itm[0])
38         progressions["Last Progression"].append(
39             itm[1].strftime('%Y-%m-%d %H:%M'))
40
41     return [
42         dbc.Table.from_dataframe(pd.DataFrame.from_dict({
43             "Job": job_data["job"],
44             "Last Build": job_data["build"],
45             "Date": job_data["start"],
46             "DUT": job_data["dut_type"],
47             "DUT Version": job_data["dut_version"],
48             "Hosts": ", ".join(job_data["hosts"].to_list()[0])
49         }), bordered=True, striped=True, hover=True, size="sm", color="light"),
50         dbc.Table.from_dataframe(pd.DataFrame.from_dict({
51             (
52                 f"Last Failed Tests on "
53                 f"{job_data['start'].values[0]} ({len(failed)})"
54             ): failed
55         }), bordered=True, striped=True, hover=True, size="sm", color="light"),
56         dbc.Label(
57             class_name="p-0",
58             size="lg",
59             children=(
60                 f"Regressions during the last {TIME_PERIOD} days "
61                 f"({len(regressions['Test Name'])})"
62             )
63         ),
64         dbc.Table.from_dataframe(
65             pd.DataFrame.from_dict(regressions),
66             bordered=True, striped=True, hover=True, size="sm", color="light"),
67         dbc.Label(
68             class_name="p-0",
69             size="lg",
70             children=(
71                 f"Progressions during the last {TIME_PERIOD} days "
72                 f"({len(progressions['Test Name'])})"
73             )
74         ),
75         dbc.Table.from_dataframe(
76             pd.DataFrame.from_dict(progressions),
77             bordered=True, striped=True, hover=True, size="sm", color="light")
78     ]