You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
4.6 KiB
114 lines
4.6 KiB
import os
|
|
from quart import jsonify, request,session,flash,redirect
|
|
from . import api
|
|
from web.common.utils import login_required
|
|
from core.DBManager import mDBM
|
|
from core.Upload_file import allowed_file,check_file,updata_model
|
|
from myutils.ConfigManager import myCongif
|
|
from werkzeug.utils import secure_filename
|
|
|
|
@api.route('/model/list',methods=['GET'])
|
|
@login_required
|
|
async def model_list(): #获取算法列表
|
|
strsql = "select ID,model_name,version,duration_time,proportion from model;"
|
|
datas = mDBM.do_select(strsql)
|
|
reMsg = [{"ID":data[0],"name":data[1],"version":data[2],"duration_time":data[3],
|
|
"proportion":data[4]} for data in datas]
|
|
return jsonify(reMsg)
|
|
|
|
@api.route('/model/upload',methods=['POST'])
|
|
@login_required
|
|
async def model_upload(): #上传算法文件--需要进行文件校验
|
|
form = await request.form
|
|
model_name = form['model_name']
|
|
files = await request.files
|
|
if 'file' not in files:
|
|
flash('参数错误')
|
|
return redirect(request.url)
|
|
file = files['file']
|
|
if file.filename == '':
|
|
flash('没有选择文件')
|
|
return redirect(request.url)
|
|
if file and allowed_file(file.filename):
|
|
filename = secure_filename(file.filename)
|
|
file_path = os.path.join(myCongif.get_data('UPLOAD_FOLDER'), filename)
|
|
await file.save(file_path)
|
|
if check_file(file_path,2): #itype--2 是算法模型升级
|
|
strsql = (f"insert into upgrade (itype,filepath,model_name) values (2,'{file_path}','{model_name}')"
|
|
f" on conflict(itype,model_name) do update set filepath=excluded.filepath;")
|
|
ret = mDBM.do_sql(strsql)
|
|
# session['model'] = file_path
|
|
if ret:
|
|
strsql = f"select id from upgrade where itype=2 and model_name='{model_name}';"
|
|
data=mDBM.do_select(strsql,1)
|
|
reStatus = data[0]
|
|
reMsg = "升级包上传成功"
|
|
else:
|
|
reStatus = 0
|
|
reMsg = "升级包上传失败"
|
|
return jsonify({'status': reStatus, 'msg': reMsg})
|
|
else:
|
|
flash('升级包不合法,请重新上传')
|
|
# return redirect(url_for('main.get_html', html='系统管理.html'))
|
|
return redirect(request.url)
|
|
else:
|
|
flash('只允许上传zip文件')
|
|
return redirect(request.url)
|
|
|
|
@api.route('/model/add',methods=['POST'])
|
|
@login_required
|
|
async def model_add(): #新增算法,需要先上传算法文件
|
|
model_name = (await request.form)['model_name']
|
|
upgrade_id = (await request.form)['upgrade_id'] #升级文件ID
|
|
###---需要根据升级包获取模型文件路径,算法版本号等信息,若根据upgrade_id获取不了对应的信息,则返回报错
|
|
###
|
|
strsql = f"select ID from model where model_name='{model_name}';"
|
|
data = mDBM.do_select(strsql,1)
|
|
if data:
|
|
reStatus = 0
|
|
reMsg = "算法名称重复,请修改!"
|
|
else:
|
|
strsql = f"insert into model (model_name) values ('{model_name}');" #还有参数未写全
|
|
ret = mDBM.do_sql(strsql)
|
|
if ret:
|
|
reStatus = 1
|
|
reMsg = "新增算法成功!"
|
|
else:
|
|
reStatus = 0
|
|
reMsg = "新增算法失败,请联系技术支持!"
|
|
return jsonify({'status': reStatus, 'msg': reMsg})
|
|
|
|
@api.route('/model/upgrade',methods=['POST'])
|
|
@login_required
|
|
async def model_upgrade(): #升级算法,需要先上传算法文件
|
|
return jsonify(1)
|
|
|
|
@api.route('/model/config',methods=['GET'])
|
|
@login_required
|
|
async def model_config(): #获取算法的配置信息 --- list已经获取
|
|
ID = request.args.get('ID')
|
|
strsql = f"select model_name,version,duration_time,proportion from model where ID={ID};"
|
|
data = mDBM.do_select(strsql,1)
|
|
reMsg = {"model_name":data[0],"version":data[1],"duration_time":data[2],"proportion":data[3]}
|
|
return jsonify(reMsg)
|
|
|
|
@api.route('/model/changecnf',methods=['POST'])
|
|
@login_required
|
|
async def model_config_change(): #修改算法的配置信息
|
|
ID = (await request.form)['ID']
|
|
duration_time = (await request.form)['duration_time']
|
|
proportion = float((await request.form)['proportion'])
|
|
if proportion>0 and proportion < 1:
|
|
strsql = f"update model set duration_time='{duration_time}',proportion='{proportion}' where ID={ID};"
|
|
ret = mDBM.do_sql(strsql)
|
|
if ret:
|
|
reStatus = 1
|
|
reMsg = "修复算法配置成功"
|
|
else:
|
|
reStatus = 0
|
|
reMsg = "修复算法配置失败"
|
|
else:
|
|
reStatus = 0
|
|
reMsg = "占比需要为大于0,小于1的值"
|
|
return jsonify({'status': reStatus, 'msg': reMsg})
|
|
|
|
|