datagen-rs-progress-plugin

Crates.iodatagen-rs-progress-plugin
lib.rsdatagen-rs-progress-plugin
version0.1.0
sourcesrc
created_at2023-09-26 10:14:41.69139
updated_at2023-09-26 10:14:41.69139
descriptionA progress plugin for datagen-rs
homepage
repositoryhttps://github.com/MarkusJx/datagen
max_upload_size
id983476
size13,522
Markus (MarkusJx)

documentation

README

progress-plugin

The progress plugin is a native plugin providing progress for the generation process.

Usage

The easiest way to use the progress plugin is to call ProgressPlugin::with_schema() while providing a schema and a callback function:

use std::error::Error;

use datagen_rs::schema::schema_definition::Schema;
use progress_plugin::{PluginWithSchemaResult, ProgressPlugin};
use datagen_rs::util::helpers::generate_random_data;

fn generate(schema: Schema) -> Result<(), Box<dyn Error>> {
    let PluginWithSchemaResult {
        schema,
        plugins,
    } = ProgressPlugin::with_schema(schema, |current, total| {
        println!("{} / {}", current, total);
    })?;

    let generated = generate_random_data(schema, Some(plugins))?;
    println!("{}", generated);
}

How the number of elements is calculated

The progress is calculated by first generating a list of array lengths for all arrays in the schema.

If the array length is a fixed value, the progress is calculated by multiplying the fixed value with the number of elements in the array. This is a recursive process, so if the array contains another array, the progress is calculated by multiplying the length of the array with the length of the inner array.

If the array length is a random value, the array length is calculated by generating a random value between the minimum and maximum value and storing this value in a list containing all array lengths. Then this value is multiplied with the number of elements in the array.

The number of elements in objects and anyOf is also taken into account.

Commit count: 20

cargo fmt