Skip to content

Commit

Permalink
Merge pull request #121 from instaclustr/issue-108
Browse files Browse the repository at this point in the history
issue-108, unnecessary comments and code were removed
  • Loading branch information
cjrolo authored Nov 12, 2024
2 parents 95ad313 + da6d7a8 commit 87dcb2c
Show file tree
Hide file tree
Showing 38 changed files with 20 additions and 4,006 deletions.
987 changes: 8 additions & 979 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
[workspace]
members = [
"brro-compressor",
"optimizer",
"prometheus-remote",
"tools",
"wavbrro",
"vsri",
Expand Down
141 changes: 0 additions & 141 deletions brro-compressor/src/compare.rs

This file was deleted.

9 changes: 0 additions & 9 deletions brro-compressor/src/compressor/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ impl Decode for Constant {
) -> Result<Self, ::bincode::error::DecodeError> {
let id = Decode::decode(decoder)?;
let bitdepth = Decode::decode(decoder)?;
// Here is where the pig twists the tail
let constant: f64 = match bitdepth {
Bitdepth::U8 => {
debug!("Decoding as u8");
Expand Down Expand Up @@ -112,11 +111,6 @@ impl Constant {
}
}

/// This compressor is about having a single constant for the whole segment
pub fn set_constant(&mut self, constant_value: f64) {
self.constant = constant_value;
}

/// Receives a data stream and generates a Constant
pub fn decompress(data: &[u8]) -> Self {
let config = BinConfig::get();
Expand All @@ -126,7 +120,6 @@ impl Constant {

/// This function transforms the structure into a Binary stream
pub fn to_bytes(&self) -> Vec<u8> {
// Use Bincode and flate2-rs? Do this at the Stream Level?
let config = BinConfig::get();
bincode::encode_to_vec(self, config).unwrap()
}
Expand All @@ -141,9 +134,7 @@ impl Constant {

pub fn constant_compressor(data: &[f64], stats: DataStats) -> CompressorResult {
debug!("Initializing Constant Compressor. Error and Stats provided");
// Initialize the compressor
let c = Constant::new(data.len(), stats.min, stats.bitdepth);
// Convert to bytes
CompressorResult::new(c.to_bytes(), 0.0)
}

Expand Down
33 changes: 1 addition & 32 deletions brro-compressor/src/compressor/fft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,6 @@ pub struct FrequencyPoint {
}

impl FrequencyPoint {
pub fn new(real: f32, img: f32) -> Self {
FrequencyPoint {
pos: 0,
freq_real: real,
freq_img: img,
}
}

pub fn with_position(real: f32, img: f32, pos: u16) -> Self {
FrequencyPoint {
pos,
freq_real: real,
freq_img: img,
}
}

pub fn from_complex(complex: Complex<f32>) -> Self {
FrequencyPoint {
pos: 0,
freq_real: complex.re,
freq_img: complex.im,
}
}

pub fn from_complex_with_position(complex: Complex<f32>, pos: u16) -> Self {
FrequencyPoint {
pos,
Expand Down Expand Up @@ -132,15 +108,10 @@ impl Ord for FrequencyPoint {
/// FFT Compressor. Applies FFT to a signal, picks the N best frequencies, discards the rest. Always LOSSY
#[derive(PartialEq, Debug)]
pub struct FFT {
/// Compressor ID
pub id: u8,
/// Stored frequencies
pub frequencies: Vec<FrequencyPoint>,
/// The maximum numeric value of the points in the frame
pub max_value: f32,
/// The minimum numeric value of the points in the frame
pub min_value: f32,
/// Compression error
pub error: Option<f64>,
}

Expand Down Expand Up @@ -391,7 +362,7 @@ impl FFT {
}

/// Compresses data via FFT
/// The set of frequencies to store is 1/100 of the data lenght OR 3, which is bigger.
/// The set of frequencies to store is 1/100 of the data length OR 3, which is bigger.
pub fn compress(&mut self, data: &[f64]) {
if self.max_value == self.min_value {
debug!("Same max and min, we're done here!");
Expand All @@ -415,8 +386,6 @@ impl FFT {
buffer.truncate(size);
self.frequencies = FFT::fft_trim(&mut buffer, max_freq);
}

/// Decompresses data
pub fn decompress(data: &[u8]) -> Self {
let config = BinConfig::get();
let (fft, _) = bincode::decode_from_slice(data, config).unwrap();
Expand Down
6 changes: 1 addition & 5 deletions brro-compressor/src/compressor/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,14 @@ impl Noop {
data: Vec::with_capacity(sample_count),
}
}
///Optimize
pub fn optimize(data: &[f64]) -> Vec<i64> {
let mut out_vec = Vec::with_capacity(data.len());
for &element in data {
// Round the floating-point number before casting to i64
out_vec.push(element.round() as i64);
}
out_vec
}

/// "Compress"
pub fn compress(&mut self, data: &[f64]) {
self.data = Noop::optimize(data);
debug!(
Expand All @@ -67,7 +64,6 @@ impl Noop {
bincode::encode_to_vec(self, config).unwrap()
}

/// Returns an array of data
pub fn to_data(&self, _frame_size: usize) -> Vec<i64> {
self.data.clone()
}
Expand Down Expand Up @@ -118,7 +114,7 @@ mod tests {
fn test_optimize() {
// Test case with floating-point numbers that have fractional parts
let input_data = [1.5, 2.7, 3.3, 4.9];
let expected_output = [2, 3, 3, 5]; // Rounded to the nearest integer
let expected_output = [2, 3, 3, 5];

let result = Noop::optimize(&input_data);
assert_eq!(result, expected_output);
Expand Down
Loading

0 comments on commit 87dcb2c

Please sign in to comment.