From e1b9f68ff7c16a9411add9beabcdbfa545d1679b Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 18 May 2022 14:15:12 +0300 Subject: add main file --- src/main.rs | 34 ++++++++++++++++++++++++++++++++++ src/parser.rs | 8 ++++---- src/sample_json_file.json | 2 +- 3 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 src/main.rs (limited to 'src') diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..781ee2b --- /dev/null +++ b/src/main.rs @@ -0,0 +1,34 @@ +use std::env; +use correlation_rust::parser; +use correlation_rust::correlations; +fn main () { + + + let json_file = match env::args().nth(1){ + Some(tmp_file) => { + let results = parser::JsonData::new(&tmp_file); + + + let parsed_x_vals:Vec = results.x_vals.split(",").map(|f|f.trim().parse::().unwrap()).collect(); + + + + let computation = correlations::Compute::new( + ',', + "pearson", + &results.file_path, + &parsed_x_vals + + ).compute(); + + //println!("{:?}",computation); + + } + None => panic!("expected an arugment for the json file") + }; + + + + + +} \ No newline at end of file diff --git a/src/parser.rs b/src/parser.rs index c42b268..57465a2 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -5,15 +5,15 @@ use serde::Deserialize; //#[serde(rename_all = "PascalCase")] pub struct JsonData { - file_path:String, - x_vals: String, - sample_values:String, + pub file_path:String, + pub x_vals: String, + pub sample_values:String, } impl JsonData { - fn new(json_file_path:&str) -> JsonData{ + pub fn new(json_file_path:&str) -> JsonData{ let mut file = std::fs::File::open(json_file_path).unwrap(); diff --git a/src/sample_json_file.json b/src/sample_json_file.json index a49c189..dcc3817 100644 --- a/src/sample_json_file.json +++ b/src/sample_json_file.json @@ -1,5 +1,5 @@ { - "file_path":"/home/kabui/correlation_rust/src/matrix80.txt", + "file_path":"/home/kabui/correlation_rust/src/matrix_80.txt", "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", "sample_values":"bxd1" } \ No newline at end of file -- cgit 1.4.1