From 79fc2f4266ac76efabb89581029f598d9982d0f6 Mon Sep 17 00:00:00 2001 From: Sean Leishman Date: Tue, 15 Oct 2024 22:00:01 +0100 Subject: [PATCH] Initial commit --- lib/core/src/types.rs | 14 ++++++ .../src/preprocessing/accelerometer.rs | 49 +++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/lib/core/src/types.rs b/lib/core/src/types.rs index ea7e87c..d814b2b 100644 --- a/lib/core/src/types.rs +++ b/lib/core/src/types.rs @@ -14,6 +14,20 @@ impl DigitalSignal { } } +type AccelerometerData = Vec; +type RawAccelerometerData = Vec; + +struct RawAccelerationData { + x: i32, + y: i32, + z: i32, + timestamp: i32, + is_sensor_active: bool, +} + +static kNumAccelerators: i32 = 3; +static kNumAxis: i32 = 3; + #[cfg(test)] mod tests { use super::*; diff --git a/lib/localisation/src/preprocessing/accelerometer.rs b/lib/localisation/src/preprocessing/accelerometer.rs index 0ae040b..250589f 100644 --- a/lib/localisation/src/preprocessing/accelerometer.rs +++ b/lib/localisation/src/preprocessing/accelerometer.rs @@ -1 +1,50 @@ //test +pub core::types + +trait AcclerometerPreprocessor{ + num_reliable_accelerometers_: i32; + reliable_accelerometers_: Vec; + + fn processData(&self, data: core::types::AccelerometerData) -> core::types::AccelerometerData; + + fn(handleOutliers(&self, data: core::types::AccelerometerData) -> core::types::AccelerometerData; +} + +impl AcclerometerPreprocessor for core::types::AccelerometerData{ + fn processData(&self, data: core::types::AccelerometerData) -> core::types::AccelerometerData{ + // do some processing + let accelerometer_data: core::types::AccelerometerData; + + core::types::kNumAccelerometers.iter().for_each(|i| { + data[i] = data[i] * 2; + magnitude: f32 = 0.0; + core::type::kNumAxis.iter().for_each(|j| { + magnitude += data[i][j] * data[i][j]; + }); + accelerometer_data[i] = magnitude.sqrt(); + }); + + const clean_accelerometer_data: core::types::AccelerometerData = handleOutliers(accelerometer_data); + + return data; + } + + fn handleOutliers(&self, data: core::types::AccelerometerData) { + quartiles: Quartiles; + if (num_reliable_accelerometers_ == core::types::kNumAccelerometers) { + quartiles = getQuartiles(data); + } + else if (num_reliable_accelerometers_ == core::types::kNumAccelerometers - 1) { + let filtered_data = Box::new([0.0; core::types::kNumAccelerometers-1]); + core::type::kNumAccelerometers.iter().for_each(|i| { + if (reliable_accelerometers_.contains(i)) { + filtered_data.push(data[i]); + } + }); + quartiles = getQuartiles(data); + } + else { + num_reliable_accelerometers_++; + } + } +}