提交 61f832bc 编写于 作者: J jinhai

Add more code on engine


Former-commit-id: 097420ff7b8d70b175640bcd71a0bf547ef17b3f
上级 0554aaed
class ErrorCode(object):
SUCCESS_CODE = 0
FAULT_CODE = 1
GROUP_NOT_EXIST = 2
ALREADY_EXIST = 3
\ No newline at end of file
from engine.model.group_table import GroupTable
from engine.model.file_table import FileTable
from engine.controller.error_code import ErrorCode
class MetaManager(object):
def Sync(self):
db.session.commit()
def AddGroup(self, group_name, dimension):
group = GroupTable.query.filter(GroupTable.group_name==group_id).first()
if group:
return ErrorCode.ALREADY_EXIST, group_name, group_filenumber
else:
new_group = GroupTable(group_name, dimension)
GroupHandler.CreateGroupDirectory(group_id)
# add into database
db.session.add(new_group)
return ErrorCode.SUCCESS_CODE, group_name, 0
@staticmethod
def GetGroup(group_name):
group = GroupTable.query.filter(GroupTable.group_name==group_name).first()
if group:
return ErrorCode.SUCCESS_CODE, group
else:
return ErrorCode.FAULT_CODE, None
# def DeleteGroup(group_id):
# group = GroupTable.query.filter(GroupTable.group_name==group_id).first()
# if(group):
# db.session.delete(group)
# else:
\ No newline at end of file
......@@ -11,7 +11,7 @@ logger = logging.getLogger(__name__)
class TestVectorEngine:
def setup_class(self):
self.__vectors = [[1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8]]
self.__vectors = [[1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8] for _ in range(10) ]
self.__vector = [1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8]
self.__limit = 1
......@@ -52,22 +52,7 @@ class TestVectorEngine:
# Add vector for exist group
code, vector_id = VectorEngine.AddVector('test_group', self.__vectors)
assert code == VectorEngine.SUCCESS_CODE
assert vector_id == ['test_group.0']
# Add vector for exist group
code, vector_id = VectorEngine.AddVector('test_group', self.__vectors)
assert code == VectorEngine.SUCCESS_CODE
assert vector_id == ['test_group.1']
# Add vector for exist group
code, vector_id = VectorEngine.AddVector('test_group', self.__vectors)
assert code == VectorEngine.SUCCESS_CODE
assert vector_id == ['test_group.2']
# Add vector for exist group
code, vector_id = VectorEngine.AddVector('test_group', self.__vectors)
assert code == VectorEngine.SUCCESS_CODE
assert vector_id == ['test_group.3']
assert vector_id == ['test_group.0', 'test_group.1', 'test_group.2', 'test_group.3', 'test_group.4', 'test_group.5', 'test_group.6', 'test_group.7', 'test_group.8', 'test_group.9']
# Check search vector interface
code, vector_id = VectorEngine.SearchVector('test_group', self.__vector, self.__limit)
......
......@@ -9,6 +9,8 @@ from engine import db
from engine.ingestion import build_index
from engine.controller.scheduler import Scheduler
from engine.ingestion import serialize
from engine.controller.meta_manager import MetaManager
from engine.controller.error_code import ErrorCode
import sys, os
class VectorEngine(object):
......@@ -19,21 +21,18 @@ class VectorEngine(object):
GROUP_NOT_EXIST = 2
@staticmethod
def AddGroup(group_id, dimension):
group = GroupTable.query.filter(GroupTable.group_name==group_id).first()
if group:
print('Already create the group: ', group_id)
return VectorEngine.FAULT_CODE, group_id, group.file_number
# return jsonify({'code': 1, 'group_name': group_id, 'file_number': group.file_number})
def AddGroup(group_name, dimension):
error, group = MetaManager.GetGroup(group_name)
if(error == ErrorCode.SUCCESS_CODE):
return ErrorCode.FAULT_CODE, group_name, group.file_number
else:
print('To create the group: ', group_id)
new_group = GroupTable(group_id, dimension)
GroupHandler.CreateGroupDirectory(group_id)
new_group = GroupTable(group_name, dimension)
GroupHandler.CreateGroupDirectory(group_name)
# add into database
db.session.add(new_group)
db.session.commit()
return VectorEngine.SUCCESS_CODE, group_id, 0
return VectorEngine.SUCCESS_CODE, group_name, 0
@staticmethod
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册