fix: Face processor now saves status and total_faces to face.json

This commit is contained in:
Accusys
2026-09-26 23:06:11 +08:00
parent 8a736a4103
commit 357e585399
99 changed files with 13881 additions and 1065 deletions
+113 -20
View File
@@ -18,6 +18,10 @@ struct FileStatsResponse {
file_uuid: String,
file_name: Option<String>,
status: Option<String>,
// Timestamps
created_at: Option<String>,
updated_at: Option<String>,
processing_completed_at: Option<String>,
// Processor status
processors: Vec<ProcessorStatus>,
// PostgreSQL counts
@@ -30,6 +34,8 @@ struct FileStatsResponse {
face_dedup: FaceDedupStats,
// VLM Summary progress
vlm_summary: VlmSummaryStats,
// Scene VLM stats
scene_vlm: SceneVlmStats,
// On-disk face artifact counts (vs expected)
face_artifacts: FaceArtifactsCounts,
}
@@ -95,6 +101,14 @@ struct VlmSummaryStats {
done: i64,
}
#[derive(Debug, Serialize, Default)]
struct SceneVlmStats {
total_scenes: i64,
status: String,
vlm_done: i64,
vlm_total: i64,
}
#[derive(Debug, Serialize, Deserialize)]
struct ScannedFileInfo {
file_name: String,
@@ -106,6 +120,7 @@ struct ScannedFileInfo {
file_uuid: Option<String>,
status: Option<String>,
registration_time: Option<String>,
status_updated_at: Option<String>,
job_id: Option<i32>,
}
@@ -140,7 +155,7 @@ fn scan_directory_recursive(
allowed_extensions: &[&str],
registered_paths: &std::collections::HashMap<
String,
(String, String, Option<String>, Option<i32>),
(String, String, Option<String>, Option<String>, Option<i32>),
>,
files: &mut Vec<ScannedFileInfo>,
) {
@@ -181,7 +196,9 @@ fn scan_directory_recursive(
.unwrap_or_default();
match registered_paths.get(&abs_path) {
Some((uuid, status, reg_time, jid)) if status != "unregistered" => {
Some((uuid, status, reg_time, updated_at, jid))
if status != "unregistered" =>
{
files.push(ScannedFileInfo {
file_name,
relative_path: rel_path,
@@ -192,6 +209,7 @@ fn scan_directory_recursive(
file_uuid: Some(uuid.clone()),
status: Some(status.clone()),
registration_time: reg_time.clone(),
status_updated_at: updated_at.clone(),
job_id: *jid,
});
}
@@ -206,6 +224,7 @@ fn scan_directory_recursive(
file_uuid: None,
status: Some("unregistered".to_string()),
registration_time: None,
status_updated_at: None,
job_id: None,
});
}
@@ -232,27 +251,37 @@ async fn scan_files(
let table = schema::table_name("videos");
let mj_table = schema::table_name("monitor_jobs");
let registered_db: Vec<(String, String, String, String, Option<String>, Option<i32>)> =
sqlx::query_as(&format!(
"SELECT v.file_path, v.file_name, v.file_uuid, v.status, v.registration_time::text, \
let registered_db: Vec<(
String,
String,
String,
String,
Option<String>,
Option<String>,
Option<i32>,
)> = sqlx::query_as(&format!(
"SELECT v.file_path, v.file_name, v.file_uuid, v.status, v.registration_time::text, \
v.updated_at::text, \
latest_job.id as job_id \
FROM {} v \
LEFT JOIN LATERAL ( \
SELECT id FROM {} WHERE uuid = v.file_uuid ORDER BY id DESC LIMIT 1 \
) latest_job ON true \
ORDER BY v.id",
table, mj_table
))
.fetch_all(state.db.pool())
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
table, mj_table
))
.fetch_all(state.db.pool())
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
let registered_paths: std::collections::HashMap<
String,
(String, String, Option<String>, Option<i32>),
(String, String, Option<String>, Option<String>, Option<i32>),
> = registered_db
.into_iter()
.map(|(path, _name, uuid, status, reg_time, jid)| (path, (uuid, status, reg_time, jid)))
.map(|(path, _name, uuid, status, reg_time, updated_at, jid)| {
(path, (uuid, status, reg_time, updated_at, jid))
})
.collect();
let mut result_files = Vec::new();
@@ -785,8 +814,8 @@ async fn get_file_stats(
// 1. Get file info from PostgreSQL
let videos_table = schema::table_name("videos");
let file_info: Option<(String, String, String)> = sqlx::query_as(&format!(
"SELECT file_uuid, file_name, status FROM {} WHERE file_uuid = $1",
let file_info: Option<(String, String, String, Option<String>, Option<String>)> = sqlx::query_as(&format!(
"SELECT file_uuid, file_name, status, created_at::text, updated_at::text FROM {} WHERE file_uuid = $1",
videos_table
))
.bind(&file_uuid)
@@ -794,9 +823,15 @@ async fn get_file_stats(
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
let (file_uuid_str, file_name, status) = file_info
.map(|(uuid, name, s)| (uuid, Some(name), Some(s)))
.unwrap_or_else(|| (file_uuid.clone(), None, None));
let (file_uuid_str, file_name, status, created_at, updated_at) =
file_info.unwrap_or_else(|| (file_uuid.clone(), String::new(), String::new(), None, None));
// Determine processing_completed_at based on status
let processing_completed_at = if status == "completed" {
updated_at.clone()
} else {
None
};
// 2. Get processor status from processing_status JSONB
let processing_status: serde_json::Value = sqlx::query_scalar(&format!(
@@ -1101,16 +1136,70 @@ async fn get_file_stats(
done: vlm_done,
};
// 9. Scene VLM stats
let scenes_path = format!("{}/{}.scenes.json", output_dir, file_uuid);
let scene_vlm = if std::path::Path::new(&scenes_path).exists() {
if let Ok(scenes_json) = std::fs::read_to_string(&scenes_path) {
if let Ok(scenes_data) = serde_json::from_str::<serde_json::Value>(&scenes_json) {
let total_scenes = scenes_data
.get("total_scenes")
.and_then(|v| v.as_i64())
.unwrap_or(0);
let status = scenes_data
.get("status")
.and_then(|v| v.as_str())
.unwrap_or("pending")
.to_string();
let scenes_array = scenes_data
.get("scenes")
.and_then(|v| v.as_array())
.map(|arr| arr.len() as i64)
.unwrap_or(0);
let vlm_done = scenes_data
.get("scenes")
.and_then(|v| v.as_array())
.map(|arr| {
arr.iter()
.filter(|s| {
let status = s.get("vlm_status").and_then(|v| v.as_str());
status == Some("completed") || status == Some("done")
})
.count() as i64
})
.unwrap_or(0);
SceneVlmStats {
total_scenes: total_scenes.max(scenes_array),
status,
vlm_done,
vlm_total: total_scenes.max(scenes_array),
}
} else {
SceneVlmStats::default()
}
} else {
SceneVlmStats::default()
}
} else {
SceneVlmStats::default()
};
Ok(Json(FileStatsResponse {
file_uuid: file_uuid_str,
file_name,
status,
file_name: Some(file_name).filter(|s| !s.is_empty()),
status: Some(status).filter(|s| !s.is_empty()),
created_at,
updated_at,
processing_completed_at,
processors,
postgres,
qdrant: qdrant_stats,
tkg,
face_dedup,
vlm_summary,
scene_vlm,
face_artifacts,
}))
}
@@ -1326,7 +1415,11 @@ async fn get_pipeline_progress_handler(
} else {
0.0
};
let status = if vlm_done == vlm_total { "completed" } else { "running" };
let status = if vlm_done == vlm_total {
"completed"
} else {
"running"
};
pp.update_stage(
"vlm_summary",
vlm_progress,