Skip to content

Commit

Permalink
Merge pull request #96 from instaclustr/maintenence
Browse files Browse the repository at this point in the history
Update rust + deps
  • Loading branch information
rukai authored Aug 2, 2024
2 parents 780ea7c + d7132a2 commit a29a36a
Show file tree
Hide file tree
Showing 16 changed files with 564 additions and 679 deletions.
1,099 changes: 521 additions & 578 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions brro-compressor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ description = "An Advanced Time-Series Compressor"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
env_logger = "0.10.0"
env_logger = "0.11.0"
log = "0.4.0"
clap = {version = "4.3.14", features = ["derive"] }
bincode = "2.0.0-rc.3"
rustfft = "6.1.0"
tempfile = "3.2"
average = "0.14.1"
average = "0.15.1"
regex = "1.9.1"
hound = "3.5"
median = "0.3.2"
Expand Down
39 changes: 16 additions & 23 deletions brro-compressor/src/compressor/fft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,6 @@ impl FrequencyPoint {
im: self.freq_img * -1.0,
}
}

/// To allow to use rust std structures
fn partial_cmp(&self, other: &Self) -> Ordering {
let c1 = Complex {
re: self.freq_real,
im: self.freq_img,
};
let c2 = Complex {
re: other.freq_real,
im: other.freq_img,
};
if self == other {
Ordering::Equal
} else if c1.norm() > c2.norm() {
return Ordering::Greater;
} else {
return Ordering::Less;
}
}
}

// This is VERY specific for this use case, DO NOT RE-USE! This NORM comparison is false for complex numbers
Expand All @@ -105,13 +86,27 @@ impl Eq for FrequencyPoint {}

impl PartialOrd for FrequencyPoint {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.partial_cmp(other))
Some(self.cmp(other))
}
}

impl Ord for FrequencyPoint {
fn cmp(&self, other: &Self) -> Ordering {
self.partial_cmp(other)
let c1 = Complex {
re: self.freq_real,
im: self.freq_img,
};
let c2 = Complex {
re: other.freq_real,
im: other.freq_img,
};
if self == other {
Ordering::Equal
} else if c1.norm() > c2.norm() {
return Ordering::Greater;
} else {
return Ordering::Less;
}
}
}

Expand Down Expand Up @@ -179,9 +174,7 @@ impl FFT {
FFT {
id: FFT_COMPRESSOR_ID,
frequencies: Vec::with_capacity(sample_count),
/// The maximum numeric value of the points in the frame
max_value: FFT::f64_to_f32(max),
/// The minimum numeric value of the points in the frame
min_value: FFT::f64_to_f32(min),
error: None,
}
Expand Down
2 changes: 1 addition & 1 deletion csv-compressor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ csv = "1.3.0"
serde = { version = "1.0.171", features = ["derive"] }
wavbrro = { version = "0.1.0", path = "../wavbrro" }
log = "0.4.19"
env_logger = "0.10.0"
env_logger = "0.11.0"
vsri = { version = "0.1.0", path = "../vsri" }
[dev-dependencies]
tempdir = "0.3.7"
3 changes: 1 addition & 2 deletions optimizer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ description = "Optimizer stage for the compressor."

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
sysinfo = "0.29.0"
hound = "3.5"
chrono = "0.4.26"
claxon = "0.4.3"
env_logger = "0.10.0"
env_logger = "0.11.0"
log = "0.4.0"
clap = {version = "4.3.14", features = ["derive"] }
regex = "1.9.1"
Expand Down
14 changes: 2 additions & 12 deletions optimizer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,7 @@ fn write_optimal_wav(filename: &str, data: Vec<f64>, bitdepth: i32, dc: i64, cha
let mut file_path = filename.to_string();
file_path.truncate(file_path.len() - 4);
file_path = format!("{}_OPT.wav", file_path);
let file = std::fs::OpenOptions::new()
.write(true)
.create(true)
.read(true)
.open(file_path)
.unwrap();
let file = File::create(file_path).unwrap();
let mut wav_writer = WavWriter::new(file, header).unwrap();
for sample in data {
let _ = match bitdepth {
Expand All @@ -107,12 +102,7 @@ fn write_optimal_int_wav(filename: &str, data: Vec<i64>, bitdepth: i32, dc: i64,
let mut file_path = filename.to_string();
file_path.truncate(file_path.len() - 4);
file_path = format!("{}_OPT.wav", file_path);
let file = std::fs::OpenOptions::new()
.write(true)
.create(true)
.read(true)
.open(file_path)
.unwrap();
let file = File::create(file_path).unwrap();
let mut wav_writer = WavWriter::new(file, header).unwrap();
for sample in data {
let _ = match bitdepth {
Expand Down
3 changes: 1 addition & 2 deletions prometheus-remote/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ description = "Remote Read/Write server for prometheus"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
sysinfo = "0.29.0"
hound = "3.5"
chrono = "0.4.26"
claxon = "0.4.3"
Expand All @@ -17,7 +16,7 @@ tokio = { version= "1", features = ["full"] }
symphonia = { version = "0.5.3", features = ["flac"] }
prom-remote-api = { version = "0.3.0", features = ["warp"] }
async-trait = "0.1.71"
env_logger = "0.10.0"
env_logger = "0.11.0"
log = "0.4.0"
clap = {version = "4.3.14", features = ["derive"] }
regex = "1.9.1"
Expand Down
10 changes: 3 additions & 7 deletions prometheus-remote/src/flac_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,7 @@ impl FlacMetric {

fn datetime_from_ms(real_time: i64) -> String {
// Time is in ms, convert it to seconds
let datetime = DateTime::<Utc>::from_utc(
chrono::NaiveDateTime::from_timestamp_opt(real_time / 1000, 0).unwrap(),
Utc,
);
let datetime = DateTime::<Utc>::from_timestamp(real_time / 1000, 0).unwrap();
// Transform datetime to string with the format YYYY-MM-DD
let datetime_str = datetime.format("%Y-%m-%d").to_string();
datetime_str
Expand Down Expand Up @@ -163,10 +160,9 @@ impl FlacMetric {
// Get the default track.
let track = format.default_track().unwrap();
// Create a decoder for the track.
let decoder = symphonia::default::get_codecs()
symphonia::default::get_codecs()
.make(&track.codec_params, &decoder_opts)
.unwrap();
decoder
.unwrap()
}

/// Read samples from a file with an optional start and end point.
Expand Down
30 changes: 6 additions & 24 deletions prometheus-remote/src/fs_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,8 @@ impl DataLocator {
) -> Option<Vec<DataLocator>> {
let mut file_index_vec = Vec::new();
let data_locator_vec: Vec<DataLocator>;
let start_date = DateTime::<Utc>::from_utc(
chrono::NaiveDateTime::from_timestamp_opt(start_time / 1000, 0).unwrap(),
Utc,
);
let end_date = DateTime::<Utc>::from_utc(
chrono::NaiveDateTime::from_timestamp_opt(end_time / 1000, 0).unwrap(),
Utc,
);
let start_date = DateTime::<Utc>::from_timestamp(start_time / 1000, 0).unwrap();
let end_date = DateTime::<Utc>::from_timestamp(end_time / 1000, 0).unwrap();
let file_time_intervals = time_intervals(start_time, end_time);
debug!(
"[READ] Time intervals for the range {:?} ",
Expand Down Expand Up @@ -255,14 +249,8 @@ impl DataLocator {
/// Returns a Vector of array of time intervals (in seconds) for the interval of time
fn time_intervals(start_time: i64, end_time: i64) -> Vec<[i32; 2]> {
let mut time_intervals = Vec::new();
let start_date = DateTime::<Utc>::from_utc(
chrono::NaiveDateTime::from_timestamp_opt(start_time / 1000, 0).unwrap(),
Utc,
);
let end_date = DateTime::<Utc>::from_utc(
chrono::NaiveDateTime::from_timestamp_opt(end_time / 1000, 0).unwrap(),
Utc,
);
let start_date = DateTime::<Utc>::from_timestamp(start_time / 1000, 0).unwrap();
let end_date = DateTime::<Utc>::from_timestamp(end_time / 1000, 0).unwrap();
let start_ts_i32 = day_elapsed_seconds(start_time);
let end_ts_i32 = day_elapsed_seconds(end_time);
let date_spread_size = DateRange(start_date, end_date).count();
Expand Down Expand Up @@ -325,14 +313,8 @@ pub fn get_data_between_timestamps(
// How many files to process
let file_count = file_vec.len();
// Get the baseline timestamps to add to the index timestamps
let start_date = DateTime::<Utc>::from_utc(
chrono::NaiveDateTime::from_timestamp_opt(start_time / 1000, 0).unwrap(),
Utc,
);
let end_date = DateTime::<Utc>::from_utc(
chrono::NaiveDateTime::from_timestamp_opt(end_time / 1000, 0).unwrap(),
Utc,
);
let start_date = DateTime::<Utc>::from_timestamp(start_time / 1000, 0).unwrap();
let end_date = DateTime::<Utc>::from_timestamp(end_time / 1000, 0).unwrap();
let ts_bases: Vec<i64> = DateRange(start_date, end_date).map(start_day_ts).collect();
let start_ts_i32 = day_elapsed_seconds(start_time);
let end_ts_i32 = day_elapsed_seconds(end_time);
Expand Down
5 changes: 1 addition & 4 deletions prometheus-remote/src/lib_vsri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ pub static MAX_INDEX_SAMPLES: i32 = 86400;
// Helper functions, this should be moved somewhere
/// Returns the number of seconds elapsed for the day provided in the `timestamp_sec`
pub fn day_elapsed_seconds(timestamp_sec: i64) -> i32 {
let datetime = DateTime::<Utc>::from_utc(
chrono::NaiveDateTime::from_timestamp_opt(timestamp_sec, 0).unwrap(),
Utc,
);
let datetime = DateTime::<Utc>::from_timestamp(timestamp_sec, 0).unwrap();
// Extract the time components (hour, minute, and second) from the DateTime
let hour = datetime.time().hour();
let minute = datetime.time().minute();
Expand Down
11 changes: 2 additions & 9 deletions prometheus-remote/src/wav_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ impl WavMetric {
/// Create a new WavMetric struct. `start_sample_ts` *must be* timestamp with miliseconds!
pub fn new(name: String, source: String, job: String, start_sample_ts: i64) -> WavMetric {
// Sample needs to fall within the file that the TS refers too, not the calendar day
let start_date = DateTime::<Utc>::from_utc(
chrono::NaiveDateTime::from_timestamp_opt(start_sample_ts / 1000, 0).unwrap(),
Utc,
);
let start_date = DateTime::<Utc>::from_timestamp(start_sample_ts / 1000, 0).unwrap();
// TODO: Do not ignore JOB!
WavMetric {
metric_name: name,
Expand Down Expand Up @@ -143,11 +140,7 @@ impl WavMetric {
return Ok((wav_writer, Vsri::load(&file_name).unwrap()));
}
}
let file = OpenOptions::new()
.write(true)
.create(true)
.read(true)
.open(&file_path)?;
let file = File::create(&file_path)?;
let wav_writer = WavWriter::new(file, spec)?;
self.last_file_created = Some(file_path);
// TODO: Y can't be 0. Needs to be TS
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.71"
channel = "1.80"
components = [ "rustfmt", "clippy" ]
3 changes: 1 addition & 2 deletions tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ description = "Tools for testing/supporting the development/validation of the co
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
wavbrro = { path = "../wavbrro" }
sysinfo = "0.29.0"
hound = "3.5"
chrono = "0.4.26"
claxon = "0.4.3"
symphonia = { version = "0.5.3", features = ["flac"] }
env_logger = "0.10.0"
env_logger = "0.11.0"
log = "0.4.0"
clap = {version = "4.3.14", features = ["derive"] }
regex = "1.9.1"
Expand Down
9 changes: 3 additions & 6 deletions tools/src/bin/mid_channel_computing.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fs::File;

use clap::Parser;
use hound::{WavSpec, WavWriter};

Expand Down Expand Up @@ -49,12 +51,7 @@ fn join_u16_into_f64(bits: [u16; 4]) -> f64 {
fn write_optimal_int_wav(filename: &str, data: Vec<i16>, bitdepth: i32, channels: i32) {
let header: WavSpec = generate_wav_header(Some(channels), bitdepth as u16, 8000);
let file_path = format!("{filename}.wav");
let file = std::fs::OpenOptions::new()
.write(true)
.create(true)
.read(true)
.open(file_path)
.unwrap();
let file = File::create(file_path).unwrap();
let mut wav_writer = WavWriter::new(file, header).unwrap();
for sample in data {
let _ = wav_writer.write_sample(sample as i8);
Expand Down
5 changes: 1 addition & 4 deletions vsri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ pub static MAX_INDEX_SAMPLES: i32 = 86400;
// Helper functions, this should be moved somewhere
/// Returns the number of seconds elapsed for the day provided in the `timestamp_sec`
pub fn day_elapsed_seconds(timestamp_sec: i64) -> i32 {
let datetime = DateTime::<Utc>::from_utc(
chrono::NaiveDateTime::from_timestamp_opt(timestamp_sec, 0).unwrap(),
Utc,
);
let datetime = DateTime::<Utc>::from_timestamp(timestamp_sec, 0).unwrap();
// Extract the time components (hour, minute, and second) from the DateTime
let hour = datetime.time().hour();
let minute = datetime.time().minute();
Expand Down
4 changes: 2 additions & 2 deletions wavbrro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ description = "An adaptation of the WAV format for use by the BRRO compressor"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
env_logger = "0.10.0"
env_logger = "0.11.0"
log = "0.4.0"
rkyv = { version = "0.7.42", features = ["validation"] }
tempfile = "3.2.0"

[dev-dependencies]
env_logger = "0.10.0"
env_logger = "0.11.0"

0 comments on commit a29a36a

Please sign in to comment.