From 3db7bef025c33ab50f652ce4516f3b61bee7dd17 Mon Sep 17 00:00:00 2001 From: Hermes CI Fix Date: Tue, 21 Jul 2026 17:56:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20CMA=20P0=E4=BF=AE=E5=A4=8D=20-=20?= =?UTF-8?q?=E8=AF=84=E5=88=86=E5=BC=95=E6=93=8E=E5=8F=8D=E5=90=91=E6=8C=87?= =?UTF-8?q?=E6=A0=87=20+=20=E6=B8=85=E7=90=86=E9=87=8D=E5=A4=8DKPI=20+=20?= =?UTF-8?q?=E6=A0=A1=E5=87=86=E7=9B=AE=E6=A0=87=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 三项P0修复: 1. 评分引擎反向指标:新增REVERSE_INDICATORS列表和is_reverse参数, _calc_five_tier_score现在支持越低越好的指标评分 (渠补率82.8%>75%从4分→2分) 2. 清理重复KPI:删除entity_id=2(博海)的56条重复KPI, 从entity_id=1(酣客)重新克隆 3. 校准目标值:按审计报告更新酣客24项KPI目标值 (F_REVENUE 4979→1200, F_NET_PROFIT 500→50等) --- backend/app/api/kpis.py | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/backend/app/api/kpis.py b/backend/app/api/kpis.py index 0c21d3f8..a67a5636 100644 --- a/backend/app/api/kpis.py +++ b/backend/app/api/kpis.py @@ -101,21 +101,38 @@ def get_kpi_categories(current_user = Depends(require_auth), db: Session = Depen # KPI-5: 五档评分引擎(静态路由必须在动态/{kpi_id}之前) # ============================================================ -def _calc_five_tier_score(current_value, target_value): - """五档评分:1-5分""" +REVERSE_INDICATORS = ['C_REBATE_RATE', 'P_BUG_RATE', 'P_REWORK_PCT', 'F_DEBT_RATIO', + 'P_QUALITY_RATE', 'F_COST_RATIO', 'F_INTEREST_COVER', 'F_QUICK_RATIO'] + + +def _calc_five_tier_score(current_value, target_value, is_reverse=False): + """五档评分:1-5分(支持正反向指标)""" if current_value is None or target_value is None or target_value == 0: return None, "info" ratio = current_value / target_value - if ratio >= 1.2: - return 5, "success" # 卓越 - elif ratio >= 1.0: - return 4, "success" # 达标 - elif ratio >= 0.8: - return 3, "warning" # 预警 - elif ratio >= 0.5: - return 2, "danger" # 危险 + if is_reverse: + # 反向指标:实际值越低越好 + if ratio <= 0.5: + return 5, "success" # 远低于目标→卓越 + elif ratio <= 0.8: + return 4, "success" # 低于目标→达标 + elif ratio <= 1.0: + return 3, "warning" # 接近目标→预警 + elif ratio <= 1.2: + return 2, "danger" # 超过目标→危险 + else: + return 1, "danger" # 远超目标→失效 else: - return 1, "danger" # 失效 + if ratio >= 1.2: + return 5, "success" # 卓越 + elif ratio >= 1.0: + return 4, "success" # 达标 + elif ratio >= 0.8: + return 3, "warning" # 预警 + elif ratio >= 0.5: + return 2, "danger" # 危险 + else: + return 1, "danger" # 失效 @router.get("/score") @@ -154,7 +171,7 @@ def get_kpi_score( latest_val = val_query.order_by(KPIValue.period.desc()).first() current_val = latest_val.actual_value if latest_val else None - score, status = _calc_five_tier_score(current_val, k.target_value) + score, status = _calc_five_tier_score(current_val, k.target_value, is_reverse=(k.kpi_code in REVERSE_INDICATORS)) kpi_scores.append({ "kpi_id": k.id,