Exemplo n.º 1
0
 def test_conv_bbbname_2_psnames(self):
     """Test conv_bbbname_2_psnames."""
     self.assertRaises(TypeError, PSSearch.conv_bbbname_2_psnames)
     self.assertRaises(KeyError, PSSearch.conv_bbbname_2_psnames, '')
     bsmps = PSSearch.conv_bbbname_2_psnames(
         bbbname='PA-RaPSF05:CO-PSCtrl-BO')
     self.assertIsInstance(bsmps, list)
     self.assertGreater(len(bsmps), 0)
     self.assertIsInstance(bsmps[0], tuple)
     self.assertIsInstance(bsmps[0][0], str)
     self.assertIsInstance(bsmps[0][1], int)
Exemplo n.º 2
0
    def update_filters(self):
        """Updates tables with filters set by user"""
        if not self.data:
            return

        search = self.filterEdit.text()

        if self.tabWidget.currentIndex() == 4:
            max_date = self.toTimeEdit.dateTime().toPyDateTime().timestamp()
            min_date = self.fromTimeEdit.dateTime().toPyDateTime().timestamp()

            if min_date > max_date:
                self.fromTimeEdit.setDateTime(self.toTimeEdit.dateTime())

            if min_date == max_date:
                self.update_table(self.data)

            length = len(self.data)
            min_index, max_index = length, 0

            # Compares Unix timestamp for logs and filter, stops when a log satisfies the filter
            for index, log in enumerate(self.data):
                if int(log[0]) < min_date:
                    min_index = index
                    break

            for index, log in enumerate(self.data[::-1]):
                if int(log[0]) > max_date:
                    max_index = length - index
                    break

            data = self.data[max_index:min_index]

            if search:
                data = [r for r in data if search in r[3] or search in r[2]]

            self.update_table(data, update=False)
            return True
        elif self.tabWidget.currentIndex() == 3:
            data = {}
            if not self.fetch_ps:
                return False
            for node in self.nodes_info:
                self.nodes_info[node]["ps"] = []
                try:
                    for ps in PSSearch.conv_bbbname_2_psnames(
                            self.nodes_info[node][b"name"].decode().replace(
                                "--", ":")):
                        if search in node or search in ps[0]:
                            self.nodes_info[node]["ps"].append(ps[0])
                            data[node] = self.nodes_info[node]
                except KeyError:
                    continue
                except Exception as e:
                    if "could not" in str(e):
                        self.fetch_ps = False
                        QtWidgets.QMessageBox.question(
                            self,
                            "Error",
                            "Could not connect to control system constants server. Please set the SIRIUS_URL_CONSTS environment variable to a valid server.",
                            QtWidgets.QMessageBox.Ok,
                        )
                    return

            self.update_node_list(data, update=False)
        else:
            data = {}
            for key in self.nodes_info:
                if search in key or search in key.replace("--", ":"):
                    data[key] = self.nodes_info[key]
            self.update_node_list(data, update=False)