fix: file/identities — replace NULL first/last_appearance with actual start_frame/end_frame + start_time/end_time + fps
This commit is contained in:
@@ -57,16 +57,15 @@ pub struct CandidateRecord {
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct FileIdentityRecord {
|
||||
pub id: i32,
|
||||
pub file_uuid: String,
|
||||
pub identity_id: i32,
|
||||
pub name: String,
|
||||
pub metadata: serde_json::Value,
|
||||
pub face_count: Option<i32>,
|
||||
pub speaker_count: Option<i32>,
|
||||
pub first_appearance: Option<f64>,
|
||||
pub last_appearance: Option<f64>,
|
||||
pub start_frame: Option<i32>,
|
||||
pub end_frame: Option<i32>,
|
||||
pub confidence: Option<f64>,
|
||||
pub fps: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
|
||||
@@ -2402,22 +2401,29 @@ impl PostgresDb {
|
||||
limit: i32,
|
||||
offset: i64,
|
||||
) -> Result<Vec<FileIdentityRecord>> {
|
||||
let query = r#"
|
||||
SELECT 0 as id, fd.file_uuid, fd.identity_id::int4, i.name, i.metadata,
|
||||
let table = schema::table_name("face_detections");
|
||||
let ident_table = schema::table_name("identities");
|
||||
let videos_table = schema::table_name("videos");
|
||||
let query = format!(
|
||||
r#"
|
||||
SELECT fd.identity_id::int4, i.name, i.metadata,
|
||||
COUNT(*)::int4 as face_count,
|
||||
0::int4 as speaker_count,
|
||||
NULL::float8 as first_appearance,
|
||||
NULL::float8 as last_appearance,
|
||||
AVG(fd.confidence)::float8 as confidence
|
||||
FROM face_detections fd
|
||||
JOIN identities i ON fd.identity_id = i.id
|
||||
MIN(fd.frame_number) as start_frame,
|
||||
MAX(fd.frame_number) as end_frame,
|
||||
AVG(fd.confidence)::float8 as confidence,
|
||||
(SELECT COALESCE(fps, 24.0) FROM {} WHERE file_uuid = $1)::float8 as fps
|
||||
FROM {} fd
|
||||
JOIN {} i ON fd.identity_id = i.id
|
||||
WHERE fd.file_uuid = $1 AND fd.identity_id IS NOT NULL
|
||||
GROUP BY fd.file_uuid, fd.identity_id, i.name, i.metadata
|
||||
GROUP BY fd.identity_id, i.name, i.metadata
|
||||
ORDER BY confidence DESC
|
||||
LIMIT $2 OFFSET $3
|
||||
"#;
|
||||
"#,
|
||||
videos_table, table, ident_table
|
||||
);
|
||||
|
||||
let rows = sqlx::query_as(query)
|
||||
let rows = sqlx::query_as(&query)
|
||||
.bind(file_uuid)
|
||||
.bind(limit)
|
||||
.bind(offset)
|
||||
|
||||
Reference in New Issue
Block a user