[][src]Struct test_data_generation::data_sample_parser::DataSampleParser

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

Implementations

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: &String) -> 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(&String::from("./config/tdg.yaml"));
}

pub fn from_file(path: &String) -> DataSampleParser[src]

Constructs a new DataSampleParser from an exported JSON file. This is used when restoring from "archive"

Arguments

  • path: &String - The full path name of the json formatted Data Sample Parser archive file.

#Example

extern crate test_data_generation;

use test_data_generation::data_sample_parser::DataSampleParser;

fn main() {
	let mut dsp = DataSampleParser::from_file(&String::from("./tests/samples/sample-00-dsp"));

	assert_eq!(dsp.generate_record()[0], "OK".to_string());
}

pub fn analyze_csv_file(&mut self, path: &String) -> Result<i32, String>[src]

This function analyzes sample data that is a csv formatted file 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: &String - 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(&String::from("./tests/samples/sample-01.csv")).unwrap(),1);
}

pub fn analyze_csv_data(&mut self, data: &String) -> 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

  • data: &String - The textual content of a 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();
	let mut data = String::from("");
	data.push_str("\"firstname\",\"lastname\"\n");
	data.push_str("\"Aaron\",\"Aaberg\"\n");
	data.push_str("\"Aaron\",\"Aaby\"\n");
	data.push_str("\"Abbey\",\"Aadland\"\n");
	data.push_str("\"Abbie\",\"Aagaard\"\n");
	data.push_str("\"Abby\",\"Aakre\"");

	assert_eq!(dsp.analyze_csv_data(&data).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 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(&String::from("./tests/samples/sample-01.csv")).unwrap();
    let headers = dsp.extract_headers();

	assert_eq!(headers.len(), 2);
}

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(&String::from("./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(&String::from("./tests/samples/sample-01.csv")).unwrap();
    println!("Generated data record: {:?}",dsp.generate_record());
}

pub fn generate_csv(
    &mut self,
    row_count: u32,
    path: &String
) -> Result<(), Box<dyn Error>>
[src]

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: &String - 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(&String::from("./tests/samples/sample-01.csv")).unwrap();
    dsp.generate_csv(100, &String::from("./tests/samples/generated-01.csv")).unwrap();
}

pub fn levenshtein_distance(
    &mut self,
    control: &String,
    experiment: &String
) -> usize
[src]

This function calculates the levenshtein distance between 2 strings. See: https://crates.io/crates/levenshtein

Arguments

  • control: &String - The string to compare against. This would be the real data from the data sample.
  • experiment: &String - The string to compare. This would be the generated data for which you want to find the distance.

#Example

extern crate test_data_generation;

use test_data_generation::data_sample_parser::DataSampleParser;

fn main() {
	// analyze the dataset
	let mut dsp =  DataSampleParser::new();

    assert_eq!(dsp.levenshtein_distance(&"kitten".to_string(), &"sitting".to_string()), 3 as usize);
}

pub fn realistic_test(&mut self, control: &String, experiment: &String) -> f64[src]

This function calculates the percent difference between 2 strings.

Arguments

  • control: &String - The string to compare against. This would be the real data from the data sample.
  • experiment: &String - The string to compare. This would be the generated data for which you want to find the percent difference.

#Example

extern crate test_data_generation;

use test_data_generation::data_sample_parser::DataSampleParser;

fn main() {
	// analyze the dataset
	let mut dsp =  DataSampleParser::new();

    assert_eq!(dsp.realistic_test(&"kitten".to_string(), &"sitting".to_string()), 76.92307692307692 as f64);
}

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(&String::from("./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: &String) -> 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(&String::from("./tests/samples/sample-00.csv")).unwrap();

    assert_eq!(dsp.save(&String::from("./tests/samples/sample-00-dsp")).unwrap(), true);
}

Trait Implementations

impl CsvManipulator for DataSampleParser[src]

impl Debug for DataSampleParser[src]

impl<'de> Deserialize<'de> for DataSampleParser[src]

impl Engine for DataSampleParser[src]

impl Serialize for DataSampleParser[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DebugAny for T where
    T: Any + Debug

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> UnsafeAny for T where
    T: Any

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,