feat: 预测性成本智能升级 — 历史回归弹性校准 + 预测偏差告警
升级1: 宏观敏感性弹性历史校准 - 内置宏观历史数据(oil/usd/cpi 2026-01~07月度) - 变化率弹性: 同period匹配KPI历史vs因素历史算弹性 - 合理性校验: |弹性|超出[0.01,0.5]视为噪声回退规则(诚实标注) 升级2: 预测偏差告警闭环 - 新表 kpi_forecast_log(预测历史)+模型KpiForecastLog - 预测时落库(同KPI同预测期覆盖) - alert_rules 支持 rule_type=forecast_deviation(threshold_pct) - POST /alert-rules/run-forecast-deviation: 预测vs实际偏差>阈值生成预警(去重, 超2倍阈值红色) - 端到端验证: 模拟实际500vs预测399.55→偏差20.1%>5%→红色预警生成 回归: pytest 40 passed(predict+alerts)
This commit is contained in:
@@ -306,6 +306,21 @@ class MpmResult(Base):
|
||||
created_at = Column(DateTime, server_default=func.now())
|
||||
|
||||
|
||||
class KpiForecastLog(Base):
|
||||
"""KPI预测历史 — 预测偏差告警数据源 (2026-08-25 升级2a)"""
|
||||
__tablename__ = "kpi_forecast_log"
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
entity_id = Column(Integer, nullable=False, comment="企业ID")
|
||||
kpi_id = Column(Integer, nullable=False, comment="KPI ID")
|
||||
kpi_code = Column(String(50), nullable=False, comment="KPI编码")
|
||||
period = Column(String(20), nullable=False, comment="预测期间")
|
||||
forecast_value = Column(Float, nullable=True, comment="预测值")
|
||||
model = Column(String(30), default="linear", comment="预测模型")
|
||||
confidence = Column(String(10), nullable=True, comment="置信度")
|
||||
trend = Column(String(10), nullable=True, comment="趋势")
|
||||
created_at = Column(DateTime, server_default=func.now())
|
||||
|
||||
|
||||
class BotBridgeConfig(Base):
|
||||
"""Bot桥接鉴权配置"""
|
||||
__tablename__ = "bot_bridge_config"
|
||||
|
||||
Reference in New Issue
Block a user