changes 模型管理

This commit is contained in:
P3ngSaM 2023-06-15 15:48:53 +08:00
parent 7625be35c7
commit bedfa0736d
5 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,13 @@
import gridfs
from bson import ObjectId
def insert_file(db, file: bytes):
fs = gridfs.GridFS(db, 'xlxs')
return fs.put(file)
def model_add(db, type_name, data):
col = db[type_name]
col.insert_one(data)
return True

View File

View File

@ -0,0 +1,34 @@
from fastapi import APIRouter, Depends, HTTPException, Header, UploadFile, File
from sqlalchemy.orm import Session
from Context.common import common_db, mg_db
from Mods.ModelManagement import Crud
from Utils.MongoUtils import MongoConnect
router = APIRouter(
prefix="/api/model_management"
)
@router.post("upload_model_excel", summary="新模型Excel上传", tags=["模型管理"])
async def func(model_name: str = '母婴保健信誉评级模型', file: UploadFile = File(...),
mongo_db: MongoConnect = Depends(mg_db.get_db)):
contents = await file.read()
file_id = Crud.insert_file(mongo_db, file=contents)
Crud.model_add(mongo_db, type_name="模型数据", data={"模型名称": model_name, "模型ID": file_id})
return {"message": "文件上传成功", "file_id": str(file_id)}
@router.post("download_model_excel", summary="新模型Excel读取", tags=["模型管理"])
async def func(model_name: str = '母婴保健信誉评级模型', mongo_db: MongoConnect = Depends(mg_db.get_db)):
pass
@router.post("download_questionnaire", summary="下载模型问卷", tags=["模型管理"])
async def func(model_name: str = '母婴保健信誉评级模型', mongo_db: MongoConnect = Depends(mg_db.get_db)):
pass
@router.post("analysis_model_excel", summary="解析模型excel", tags=["模型管理"])
async def func(ile: UploadFile = File(...), mongo_db: MongoConnect = Depends(mg_db.get_db)):
pass

View File

View File