功能:VLM提示词和告警级别支持车辆违停/拥堵算法
- vlm_service.py: 新增illegal_parking和vehicle_congestion VLM复核提示词模板 - alarm_event_service.py: 新增违停告警级别逻辑(按停留时长分级)和拥堵告警级别 - wechat_service.py: ALARM_TYPE_NAMES新增车辆违停/拥堵中文映射 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -39,6 +39,17 @@ def _determine_alarm_level(alarm_type: str, confidence: float, duration_ms: Opti
|
|||||||
elif duration_ms > 10 * 60 * 1000:
|
elif duration_ms > 10 * 60 * 1000:
|
||||||
return 2 # 一般
|
return 2 # 一般
|
||||||
return 1 # 提醒
|
return 1 # 提醒
|
||||||
|
elif alarm_type == "illegal_parking":
|
||||||
|
# 违停:根据停留时长判断级别
|
||||||
|
if duration_ms is None:
|
||||||
|
return 2 # 一般级别(刚触发)
|
||||||
|
if duration_ms > 60 * 60 * 1000:
|
||||||
|
return 3 # 严重(超过1小时)
|
||||||
|
elif duration_ms > 15 * 60 * 1000:
|
||||||
|
return 2 # 一般(超过15分钟)
|
||||||
|
return 1 # 提醒
|
||||||
|
elif alarm_type == "vehicle_congestion":
|
||||||
|
return 2 # 一般级别(拥堵本身不分等级,由持续时长在resolve时重算)
|
||||||
elif confidence and confidence > 0.9:
|
elif confidence and confidence > 0.9:
|
||||||
return 3 # 严重
|
return 3 # 严重
|
||||||
elif confidence and confidence > 0.7:
|
elif confidence and confidence > 0.7:
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ from app.utils.logger import logger
|
|||||||
ALARM_TYPE_NAMES = {
|
ALARM_TYPE_NAMES = {
|
||||||
"leave_post": "离岗",
|
"leave_post": "离岗",
|
||||||
"intrusion": "周界入侵",
|
"intrusion": "周界入侵",
|
||||||
|
"illegal_parking": "车辆违停",
|
||||||
|
"vehicle_congestion": "车辆拥堵",
|
||||||
}
|
}
|
||||||
|
|
||||||
# 算法类型 → VLM Prompt 模板
|
# 算法类型 → VLM Prompt 模板
|
||||||
@@ -38,6 +40,24 @@ description要求:≤15字,直接说结论。
|
|||||||
告警成立示例:"有人员进入周界区域"
|
告警成立示例:"有人员进入周界区域"
|
||||||
误报示例:"画面中无周界入侵情况"
|
误报示例:"画面中无周界入侵情况"
|
||||||
仅输出JSON:{{"confirmed":true,"description":"..."}}""",
|
仅输出JSON:{{"confirmed":true,"description":"..."}}""",
|
||||||
|
|
||||||
|
"illegal_parking": """你是安防监控AI复核员。算法类型:车辆违停检测,监控区域:{roi_name}。
|
||||||
|
判断该区域是否有车辆违规停放。注意:3米高度物业摄像头俯拍视角。
|
||||||
|
- confirmed=true:有车辆违停(告警成立)
|
||||||
|
- confirmed=false:无车辆违停(误报,如车辆正在行驶、无车辆、或属于合法停车位)
|
||||||
|
description要求:≤15字,直接说结论,注明车辆类型。
|
||||||
|
告警成立示例:"一辆轿车违停在消防通道"
|
||||||
|
误报示例:"该区域无违停车辆"
|
||||||
|
仅输出JSON:{{"confirmed":true,"description":"..."}}""",
|
||||||
|
|
||||||
|
"vehicle_congestion": """你是安防监控AI复核员。算法类型:车辆拥堵检测,监控区域:{roi_name}。
|
||||||
|
判断该区域是否存在车辆拥堵。注意:3米高度物业摄像头俯拍视角。
|
||||||
|
- confirmed=true:存在车辆拥堵(告警成立,多辆车辆密集停留或缓行)
|
||||||
|
- confirmed=false:无拥堵(误报,如车辆正常通行、车辆数量少)
|
||||||
|
description要求:≤15字,直接说结论,注明大致车辆数。
|
||||||
|
告警成立示例:"约5辆车拥堵在路口"
|
||||||
|
误报示例:"车辆正常通行无拥堵"
|
||||||
|
仅输出JSON:{{"confirmed":true,"description":"..."}}""",
|
||||||
}
|
}
|
||||||
|
|
||||||
# 通用降级 prompt(未知算法类型时使用)
|
# 通用降级 prompt(未知算法类型时使用)
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ from app.utils.logger import logger
|
|||||||
ALARM_TYPE_NAMES = {
|
ALARM_TYPE_NAMES = {
|
||||||
"leave_post": "人员离岗",
|
"leave_post": "人员离岗",
|
||||||
"intrusion": "周界入侵",
|
"intrusion": "周界入侵",
|
||||||
|
"illegal_parking": "车辆违停",
|
||||||
|
"vehicle_congestion": "车辆拥堵",
|
||||||
}
|
}
|
||||||
|
|
||||||
# 告警级别映射
|
# 告警级别映射
|
||||||
@@ -365,13 +367,17 @@ class WeChatService:
|
|||||||
replace_text = action_text.get(action, "已处理")
|
replace_text = action_text.get(action, "已处理")
|
||||||
|
|
||||||
body = {
|
body = {
|
||||||
"userids": user_ids,
|
"userids": user_ids if user_ids else [],
|
||||||
"agentid": self.agent_id_int,
|
"agentid": self.agent_id_int,
|
||||||
"response_code": response_code,
|
"response_code": response_code,
|
||||||
"button": {
|
"button": {
|
||||||
"replace_name": replace_text,
|
"replace_name": replace_text,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
# 如果 user_ids 为空(如边缘自动结单),用 atall=1 更新全部接收人
|
||||||
|
if not user_ids:
|
||||||
|
body.pop("userids")
|
||||||
|
body["atall"] = 1
|
||||||
|
|
||||||
url = f"https://qyapi.weixin.qq.com/cgi-bin/message/update_template_card?access_token={access_token}"
|
url = f"https://qyapi.weixin.qq.com/cgi-bin/message/update_template_card?access_token={access_token}"
|
||||||
async with httpx.AsyncClient(timeout=10) as client:
|
async with httpx.AsyncClient(timeout=10) as client:
|
||||||
|
|||||||
Reference in New Issue
Block a user