1 # Copyright (c) 2024 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.
14 """The search data tables.
20 from ..utils.constants import Constants as C
23 def select_search_data(data: pd.DataFrame, selection: list) -> pd.DataFrame:
24 """Return the searched data based on the user's "selection".
26 :param data: Input data to be searched through.
27 :param selection: User selection.
28 :type data: pandas.DataFrame
29 :type selection: list[dict]
30 :returns: A dataframe with selected tests.
31 :trype: pandas.DataFrame
34 sel_data = data[selection["datatype"]]
36 if selection["datatype"] == "trending":
37 df = pd.DataFrame(sel_data.loc[
38 sel_data["dut_type"] == selection["dut"]
41 df = pd.DataFrame(sel_data.loc[(
42 (sel_data["dut_type"] == selection["dut"]) &
43 (sel_data["release"] == selection["release"])
47 df.full_id.str.contains(
48 selection["regexp"].replace(" ", ".*"),
58 def search_table(data: pd.DataFrame, selection: list) -> pd.DataFrame:
59 """Generate a table listing tests based on user's selection.
61 :param data: Input data (all tests).
62 :param selection: User selection.
63 :type data: pandas.DataFrame
64 :type selection: list[dict]
65 :returns: A dataframe with selected tests/
66 :rtype: pandas.DataFrame
69 sel = select_search_data(data, selection)
73 l_tb, l_nic, l_drv, l_test, = list(), list(), list(), list()
74 if selection["datatype"] == "trending":
75 cols = ["job", "test_id"]
78 cols = ["job", "test_id", "dut_version"]
79 for _, row in sel[cols].drop_duplicates().iterrows():
80 l_id = row["test_id"].split(".")
81 suite = l_id[-2].replace("2n1l-", "").replace("1n1l-", "").\
83 l_tb.append("-".join(row["job"].split("-")[-2:]))
84 l_nic.append(suite.split("-")[0])
85 if selection["datatype"] != "trending":
86 l_dutver.append(row["dut_version"])
87 for driver in C.DRIVERS:
93 l_test.append(l_id[-1])
95 if selection["datatype"] == "trending":
96 selected = pd.DataFrame.from_dict({
103 selected.sort_values(
104 by=["Test Bed", "NIC", "Driver", "Test"],
109 selected = pd.DataFrame.from_dict({
110 "DUT Version": l_dutver,
117 selected.sort_values(
118 by=["DUT Version", "Test Bed", "NIC", "Driver", "Test"],