extern crate serde;
extern crate serde_pickle;
use std::fs::File;
use std::io::prelude::*;
use std::env;
use std::process::Command;
extern crate rand;
pub fn plot(basic_vectors: &(Vec<f64>, Vec<f64>)) {
let global_path = env::current_dir().unwrap();
let ser_path: &str = &format!("{}/output.tmp.pkl", global_path.to_str().unwrap());
let serialized = serde_pickle::to_vec(basic_vectors, true).unwrap();
let mut buffer = File::create(ser_path).unwrap();
match buffer.write(&serialized) {
Err(_x) => panic!(
"Failed to write serialized data to file at path = \"{}\"",
ser_path
),
_ => {}
};
let py_path = &format!("{}/plotter.py", global_path.to_str().unwrap());
let _new_command = Command::new("pythonw")
.arg(py_path)
.arg(ser_path)
.status()
.expect("Failed to start plotter.");
match std::fs::remove_file(ser_path) {
Err(_x) => panic!("Failed to remove temporary file at path = \"{}\"", ser_path),
_ => {}
};
}
#[cfg(test)]
mod tests {
use rand::{thread_rng, Rng};
#[test]
fn test_serialize() {
let mut a: Vec<f64> = vec![];
let mut b: Vec<f64> = vec![];
let mut rng = thread_rng();
for i in 0..100000 {
let x: f64 = rng.gen();
let y: f64 = rng.gen();
a.push(x);
b.push(y);
}
let serialized = serde_pickle::to_vec(&(&a, &b), true).unwrap();
let deserialized = serde_pickle::from_slice(&serialized).unwrap();
assert_eq!((a, b), deserialized);
}
#[test]
fn test_fs() {}
}