예제 #1
0
    def test_count(self):
        """Test that the count of records is correct."""
        n_records = 500
        for i, data in enumerate(mock_data(n_records, self.channel_count)):
            buffer_server.append(self.pid,
                                 Record(data=data, timestamp=i, rownum=None))

        self.assertEqual(buffer_server.count(self.pid), n_records)
예제 #2
0
    def test_count(self):
        n = 500
        for i in range(n):
            d = self._new_data()
            buffer_server.append(self.pid,
                                 Record(data=d, timestamp=i, rownum=None))

        self.assertEqual(buffer_server.count(self.pid), n)
예제 #3
0
    def test_get_all_data(self):
        n = 150
        data = [self._new_data() for x in range(n)]
        for i, d in enumerate(data):
            buffer_server.append(self.pid,
                                 Record(data=d, timestamp=i, rownum=None))

        result = buffer_server.get_data(self.pid)
        self.assertEqual([r.data for r in result], data, "Should return all \
            data")
예제 #4
0
    def test_get_all_data(self):
        """Test method to get all data from buffer."""

        data = list(mock_data(n_records=150, n_cols=self.channel_count))
        for record_index, record in enumerate(data):
            buffer_server.append(
                self.pid,
                Record(data=record, timestamp=record_index, rownum=None))

        result = buffer_server.get_data(self.pid)
        self.assertEqual([r.data for r in result], data, "Should return all \
            data")
예제 #5
0
    def test_get_data_slice(self):
        n = 150
        data = [self._new_data() for x in range(n)]
        for i, d in enumerate(data):
            buffer_server.append(self.pid,
                                 Record(data=d, timestamp=i, rownum=None))

        start = 10
        end = 20

        result = buffer_server.get_data(self.pid,
                                        start,
                                        end,
                                        field='timestamp')
        self.assertEqual([r.data for r in result], data[start:end], "Should \
            return the slice of data requested.")
예제 #6
0
    def test_query_data(self):
        n = 150
        data = [self._new_data() for x in range(n)]
        last_channel = self.channels[-1]

        for i, d in enumerate(data):
            d[-1] = 1.0 if i >= 100 else 0.0
            buffer_server.append(self.pid,
                                 Record(data=d, timestamp=i, rownum=None))

        result = buffer_server.query(self.pid,
                                     filters=[(last_channel, ">", 0)],
                                     ordering=("timestamp", "asc"),
                                     max_results=1)
        self.assertEqual(len(result), 1)
        self.assertEqual(result[0].data[-1], 1.0)
        self.assertEqual(result[0].timestamp, 100.0)
예제 #7
0
    def test_get_data_slice(self):
        """Test querying for a slice of data."""

        data = list(mock_data(n_records=150, n_cols=self.channel_count))
        for i, record in enumerate(data):
            buffer_server.append(self.pid,
                                 Record(data=record, timestamp=i, rownum=None))

        start = 10
        end = 20

        result = buffer_server.get_data(self.pid,
                                        start,
                                        end,
                                        field='timestamp')
        self.assertEqual([r.data for r in result], data[start:end], "Should \
            return the slice of data requested.")
예제 #8
0
    def run(self):
        """Process startup. Connects to the device and start reading data.
        Since this is done in a separate process from the main thread, any
        errors encountered will be written to the msg_queue.
        """

        try:
            log.debug("Connecting to device")
            self._connector.connect()
            self._connector.acquisition_init()
        except Exception as error:
            self.msg_queue.put((MSG_ERROR, str(error)))
            raise error

        # Send updated device info to the main thread; this also signals that
        # initialization is complete.
        self.msg_queue.put((MSG_DEVICE_INFO, self._connector.device_info))

        # Wait for db server start
        self.msg_queue.get()
        self.msg_queue = None

        log.debug("Starting Acquisition read data loop")
        sample = 0
        data = self._connector.read_data()

        # begin continuous acquisition process as long as data received
        while self.running() and data:
            sample += 1
            if DEBUG and sample % DEBUG_FREQ == 0:
                log.debug("Read sample: %s", str(sample))

            buffer_server.append(self._buf,
                                 Record(data, self._clock.getTime(), sample))
            try:
                # Read data again
                data = self._connector.read_data()
            # pylint: disable=broad-except
            except Exception as error:
                log.error("Error reading data from device: %s", str(error))
                data = None
                break
        log.debug("Total samples read: %s", str(sample))
        self._connector.disconnect()
예제 #9
0
파일: client.py 프로젝트: shiva16/BciPy
    def run(self):
        """Reads from the queue of data and performs processing an item at a
        time. Also writes data to buffer."""

        logging.debug("Starting Data Processing loop.")
        count = 0
        with self._processor as p:
            while self.running():
                try:
                    record = self._data_queue.get(True, self._wait)
                    count += 1
                    if DEBUG and count % DEBUG_FREQ == 0:
                        logging.debug("Processed sample: " + str(count))
                    buffer_server.append(self._buf, record)
                    p.process(record.data, record.timestamp)
                    self._data_queue.task_done()
                except Empty:
                    pass
            logging.debug("Total samples processed: " + str(count))
예제 #10
0
    def test_multiple_servers(self):
        """Test multiple concurrent servers."""
        pid2 = buffer_server.start(self.channels, self._next_buf_name())

        n_records = 200
        for count, data in enumerate(mock_data(n_records, self.channel_count)):
            if count % 2 == 0:
                buffer_server.append(self.pid, Record(data, count, None))
            else:
                buffer_server.append(pid2, Record(data, count, None))

        self.assertEqual(buffer_server.count(self.pid), n_records / 2)
        self.assertEqual(buffer_server.count(pid2), n_records / 2)

        server1_data = buffer_server.get_data(self.pid, 0, 5)
        server2_data = buffer_server.get_data(pid2, 0, 5)

        self.assertNotEqual(server1_data, server2_data)
        buffer_server.stop(pid2)
예제 #11
0
    def test_query_data(self):
        """Test query_data method"""

        data = list(mock_data(n_records=150, n_cols=self.channel_count))
        last_channel = self.channels[-1]

        for record_index, record in enumerate(data):
            record[-1] = 1.0 if record_index >= 100 else 0.0
            buffer_server.append(
                self.pid,
                Record(data=record, timestamp=record_index, rownum=None))

        result = buffer_server.query(self.pid,
                                     filters=[(last_channel, ">", 0)],
                                     ordering=("timestamp", "asc"),
                                     max_results=1)
        self.assertEqual(len(result), 1)
        self.assertEqual(result[0].data[-1], 1.0)
        self.assertEqual(result[0].timestamp, 100.0)
예제 #12
0
    def run(self):
        """Reads from the queue of data and performs processing an item at a
        time. Also writes data to buffer."""

        log.debug("Starting Data Processing loop.")
        count = 0
        with self._processor as processor:
            # Signal that initialization is complete.
            self._msg_queue.put((MSG_PROCESSOR_INITIALIZED, True))

            while self.running():
                try:
                    record = self._data_queue.get(True, self._wait)
                    count += 1
                    if DEBUG and count % DEBUG_FREQ == 0:
                        log.debug("Processed sample: %s", str(count))
                    buffer_server.append(self._buf, record)
                    processor.process(record.data, record.timestamp)
                    self._data_queue.task_done()
                except Empty:
                    pass
            log.debug("Total samples processed: %s", str(count))
예제 #13
0
    def test_multiple_servers(self):
        pid2 = buffer_server.start(self.channels, self._next_buf_name())

        n = 200
        for i in range(n):
            d = [
                np.random.uniform(-1000, 1000)
                for cc in range(self.channel_count)
            ]
            if i % 2 == 0:
                buffer_server.append(self.pid, Record(d, i, None))
            else:
                buffer_server.append(pid2, Record(d, i, None))

        self.assertEqual(buffer_server.count(self.pid), n / 2)
        self.assertEqual(buffer_server.count(pid2), n / 2)

        server1_data = buffer_server.get_data(self.pid, 0, 5)
        server2_data = buffer_server.get_data(pid2, 0, 5)

        self.assertNotEqual(server1_data, server2_data)
        buffer_server.stop(pid2)