All cases passed

This commit is contained in:
jinhai 2019-03-27 14:07:32 +08:00
parent 1cd00d8544
commit 471747b3b0
4 changed files with 16 additions and 10 deletions

View File

@ -71,7 +71,7 @@ class TestVectorEngine:
# Check search vector interface
code, vector_id = VectorEngine.SearchVector('test_group', self.__vector, self.__limit)
assert code == VectorEngine.SUCCESS_CODE
assert vector_id == [0]
assert vector_id == ['test_group.0']
# Check create index interface
code = VectorEngine.CreateIndex('test_group')
@ -103,7 +103,7 @@ class TestVectorEngine:
assert code == VectorEngine.SUCCESS_CODE
def test_raw_file(self):
filename = VectorEngine.InsertVectorIntoRawFile('test_group', 'test_group.raw', self.__vector, 'test_group.0')
filename = VectorEngine.InsertVectorIntoRawFile('test_group', 'test_group.raw', self.__vector, 0)
assert filename == 'test_group.raw'
expected_list = [self.__vector]

View File

@ -71,7 +71,7 @@ class TestViews:
resp = test_client.get('/vector/search/6', data=json.dumps(limit), headers = TestViews.HEADERS)
assert resp.status_code == 200
assert self.loads(resp)['code'] == 0
assert self.loads(resp)['vector_id'] == [0]
assert self.loads(resp)['vector_id'] == ['6.0']
resp = test_client.delete('/vector/group/6', headers = TestViews.HEADERS)
assert resp.status_code == 200

View File

@ -91,7 +91,7 @@ class VectorEngine(object):
if file:
print('insert into exist file')
# create vector id
vector_id = group_id + '.' + (str)(file.seq_no + 1)
vector_id = file.seq_no + 1
# insert into raw file
VectorEngine.InsertVectorIntoRawFile(group_id, file.filename, vector, vector_id)
@ -127,14 +127,15 @@ class VectorEngine(object):
# first raw file
raw_filename = group_id + '.raw'
# create vector id
vector_id = group_id + '.' + (str)(0)
vector_id = 0
# create and insert vector into raw file
VectorEngine.InsertVectorIntoRawFile(group_id, raw_filename, vector, vector_id)
# insert a record into database
db.session.add(FileTable(group_id, raw_filename, 'raw', 1))
db.session.commit()
return VectorEngine.SUCCESS_CODE, vector_id
vector_id_str = group_id + '.' + str(vector_id)
return VectorEngine.SUCCESS_CODE, vector_id_str
@staticmethod
@ -159,8 +160,11 @@ class VectorEngine(object):
result = scheduler_instance.search(index_map, vectors, limit)
vector_id = [0]
vector_ids_str = []
for int_id in vector_id:
vector_ids_str.append(group_id + '.' + str(int_id))
return VectorEngine.SUCCESS_CODE, vector_id
return VectorEngine.SUCCESS_CODE, vector_ids_str
@staticmethod
@ -203,7 +207,9 @@ class VectorEngine(object):
@staticmethod
def GetVectorListFromRawFile(group_id, filename="todo"):
return serialize.to_array(VectorEngine.group_vector_dict[group_id]), serialize.to_str_array(VectorEngine.group_vector_id_dict[group_id])
print("GetVectorListFromRawFile, vectors: ", serialize.to_array(VectorEngine.group_vector_dict[group_id]))
print("GetVectorListFromRawFile, vector_ids: ", serialize.to_int_array(VectorEngine.group_vector_id_dict[group_id]))
return serialize.to_array(VectorEngine.group_vector_dict[group_id]), serialize.to_int_array(VectorEngine.group_vector_id_dict[group_id])
@staticmethod
def ClearRawFile(group_id):

View File

@ -14,5 +14,5 @@ def to_array(vec):
return np.asarray(vec).astype('float32')
def to_str_array(vec):
return np.asarray(vec).astype('str')
def to_int_array(vec):
return np.asarray(vec).astype('int64')