about summary refs log tree commit diff
path: root/src/parser.rs
diff options
context:
space:
mode:
authorAlexander <alexanderkabua@gmail.com>2022-05-18 12:42:48 +0300
committerAlexander <alexanderkabua@gmail.com>2022-05-18 12:42:48 +0300
commit2d5f9f3b8b90c47abfdc3f7c2ddd9c04bfb37616 (patch)
treed070d1f7be88bea36839fca4e64565be72d1ec33 /src/parser.rs
parentc45d7bece4355fbede4012d177005de7fba79bb8 (diff)
downloadcorrelation_rust-2d5f9f3b8b90c47abfdc3f7c2ddd9c04bfb37616.tar.gz
add parser for json files
Diffstat (limited to 'src/parser.rs')
-rw-r--r--src/parser.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/parser.rs b/src/parser.rs
index 248411b..c42b268 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -1,7 +1,42 @@
+use std::fs::File;
+use std::io::Read;
+use serde::Deserialize;
+#[derive(Debug, Deserialize,PartialEq)]
+//#[serde(rename_all = "PascalCase")]
+
+pub struct JsonData {
+    file_path:String,
+    x_vals: String,
+    sample_values:String,
+
+}
+
+
+impl JsonData {
+    fn new(json_file_path:&str) -> JsonData{
+
+
+    let mut  file = std::fs::File::open(json_file_path).unwrap();
+    let mut buff = String::new();
+    file.read_to_string(&mut buff).unwrap();
+
+
+    let results  = match serde_json::from_str(&buff){
+        Ok(val) => val,
+        Err(error) => panic!("json file not well formatted {:?}",error)
+    };
+
+    results
 
 
 
 
+    }         
+
+         
+}
+
+
 #[derive(PartialEq, Debug)]
 pub struct CorrelationEvaluateRow {
     pub row_name:String,
@@ -139,5 +174,15 @@ mod tests{
 
         }
     }
+
+
+    #[test]
+    fn test_json_file_read(){
+        let json_struct = JsonData::new("/home/kabui/correlation_rust/src/sample_json_file.json");
+
+        let k = JsonData { file_path: String::from("/home/kabui/correlation_rust/src/matrix80.txt"), x_vals: String::from("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") };
+
+        assert_eq!(k,json_struct)
+    }
 }