aboutsummaryrefslogtreecommitdiffstats
path: root/csit.infra.dash/app/cdash/search/tables.py
diff options
context:
space:
mode:
authorTibor Frank <tifrank@cisco.com>2024-02-20 11:04:48 +0000
committerTibor Frank <tifrank@cisco.com>2024-02-28 14:15:28 +0000
commit7d3054dede4f630e9b20ac0e69f029bea93bdf5f (patch)
tree1dfa9c41fd326a822a0aeefab8982a5fda61f051 /csit.infra.dash/app/cdash/search/tables.py
parent0e11b36be7f77578ecab1fc6a4fb6ac16e615b8f (diff)
C-Dash: Add search in testsoper-240304
Change-Id: Ia250c4b4e299d48bc68cf01e65fe37a281047060 Signed-off-by: Tibor Frank <tifrank@cisco.com>
Diffstat (limited to 'csit.infra.dash/app/cdash/search/tables.py')
-rw-r--r--csit.infra.dash/app/cdash/search/tables.py123
1 files changed, 123 insertions, 0 deletions
diff --git a/csit.infra.dash/app/cdash/search/tables.py b/csit.infra.dash/app/cdash/search/tables.py
new file mode 100644
index 0000000000..a5ffd76d3d
--- /dev/null
+++ b/csit.infra.dash/app/cdash/search/tables.py
@@ -0,0 +1,123 @@
+# Copyright (c) 2024 Cisco and/or its affiliates.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""The search data tables.
+"""
+
+
+import pandas as pd
+
+from ..utils.constants import Constants as C
+
+
+def select_search_data(data: pd.DataFrame, selection: list) -> pd.DataFrame:
+ """Return the searched data based on the user's "selection".
+
+ :param data: Input data to be searched through.
+ :param selection: User selection.
+ :type data: pandas.DataFrame
+ :type selection: list[dict]
+ :returns: A dataframe with selected tests.
+ :trype: pandas.DataFrame
+ """
+
+ sel_data = data[selection["datatype"]]
+
+ if selection["datatype"] == "trending":
+ df = pd.DataFrame(sel_data.loc[
+ sel_data["dut_type"] == selection["dut"]
+ ])
+ else:
+ df = pd.DataFrame(sel_data.loc[(
+ (sel_data["dut_type"] == selection["dut"]) &
+ (sel_data["release"] == selection["release"])
+ )])
+ try:
+ df = df[
+ df.full_id.str.contains(
+ selection["regexp"].replace(" ", ".*"),
+ regex=True
+ )
+ ]
+ except Exception:
+ return pd.DataFrame()
+
+ return df
+
+
+def search_table(data: pd.DataFrame, selection: list) -> pd.DataFrame:
+ """Generate a table listing tests based on user's selection.
+
+ :param data: Input data (all tests).
+ :param selection: User selection.
+ :type data: pandas.DataFrame
+ :type selection: list[dict]
+ :returns: A dataframe with selected tests/
+ :rtype: pandas.DataFrame
+ """
+
+ sel = select_search_data(data, selection)
+ if sel.empty:
+ return pd.DataFrame()
+
+ l_tb, l_nic, l_drv, l_test, = list(), list(), list(), list()
+ if selection["datatype"] == "trending":
+ cols = ["job", "test_id"]
+ else:
+ l_dutver = list()
+ cols = ["job", "test_id", "dut_version"]
+ for _, row in sel[cols].drop_duplicates().iterrows():
+ l_id = row["test_id"].split(".")
+ suite = l_id[-2].replace("2n1l-", "").replace("1n1l-", "").\
+ replace("2n-", "")
+ l_tb.append("-".join(row["job"].split("-")[-2:]))
+ l_nic.append(suite.split("-")[0])
+ if selection["datatype"] != "trending":
+ l_dutver.append(row["dut_version"])
+ for driver in C.DRIVERS:
+ if driver in suite:
+ l_drv.append(driver)
+ break
+ else:
+ l_drv.append("dpdk")
+ l_test.append(l_id[-1])
+
+ if selection["datatype"] == "trending":
+ selected = pd.DataFrame.from_dict({
+ "Test Bed": l_tb,
+ "NIC": l_nic,
+ "Driver": l_drv,
+ "Test": l_test
+ })
+
+ selected.sort_values(
+ by=["Test Bed", "NIC", "Driver", "Test"],
+ ascending=True,
+ inplace=True
+ )
+ else:
+ selected = pd.DataFrame.from_dict({
+ "DUT Version": l_dutver,
+ "Test Bed": l_tb,
+ "NIC": l_nic,
+ "Driver": l_drv,
+ "Test": l_test
+ })
+
+ selected.sort_values(
+ by=["DUT Version", "Test Bed", "NIC", "Driver", "Test"],
+ ascending=True,
+ inplace=True
+ )
+
+ return selected