Struct DataSampleParser

Source
pub struct DataSampleParser {
    pub issues: bool,
    /* private fields */
}
Expand description

Represents the Parser for sample data to be used

Fields§

§issues: bool

indicates if there were issues parsing and anlyzing the data sample

Implementations§

Source§

impl DataSampleParser

Source

pub fn new() -> DataSampleParser

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();
}
Source

pub fn new_with(path: &String) -> DataSampleParser

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"));
}
Source

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

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());
}
Source

pub fn analyze_csv_data( &mut self, data: &String, delimiter: Option<u8>, ) -> Result<i32, String>

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.
  • delimiter: Option<u8> - The delimiter to use, otherwise use the default.
§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\"");

    // Use the default delimiter (comma)
	assert_eq!(dsp.analyze_csv_data(&data, None).unwrap(),1);
}
Source

pub fn analyze_csv_file( &mut self, path: &String, delimiter: Option<u8>, ) -> Result<i32, String>

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.
  • delimiter: Option<u8> - The delimiter to use, otherwise use the default.
§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();

    // Use the default delimiter (comma)
	assert_eq!(dsp.analyze_csv_file(&String::from("./tests/samples/sample-01.csv"), None).unwrap(),1);
}
Source

pub fn demo_date(&self) -> String

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());
}
Source

pub fn demo_person_name(&self) -> String

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());
}
Source

pub fn extract_headers(&mut self) -> Vec<String>

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"), None).unwrap();
    let headers = dsp.extract_headers();

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

pub fn generate_by_field_name(&mut self, field: String) -> String

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"), None).unwrap();
    println!("Generated data for first name {}",dsp.generate_by_field_name("firstname".to_string()));
}
Source

pub fn generate_record(&mut self) -> Vec<String>

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"), None).unwrap();
    println!("Generated data record: {:?}",dsp.generate_record());
}
Source

pub fn generate_csv( &mut self, row_count: u32, path: &String, delimiter: Option<u8>, ) -> Result<(), Box<dyn 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: &String - The full path name where to save the csv file.
  • delimiter: Option<u8> - The delimiter to use, otherwise use the default.
§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"), None).unwrap();
    dsp.generate_csv(100, &String::from("./tests/samples/generated-01.csv"), None).unwrap();
}
Source

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

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);
}
Source

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

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);
}
Source

pub fn running_with_issues(&self) -> &bool

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);
}
Source

pub fn save(&mut self, path: &String) -> Result<bool, Error>

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"), None).unwrap();

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

Trait Implementations§

Source§

impl CsvManipulator for DataSampleParser

Source§

fn read_as_columns(rdr: Reader<&[u8]>) -> Vec<Vec<String>>

This function parses all the rows and splits the columns into separate Vectors Read more
Source§

impl Debug for DataSampleParser

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for DataSampleParser

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Engine for DataSampleParser

Source§

impl Serialize for DataSampleParser

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V

Source§

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