Beispiel #1
0
    def test_matrix(self):
        matrix = bspump.Matrix(app=self.App,
                               dtype=[
                                   ('f1', 'i8'),
                                   ('f2', 'i8'),
                                   ('f3', 'i8'),
                               ])

        for i in range(100):
            n = matrix.add_row()
            matrix.Array[n][0] = 1  # Access by a field index
            matrix.Array[n]['f2'] = 1  # Access by a field name
            matrix.Array[n][2] = 1
            self.assertEqual(n, i)

        closed = set()
        closed |= matrix.ClosedRows

        for i in range(20, 40):
            matrix.close_row(i)
            closed.add(i)
            self.assertIn(i, matrix.ClosedRows)

        self.assertEqual(closed, matrix.ClosedRows)

        for i in range(20):
            n = matrix.add_row()
            self.assertIn(n, closed)
Beispiel #2
0
	def test_matrix_decode_row(self):
		dtype = [
			('f0', 'U3'),
			('f1', 'U8'),
		]
		matrix = bspump.matrix.SessionMatrix(app=self.App, dtype=dtype, config={'primary_name':'event_id'})
		event_id = 'abc'
		index = matrix.add_row(event_id)
		matrix.Array[index]['f0'] = 'aaa'
		matrix.Array[index]['f1'] = 'bbb'

		event = matrix.decode_row(index)
		self.assertEqual(len(event), 3)
		self.assertEqual(event['event_id'], event_id)
		self.assertEqual(event['f0'], matrix.Array[index]['f0'])
		self.assertEqual(event['f1'], matrix.Array[index]['f1'])

		event_id = 'bcd'
		index = matrix.add_row(event_id)
		matrix.Array[index]['f0'] = 'bbb'
		matrix.Array[index]['f1'] = 'ccc'

		event = matrix.decode_row(index, keys=['f0'])
		self.assertEqual(len(event), 2)
		self.assertEqual(event['event_id'], event_id)
		self.assertEqual(event['f0'], matrix.Array[index]['f0'])
Beispiel #3
0
	def test_matrix_get_row_name(self):
		matrix = bspump.matrix.NamedMatrix(app=self.App)
		n = 100
		for i in range(n):
			name = "id_" + str(i)
			index = matrix.add_row(name)
			name_obtained = matrix.get_row_name(i)
			self.assertEqual(name, name_obtained)
Beispiel #4
0
    def test_matrix_zeros(self):
        matrix = bspump.Matrix(app=self.App)

        for i in range(100):
            n = matrix.add_row()
            self.assertEqual(n, i)

        matrix.zeros()

        self.assertEqual(matrix.Array.shape, (0, ))
Beispiel #5
0
	def test_matrix_store_event(self):
		dtype = [
			('f1', 'U20'),
			('f2', 'i8'),
			('f3', 'f8'),
			('f4', 'U30')
		]
		matrix = bspump.matrix.SessionMatrix(app=self.App, dtype=dtype)
		index = matrix.add_row("abc")
		event = {
			'id': 'abc',
			'f0' : 7,
			'f1': 'abcd',
			'f2': 123,
			'f3' : 123.0
		}
		matrix.store_event(index, event)
		row = np.zeros(1, dtype=dtype)
		row['f1'] = event['f1']
		row['f2'] = event['f2']
		row['f3'] = event['f3']
		row['f4'] = ''

		for key in row.dtype.names:
			self.assertEqual(row[key], matrix.Array[index][key])

		index = matrix.add_row("bcd")
		event = {
			'id' : 'bcd',
			'f0' : 666,
			'f2': 88,
			'f4': 'cdef'
		}
		
		matrix.store_event(index, event, keys=['f2', 'f4', 'f5'])
		row = np.zeros(1, dtype=dtype)
		row['f1'] = ''
		row['f2'] = event['f2']
		row['f3'] = 0
		row['f4'] = event['f4']
		
		for key in row.dtype.names:
			self.assertEqual(row[key], matrix.Array[index][key])
Beispiel #6
0
	def test_matrix_close_row(self):
		matrix = bspump.matrix.NamedMatrix(app=self.App)
		n = 100
		for i in range(n):
			index = matrix.add_row(str(i))

		for i in range(0, 5):
			matrix.close_row(str(i))
			self.assertNotIn(i, matrix.Index.I2NMap)

		self.assertEqual(len(matrix.Index.I2NMap), len(matrix.Index.N2IMap))
Beispiel #7
0
	def test_matrix_add_row(self):
		matrix = bspump.matrix.NamedMatrix(app=self.App)
		n = 100
		n2i = collections.OrderedDict()
		i2n = collections.OrderedDict()
		for i in range(n):
			name = "id_" + str(i)
			index = matrix.add_row(name)
			n2i[name] = index
			i2n[index] = name

		self.assertEqual(n2i, matrix.Index.N2IMap)
		self.assertEqual(i2n, matrix.Index.I2NMap)
Beispiel #8
0
    def test_matrix_dtypes(self):
        matrix = bspump.Matrix(app=self.App,
                               dtype=[
                                   ('f1', 'U20'),
                                   ('f2', 'i8'),
                                   ('f3', 'i8'),
                               ])

        row_index = matrix.add_row()
        row = matrix.Array[row_index]

        row['f1'] = "Ahoj"
        row['f2'] = 64
Beispiel #9
0
    def test_matrix_flush(self):
        matrix = bspump.Matrix(app=self.App)

        for i in range(100):
            n = matrix.add_row()
            self.assertEqual(n, i)

        for i in range(20, 40):
            matrix.close_row(i)
            self.assertIn(i, matrix.ClosedRows)

        matrix.flush()

        self.assertEqual(len(matrix.ClosedRows), 0)
Beispiel #10
0
    def test_matrix(self):
        matrix = bspump.Matrix(app=self.App,
                               dtype=[
                                   ('f1', 'i8'),
                                   ('f2', 'i8'),
                                   ('f3', 'i8'),
                               ])

        for i in range(100):
            n = matrix.add_row()
            matrix.Array[n][0] = 1  # Access by a field index
            matrix.Array[n]['f2'] = 1  # Access by a field name
            matrix.Array[n][2] = 1
            self.assertEqual(n, i)
Beispiel #11
0
	def test_matrix_store(self):
		dtype = [
			('f1', 'U20'),
			('f2', 'i8'),
		]
		matrix = bspump.matrix.SessionMatrix(app=self.App, dtype=dtype)
		n = 100
		for i in range(n):
			name = "id_" + str(i)
			index = matrix.add_row(str(name))
			row = np.zeros(1, dtype=dtype)
			f1 = "something" + str(i)
			row['f1'] = f1
			row['f2'] = i
			matrix.store(name, row)
			self.assertEqual(matrix.Array[index]['f1'], f1)
			self.assertEqual(matrix.Array[index]['f2'], i)
Beispiel #12
0
	def test_matrix_flush(self):
		matrix = bspump.matrix.NamedMatrix(app=self.App)
		n = 100
		indexes = []
		for i in range(n):
			index = matrix.add_row(str(i))
			indexes.append(index)
			matrix.Array[index] = i
		
		check_array = matrix.Array[40:100]

		for i in range(0, 40):
			matrix.close_row(str(i))

		matrix.flush()
		self.assertEqual(matrix.Array.shape, (n - 40,))
		self.assertEqual(len(matrix.Index.N2IMap), n - 40)
		self.assertEqual(len(matrix.Index.I2NMap), n - 40)
		self.assertEqual(len(check_array), len(matrix.Array))
		for i in range(len(check_array)):
			self.assertEqual(check_array[i], matrix.Array[i])