feat: round output JSON floats to 2dp + unify ensure_ascii for asr/asrx

This commit is contained in:
Accusys
2026-08-16 06:38:39 +08:00
parent 39e9ce4c3b
commit 5e6a7b7d51
18 changed files with 249 additions and 45 deletions
+20 -5
View File
@@ -10,6 +10,7 @@ const CUT_TIMEOUT: Duration = Duration::from_secs(3600);
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct CutResult {
pub frame_count: u64,
#[serde(serialize_with = "round_two")]
pub fps: f64,
pub scenes: Vec<CutScene>,
}
@@ -19,10 +20,21 @@ pub struct CutScene {
pub scene_number: u32,
pub start_frame: u64,
pub end_frame: u64,
#[serde(serialize_with = "round_two")]
pub start_time: f64,
#[serde(serialize_with = "round_two")]
pub end_time: f64,
}
/// Serialize an f64 rounded to 2 decimal places (JSON output only).
/// In-memory values are preserved; only the serialized form is rounded.
fn round_two<S>(v: &f64, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_f64((v * 100.0).round() / 100.0)
}
pub async fn process_cut(
video_path: &str,
output_path: &str,
@@ -157,8 +169,11 @@ fn try_native_cut(video_path: &str) -> Result<CutResult> {
// Step 3: Build scenes from cut points
let mut scenes: Vec<CutScene> = Vec::new();
let round_time = |t: f64| (t * 1000.0).round() / 1000.0;
let mut prev_time = 0.0;
let mut prev_frame: u64 = 0;
let round_time = |t: f64| (t * 1000.0).round() / 1000.0;
for (i, &cut_time) in scene_times.iter().enumerate() {
let end_frame = (cut_time * fps).round() as u64;
@@ -169,8 +184,8 @@ fn try_native_cut(video_path: &str) -> Result<CutResult> {
scene_number: (i + 1) as u32,
start_frame: prev_frame,
end_frame: end_frame.saturating_sub(1),
start_time: prev_time,
end_time: cut_time - (1.0 / fps),
start_time: round_time(prev_time),
end_time: round_time(cut_time - (1.0 / fps)),
});
}
@@ -184,8 +199,8 @@ fn try_native_cut(video_path: &str) -> Result<CutResult> {
scene_number: (scenes.len() + 1) as u32,
start_frame: prev_frame,
end_frame: total_frames.saturating_sub(1),
start_time: prev_time,
end_time: duration,
start_time: round_time(prev_time),
end_time: round_time(duration),
});
}
@@ -196,7 +211,7 @@ fn try_native_cut(video_path: &str) -> Result<CutResult> {
start_frame: 0,
end_frame: total_frames.saturating_sub(1),
start_time: 0.0,
end_time: duration,
end_time: round_time(duration),
});
}
+5 -1
View File
@@ -1564,7 +1564,11 @@ async fn build_face_track_nodes_from_qdrant(
if kface_path.exists() {
trace_profile.key_face = Some("key_face.jpg".to_string());
}
if let Ok(json) = serde_json::to_string_pretty(&trace_profile) {
if let Ok(json) = serde_json::to_string_pretty(
&crate::core::file_profile::round_json_value(
&serde_json::to_value(&trace_profile).unwrap_or_default(),
),
) {
let _ = std::fs::write(&tp_path, json);
if tp_path.exists() {
tracing::info!("[TKG-VERIFY] trace {}: trace_profile.json rewritten", tid);