From cd8df324bed92c1bdeef0c2b445cdd33df020895 Mon Sep 17 00:00:00 2001 From: Accusys Date: Fri, 7 Aug 2026 14:04:54 +0800 Subject: [PATCH] fix: tkg.rs avg_confidence moved before props construction + schema.rs ON CONFLICT backfill derived fields - tkg.rs: avg_confidence calculation moved to line 1207 (before props json) - tkg.rs: Added 'avg_confidence' to props json (round4) - schema.rs: ON CONFLICT DO UPDATE expanded to backfill start_frame, end_frame, frame_count, key_frame, key_face, avg_confidence from tkg_nodes.properties This fixes trace_profiles.avg_confidence always being NULL, and enables automatic self-healing when upsert_trace_profile is called from any caller. --- src/core/db/schema.rs | 9 ++++++++- src/core/processor/tkg.rs | 13 +++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/core/db/schema.rs b/src/core/db/schema.rs index 1cbc4e69..d81f33e6 100644 --- a/src/core/db/schema.rs +++ b/src/core/db/schema.rs @@ -52,7 +52,14 @@ pub async fn upsert_trace_profile( VALUES ($1, $2, $3, {sf}, {ef}, {fc}, {kf}, {kface}, 'pending', {avgc}, \ COALESCE($4::jsonb, {props_sub}, '{{}}'::jsonb)) \ ON CONFLICT (file_uuid, trace_id) \ - DO UPDATE SET name = EXCLUDED.name{update_props}, updated_at = NOW()", + DO UPDATE SET name = EXCLUDED.name{update_props}, \ + start_frame = EXCLUDED.start_frame, \ + end_frame = EXCLUDED.end_frame, \ + frame_count = EXCLUDED.frame_count, \ + key_frame = EXCLUDED.key_frame, \ + key_face = EXCLUDED.key_face, \ + avg_confidence = EXCLUDED.avg_confidence, \ + updated_at = NOW()", sf = tkg_sub("(tn.properties->>'start_frame')::bigint"), ef = tkg_sub("(tn.properties->>'end_frame')::bigint"), fc = tkg_sub("(tn.properties->>'frame_count')::int"), diff --git a/src/core/processor/tkg.rs b/src/core/processor/tkg.rs index f3479317..47481469 100644 --- a/src/core/processor/tkg.rs +++ b/src/core/processor/tkg.rs @@ -1204,6 +1204,12 @@ async fn build_face_track_nodes_from_qdrant( (0.0, 0.0, 0.0) }; + let avg_confidence = if agg.frame_count > 0 { + agg.sum_confidence / agg.frame_count as f64 + } else { + 0.0 + }; + let props = serde_json::json!({ "trace_id": tid, "frame_count": agg.frame_count, @@ -1221,6 +1227,7 @@ async fn build_face_track_nodes_from_qdrant( "avg_pitch": (avg_pitch * 1000.0).round() / 1000.0, "avg_roll": (avg_roll * 1000.0).round() / 1000.0, "pose_count": pose_count, + "avg_confidence": (avg_confidence * 1000.0).round() / 1000.0, "status": "pending", }); @@ -1250,12 +1257,6 @@ async fn build_face_track_nodes_from_qdrant( .flatten() .unwrap_or(30.0); - let avg_confidence = if agg.frame_count > 0 { - agg.sum_confidence / agg.frame_count as f64 - } else { - 0.0 - }; - let mut trace_profile = crate::core::file_profile::FaceTraceProfile::new( file_uuid, *tid,