From 35edbc900d328e72cbe403cc00c81c08bb81a495 Mon Sep 17 00:00:00 2001 From: P3ngSaM <61768364+P3ngSaM@users.noreply.github.com> Date: Wed, 10 May 2023 16:39:42 +0800 Subject: [PATCH] =?UTF-8?q?changes=20=E4=BF=9D=E5=81=A5=E4=B8=9A=E6=89=93?= =?UTF-8?q?=E5=88=86=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- APP/Router/HealthIndustryRouter.py | 49 ++++++++++++++---------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/APP/Router/HealthIndustryRouter.py b/APP/Router/HealthIndustryRouter.py index 93f072e..b35dba4 100644 --- a/APP/Router/HealthIndustryRouter.py +++ b/APP/Router/HealthIndustryRouter.py @@ -276,32 +276,29 @@ def func(schemas: ComputeSchemas.ComputeModelReqBody, mongodb: MongoHelper = Dep # 指标权重 weight = index.get('权重') # 指标数值分为四种:常规数值型、直接进在区间内进行计算,部分区间可能缺失;财务指标数值型,经过计算的财务指标数值直接在区间进行计算;字符串型,直接与档位匹配,布尔型:是与否,一档与八档 - if isinstance(value, str): - # 遍历档位 - for key, val in index.items(): - if value == val: - index_dict['得分'] = score_func(key, weight) - index_dict['档位'] = score_level(key) - index_score.append(index_dict) - test_list.append(index_name) - print(index_name) - elif isinstance(value, float) or isinstance(value, int): - # 提取档位 - key_list = ['一级指标', '二级指标', '三级指标', '四级指标', '权重', '单位', '计算公式'] - level_dict = dict() - for key, val in index.items(): - if key not in key_list: - level_dict[key] = val - test_list.append(index_name) - print(index_name) - result = score_func_by_number(level_dict, value, weight) - index_dict['得分'] = result.get('得分') - index_dict['档位'] = result.get('档位') - index_score.append(index_dict) - - for da in data.keys(): - if da not in test_list: - print(da) + try: + if isinstance(value, str): + # 遍历档位 + for key, val in index.items(): + if value == val: + index_dict['得分'] = score_func(key, weight) + index_dict['档位'] = score_level(key) + index_score.append(index_dict) + test_list.append(index_name) + elif isinstance(value, float) or isinstance(value, int): + # 提取档位 + key_list = ['一级指标', '二级指标', '三级指标', '四级指标', '权重', '单位', '计算公式'] + level_dict = dict() + for key, val in index.items(): + if key not in key_list: + level_dict[key] = val + test_list.append(index_name) + result = score_func_by_number(level_dict, value, weight) + index_dict['得分'] = result.get('得分') + index_dict['档位'] = result.get('档位') + index_score.append(index_dict) + except TypeError: + raise HTTPException(status_code=400, detail="{}指标值不符合规范".format(index_name)) # 汇总得分 total_score = round(sum(item.get('得分') for item in index_score), 2)