Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update valueslopesplitwriter.rs #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion writer-common/src/valueslopesplitwriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub struct ValueSlopeSplitWriter {
pub previous_value: i64,
pub previous_slope: i64,
pub min_offset: i32,
pub phase: bool,
pub previous_value_cache: i64,
pub writer: Box<dyn FrameWriter>,
progress_bar: indicatif::ProgressBar,
}
Expand All @@ -21,6 +23,8 @@ impl ValueSlopeSplitWriter {
previous_value: 0,
previous_slope: 0,
min_offset: 0,
phase: false,
previous_value_cache: 0,
progress_bar,
writer,
}
Expand All @@ -37,12 +41,28 @@ impl ValueSlopeSplitWriter {
previous_value: 0,
previous_slope: 0,
min_offset,
phase: false,
previous_value_cache: 0,
progress_bar,
writer,
}
}

pub fn write_row(&mut self, row: VeloPoint, slope_value: i64) {
let diff = slope_value - self.previous_value;
if diff < 0 && diff > -5000 {
self.phase = !self.phase;
if !self.phase {
self.previous_value_cache = self.previous_value;
}
else {
self.previous_value = self.previous_value_cache;
}
}
if !self.phase {
self.previous_value = slope_value;
return;
}
let is_new_frame = self.is_new_frame(slope_value);
if is_new_frame {
self.writer.split_frame();
Expand All @@ -68,7 +88,7 @@ impl ValueSlopeSplitWriter {
return false;
}
let is_slope_same_direction = new_slope.signum() == self.previous_slope.signum();
if is_slope_same_direction {
if is_slope_same_direction || new_slope.abs() < 2000 {
return false;
} else {
self.previous_slope = 0;
Expand Down