适配: Edge 全局参数解析 + AlgorithmManager 三级参数合并

This commit is contained in:
2026-04-09 17:04:11 +08:00
parent c6d8430867
commit 3266241064
4 changed files with 104 additions and 1 deletions

View File

@@ -1556,6 +1556,7 @@ class AlgorithmManager:
self.working_hours = working_hours or []
self._update_lock = threading.Lock()
self._registered_keys: set = set() # 已注册的 (roi_id, bind_id, algo_type) 缓存
self._global_params: Dict[str, Dict] = {} # 全局参数 {algo_code: params_dict}
# Bug fix: 默认参数与算法构造函数一致
self.default_params = {
@@ -1598,6 +1599,28 @@ class AlgorithmManager:
self._pubsub_thread = None
self._running = False
def update_global_params(self, global_params_map: Dict[str, Dict]):
"""更新全局参数
Args:
global_params_map: {algo_code: params_dict} 格式的全局参数
"""
with self._update_lock:
self._global_params = global_params_map or {}
logger.info(f"全局参数已更新: {list(self._global_params.keys())}")
def get_min_alarm_duration(self, algorithm_type: str) -> Optional[int]:
"""从全局参数获取最小告警持续时间(秒)
Args:
algorithm_type: 算法类型(如 leave_post, intrusion
Returns:
最小告警持续时间秒数,未配置返回 None
"""
gp = self._global_params.get(algorithm_type, {})
return gp.get("min_alarm_duration_sec")
def start_config_subscription(self):
"""启动配置变更订阅"""
try:
@@ -2074,6 +2097,10 @@ class AlgorithmManager:
self.algorithms[roi_id][key] = {}
algo_params = self.default_params.get(algorithm_type, {}).copy()
# 三级合并:默认参数 → 全局参数 → 绑定级参数
global_p = self._global_params.get(algorithm_type, {})
if global_p:
algo_params.update(global_p)
if params:
algo_params.update(params)