fix(h2-forecast): 对外 KPIValue 残余读路径统一实测区口径(7 处)
任总 2026-10-02 11:35 直令「对外 /api/cma/** 读 KPIValue 默认只取实测区;
预估禁进趋势序列 / 禁作预警与预算依据」的同族残余读路径收口。
7 处逐处改(均引 app/utils/kpi_value_scope.actual_only_clause,不新写字面量口径):
- kpis.py:604 GET /kpis/{id} 详情历史值(预估禁进趋势序列)
- ai_analysis.py:363 GET /ai/kpi-analysis/{id} 趋势序列/LLM 上下文
- thresholds.py:132 GET /thresholds/suggest/{id} 阈值推荐依据
- budget_generate.py:94 GET /budget/kpi-budget-candidates 预算候选最新值
- budget.py:1380 POST /budget/apply-method 派生基数(预算依据)
- maps.py:657 GET /maps/{id}/review 地图节点最新值
- data_quality.py:363 GET /data-quality/stats 缺失判定(仅预估行不算有实际值)
证据:同脚本双树 A/B 11/11(改前 3/11 FAIL)+ pytest 3 failed/1529 passed 与基线逐条同 ID。
不 push / 不部署 / 不重启 / 不写库。
This commit is contained in:
@@ -12,6 +12,7 @@ from app.auth_middleware import require_auth, require_role, filter_kpis_by_role,
|
||||
from app.models import StrategicMap, MapObjective, KPIDefinition, KPIValue, KPIAlert, OperationLog, Entity, KPICausality, KPIHierarchy, User
|
||||
from app.utils.oplog import log_op
|
||||
from app.utils.alert_entity_scope import month_period_clause
|
||||
from app.utils.kpi_value_scope import actual_only_clause
|
||||
from app.api.kpi_governance import validate_kpi_payload, kpi_issues_message
|
||||
from app.utils.threshold_parser import (
|
||||
calc_level as _tp_calc_level,
|
||||
@@ -604,6 +605,8 @@ def get_kpi(kpi_id: int, db: Session = Depends(get_db), entity_id: int = Depends
|
||||
vals = db.query(KPIValue).filter(
|
||||
KPIValue.kpi_id == kpi_id,
|
||||
KPIValue.actual_value.isnot(None),
|
||||
# 实测区口径:预估行禁入趋势序列(kpi_value_scope.actual_only_clause)
|
||||
actual_only_clause(),
|
||||
).order_by(KPIValue.period.asc()).all()
|
||||
is_reverse = kpi.kpi_code in REVERSE_INDICATORS
|
||||
target = kpi.target_value
|
||||
|
||||
Reference in New Issue
Block a user