Files
X-Financial/server/src/app/services/risk_rule_value_compare.py
caoxiaozhu 7989f3a159 feat: 新增风险图谱算法与系统仪表盘及操作反馈体系
后端新增风险图谱算法模块、风险观察与反馈服务、规则 DSL
校验器和可解释性引擎,完善系统仪表盘和财务仪表盘统计,
优化 agent 运行和编排执行链路,清理旧开发文档,前端新增
系统趋势、负载热力图等多种仪表盘图表组件,完善操作反馈
对话框和工作台日期选择器,优化报销创建和审批详情交互,
补充单元测试覆盖。
2026-05-30 15:46:51 +08:00

47 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from __future__ import annotations
import re
from typing import Any
def parse_number_value(value: Any) -> float | None:
if isinstance(value, (int, float)):
return float(value)
text = re.sub(r"[,\s元¥¥]", "", str(value or ""))
match = re.search(r"-?\d+(?:\.\d+)?", text)
if not match:
return None
try:
return float(match.group(0))
except ValueError:
return None
def compare_numbers(left: float, right: float, compare: str) -> bool:
if compare in {"gt", ">", "greater_than"}:
return left > right
if compare in {"gte", ">=", "greater_or_equal"}:
return left >= right
if compare in {"lt", "<", "less_than"}:
return left < right
if compare in {"lte", "<=", "less_or_equal"}:
return left <= right
if compare in {"eq", "=", "equals"}:
return left == right
return left > right
def duplicate_text_values(values: list[Any]) -> list[str]:
seen: set[str] = set()
duplicates: list[str] = []
for value in values:
items = value if isinstance(value, (list, tuple, set)) else [value]
for item in items:
text = re.sub(r"\s+", "", str(item or "")).strip().lower()
if not text:
continue
if text in seen and text not in duplicates:
duplicates.append(text)
seen.add(text)
return duplicates