From 80c47fbf5cfc579970b946f6a281af85566c0c1b Mon Sep 17 00:00:00 2001 From: Sander Willems Date: Fri, 14 Jun 2024 15:05:30 +0200 Subject: [PATCH] FEAT: cleaned up code --- src/io/readers/common/sql_frames.rs | 58 ++--------------------------- src/io/readers/common/sql_reader.rs | 4 ++ 2 files changed, 8 insertions(+), 54 deletions(-) diff --git a/src/io/readers/common/sql_frames.rs b/src/io/readers/common/sql_frames.rs index 509c2b8..15124e8 100644 --- a/src/io/readers/common/sql_frames.rs +++ b/src/io/readers/common/sql_frames.rs @@ -1,6 +1,6 @@ use super::sql_reader::SqlReadable; -#[derive(Debug, Default, PartialEq)] +#[derive(Debug, PartialEq)] pub struct SqlFrame { pub id: usize, pub scan_mode: u8, @@ -9,11 +9,12 @@ pub struct SqlFrame { pub rt: f64, pub scan_count: u64, pub binary_offset: usize, + pub accumulation_time: f64, } impl SqlReadable for SqlFrame { fn get_sql_query() -> String { - "SELECT Id, ScanMode, MsMsType, NumPeaks, Time, NumScans, TimsId FROM Frames".to_string() + "SELECT Id, ScanMode, MsMsType, NumPeaks, Time, NumScans, TimsId, AccumulationTime FROM Frames".to_string() } fn from_sql_row(row: &rusqlite::Row) -> Self { @@ -25,58 +26,7 @@ impl SqlReadable for SqlFrame { rt: row.get(4).unwrap_or_default(), scan_count: row.get(5).unwrap_or_default(), binary_offset: row.get(6).unwrap_or_default(), + accumulation_time: row.get(7).unwrap_or_default(), } } } - -#[cfg(test)] -mod tests { - use super::*; - use crate::io::readers::common::sql_reader::SqlReader; - - #[test] - fn test_get() { - let reader = - SqlReader::open("tests/test.d/analysis.tdf".to_string()).unwrap(); - let sql_frames = SqlFrame::from_sql_reader(&reader).unwrap(); - let target = [ - SqlFrame { - id: 1, - scan_mode: 8, - msms_type: 0, - peak_count: 10, - rt: 0.1, - scan_count: 4, - binary_offset: 0, - }, - SqlFrame { - id: 2, - scan_mode: 8, - msms_type: 8, - peak_count: 26, - rt: 0.2, - scan_count: 4, - binary_offset: 48, - }, - SqlFrame { - id: 3, - scan_mode: 8, - msms_type: 0, - peak_count: 42, - rt: 0.3, - scan_count: 4, - binary_offset: 130, - }, - SqlFrame { - id: 4, - scan_mode: 8, - msms_type: 8, - peak_count: 58, - rt: 0.4, - scan_count: 4, - binary_offset: 235, - }, - ]; - assert_eq!(sql_frames, target); - } -} diff --git a/src/io/readers/common/sql_reader.rs b/src/io/readers/common/sql_reader.rs index 0abe977..2540312 100644 --- a/src/io/readers/common/sql_reader.rs +++ b/src/io/readers/common/sql_reader.rs @@ -14,6 +14,10 @@ impl SqlReader { let connection = Connection::open(&path)?; Ok(Self { path, connection }) } + + pub fn get_path(&self) -> PathBuf { + self.path.clone() + } } pub trait SqlReadable {