40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
#!/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
|
|
# 劳保鞋
|
|
for r in n.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 n.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 — 重新下发设备配置即生效')
|