62728141655bc082c602e8f9ba9200aabee1a6a5
[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 from ..utils.constants import Constants as C
21
22
23 def table_news(data: pd.DataFrame, job: str) -> list:
24     """
25     """
26
27     job_data = data.loc[(data["job"] == job)]
28     failed = job_data["failed"].to_list()[0]
29     regressions = {"Test Name": list(), "Last Regression": list()}
30     for itm in job_data["regressions"].to_list()[0]:
31         regressions["Test Name"].append(itm[0])
32         regressions["Last Regression"].append(itm[1].strftime('%Y-%m-%d %H:%M'))
33     progressions = {"Test Name": list(), "Last Progression": list()}
34     for itm in job_data["progressions"].to_list()[0]:
35         progressions["Test Name"].append(itm[0])
36         progressions["Last Progression"].append(
37             itm[1].strftime('%Y-%m-%d %H:%M'))
38
39     return [
40         dbc.Table.from_dataframe(pd.DataFrame.from_dict({
41             "Job": job_data["job"],
42             "Last Build": job_data["build"],
43             "Date": job_data["start"],
44             "DUT": job_data["dut_type"],
45             "DUT Version": job_data["dut_version"],
46             "Hosts": ", ".join(job_data["hosts"].to_list()[0])
47         }), bordered=True, striped=True, hover=True, size="sm", color="light"),
48         dbc.Table.from_dataframe(pd.DataFrame.from_dict({
49             (
50                 f"Last Failed Tests on "
51                 f"{job_data['start'].values[0]} ({len(failed)})"
52             ): failed
53         }), bordered=True, striped=True, hover=True, size="sm", color="light"),
54         dbc.Label(
55             class_name="p-0",
56             size="lg",
57             children=(
58                 f"Regressions during the last {C.NEWS_TIME_PERIOD} days "
59                 f"({len(regressions['Test Name'])})"
60             )
61         ),
62         dbc.Table.from_dataframe(
63             pd.DataFrame.from_dict(regressions),
64             bordered=True, striped=True, hover=True, size="sm", color="light"),
65         dbc.Label(
66             class_name="p-0",
67             size="lg",
68             children=(
69                 f"Progressions during the last {C.NEWS_TIME_PERIOD} days "
70                 f"({len(progressions['Test Name'])})"
71             )
72         ),
73         dbc.Table.from_dataframe(
74             pd.DataFrame.from_dict(progressions),
75             bordered=True, striped=True, hover=True, size="sm", color="light")
76     ]