diff --git a/scripts/store_traced_faces.py b/scripts/store_traced_faces.py index b2ed165f..296f368f 100644 --- a/scripts/store_traced_faces.py +++ b/scripts/store_traced_faces.py @@ -285,15 +285,32 @@ def store_traced_faces(file_uuid: str, traced_json_path: str, schema: str = SCHE # Build trace_mapping for Qdrant update: {frame: {bbox_key: trace_id}} trace_mapping = {} - for frame_num_str, frame_data in sorted(frames.items(), key=lambda x: int(x[0])): - frame_num = int(frame_num_str) - trace_mapping[frame_num] = {} - for face in frame_data.get("faces", []): - trace_id = face.get("trace_id") - if trace_id is None: + + # Handle both list and dict formats + if isinstance(frames, list): + # New format: frames is a list of frame objects + for frame_data in frames: + frame_num = frame_data.get("frame") + if frame_num is None: continue - bbox_key = f"{face['x']}_{face['y']}_{face['width']}_{face['height']}" - trace_mapping[frame_num][bbox_key] = trace_id + trace_mapping[frame_num] = {} + for face in frame_data.get("faces", []): + trace_id = face.get("trace_id") + if trace_id is None: + continue + bbox_key = f"{face['x']}_{face['y']}_{face['width']}_{face['height']}" + trace_mapping[frame_num][bbox_key] = trace_id + else: + # Old format: frames is a dict with frame numbers as keys + for frame_num_str, frame_data in sorted(frames.items(), key=lambda x: int(x[0])): + frame_num = int(frame_num_str) + trace_mapping[frame_num] = {} + for face in frame_data.get("faces", []): + trace_id = face.get("trace_id") + if trace_id is None: + continue + bbox_key = f"{face['x']}_{face['y']}_{face['width']}_{face['height']}" + trace_mapping[frame_num][bbox_key] = trace_id # Update Qdrant _faces collection with trace_id. # return_trace_ids=True makes update_trace_ids also return the trace_id set seen @@ -310,12 +327,21 @@ def store_traced_faces(file_uuid: str, traced_json_path: str, schema: str = SCHE # Unique trace count from the update scroll (no extra full scan needed). qdrant_trace_count = len(trace_ids) - total_faces = sum( - 1 - for fd in frames.values() - for f in fd.get("faces", []) - if f.get("trace_id") is not None - ) + # Count total faces with trace_id + if isinstance(frames, list): + total_faces = sum( + 1 + for frame_data in frames + for f in frame_data.get("faces", []) + if f.get("trace_id") is not None + ) + else: + total_faces = sum( + 1 + for fd in frames.values() + for f in fd.get("faces", []) + if f.get("trace_id") is not None + ) print( f"[TRACE] Updated {qdrant_updated} Qdrant points with trace_id, {qdrant_trace_count} unique traces"