From 6d824067de272f865206a63bc9173c407cecaef6 Mon Sep 17 00:00:00 2001 From: Harry Hogg Date: Wed, 11 Sep 2024 18:57:54 +0100 Subject: [PATCH] Added buildTimeMs to tilings --- .../tilings/src-rust/tiling/src/build/context.rs | 5 ++++- .../tilings/src-rust/tiling/src/build/result.rs | 11 +++++++++-- workspaces/tilings/src-rust/tiling/src/tiling.rs | 8 +++++++- workspaces/tilings/src/types.ts | 1 + 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/workspaces/tilings/src-rust/tiling/src/build/context.rs b/workspaces/tilings/src-rust/tiling/src/build/context.rs index a5740a1d..12b2824e 100644 --- a/workspaces/tilings/src-rust/tiling/src/build/context.rs +++ b/workspaces/tilings/src-rust/tiling/src/build/context.rs @@ -1,3 +1,4 @@ +use chrono::TimeDelta; use serde::Serialize; use typeshare::typeshare; @@ -20,6 +21,7 @@ impl Context { notation: &Notation, plane: &Plane, result: &Result<(), TilingError>, + duration: TimeDelta, ) { self.count_total_tilings += 1; @@ -35,7 +37,8 @@ impl Context { super::Result::default() .with_notation(notation.to_string()) .with_hash(plane.classifier.get_unique_key()) - .with_transform_index(notation.transforms.index), + .with_transform_index(notation.transforms.index) + .with_build_time_ms(duration.num_milliseconds() as i32), ); } _ => {} diff --git a/workspaces/tilings/src-rust/tiling/src/build/result.rs b/workspaces/tilings/src-rust/tiling/src/build/result.rs index 3aaaf825..8702d9ac 100644 --- a/workspaces/tilings/src-rust/tiling/src/build/result.rs +++ b/workspaces/tilings/src-rust/tiling/src/build/result.rs @@ -12,11 +12,12 @@ pub struct Result { pub uniform: i32, #[typeshare(serialized_as = "string")] pub timestamp: NaiveDateTime, + pub build_time_ms: i32, } impl Result { - pub fn with_notation(mut self, notation: String) -> Self { - self.notation = notation.clone(); + pub fn with_build_time_ms(mut self, build_time_ms: i32) -> Self { + self.build_time_ms = build_time_ms; self } @@ -25,6 +26,11 @@ impl Result { self } + pub fn with_notation(mut self, notation: String) -> Self { + self.notation = notation.clone(); + self + } + pub fn with_transform_index(mut self, transform_index: i32) -> Self { self.transform_index = transform_index; self @@ -39,6 +45,7 @@ impl Default for Result { transform_index: 0, uniform: 0, timestamp: Utc::now().naive_utc(), + build_time_ms: 0, } } } diff --git a/workspaces/tilings/src-rust/tiling/src/tiling.rs b/workspaces/tilings/src-rust/tiling/src/tiling.rs index 2e50c02b..c9078f32 100644 --- a/workspaces/tilings/src-rust/tiling/src/tiling.rs +++ b/workspaces/tilings/src-rust/tiling/src/tiling.rs @@ -2,6 +2,7 @@ #[cfg(test)] mod tests; +use chrono::{TimeDelta, Utc}; use serde::Serialize; use serde_with::{serde_as, DisplayFromStr}; use typeshare::typeshare; @@ -145,13 +146,18 @@ impl Tiling { } pub fn build(&mut self) -> Result<(), TilingError> { + let start = Utc::now(); + let build_result = self .plane .build(&self.notation, self.option_expansion_phases); + let end = Utc::now(); + let duration: TimeDelta = end - start; + self .build_context - .add_result(&self.notation, &self.plane, &build_result); + .add_result(&self.notation, &self.plane, &build_result, duration); build_result } diff --git a/workspaces/tilings/src/types.ts b/workspaces/tilings/src/types.ts index 5d79706b..2b493749 100644 --- a/workspaces/tilings/src/types.ts +++ b/workspaces/tilings/src/types.ts @@ -205,6 +205,7 @@ export interface Result { transformIndex: number; uniform: number; timestamp: string; + buildTimeMs: number; } export interface Context {