about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlexander <alexanderkabua@gmail.com>2022-05-04 02:26:35 +0300
committerAlexander <alexanderkabua@gmail.com>2022-05-04 02:26:35 +0300
commitea2be8e691613334120ffc259fdf2be9bbd53e58 (patch)
treeb5d85df01cb361f9379a2317ec3822b250124e90 /src
parent794f5933590cebb9ae572fed7fbea45b36a6ffe1 (diff)
downloadcorrelation_rust-ea2be8e691613334120ffc259fdf2be9bbd53e58.tar.gz
code refactoring
Diffstat (limited to 'src')
-rw-r--r--src/correlations.rs31
-rw-r--r--src/parser.rs2
-rw-r--r--src/reader.rs49
3 files changed, 12 insertions, 70 deletions
diff --git a/src/correlations.rs b/src/correlations.rs
index 95b892d..ae0e00d 100644
--- a/src/correlations.rs
+++ b/src/correlations.rs
@@ -1,11 +1,10 @@
 
 use crate::reader::BufferReader;
-
+use crate::parser::parse_rows;
 
 use std::env;
 
 
-
 //way to parse the args
 use rgsl::{
     randist::t_distribution::{tdist_P, tdist_Q},
@@ -109,7 +108,7 @@ impl <'a> Compute<'a>{
     fn new (file_delimeter:char,method:&str,dataset_path:&'a str,x_vals:&'a [f64]) -> Self{
         //capitalize method/same cases
 
-        let method = match method {
+        let method = match method.to_lowercase().as_str() {
             "pearson" => CorrelationMethod::Pearson,
             "spearman" => CorrelationMethod::Spearman,
             _ => panic!("method cannot be found")
@@ -141,28 +140,21 @@ impl <'a> Compute<'a>{
                 while let Some(val) = buffer_read.read_line(& mut n_string){
                     if let Ok(array_new_val) = val {
 
-                        //issue here 
-
-                        let x_vals = [9.,5.,0.,7.,6.,1.,5.,0.,1.,5.,4.,2.,11.,15.,17.,21.];
-
-        
-                        let new_array:[f64;16]=  array_new_val
-                        .split(",")
-                        .map(|s| s.trim().parse::<f64>().expect("parse error"))
-                        .collect::<Vec<f64>>().try_into().unwrap_or_else(|_v|panic!("Expected vla"));
-        
+    
+                        let (parsed_x_val,parsed_y_val) = parse_rows(self.x_vals,&array_new_val
+                    
+                            .split(self.file_delimiter)
+                            .collect::<Vec<&str>>());
 
-                        let pearson = Pearson::new(5);
-                        let results = pearson.correlate(&x_vals,&new_array);
+                        let results =  Pearson::new(parsed_x_val.len())
+                        .correlate(&parsed_x_val,&parsed_y_val);
 
                         corr_results.push(results);
 
 
                     }
 
-                }
-
-            
+                }    
 
             }
 
@@ -311,10 +303,9 @@ mod test{
 
     fn test_huge_dataset(){
         let x_vals = [25.08439 ,72.02225 ,47.56293 ,22.87893 ,14.28721 ,71.84655 ,87.81991 ,84.86824 ,6.72478 ,5.72373 ,73.47078 ,63.74703];
-
         
 
-        let compute_obj = Compute::new(',',"pearson","/home/kabui/correlation_rust/src/db300.txt",&x_vals);
+        let compute_obj = Compute::new(',',"pearson","/home/kabui/correlation_rust/src/matrix_80.txt",&x_vals);
 
 
         assert_eq!(vec![(1.2,1.5)],compute_obj.compute())
diff --git a/src/parser.rs b/src/parser.rs
index 7ce317d..f2dacc3 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -1,5 +1,5 @@
 
-fn parse_rows (x_vals:&[f64],y_vals:&[&str]) -> (Vec<f64>,Vec<f64>){
+pub fn parse_rows (x_vals:&[f64],y_vals:&[&str]) -> (Vec<f64>,Vec<f64>){
     //pointer
 
     let mut  parsed_x_vals= Vec::new();
diff --git a/src/reader.rs b/src/reader.rs
index 197638a..016a119 100644
--- a/src/reader.rs
+++ b/src/reader.rs
@@ -40,55 +40,6 @@ impl BufferReader{
         }).transpose()
 }
 
-    pub fn fetch_keys <'a>(&self,row:& 'a str) -> (&str,[&str]){
-
-
-        // parse the line and return (trait_name and trait_values)
-
-        //parse the other  body to float type
-
-        let mut buf = String::new();
-       // should be taken to  own  line
-
-
-        let sample_buffer =  self.read_line(&mut buf);
-
-        let sample_names = match sample_buffer{
-
-            Some(val)=> {
-                if let Ok(new_vak) = val{
-
-                    new_vak
-
-                }
-
-                else {
-                    panic!("error happened");
-                }
-            },
-
-            None =>  panic!("no sample values found")
-
-        };
-
- 
-    
-
-        let string_vec : Vec<&str>= row.split(",").collect();
-
-        //issue is that spaces are included
-
-        return [string_vec[0],string_vec[1..]];
-    }  
-pub fn row_parser <'a>(&self,row :&'a mut String) ->(& 'a str,Vec<&'a str>){
-
-    let parsed_row:Vec<&str> = row.split(",").map(|s|s.trim()).collect();
-
-    let (trait_name,trait_vals) =  (parsed_row[0],parsed_row[1..].to_vec());
-
-    (parsed_row[0],parsed_row[1..].to_vec())
-
-}     
 }