diff options
author | ClementTsang <clementjhtsang@gmail.com> | 2020-01-28 22:06:06 -0500 |
---|---|---|
committer | ClementTsang <clementjhtsang@gmail.com> | 2020-01-28 22:06:06 -0500 |
commit | 3d4de7867ce30a68b866ca8b0c37f64f673129d8 (patch) | |
tree | 3385951f30b47df653188639954be6ce1ed1b070 /src | |
parent | abe8a4bb861988daf67e37803b05d94507eddbda (diff) |
Added cleaning function.
Diffstat (limited to 'src')
-rw-r--r-- | src/app/data_farmer.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/app/data_farmer.rs b/src/app/data_farmer.rs index 0acb7343..44d69f62 100644 --- a/src/app/data_farmer.rs +++ b/src/app/data_farmer.rs @@ -77,8 +77,19 @@ impl Default for DataCollection { } impl DataCollection { - pub fn clean_data(&mut self) { - // TODO: [OPT] To implement to clean + pub fn clean_data(&mut self, max_time_millis: u128) { + let current_time = Instant::now(); + + let mut remove_index = 0; + for entry in &self.timed_data_vec { + if current_time.duration_since(entry.0).as_millis() > max_time_millis { + remove_index += 1; + } else { + break; + } + } + + self.timed_data_vec.drain(0..remove_index); } pub fn eat_data(&mut self, harvested_data: &Data) { |