datagen-rs-progress-plugin 0.1.0

A progress plugin for datagen-rs
Documentation
  • Coverage
  • 0%
    0 out of 8 items documented0 out of 5 items with examples
  • Size
  • Source code size: 30.69 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.8 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 47s Average build duration of successful builds.
  • all releases: 47s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • MarkusJx/datagen
    4 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • MarkusJx

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.