From 1f5bdb26f6bd9c8a19bc841b6e830c723129844a Mon Sep 17 00:00:00 2001 From: orangels Date: Sun, 10 May 2026 12:00:05 +0800 Subject: [PATCH] feat: group reports by local date --- src/report.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/report.rs b/src/report.rs index 33a2eba..c9c2348 100644 --- a/src/report.rs +++ b/src/report.rs @@ -1,6 +1,6 @@ use crate::metrics::ErrorCount; use anyhow::{Context, Result}; -use chrono::{DateTime, Utc}; +use chrono::{DateTime, Local, Utc}; use serde::Serialize; use serde_json::Value; use std::path::{Path, PathBuf}; @@ -234,14 +234,17 @@ fn write_report( started_at: DateTime, report: &T, ) -> Result { - let reports_dir = root.join("reports"); + let local_started_at = started_at.with_timezone(&Local); + let reports_dir = root + .join("reports") + .join(local_started_at.format("%Y%m%d").to_string()); std::fs::create_dir_all(&reports_dir).with_context(|| { format!( "failed to create reports directory {}", reports_dir.display() ) })?; - let timestamp = started_at.format("%Y%m%dT%H%M%SZ"); + let timestamp = local_started_at.format("%Y%m%dT%H%M%S%z"); let filename = format!( "{}-{}-{}-{timestamp}.json", sanitize_filename_component(benchmark), @@ -296,6 +299,7 @@ mod tests { #[test] fn writes_benchmark_report_under_reports_dir() { let temp_dir = tempfile::tempdir().expect("create temp dir"); + let started_at = Utc.with_ymd_and_hms(2026, 5, 6, 1, 2, 3).unwrap(); let report = BenchmarkReport { benchmark: "aime2026".to_string(), provider: "openai".to_string(), @@ -318,7 +322,7 @@ mod tests { local_path: "data/benchmarks/aime2026/aime2026.jsonl".to_string(), }, run: RunReport { - started_at: Utc.with_ymd_and_hms(2026, 5, 6, 1, 2, 3).unwrap(), + started_at, duration_ms: 123, concurrency: 2, limit: Some(1), @@ -351,7 +355,12 @@ mod tests { let path = write_benchmark_report(temp_dir.path(), &report).expect("write report"); - assert!(path.ends_with("reports/aime2026-openai-gpt-test-20260506T010203Z.json")); + let local_started_at = started_at.with_timezone(&chrono::Local); + let expected_date = local_started_at.format("%Y%m%d").to_string(); + let expected_timestamp = local_started_at.format("%Y%m%dT%H%M%S%z").to_string(); + assert!(path.ends_with(format!( + "reports/{expected_date}/aime2026-openai-gpt-test-{expected_timestamp}.json" + ))); assert!(path.exists()); }