From df557c6f6ca0e4208fc5536dc4d0f8658bb6fb9a Mon Sep 17 00:00:00 2001 From: P3ngSaM <61768364+P3ngSaM@users.noreply.github.com> Date: Wed, 9 Feb 2022 16:07:12 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BF=AE=E6=94=B9=E6=89=93=E5=88=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Rating/scripts/financial_score.py | 82 ++++++------------------------- 1 file changed, 16 insertions(+), 66 deletions(-) diff --git a/Rating/scripts/financial_score.py b/Rating/scripts/financial_score.py index 9353882..7edf239 100644 --- a/Rating/scripts/financial_score.py +++ b/Rating/scripts/financial_score.py @@ -33,41 +33,34 @@ def financial_score(param1, param2): else: refer = list(map(float, refers[key])) weight = weights[key] - # 判断打分是正相关还是反相关 + standard = [weight, weight*0.8, weight*0.6, weight*0.4, weight*0.2] + # 判断正反相关 if refer[0] > refer[1]: - # 正相关判断 if value >= refer[0]: score = weight elif value > refer[1]: - standard_score = round(weight * 1, 2) - score = linear_correlation_type_positive(value, standard_score, refer[0]) + score = linear_correlation_type(value, standard[0], standard[1], refer[0], refer[1]) elif value > refer[2]: - standard_score = round(weight * 0.8, 2) - score = linear_correlation_type_positive(value, standard_score, refer[1]) + score = linear_correlation_type(value, standard[1], standard[2], refer[1], refer[2]) elif value > refer[3]: - standard_score = round(weight * 0.5, 2) - score = linear_correlation_type_positive(value, standard_score, refer[2]) + score = linear_correlation_type(value, standard[2], standard[3], refer[2], refer[3]) elif value > refer[4]: - standard_score = round(weight * 0.25, 2) - score = linear_correlation_type_positive(value, standard_score, refer[3]) + score = linear_correlation_type(value, standard[3], standard[4], refer[3], refer[4]) else: score = 0 else: if value <= refer[0]: score = weight elif value < refer[1]: - standard_score = round(weight * 1, 2) - score = linear_correlation_type_anti(value, standard_score, refer[0]) + score = linear_correlation_type(value, standard[0], standard[1], refer[0], refer[1]) elif value < refer[2]: - standard_score = round(weight * 0.8, 2) - score = linear_correlation_type_anti(value, standard_score, refer[1]) + score = linear_correlation_type(value, standard[1], standard[2], refer[1], refer[2]) elif value < refer[3]: - standard_score = round(weight * 0.5, 2) - score = linear_correlation_type_anti(value, standard_score, refer[2]) + score = linear_correlation_type(value, standard[2], standard[3], refer[2], refer[3]) elif value < refer[4]: - standard_score = round(weight * 0.25, 2) - score = linear_correlation_type_anti(value, standard_score, refer[3]) - + score = linear_correlation_type(value, standard[3], standard[4], refer[3], refer[4]) + else: + score = 0 scores[key] = round(score, 2) result = dict() @@ -93,63 +86,20 @@ def financial_score(param1, param2): return result -def linear_correlation_type(value, standard_score, refer1, refer2): +def linear_correlation_type(value, standard1, standard2, refer1, refer2): """ 线性相关类型 正相关/反相关 Parameters value float 指标值 - standard_score float 标准分 + standard1 float 标准分1 + standard2 float 标准分2 refer1 阈值1 refer2 阈值2 Returns score float 得分 """ # main - # 正相关打分 - if refer1 > refer2: - if value <= refer2: - score = 0 - elif value >= refer1: - score = standard_score - else: - score = standard_score * (1 - (refer1 - value) / (refer1 - refer2)) - # 反相关打分 - else: - if value <= refer2: - score = standard_score - elif value >= refer1: - score = 0 - else: - score = standard_score * (1 - (value - refer2) / (refer1 - refer2)) + score = standard2 + (value - refer2) / (refer1 - refer2) * (standard1 - standard2) return score - -def linear_correlation_type_positive(value, standard_score, refer1): - """ - 线性相关类型 正相关/反相关 - Parameters - value float 指标值 - standard_score float 标准分 - refer1 阈值1 - Returns - score float 得分 - """ - score = standard_score * (value / refer1) - - return score - - -def linear_correlation_type_anti(value, standard_score, refer1): - """ - 线性相关类型 正相关/反相关 - Parameters - value float 指标值 - standard_score float 标准分 - refer1 阈值1 - Returns - score float 得分 - """ - score = standard_score - (standard_score * (value / refer1) - standard_score) - - return score