44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
"""信号相关 Pydantic 模型"""
|
|
|
|
from enum import Enum
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class SignalPriority(str, Enum):
|
|
"""
|
|
信号优先级
|
|
|
|
- CRITICAL: impact >= 0.9, 立即处理 + 通知
|
|
- HIGH: 0.7 <= impact < 0.9, 异步处理 + 通知
|
|
- MEDIUM: 0.5 <= impact < 0.7, 仅异步处理
|
|
- LOW: impact < 0.5, 仅记录
|
|
"""
|
|
|
|
CRITICAL = "critical"
|
|
HIGH = "high"
|
|
MEDIUM = "medium"
|
|
LOW = "low"
|
|
|
|
|
|
def classify_signal_priority(impact_score: float, confidence: float = 0.0) -> SignalPriority:
|
|
"""
|
|
根据 impact_score 和 confidence 分类信号优先级。
|
|
"""
|
|
if impact_score >= 0.9:
|
|
return SignalPriority.CRITICAL
|
|
elif impact_score >= 0.7 and confidence >= 0.6:
|
|
return SignalPriority.HIGH
|
|
elif impact_score >= 0.5 or (impact_score >= 0.7 and confidence < 0.6):
|
|
return SignalPriority.MEDIUM
|
|
else:
|
|
return SignalPriority.LOW
|
|
|
|
|
|
class SignalCreate(BaseModel):
|
|
"""创建信号请求"""
|
|
|
|
source: str
|
|
content: str
|
|
impact_score: float
|
|
priority: SignalPriority | None = None # 未提供时自动计算
|