From 46eb031b8ffe43f93e774e71d2beaaadca788a7a Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Thu, 7 May 2026 12:34:47 +0800 Subject: [PATCH] fix: extract target info from nested detections --- internal/service/alarm_collector.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/internal/service/alarm_collector.go b/internal/service/alarm_collector.go index f167952..1af7c9a 100644 --- a/internal/service/alarm_collector.go +++ b/internal/service/alarm_collector.go @@ -3,6 +3,7 @@ package service import ( "database/sql" "encoding/json" + "fmt" "log" "sync" "time" @@ -129,6 +130,19 @@ func (c *AlarmCollector) fetchDeviceAlarms(dev *models.Device) ([]AlarmRecord, e confidence = score } } + // Extract from nested detections if top-level fields are empty + if dets, ok := a["detections"].([]any); ok && len(dets) > 0 { + if objectLabel == "" { + objectLabel = fmt.Sprintf("%d 个检测目标", len(dets)) + } + if confidence == 0 { + if d0, ok := dets[0].(map[string]any); ok { + if s, ok := d0["score"].(float64); ok { + confidence = s + } + } + } + } durationMs, _ := a["duration_ms"].(float64) alarms = append(alarms, AlarmRecord{ ID: id,