fix: remove trace_chunks from API + fix OCR frame calculation
- Removed trace_chunks field from PostgresStats struct - Removed trace_chunks query from get_file_stats and get_ingestion_status - Fixed OCR fetch_ocr_texts to compute frames from start_time*FPS - Updated scan.rs to use separate count_nodes/count_edges functions
This commit is contained in:
@@ -14,7 +14,7 @@ pub async fn execute_rule1(db: &PostgresDb, file_uuid: &str, fps: f64) -> Result
|
||||
let pre_chunks_table = schema::table_name("pre_chunks");
|
||||
|
||||
let asr_segments = fetch_asr_segments(pool, file_uuid, &pre_chunks_table, fps).await?;
|
||||
let ocr_map = fetch_ocr_texts(pool, file_uuid, &pre_chunks_table).await?;
|
||||
let ocr_map = fetch_ocr_texts(pool, file_uuid, &pre_chunks_table, fps).await?;
|
||||
|
||||
let video = db
|
||||
.get_video_by_uuid(file_uuid)
|
||||
@@ -161,14 +161,15 @@ async fn fetch_ocr_texts(
|
||||
pool: &PgPool,
|
||||
file_uuid: &str,
|
||||
table: &str,
|
||||
fps: f64,
|
||||
) -> Result<BTreeMap<i64, Vec<String>>> {
|
||||
let query = format!(
|
||||
r#"
|
||||
SELECT
|
||||
coordinate_index as frame, data
|
||||
start_frame, start_time, end_time, data
|
||||
FROM {}
|
||||
WHERE file_uuid = $1 AND processor_type = 'ocr'
|
||||
ORDER BY coordinate_index
|
||||
ORDER BY start_frame
|
||||
"#,
|
||||
table
|
||||
);
|
||||
@@ -177,9 +178,16 @@ async fn fetch_ocr_texts(
|
||||
|
||||
let mut map: BTreeMap<i64, Vec<String>> = BTreeMap::new();
|
||||
for row in rows {
|
||||
let frame: i64 = row.try_get("frame").unwrap_or(0);
|
||||
let start_time: f64 = row.try_get("start_time").unwrap_or(0.0);
|
||||
let end_time_raw: Option<f64> = row.try_get("end_time").ok();
|
||||
let data: Value = row.try_get("data").unwrap_or(Value::Null);
|
||||
|
||||
let start_frame = (start_time * fps) as i64;
|
||||
let end_frame = end_time_raw
|
||||
.filter(|t| *t > 0.0)
|
||||
.map(|t| (t * fps) as i64)
|
||||
.unwrap_or(start_frame + 1);
|
||||
|
||||
let texts: Vec<String> = data
|
||||
.get("texts")
|
||||
.and_then(|t| t.as_array())
|
||||
@@ -201,7 +209,16 @@ async fn fetch_ocr_texts(
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
map.insert(frame, texts);
|
||||
// Store texts for each frame in the range
|
||||
for frame in start_frame..=end_frame {
|
||||
map.entry(frame).or_default().extend(texts.clone());
|
||||
}
|
||||
}
|
||||
|
||||
// Deduplicate texts per frame
|
||||
for (_frame, texts) in map.iter_mut() {
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
texts.retain(|t| seen.insert(t.clone()));
|
||||
}
|
||||
|
||||
Ok(map)
|
||||
|
||||
Reference in New Issue
Block a user