63fbbe1225
Major Changes: - Pipeline Queue integration completed (internal.file + pipeline.commands) - Fixed old job_worker database compatibility with new command_queue table - Compiled Swift OCR binary (was missing, causing empty OCR results) - Added deep scan functionality through re-scan API Fixes: - Changed CommandJob.id from i32 to i64 for database compatibility - Added UUID generation in create_command (message_id field) - Fixed claim_pending_commands to query queue_name = 'internal.file' - Fixed field mappings: command_id → message_id, job_type → command_type - Added support for 'processing' status in CommandJobStatus Queue System: - internal.file queue: for register/unregister/re-scan commands (job_worker) - pipeline.commands queue: for vectorize/store_asrx/etc commands (pipeline_worker) Documentation: - Added comprehensive queue system documentation - Created M4 workspace status reports - Updated AGENTS.md with queue system details
202 lines
5.9 KiB
Rust
202 lines
5.9 KiB
Rust
use momentry_core::core::processor::face::FaceResult;
|
|
use momentry_core::core::processor::face_tracker::track_faces;
|
|
|
|
#[test]
|
|
fn test_track_faces_with_real_data() {
|
|
// 測試數據
|
|
let face_json = r#"{
|
|
"status": "has_faces",
|
|
"frame_count": 3,
|
|
"fps": 30.0,
|
|
"total_faces": 3,
|
|
"frames": [
|
|
{
|
|
"frame": 0,
|
|
"timestamp": 0.0,
|
|
"faces": [
|
|
{
|
|
"x": 100,
|
|
"y": 100,
|
|
"width": 50,
|
|
"height": 60,
|
|
"confidence": 0.9,
|
|
"embedding": [0.1, 0.2, 0.3],
|
|
"trace_id": null
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"frame": 1,
|
|
"timestamp": 0.033,
|
|
"faces": [
|
|
{
|
|
"x": 102,
|
|
"y": 101,
|
|
"width": 51,
|
|
"height": 61,
|
|
"confidence": 0.88,
|
|
"embedding": [0.11, 0.21, 0.31],
|
|
"trace_id": null
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"frame": 2,
|
|
"timestamp": 0.066,
|
|
"faces": [
|
|
{
|
|
"x": 105,
|
|
"y": 102,
|
|
"width": 52,
|
|
"height": 62,
|
|
"confidence": 0.87,
|
|
"embedding": [0.12, 0.22, 0.32],
|
|
"trace_id": null
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}"#;
|
|
|
|
// 解析
|
|
let mut face_result: FaceResult =
|
|
serde_json::from_str(face_json).expect("Failed to parse test data");
|
|
|
|
println!("測試數據:");
|
|
println!(" Frames: {}", face_result.frames.len());
|
|
println!(
|
|
" Total faces: {}",
|
|
face_result
|
|
.frames
|
|
.iter()
|
|
.map(|f| f.faces.len())
|
|
.sum::<usize>()
|
|
);
|
|
|
|
// 執行追蹤
|
|
track_faces(&mut face_result, 0.3, 0.7, 100.0, true, None).expect("Failed to track faces");
|
|
|
|
println!("\n追蹤完成");
|
|
|
|
// 驗證 trace_id
|
|
let mut trace_ids = Vec::new();
|
|
for frame in &face_result.frames {
|
|
for face in &frame.faces {
|
|
if let Some(trace_id) = face.trace_id {
|
|
trace_ids.push(trace_id);
|
|
println!(" Frame {} face: trace_id = {}", frame.frame, trace_id);
|
|
} else {
|
|
panic!("Face without trace_id!");
|
|
}
|
|
}
|
|
}
|
|
|
|
// 所有 faces 應該有相同的 trace_id(因為它們是同一個人)
|
|
assert_eq!(trace_ids.len(), 3);
|
|
assert!(trace_ids.iter().all(|&id| id == trace_ids[0]));
|
|
|
|
// 驗證 metadata
|
|
assert!(face_result.metadata.is_some());
|
|
let metadata = face_result.metadata.as_ref().unwrap();
|
|
assert!(metadata.get("traces").is_some());
|
|
|
|
println!("\n✅ 測試通過");
|
|
}
|
|
|
|
#[test]
|
|
fn test_track_multiple_faces() {
|
|
let face_json = r#"{
|
|
"status": "has_faces",
|
|
"frame_count": 2,
|
|
"fps": 30.0,
|
|
"total_faces": 4,
|
|
"frames": [
|
|
{
|
|
"frame": 0,
|
|
"timestamp": 0.0,
|
|
"faces": [
|
|
{
|
|
"x": 100,
|
|
"y": 100,
|
|
"width": 50,
|
|
"height": 60,
|
|
"confidence": 0.9,
|
|
"embedding": [0.1, 0.2, 0.3],
|
|
"trace_id": null
|
|
},
|
|
{
|
|
"x": 500,
|
|
"y": 100,
|
|
"width": 50,
|
|
"height": 60,
|
|
"confidence": 0.85,
|
|
"embedding": [0.9, 0.8, 0.7],
|
|
"trace_id": null
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"frame": 1,
|
|
"timestamp": 0.033,
|
|
"faces": [
|
|
{
|
|
"x": 102,
|
|
"y": 101,
|
|
"width": 51,
|
|
"height": 61,
|
|
"confidence": 0.88,
|
|
"embedding": [0.11, 0.21, 0.31],
|
|
"trace_id": null
|
|
},
|
|
{
|
|
"x": 502,
|
|
"y": 101,
|
|
"width": 51,
|
|
"height": 61,
|
|
"confidence": 0.84,
|
|
"embedding": [0.91, 0.81, 0.71],
|
|
"trace_id": null
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}"#;
|
|
|
|
let mut face_result: FaceResult =
|
|
serde_json::from_str(face_json).expect("Failed to parse test data");
|
|
|
|
track_faces(&mut face_result, 0.3, 0.7, 100.0, true, None).expect("Failed to track faces");
|
|
|
|
// 應該有兩個不同的 trace_id
|
|
let mut trace_ids = std::collections::HashSet::new();
|
|
for frame in &face_result.frames {
|
|
for face in &frame.faces {
|
|
if let Some(trace_id) = face.trace_id {
|
|
trace_ids.insert(trace_id);
|
|
}
|
|
}
|
|
}
|
|
|
|
assert_eq!(trace_ids.len(), 2);
|
|
println!("✅ 多人追蹤測試通過: {} 個 traces", trace_ids.len());
|
|
}
|
|
|
|
#[test]
|
|
fn test_track_no_faces() {
|
|
let face_json = r#"{
|
|
"status": "no_faces",
|
|
"frame_count": 10,
|
|
"fps": 30.0,
|
|
"total_faces": 0,
|
|
"frames": []
|
|
}"#;
|
|
|
|
let mut face_result: FaceResult =
|
|
serde_json::from_str(face_json).expect("Failed to parse test data");
|
|
|
|
track_faces(&mut face_result, 0.3, 0.7, 100.0, true, None).expect("Failed to track faces");
|
|
|
|
// 不應該崩潰
|
|
println!("✅ 無人臉測試通過");
|
|
}
|