Files
cma-management/backend/scripts/verify_bep_collector_regression.py
Hermes CI Fix 1a5356a2d1 feat(kpi): CMA保本点派生KPI F_BEP_REVENUE/COVER/GAP + 每日派生执行器 + 红黄绿静态阈值判定
- kpi_definitions entity1 新增3条派生KPI(456/457/458, formula/threshold/unit齐全)
- 新增 scripts/kpi_bep_deriver.py: 从 voucher_details 按财务口径聚合
  (5001销售收入/5602管理费 YTD月均, 渠补率政策84.61%) → 计算保本销售额/
  覆盖率/缺口 → upsert kpi_values source_type='derived' 幂等 + 同步yellow/red预警
- cron 06:35 注册(紧随 collector 06:30); 自动选最近完整月(8月未结账自动回退7月)
- kpis.py get_kpi: F_BEP_* 派生KPI按静态阈值文本判红黄绿(66.9→黄), 不走target比率
- 阈值经财务Bot 2026-09-08裁决: COVER >=100绿 50~100黄 <50红; GAP <=0绿 <=50黄 >50红
2026-09-08 13:43:20 +08:00

17 lines
854 B
Python

# 回归验证: F_REVENUE(kpi_value_sources id=1) 映射仍可正常采集 (collect_for_mapping dry-run)
# 我们不修改 kpi_value_collector.py,此脚本证明现有映射路径未受影响
import sys, os
sys.path.insert(0, "/root/cma-management/backend")
from app.database import get_session_local
from app.models import KPIValueSource
from scripts.kpi_value_collector import collect_for_mapping
db = get_session_local()()
try:
for m in db.query(KPIValueSource).filter(KPIValueSource.status == "active").all():
value, message = collect_for_mapping(db, m, "2026-07", write_kpi=False)
print(f"mapping id={m.id} kpi={m.kpi_id} table={m.source_table} -> value={value} | {message}")
print("COLLECTOR_REGRESSION_OK: 现有 active 映射全部可正常试跑(未写库),collector 逻辑未受影响")
finally:
db.close()