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")
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)
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")
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)
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.")
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.")
def get_data(self, start=None, end=None, field='_rowid_'): """Queries the buffer by field. Parameters ---------- start : number, optional start of time slice; units are those of the acquisition clock. end : float, optional end of time slice; units are those of the acquisition clock. field: str, optional field on which to query; default value is the row id. Returns ------- list of Records """ if self._buf is None: return [] return buffer_server.get_data(self._buf, start, end, field)