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.
This commit is contained in:
Accusys
2026-08-07 14:04:54 +08:00
parent 64f5e3f543
commit cd8df324be
2 changed files with 15 additions and 7 deletions
+8 -1
View File
@@ -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"),
+7 -6
View File
@@ -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,