fix(kpi): single source of truth for REVERSE_INDICATORS + drop F_FACTORY_REBATE_RATE from reverse set

P-6 (M2 gate 2, FIN-CE-REVIEW-20260915-01): kpis.REVERSE_INDICATORS is now the only authoritative direction definition; dashboard.py imports it instead of carrying a literal copy; bot_kpis.py derives REVERSE_BOT_INDICATORS from it (dead import removed).

F_FACTORY_REBATE_RATE (upstream factory rebate rate, higher=better) was wrongly treated as reverse: 278.7% vs target 80 scored 1/danger, now 5/success and workbench three-color red -> green. No DB write, no scoring-engine logic change, no data_level/frontend touch.
This commit is contained in:
Hermes CI Fix
2026-09-15 17:48:56 +08:00
parent 6a48477d71
commit 5d0884cc3b
3 changed files with 29 additions and 11 deletions
+13 -1
View File
@@ -111,9 +111,21 @@ def get_kpi_categories(current_user = Depends(require_auth), db: Session = Depen
# KPI-5: 五档评分引擎(静态路由必须在动态/{kpi_id}之前)
# ============================================================
# ── 反向指标(值越低越好)· 单一事实源(single source of truth) ──
# 本表是「指标方向」的唯一权威定义(2026-09-15 M2 准入2 收口):凡按方向判级别/评分的代码
# 一律引用本表,禁止再复制字面量副本。
# - app/api/dashboard.py「工作台三色」原自带一份副本 → 已改为 from app.api.kpis import
# - app/api/bot_kpis.py 原 import 本表却未使用 → 已改为派生自本表
# 判定语义:在内 = 越低越好(实际/目标 ≤0.5 → 5 分);不在内 = 越高越好(比值 ≥1.2 → 5 分)
# 方向口径注意(两处「返补/返利」现金流方向相反,禁止误合并):
# - C_REBATE_RATE / F_REBATE_RATE = 渠道返补(对外付出,越低越好 → 反向,留在本表)
# - F_FACTORY_REBATE_RATE = 上游厂补率(厂补(捐赠收益)/主营成本,收到越多越好 → 正向,不属本表)
# 2026-09-15 修正:原被误列入本表 → 现网 278.7%(target_value=80)被判 1 分"失效";
# 与其三色阈值文本(green>=100=1.25×target / yellow>=80=target / red<80,越高越好)方向相反。
# P-6 定稿 = 改方向(阈值文本保持不动),修正后同一实测值判 5 分。
REVERSE_INDICATORS = ['C_REBATE_RATE', 'P_BUG_RATE', 'P_REWORK_PCT', 'F_DEBT_RATIO',
'F_COST_RATIO', 'F_AR_DAYS', 'F_REBATE_RATE',
'F_FACTORY_REBATE_RATE', 'F_COST_CONTROL_RATE', 'F_INV_DAYS']
'F_COST_CONTROL_RATE', 'F_INV_DAYS']
def _static_threshold_level(value, kpi) -> str: