about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlexander_Kabui <alexanderkabua@gmail.com>2022-08-08 14:09:18 +0300
committerAlexander_Kabui <alexanderkabua@gmail.com>2022-08-08 14:09:18 +0300
commit3efeead9ca1c5705ff5b50ced14401c4ea99f506 (patch)
tree069f1c018393ce80c8c3512ee7ec5b168a31ab7b /src
parentdb0b9c7fc340e09babe7be0609539359c9a05390 (diff)
downloadcorrelation_rust-3efeead9ca1c5705ff5b50ced14401c4ea99f506.tar.gz
rust clippy fixes
Diffstat (limited to 'src')
-rw-r--r--src/analysis.rs2
-rw-r--r--src/correlations.rs21
-rw-r--r--src/parser.rs22
-rw-r--r--src/reader.rs12
4 files changed, 26 insertions, 31 deletions
diff --git a/src/analysis.rs b/src/analysis.rs
index 519e602..58b80c6 100644
--- a/src/analysis.rs
+++ b/src/analysis.rs
@@ -21,7 +21,7 @@ impl Analysis {
 
         // let computation = correlations::Compute::filter_top(computation, 500);
 
-       return computation_status
+        computation_status
     }
 }
 
diff --git a/src/correlations.rs b/src/correlations.rs
index d7eda00..62f536e 100644
--- a/src/correlations.rs
+++ b/src/correlations.rs
@@ -109,10 +109,10 @@ impl<'a> Compute<'a> {
         };
 
         Self {
-            x_vals: x_vals,
-            dataset_path: dataset_path,
-            method: method,
-            output_file: output_file,
+            x_vals,
+            dataset_path,
+            method,
+            output_file,
             file_delimiter: file_delimeter,
         }
     }
@@ -135,7 +135,6 @@ impl<'a> Compute<'a> {
     }
 
     pub fn compute(&self) -> std::io::Result<String> {
-
         let mut corr_results: Vec<(String, f64, f64, i32)> = Vec::new();
 
         let reader = BufferReader::new(self.dataset_path);
@@ -161,8 +160,6 @@ impl<'a> Compute<'a> {
 
                 while let Some(val) = buffer_read.read_line(&mut n_string) {
                     if let Ok(array_new_val) = val {
-            
-
                         let ty = parse_rows_with_names(
                             self.x_vals,
                             &array_new_val
@@ -195,10 +192,7 @@ impl<'a> Compute<'a> {
 
         corr_results.sort_by(|a, b| b.1.abs().partial_cmp(&a.1.abs()).unwrap());
 
-        // corr_results.sort_by(|a,b|b.1.abs().partial_cmp(&a.1.abs()).unwrap());
-        return sort_write_to_file(String::from(self.output_file), corr_results);
-
-    
+        sort_write_to_file(String::from(self.output_file), corr_results)
     }
 }
 #[derive(PartialEq, Debug)]
@@ -323,10 +317,6 @@ mod tests {
         let corr_results = compute_obj.compute();
 
         assert!(corr_results.is_ok())
-
-
-
-   
     }
 
     #[test]
@@ -358,7 +348,6 @@ mod tests {
         )
     }
 
-
     #[test]
     fn test_sorter() {
         let mut a = vec![(1.2, 1.0), (1.3, 0.5), (1.3, 7.)];
diff --git a/src/parser.rs b/src/parser.rs
index 0a2416a..c38166a 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -55,13 +55,13 @@ pub fn parse_rows_with_names(x_vals: &[f64], y_vals: &[&str]) -> CorrelationEval
         None => String::from(""),
     };
 
-    let results = parse_rows(x_vals, &string_floats);
+    let results = parse_rows(x_vals, string_floats);
 
-    return CorrelationEvaluateRow {
+    CorrelationEvaluateRow {
         row_name,
         x_vals: results.0,
         y_vals: results.1,
-    };
+    }
 }
 pub fn parse_rows(x_vals: &[f64], y_vals: &[&str]) -> (Vec<f64>, Vec<f64>) {
     //optimization ?? memory
@@ -72,7 +72,7 @@ pub fn parse_rows(x_vals: &[f64], y_vals: &[&str]) -> (Vec<f64>, Vec<f64>) {
 
     let mut parsed_y_vals = Vec::new();
 
-    for (index, x_val) in x_vals.into_iter().enumerate() {
+    for (index, x_val) in x_vals.iter().enumerate() {
         if let Some(val) = y_vals.get(index) {
             match val.trim().parse::<f64>() {
                 Ok(float_type) => {
@@ -156,11 +156,19 @@ mod tests {
 
     #[test]
     fn test_json_file_read() {
-        let json_struct =
-            JsonData::new("tests/data/sample_json_file.json");
+        let json_struct = JsonData::new("tests/data/sample_json_file.json");
 
         let k = JsonData {
-	    file_path: String::from("tests/data/db300.txt"),output_file:String::from("output.txt"),x_vals: vec![25.08439, 72.02225, 47.56293, 22.87893, 14.28721, 71.84655, 87.81991, 84.86824, 6.72478, 5.72373, 73.47078, 63.74703],sample_values: String::from("bxd1"),method:String::from("pearson"),file_delimiter:','};
+            file_path: String::from("tests/data/db300.txt"),
+            output_file: String::from("output.txt"),
+            x_vals: vec![
+                25.08439, 72.02225, 47.56293, 22.87893, 14.28721, 71.84655, 87.81991, 84.86824,
+                6.72478, 5.72373, 73.47078, 63.74703,
+            ],
+            sample_values: String::from("bxd1"),
+            method: String::from("pearson"),
+            file_delimiter: ',',
+        };
 
         assert_eq!(k, json_struct)
     }
diff --git a/src/reader.rs b/src/reader.rs
index a53c217..2d6e748 100644
--- a/src/reader.rs
+++ b/src/reader.rs
@@ -13,9 +13,9 @@ impl BufferReader {
         let file = File::open(Path::new(file_path))?;
         //add file validator
 
-        return Ok(Self {
+        Ok(Self {
             reader: BufReader::new(file),
-        });
+        })
     }
 
     pub fn read_line<'a>(
@@ -29,7 +29,7 @@ impl BufferReader {
         self.reader
             .read_line(buf)
             .map(|u| {
-                if u == 0 as usize {
+                if u == 0_usize {
                     return None;
                 }
 
@@ -62,16 +62,14 @@ mod tests {
     #[test]
 
     fn test_file_reader() {
-        let expected_results =
-            file_reader("tests/data/mock_dataset.txt");
+        let expected_results = file_reader("tests/data/mock_dataset.txt");
 
         assert!(expected_results.is_ok());
     }
 
     #[test]
     fn test_file_reader_2() {
-        let mut buffer_reader =
-            BufferReader::new("tests/data/mock_dataset.txt").unwrap();
+        let mut buffer_reader = BufferReader::new("tests/data/mock_dataset.txt").unwrap();
         let mut buf = String::new();
         let mut data = [
             "9. ,5. ,0. ,7. ,6. ,1. ,5. ,0.\n",