feat: 告警阈值调整脚本
This commit is contained in:
parent
e68a1ab8ba
commit
941f0678a1
47
scripts/deploy/relax-alarms.py
Normal file
47
scripts/deploy/relax-alarms.py
Normal file
@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python3
|
||||
"""调整生产环境告警阈值——降低人脸误报和劳保鞋告警频率。
|
||||
运行后重新下发设备配置即生效。"""
|
||||
import sqlite3, json
|
||||
|
||||
DB = '/opt/safesightd/data/app.db'
|
||||
TEMPLATE = 'std_workshop_face_recognition_shoe_alarm'
|
||||
|
||||
c = sqlite3.connect(DB)
|
||||
body = json.loads(c.execute("SELECT body_json FROM templates WHERE name=?", (TEMPLATE,)).fetchone()[0])
|
||||
nodes = body['template']['nodes']
|
||||
|
||||
for n in nodes:
|
||||
if n.get('id') != 'alarm_violation':
|
||||
continue
|
||||
cfg = n['config']
|
||||
cfg['cooldown_ms'] = 60000
|
||||
cfg['min_score'] = 0.5
|
||||
cfg['min_duration_ms'] = 1500
|
||||
cfg['min_hits'] = 3
|
||||
cfg['hit_window_ms'] = 3000
|
||||
|
||||
# 劳保鞋
|
||||
for r in cfg.get('rules', []):
|
||||
if r['name'] == 'non_compliant_workshoe':
|
||||
r['min_score'] = 0.5
|
||||
r['cooldown_ms'] = 60000
|
||||
r['min_hits'] = 3
|
||||
r['min_duration_ms'] = 1500
|
||||
|
||||
# 陌生人脸
|
||||
for r in cfg.get('face_rules', []):
|
||||
if r['name'] == 'unknown_face':
|
||||
r['cooldown_ms'] = 30000
|
||||
r['max_known_sim'] = 0.2
|
||||
r['min_hits'] = 4
|
||||
r['hit_window_ms'] = 3000
|
||||
elif r['name'] == 'known_person':
|
||||
r['cooldown_ms'] = 30000
|
||||
r['min_sim'] = 0.75
|
||||
r['min_hits'] = 3
|
||||
r['hit_window_ms'] = 2000
|
||||
|
||||
c.execute("UPDATE templates SET body_json=? WHERE name=?", (json.dumps(body, ensure_ascii=False), TEMPLATE))
|
||||
c.commit()
|
||||
c.close()
|
||||
print('OK — 重新下发设备配置即生效')
|
||||
Loading…
Reference in New Issue
Block a user