feat: 实现配置热更新机制
数据库扩展: - roi_configs 新增算法参数字段(working_hours, confirm_on_duty_sec等) - 新增 config_update_log 表记录配置变更日志 Redis缓存: - ROI/摄像头配置缓存到 Redis(TTL 1小时) - sync_all_to_redis() 批量同步配置 - notify_config_change() 发布配置变更通知 热更新: - AlgorithmManager 订阅 Redis config_update 频道 - load_from_redis() 从 Redis 加载算法参数 - reload_algorithm() 热更新单个算法 - reload_all_algorithms() 重新加载所有算法 配置模型: - ROIInfo 添加算法参数字段
This commit is contained in:
@@ -104,6 +104,11 @@ class ROIInfo:
|
||||
alert_cooldown: int = 300
|
||||
enabled: bool = True
|
||||
extra_params: Optional[Dict[str, Any]] = None
|
||||
working_hours: Optional[List[Dict]] = None # 工作时间段
|
||||
confirm_on_duty_sec: int = 10 # 在岗确认时间
|
||||
confirm_leave_sec: int = 10 # 离岗确认时间
|
||||
cooldown_sec: int = 300 # 告警冷却时间
|
||||
target_class: str = "person" # 目标类别
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
"""转换为字典"""
|
||||
@@ -117,6 +122,11 @@ class ROIInfo:
|
||||
"alert_cooldown": self.alert_cooldown,
|
||||
"enabled": self.enabled,
|
||||
"extra_params": self.extra_params,
|
||||
"working_hours": self.working_hours,
|
||||
"confirm_on_duty_sec": self.confirm_on_duty_sec,
|
||||
"confirm_leave_sec": self.confirm_leave_sec,
|
||||
"cooldown_sec": self.cooldown_sec,
|
||||
"target_class": self.target_class,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
@@ -128,6 +138,14 @@ class ROIInfo:
|
||||
algo_type_str = data.get("algorithm_type", "leave_post")
|
||||
algo_type = AlgorithmType(algo_type_str) if algo_type_str in [e.value for e in AlgorithmType] else AlgorithmType.LEAVE_POST
|
||||
|
||||
working_hours = data.get("working_hours")
|
||||
if isinstance(working_hours, str):
|
||||
import json
|
||||
try:
|
||||
working_hours = json.loads(working_hours)
|
||||
except:
|
||||
working_hours = None
|
||||
|
||||
return cls(
|
||||
roi_id=data.get("roi_id", ""),
|
||||
camera_id=data.get("camera_id", ""),
|
||||
@@ -138,6 +156,11 @@ class ROIInfo:
|
||||
alert_cooldown=data.get("alert_cooldown", 300),
|
||||
enabled=data.get("enabled", True),
|
||||
extra_params=data.get("extra_params"),
|
||||
working_hours=working_hours,
|
||||
confirm_on_duty_sec=data.get("confirm_on_duty_sec", 10),
|
||||
confirm_leave_sec=data.get("confirm_leave_sec", 10),
|
||||
cooldown_sec=data.get("cooldown_sec", 300),
|
||||
target_class=data.get("target_class", "person"),
|
||||
)
|
||||
|
||||
def is_point_inside(self, point: List[float]) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user