fix: extract target info from nested detections

This commit is contained in:
tian 2026-05-07 12:34:47 +08:00
parent 2c97cbc26e
commit 46eb031b8f

View File

@ -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,