提交 31f02992 编写于 作者: J jinhai

Add GroupHandler and RawFileHandler

上级 5b14d5ca
import os, shutil
class GroupHandler(object):
@staticmethod
def CreateGroupDirectory(group_id):
path = GetGroupDirectory(group_id)
path = path.strip()
path=path.rstrip("\\")
if not os.path.exists():
os.makedirs(path)
@staticmethod
def DeleteGroupDirectory(group_id):
path = GetGroupDirectory(group_id)
path = path.strip()
path=path.rstrip("\\")
if os.path.exists():
shutil.rmtree(path)
@staticmethod
def GetGroupDirectory(group_id):
return DATABASE_DIRECTORY + '/' + group_id
\ No newline at end of file
class RawFileHandler(object):
@staticmethod
def Create(filename, type):
# type means: csv, parquet
pass
@staticmethod
def Read(filename, type):
pass
@staticmethod
def Append(filename, type, record):
pass
\ No newline at end of file
from engine.model.GroupTable import GroupTable from engine.model.GroupTable import GroupTable
from engine.model.FileTable import FileTable from engine.model.FileTable import FileTable
from engine.controller.RawFileHandler import RawFileHandler
from engine.controller.GroupHandler import GroupHandler
from flask import jsonify from flask import jsonify
from engine import db from engine import db
import sys import sys, os
class VectorEngine(object): class VectorEngine(object):
...@@ -15,6 +17,7 @@ class VectorEngine(object): ...@@ -15,6 +17,7 @@ class VectorEngine(object):
new_group = GroupTable(group_id) new_group = GroupTable(group_id)
db.session.add(new_group) db.session.add(new_group)
db.session.commit() db.session.commit()
GroupHandler.CreateGroupDirectory(group_id)
return jsonify({'code': 0, 'group_name': group_id, 'file_number': 0}) return jsonify({'code': 0, 'group_name': group_id, 'file_number': 0})
@staticmethod @staticmethod
...@@ -33,6 +36,7 @@ class VectorEngine(object): ...@@ -33,6 +36,7 @@ class VectorEngine(object):
# old_group = GroupTable(group_id) # old_group = GroupTable(group_id)
db.session.delete(group) db.session.delete(group)
db.session.commit() db.session.commit()
GroupHandler.DeleteGroupDirectory(group_id)
return jsonify({'code': 0, 'group_name': group_id, 'file_number': group.file_number}) return jsonify({'code': 0, 'group_name': group_id, 'file_number': group.file_number})
else: else:
return jsonify({'code': 0, 'group_name': group_id, 'file_number': 0}) return jsonify({'code': 0, 'group_name': group_id, 'file_number': 0})
...@@ -61,8 +65,8 @@ class VectorEngine(object): ...@@ -61,8 +65,8 @@ class VectorEngine(object):
CreateIndex(group_id, index_filename) CreateIndex(group_id, index_filename)
# create another raw file # create another raw file
raw_filename = file.group_id + '_' + file.seq_no raw_filename = file.seq_no
InsertVectorIntoRawFile(raw_filename, vector) InsertVectorIntoRawFile(group_id, raw_filename, vector)
# insert a record into database # insert a record into database
db.session.add(FileTable(group_id, raw_filename, 'raw', 1)) db.session.add(FileTable(group_id, raw_filename, 'raw', 1))
db.session.commit() db.session.commit()
...@@ -90,17 +94,21 @@ class VectorEngine(object): ...@@ -90,17 +94,21 @@ class VectorEngine(object):
# construct response and send back # construct response and send back
return jsonify({'code': 0}) return jsonify({'code': 0})
@staticmethod
def CreateIndex(group_id):
print(group_id)
return jsonify({'code': 0})
@staticmethod @staticmethod
def CreateIndex(group_id, filename): def CreateIndex(group_id, filename):
print(group_id, filename) path = GroupHandler.GetGroupDirectory(group_id) + '/' + filename
print(group_id, path)
return jsonify({'code': 0}) return jsonify({'code': 0})
@staticmethod @staticmethod
def InsertVectorIntoRawFile(filename, vector): def InsertVectorIntoRawFile(group_id, filename, vector):
print(sys._getframe().f_code.co_name) print(sys._getframe().f_code.co_name)
path = GroupHandler.GetGroupDirectory(group_id) + '/' + filename
# if filename exist
# append
# if filename not exist
# create file
# append
return filename return filename
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册