update 测试接口

This commit is contained in:
P3ngSaM 2022-09-15 00:30:45 +08:00
parent 562de75711
commit 642bec821c
3 changed files with 254 additions and 18 deletions

View File

@ -1,12 +1,12 @@
import json
import re
import time
import requests
from bson import ObjectId
from DBHelper.MongoHelperInstance import DB_TEST
from Modules.CodeExecutor.PythonCodeExecutor import PythonCodeExecutor
from Modules.Indicators.Tags.TagsImpl import TagsImpl
from Modules.Models.Score import ScoreUtils
from Modules.Models.Score.ModelObj import ModelObj, LevelSet, Index, DataPath, SearchSet, ErrorReplace, ScoreSet, \
ScoreInterval
from Modules.Models.Score.ScoreObj import ScoreModelObj
@ -769,12 +769,12 @@ class ScoreModelImpl(object):
@staticmethod
def view_model(**kwargs):
"""查看模型"""
mod_id = kwargs['mod_id']
object_id = kwargs['object_id']
record = DB_TEST.find_single_data(
'模型数据',
'打分模型',
{'mod_id': mod_id},
{'_id': ObjectId(object_id)},
[]
)
@ -792,10 +792,11 @@ class ScoreModelImpl(object):
@staticmethod
def edit_model(**kwargs):
"""新建模型"""
data = kwargs['data']
edit = kwargs['data']
object_id = edit['object_id']
data = edit['body']
mod = ModelObj()
mod.mod_id = data['mod_id']
mod.mod_name = data['mod_name']
# 级别设置
@ -826,9 +827,11 @@ class ScoreModelImpl(object):
search = SearchSet()
search_data = item['search_set']
if 'cid' in search_data:
search.cid = search_data['cid']
if len(search_data['cid']):
search.cid = search_data['cid']
if 'report_date' in search_data:
search.report_date = search_data['report_date']
if len(search_data['report_date']):
search.report_date = search_data['report_date']
index.search_set = search
# 异常处理
error = ErrorReplace()
@ -853,7 +856,7 @@ class ScoreModelImpl(object):
DB_TEST.upsert_single_data(
'模型数据',
'打分模型',
{'mod_id': model['mod_id']},
{'_id': ObjectId(object_id)},
model
)
return 'success'
@ -861,15 +864,68 @@ class ScoreModelImpl(object):
@staticmethod
def delete_model(**kwargs):
"""查看模型"""
mod_id = kwargs['mod_id']
object_id = kwargs['object_id']
DB_TEST.delete_single_data(
'模型数据',
'打分模型',
{'mod_id': mod_id},
{'_id': ObjectId(object_id)}
)
result = {
"info": "success",
}
return result
@staticmethod
def test(**kwargs):
"""测试"""
data = kwargs['data']
data_path = data['data_path']
search_set = data['search_set']
error_replace = data['error_replace']
# 数据路径
path = DataPath()
path.region = data_path['region']
path.directory = data_path['directory']
path.table = data_path['table']
path.feild = data_path['feild']
path_data = path.fields_toggle()
# 查询条件
search = SearchSet()
if 'cid' in search_set:
if len(search_set['cid']):
search.cid = search_set['cid']
if 'report_date' in search_set:
if len(search_set['report_date']):
search.report_date = search_set['report_date']
search_data = search.fields_toggle()
query = dict()
if 'cid' in search_data:
query['企业ID'] = search_data['cid']
if 'report_date' in search_data:
query['报告期'] = search_data['report_date']
# 异常处理
error = ErrorReplace()
error.no_exist = error_replace['no_exist']
error.none_type = error_replace['none_type']
error.empty_str = error_replace['empty_str']
error_data = error.fields_toggle()
feild = DB_TEST.find_single_column(
path_data['region'],
ScoreModelUtils.check_table(table=path_data['table']),
query,
path_data['feild']
)
if not feild:
result = error_data['no_exist']
elif feild is None:
result = error_data['none_type']
elif not len(feild):
result = error_data['empty_str']
else:
result = feild
return {"result": result}

View File

@ -52,13 +52,13 @@ def operate_score_model_route():
"""操作打分模型"""
try:
if request.method == 'GET':
RouteParamsCheck(request.args, ["mod_id"]).required()
mod_id = request.args['mod_id']
RouteParamsCheck(request.args, ["object_id"]).required()
object_id = request.args['object_id']
ipml = ScoreModelImpl()
result = ipml.view_model(mod_id=mod_id)
result = ipml.view_model(object_id=object_id)
return result, 200
if request.method == 'POST':
RouteParamsCheck(request.json, ["mod_id", "mod_name", "level_set", "index"]).required()
RouteParamsCheck(request.json, ["object_id", "body"]).required()
data = request.json
ipml = ScoreModelImpl()
result = ipml.edit_model(data=data)
@ -84,10 +84,23 @@ def lock_score_model_route():
def delete_score_model_route():
"""删除模型"""
try:
RouteParamsCheck(request.args, ["mod_id"]).required()
mod_id = request.args["mod_id"]
RouteParamsCheck(request.args, ["object_id"]).required()
object_id = request.args["object_id"]
impl = ScoreModelImpl()
result = impl.delete_model(mod_id=mod_id)
result = impl.delete_model(object_id=object_id)
return result, 200
except APIReturnError as e:
return {"info": e.__str__()}, e.status_code
@score_model_route.route('/test', methods=['POST'])
def test_route():
"""测试"""
try:
RouteParamsCheck(request.json, ["data_path", "search_set", "error_replace"]).required()
data = request.json
impl = ScoreModelImpl()
result = impl.test(data=data)
return result, 200
except APIReturnError as e:
return {"info": e.__str__()}, e.status_code

View File

@ -16,3 +16,170 @@ class ScoreModelUtils(object):
while case:
new_cid = CommonUtils.random_code(8)
return new_cid
@staticmethod
def check_table(**kwargs):
table = kwargs['table']
if table == '主体信用评级':
result = 'C1.1_主体信用评级'
elif table == '债项信用评级':
result = 'C1.2_债项信用评级'
elif table == 'ESG评级':
result = 'C1.3_ESG评级'
elif table == '每股指标':
result = 'C2.1_每股指标'
elif table == '盈利能力':
result = 'C2.2_盈利能力'
elif table == '收益质量':
result = 'C2.3_收益质量'
elif table == '现金流量':
result = 'C2.4_现金流量'
elif table == '资本结构':
result = 'C2.5_资本结构'
elif table == '偿债能力':
result = 'C2.6_偿债能力'
elif table == '营运能力':
result = 'C2.7_营运能力'
elif table == '成长能力':
result = 'C2.8_成长能力'
elif table == '经营指标':
result = 'C2.9_经营指标'
elif table == '资质指标':
result = 'C2.10_资质指标'
elif table == '行业指标':
result = 'C2.11_行业指标'
elif table == '绿色指标':
result = 'C2.12_绿色指标'
elif table == '司法指标':
result = 'C2.13_司法指标'
elif table == '合规指标':
result = 'C2.14_合规指标'
elif table == '舆情指标':
result = 'C2.15_舆情指标'
elif table == '工商信息':
result = 'C3.1_工商信息'
elif table == '股东信息':
result = 'C3.2_股东信息'
elif table == '高管信息':
result = 'C3.3_高管信息'
elif table == '对外投资':
result = 'C3.4_对外投资'
elif table == '分支机构':
result = 'C3.5_分支机构'
elif table == '工商变更':
result = 'C3.6_工商变更'
elif table == '企业标签':
result = 'C3.7_企业标签'
elif table == '定性信息':
result = 'C3.8_定性信息'
elif table == '员工统计':
result = 'C3.9_员工统计'
elif table == '补充信息':
result = 'C3.10_补充信息'
elif table == '媒体账号':
result = 'C3.11_媒体账号'
elif table == '排行榜单':
result = 'C4.1_排行榜单'
elif table == '科创认定':
result = 'C4.2_科创认定'
elif table == '荣誉奖项':
result = 'C4.3_荣誉奖项'
elif table == '监管评级':
result = 'C4.4_监管评级'
elif table == '许可认证':
result = 'C4.5_许可认证'
elif table == '政策支持':
result = 'C4.6_政策支持'
elif table == '污染监测':
result = 'C4.7_污染监测'
elif table == '进出口信用':
result = 'C4.8_进出口信用'
elif table == '商标信息':
result = 'C5.1_商标信息'
elif table == '专利信息':
result = 'C5.2_专利信息'
elif table == '软件著作权':
result = 'C5.3_软件著作权'
elif table == '网站备案':
result = 'C5.4_网站备案'
elif table == '资产负债表':
result = 'C6.1_资产负债表'
elif table == '利润表':
result = 'C6.2_利润表'
elif table == '现金流量表':
result = 'C6.3_现金流量表'
elif table == '补充数据表':
result = 'C6.4_补充数据表'
elif table == '采购数据':
result = 'C7.1_采购数据'
elif table == '销售数据':
result = 'C7.2_销售数据'
elif table == '排放数据':
result = 'C7.3_排放数据'
elif table == '银行借款':
result = 'C8.1_银行借款'
elif table == '债券融资':
result = 'C8.2_债券融资'
elif table == '股票融资':
result = 'C8.3_股票融资'
elif table == '授信额度':
result = 'C8.4_授信额度'
elif table == '开庭公告':
result = 'C9.1_开庭公告'
elif table == '被执行人':
result = 'C9.2_被执行人'
elif table == '法院公告':
result = 'C9.3_法院公告'
elif table == '立案信息':
result = 'C9.4_立案信息'
elif table == '失信人':
result = 'C9.5_失信人'
elif table == '法律诉讼':
result = 'c9.6_法律诉讼'
elif table == '送达公告':
result = 'C9.7_送达公告'
elif table == '破产重整':
result = 'C9.8_破产重整'
elif table == '限制消费令':
result = 'C9.9_限制消费令'
elif table == '终本案件':
result = 'C9.10_终本案件'
elif table == '股权出质':
result = 'C10.1_股权出质'
elif table == '动产抵押':
result = 'C10.2_动产抵押'
elif table == '土地抵押':
result = 'C10.3_土地抵押'
elif table == '劳动仲裁':
result = 'C10.4_劳动仲裁'
elif table == '产品召回':
result = 'C10.5_产品召回'
elif table == '提供担保':
result = 'C10.6_提供担保'
elif table == '获得担保':
result = 'C10.7_获得担保'
elif table == '经营异常':
result = 'C11.1_经营异常'
elif table == '行政处罚':
result = 'C11.2_行政处罚'
elif table == '严重违法':
result = 'C11.3_严重违法'
elif table == '税收违法':
result = 'C11.4_税收违法'
elif table == '软件违规':
result = 'C11.5_软件违规'
elif table == '欠税公告':
result = 'C11.6_欠税公告'
elif table == '双随机抽查':
result = 'C11.7_双随机抽查'
elif table == '相关新闻':
result = 'C12.1_相关新闻'
elif table == '公告信息':
result = 'C12.2_公告信息'
elif table == '企业研报':
result = 'C12.3_企业研报'
else:
result = 'no table'
return result