changes 模型相关

This commit is contained in:
P3ngSaM 2023-05-06 15:53:35 +08:00
parent 17a4bc8994
commit ccff930254
1 changed files with 43 additions and 5 deletions

View File

@ -79,7 +79,7 @@ async def func(file: UploadFile = File(...), mongodb: MongoHelper = Depends(get_
} }
@router.post("/download", summary="导出模型填报数据", tags=["模型仓库"]) @router.post("/download", summary="导出模型财务填报数据", tags=["填报数据"])
def func(name: str = '模型名称', year: str = "2023", mongodb: MongoHelper = Depends(get_mongodb)): def func(name: str = '模型名称', year: str = "2023", mongodb: MongoHelper = Depends(get_mongodb)):
# 根据名称查询模型是否存在 # 根据名称查询模型是否存在
search = mongodb.find_data_by_condition(dbname="打分模型", sheet="模型集", condition={"模型名称": name}) search = mongodb.find_data_by_condition(dbname="打分模型", sheet="模型集", condition={"模型名称": name})
@ -137,7 +137,7 @@ def func(name: str = '模型名称', year: str = "2023", mongodb: MongoHelper =
filename=file_path.name) filename=file_path.name)
@router.post("/upload", summary="上传填报数据excel", tags=["模型仓库"]) @router.post("/upload", summary="上传财务填报数据excel", tags=["填报数据"])
async def func(file: UploadFile = File(...)): async def func(file: UploadFile = File(...)):
data = dict() data = dict()
contents = await file.read() contents = await file.read()
@ -159,7 +159,45 @@ async def func(file: UploadFile = File(...)):
} }
@router.post("/index_calculate", summary="指标计算", tags=["模型仓库"]) @router.post("/questionnaire", summary="上传问卷excel", tags=["填报数据"])
async def func(file: UploadFile = File(...)):
data = dict()
contents = await file.read()
df = pd.read_excel(contents, sheet_name='填报数据')
questionnaire_data = df.iloc[0:53, 0:2]
questionnaire_dict = dict(zip(questionnaire_data.iloc[:, 0], questionnaire_data.iloc[:, 1]))
# 获取财务数据年份
financial_time = df.iloc[54, :].replace(np.nan, None).values.tolist()
year = 1
for j in financial_time:
try:
if '' in j:
year += 1
except TypeError:
continue
financial_dict = dict()
financial_data = df.iloc[54:, 0:year]
financial_data = financial_data.replace(np.nan, None)
for i in range(len(financial_time)):
try:
if '' in financial_time[i]:
financial_dict[financial_time[i]] = dict(zip(financial_data.iloc[:, 0], financial_data.iloc[:, i]))
except TypeError:
continue
return {
"code": 200,
"message": "上传成功",
"content": {
"问卷数据": questionnaire_dict,
"财报数据": financial_dict
}
}
@router.post("/index_calculate", summary="指标计算", tags=["指标计算"])
def func(schemas: ComputeSchemas.ComputeModelReqBody, mongodb: MongoHelper = Depends(get_mongodb)): def func(schemas: ComputeSchemas.ComputeModelReqBody, mongodb: MongoHelper = Depends(get_mongodb)):
search = mongodb.find_data_by_condition(dbname="打分模型", sheet="模型集", condition={"模型名称": schemas.name}) search = mongodb.find_data_by_condition(dbname="打分模型", sheet="模型集", condition={"模型名称": schemas.name})
if not search: if not search:
@ -202,7 +240,7 @@ def func(schemas: ComputeSchemas.ComputeModelReqBody, mongodb: MongoHelper = Dep
} }
@router.post("/score_calculate", summary="计算得分", tags=["模型仓库"]) @router.post("/score_calculate", summary="计算得分", tags=["打分评级"])
def func(schemas: ComputeSchemas.ComputeModelReqBody, mongodb: MongoHelper = Depends(get_mongodb)): def func(schemas: ComputeSchemas.ComputeModelReqBody, mongodb: MongoHelper = Depends(get_mongodb)):
search = mongodb.find_data_by_condition(dbname="打分模型", sheet="模型集", condition={"模型名称": schemas.name}) search = mongodb.find_data_by_condition(dbname="打分模型", sheet="模型集", condition={"模型名称": schemas.name})
if not search: if not search:
@ -308,7 +346,7 @@ def func(schemas: ComputeSchemas.ComputeModelReqBody, mongodb: MongoHelper = Dep
} }
@router.post("/batch_score_calculate", summary="批量计算得分(测试用)", tags=["模型仓库"]) @router.post("/batch_score_calculate", summary="批量计算得分(测试用)", tags=["打分评级"])
async def func(name: str = "模型名称", file: UploadFile = File(...), mongodb: MongoHelper = Depends(get_mongodb)): async def func(name: str = "模型名称", file: UploadFile = File(...), mongodb: MongoHelper = Depends(get_mongodb)):
search = mongodb.find_data_by_condition(dbname="打分模型", sheet="模型集", condition={"模型名称": name}) search = mongodb.find_data_by_condition(dbname="打分模型", sheet="模型集", condition={"模型名称": name})
if not search: if not search: