From efa17d4b62083eeb348dc6d1b9a673e2497a888c Mon Sep 17 00:00:00 2001 From: Accusys Date: Sun, 16 Aug 2026 23:41:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20preserve=20integers=20in=20trace=5Fprofi?= =?UTF-8?q?le.json=20=E2=80=94=20no=20more=20.0=20suffix=20on=20trace=5Fid?= =?UTF-8?q?/frame/bbox?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/file_profile.rs | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/core/file_profile.rs b/src/core/file_profile.rs index ef430100..e3c4c322 100644 --- a/src/core/file_profile.rs +++ b/src/core/file_profile.rs @@ -401,12 +401,16 @@ pub struct FaceTraceProfile { pub status: String, // pending / bound / merged } -/// Recursively round all float numbers in a JSON value to 2 decimal places. +/// Recursively round float numbers in a JSON value to 2 decimal places. +/// Integer numbers are preserved as-is (no `.0` suffix). /// Used for trace_profile.json output only; in-memory values are preserved. pub(crate) fn round_json_value(v: &serde_json::Value) -> serde_json::Value { match v { serde_json::Value::Number(n) => { - if let Some(f) = n.as_f64() { + if n.is_i64() || n.is_u64() { + // Whole numbers keep their integer representation (no `.0`). + v.clone() + } else if let Some(f) = n.as_f64() { let rounded = (f * 100.0).round() / 100.0; serde_json::Value::from(rounded) } else { @@ -628,6 +632,33 @@ mod tests { assert_eq!(path, PathBuf::from("/output/abc123.profile.json")); } + #[test] + fn test_round_json_value_preserves_integers() { + let v = serde_json::json!({ + "trace_id": 4560, + "frame_count": 21, + "start_frame": 150221, + "avg_confidence": 0.781234, + "best_confidence": 0.81, + "bbox": {"x": 336, "y": 71, "width": 113, "height": 113} + }); + let rounded = round_json_value(&v); + // Integers stay integers (no `.0` suffix) + assert_eq!(rounded["trace_id"], serde_json::json!(4560)); + assert!(rounded["trace_id"].is_i64()); + assert_eq!(rounded["frame_count"], serde_json::json!(21)); + assert!(rounded["frame_count"].is_i64()); + assert_eq!(rounded["start_frame"], serde_json::json!(150221)); + assert!(rounded["start_frame"].is_i64()); + assert_eq!(rounded["bbox"]["x"], serde_json::json!(336)); + assert!(rounded["bbox"]["x"].is_i64()); + // Floats rounded to 2 decimals + assert_eq!(rounded["avg_confidence"], serde_json::json!(0.78)); + assert!(rounded["avg_confidence"].is_f64()); + assert_eq!(rounded["best_confidence"], serde_json::json!(0.81)); + assert!(rounded["best_confidence"].is_f64()); + } + #[test] fn test_from_registration() { let profile = FileProfile::from_registration(