Struct test_data_generation::data_sample_parser::DataSampleParser
[−]
[src]
pub struct DataSampleParser { pub issues: bool, // some fields omitted }
Represents the Parser for sample data to be used
Fields
issues: bool
indicates if there were issues parsing and anlyzing the data sample
Methods
impl DataSampleParser
[src]
pub fn new() -> DataSampleParser
[src]
Constructs a new DataSampleParser
#Example
extern crate test_data_generation; use test_data_generation::data_sample_parser::DataSampleParser; fn main() { // initalize a new DataSampelParser let dsp = DataSampleParser::new(); }
pub fn new_with(path: &'static str) -> DataSampleParser
[src]
Constructs a new DataSampleParser
Arguments
- `path: String - The full path name (including the file name and extension) to the configuration file.
#Example
extern crate test_data_generation; use test_data_generation::data_sample_parser::DataSampleParser; fn main() { // initalize a new DataSampelParser // param: the path to the configuration file let dsp = DataSampleParser::new_with("./config/tdg.yaml"); }
pub fn from_file(path: &'static str) -> DataSampleParser
[src]
Constructs a new DataSampleParser from an exported JSON file. This is used when restoring from "archive"
#Example
extern crate test_data_generation; use test_data_generation::data_sample_parser::DataSampleParser; fn main() { let mut dsp = DataSampleParser::from_file("./tests/samples/sample-00-dsp"); assert_eq!(dsp.generate_record()[0], "OK".to_string()); }
pub fn analyze_csv_file(&mut self, path: &'static str) -> Result<i32, String>
[src]
This function analyzes sample data that is a csv formatted string and returns a boolean if successful. NOTE: The csv properties are as follows: + headers are included as first line + double quote wrap text + double quote escapes is enabled + delimiter is a comma
Arguments
path: &'static str
- The full path name of the csv formatted sample data file.
Example
extern crate test_data_generation; use test_data_generation::data_sample_parser::DataSampleParser; fn main() { // initalize a new DataSampelParser let mut dsp = DataSampleParser::new(); assert_eq!(dsp.analyze_csv_file("./tests/samples/sample-01.csv").unwrap(),1); }
pub fn demo_date(&self) -> String
[src]
This function generates date as strings using the a demo
profile
Example
extern crate test_data_generation; use test_data_generation::data_sample_parser::DataSampleParser; fn main() { // initalize a new DataSampelParser let dsp = DataSampleParser::new(); // generate some test data using the demo functions println!("generate date:{}", dsp.demo_date()); }
pub fn demo_person_name(&self) -> String
[src]
This function generates people's names as strings using the a demo
profile
Example
extern crate test_data_generation; use test_data_generation::data_sample_parser::DataSampleParser; fn main() { // initalize a new DataSampelParser let dsp = DataSampleParser::new(); // generate some test data using the demo functions println!("generate date:{}", dsp.demo_person_name()); }
pub fn generate_by_field_name(&mut self, field: String) -> String
[src]
This function generates test data for the specified field name.
Arguments
field: String
- The name of the field (e.g.: firstname) the represents the profile to use when generating the test data.
Example
extern crate test_data_generation; use test_data_generation::data_sample_parser::DataSampleParser; fn main() { // initalize a new DataSampelParser let mut dsp = DataSampleParser::new(); dsp.analyze_csv_file("./tests/samples/sample-01.csv").unwrap(); println!("Generated data for first name {}",dsp.generate_by_field_name("firstname".to_string())); }
pub fn generate_record(&mut self) -> Vec<String>
[src]
This function Vec of generates test data fields.
Example
extern crate test_data_generation; use test_data_generation::data_sample_parser::DataSampleParser; fn main() { // initalize a new DataSampelParser let mut dsp = DataSampleParser::new(); dsp.analyze_csv_file("./tests/samples/sample-01.csv").unwrap(); println!("Generated data record: {:?}",dsp.generate_record()); }
pub fn generate_csv(
&mut self,
row_count: u32,
path: &'static str
) -> Result<(), Box<Error>>
[src]
&mut self,
row_count: u32,
path: &'static str
) -> Result<(), Box<Error>>
This function creates a csv file of generated test data. Prior to calling this funciton, you need to call the analyze_csv_file() function. NOTE: The csv properties are as follows: + headers are included as first line + double quotes wrap text + double quote escapes is enabled + delimiter is a comma
Arguments
row_count: u32
- The number of rows to generate.path: &'static str
- The full path name where to save the csv file.
Example
extern crate test_data_generation; use test_data_generation::data_sample_parser::DataSampleParser; fn main() { // initalize a new DataSampelParser let mut dsp = DataSampleParser::new(); dsp.analyze_csv_file("./tests/samples/sample-01.csv").unwrap(); dsp.generate_csv(100, "./tests/samples/generated-01.csv").unwrap(); }
pub fn extract_headers(&mut self) -> Vec<String>
[src]
This function returns a vector of header names
Example
extern crate test_data_generation; use test_data_generation::data_sample_parser::DataSampleParser; fn main() { // initalize a new DataSampelParser let mut dsp = DataSampleParser::new(); dsp.analyze_csv_file("./tests/samples/sample-01.csv").unwrap(); let headers = dsp.extract_headers(); assert_eq!(headers.len(), 2); }
pub fn running_with_issues(&self) -> &bool
[src]
This function returns a boolean that indicates if the data sample parsing had issues
Example
extern crate test_data_generation; use test_data_generation::data_sample_parser::DataSampleParser; fn main() { // initalize a new DataSampelParser // param: the path to the configuration file is wrong let dsp = DataSampleParser::new_with("./target/debug/config/tdg.yaml"); // generate some test data using the demo functions assert_eq!(dsp.running_with_issues(), &false); }
pub fn save(&mut self, path: &'static str) -> Result<bool, Error>
[src]
This function saves (exports) the DataSampleParser to a JSON file. This is useful when you wish to reuse the algorithm to generate more test data later.
Arguments
field: String
- The full path of the export file , excluding the file extension, (e.g.: "./test/data/custom-names").
#Errors If this function encounters any form of I/O or other error, an error variant will be returned. Otherwise, the function returns Ok(true).
#Example
extern crate test_data_generation; use test_data_generation::data_sample_parser::DataSampleParser; fn main() { // analyze the dataset let mut dsp = DataSampleParser::new(); dsp.analyze_csv_file("./tests/samples/sample-00.csv").unwrap(); assert_eq!(dsp.save("./tests/samples/sample-00-dsp").unwrap(), true); }