后端新增风险图谱算法模块、风险观察与反馈服务、规则 DSL 校验器和可解释性引擎,完善系统仪表盘和财务仪表盘统计, 优化 agent 运行和编排执行链路,清理旧开发文档,前端新增 系统趋势、负载热力图等多种仪表盘图表组件,完善操作反馈 对话框和工作台日期选择器,优化报销创建和审批详情交互, 补充单元测试覆盖。
88 lines
2.5 KiB
Python
88 lines
2.5 KiB
Python
from __future__ import annotations
|
|
|
|
from decimal import Decimal
|
|
|
|
from app.algorithem.risk_graph import RiskGraphClaimItemSnapshot, RiskGraphClaimSnapshot
|
|
from app.algorithem.risk_graph.profile_baselines import ProfileBaselineUpdater
|
|
|
|
|
|
def test_profile_baseline_updater_outputs_core_dimensions() -> None:
|
|
snapshot = ProfileBaselineUpdater().build_from_claims(
|
|
[
|
|
_claim(
|
|
"c1",
|
|
employee_id="e1",
|
|
department_id="d1",
|
|
expense_type="travel",
|
|
amount="600",
|
|
supplier_id="s-hotel",
|
|
supplier_name="Hotel A",
|
|
),
|
|
_claim(
|
|
"c2",
|
|
employee_id="e1",
|
|
department_id="d1",
|
|
expense_type="travel",
|
|
amount="900",
|
|
supplier_id="s-hotel",
|
|
supplier_name="Hotel A",
|
|
),
|
|
_claim(
|
|
"c3",
|
|
employee_id="e2",
|
|
department_id="d2",
|
|
expense_type="meal",
|
|
amount="300",
|
|
supplier_id="s-meal",
|
|
supplier_name="Meal B",
|
|
),
|
|
]
|
|
)
|
|
|
|
assert snapshot.dimension_counts == {
|
|
"employee": 2,
|
|
"department": 2,
|
|
"supplier": 2,
|
|
"expense_type": 2,
|
|
}
|
|
hotel = next(bucket for bucket in snapshot.buckets if bucket.key == "s-hotel")
|
|
assert hotel.dimension == "supplier"
|
|
assert hotel.sample_size == 2
|
|
assert hotel.claim_count == 2
|
|
assert hotel.total_amount == Decimal("1500")
|
|
assert hotel.p75_amount == Decimal("825")
|
|
assert hotel.as_dict()["total_amount"] == "1500"
|
|
|
|
|
|
def _claim(
|
|
claim_id: str,
|
|
*,
|
|
employee_id: str,
|
|
department_id: str,
|
|
expense_type: str,
|
|
amount: str,
|
|
supplier_id: str,
|
|
supplier_name: str,
|
|
) -> RiskGraphClaimSnapshot:
|
|
return RiskGraphClaimSnapshot(
|
|
claim_id=claim_id,
|
|
claim_no=f"BX-{claim_id}",
|
|
employee_id=employee_id,
|
|
employee_name=employee_id,
|
|
department_id=department_id,
|
|
department_name=department_id,
|
|
expense_type=expense_type,
|
|
amount=Decimal(amount),
|
|
items=[
|
|
RiskGraphClaimItemSnapshot(
|
|
item_id=f"item-{claim_id}",
|
|
item_type=expense_type,
|
|
item_amount=Decimal(amount),
|
|
metadata={
|
|
"supplier_id": supplier_id,
|
|
"supplier_name": supplier_name,
|
|
},
|
|
)
|
|
],
|
|
)
|