feat: add BooleanValue::Toggle and FloatValue::SequentialWithInc
parent
a40fbe83b1
commit
17b22894e1
|
@ -5,8 +5,7 @@ use crate::specification::{DataSpec, FieldKind, MeasurementSpec};
|
||||||
use chrono::{DateTime, Local};
|
use chrono::{DateTime, Local};
|
||||||
use influxdb3_client::{Client, Precision};
|
use influxdb3_client::{Client, Precision};
|
||||||
use rand::distributions::Alphanumeric;
|
use rand::distributions::Alphanumeric;
|
||||||
use rand::rngs::SmallRng;
|
use rand::{Rng, RngCore};
|
||||||
use rand::{Rng, RngCore, SeedableRng};
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::ops::Add;
|
use std::ops::Add;
|
||||||
|
@ -133,9 +132,15 @@ fn create_measurement<'a>(
|
||||||
key: Arc::clone(&key),
|
key: Arc::clone(&key),
|
||||||
copy_id,
|
copy_id,
|
||||||
null_probability,
|
null_probability,
|
||||||
field_value: FieldValue::Boolean(BooleanValue::Random(
|
field_value: FieldValue::Boolean(BooleanValue::Random),
|
||||||
SmallRng::from_entropy(),
|
});
|
||||||
)),
|
}
|
||||||
|
FieldKind::BoolToggle => {
|
||||||
|
fields.push(Field {
|
||||||
|
key: Arc::clone(&key),
|
||||||
|
copy_id,
|
||||||
|
null_probability,
|
||||||
|
field_value: FieldValue::Boolean(BooleanValue::Toggle(false)),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
FieldKind::String(s) => {
|
FieldKind::String(s) => {
|
||||||
|
@ -215,6 +220,17 @@ fn create_measurement<'a>(
|
||||||
})),
|
})),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
FieldKind::FloatSeqWithInc(inc) => {
|
||||||
|
fields.push(Field {
|
||||||
|
key: Arc::clone(&key),
|
||||||
|
copy_id,
|
||||||
|
null_probability,
|
||||||
|
field_value: FieldValue::Float(FloatValue::SequentialWithInc {
|
||||||
|
next: 0f64,
|
||||||
|
inc: *inc,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -458,6 +474,10 @@ impl Field {
|
||||||
let v: f64 = rng.gen_range(range.clone());
|
let v: f64 = rng.gen_range(range.clone());
|
||||||
write!(w, "{:.3}", v)?;
|
write!(w, "{:.3}", v)?;
|
||||||
}
|
}
|
||||||
|
FloatValue::SequentialWithInc { next, inc } => {
|
||||||
|
write!(w, "{}", next)?;
|
||||||
|
*next += *inc;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
FieldValue::String(s) => match s {
|
FieldValue::String(s) => match s {
|
||||||
StringValue::Fixed(v) => write!(w, "\"{}\"", v)?,
|
StringValue::Fixed(v) => write!(w, "\"{}\"", v)?,
|
||||||
|
@ -476,10 +496,14 @@ impl Field {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
FieldValue::Boolean(f) => match f {
|
FieldValue::Boolean(f) => match f {
|
||||||
BooleanValue::Random(rng) => {
|
BooleanValue::Random => {
|
||||||
let v: bool = rng.r#gen();
|
let v: bool = rng.r#gen();
|
||||||
write!(w, "{}", v)?;
|
write!(w, "{}", v)?;
|
||||||
}
|
}
|
||||||
|
BooleanValue::Toggle(current) => {
|
||||||
|
write!(w, "{current}")?;
|
||||||
|
*current = !*current;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -498,6 +522,7 @@ pub enum IntegerValue {
|
||||||
pub enum FloatValue {
|
pub enum FloatValue {
|
||||||
Fixed(f64),
|
Fixed(f64),
|
||||||
Random(Range<f64>),
|
Random(Range<f64>),
|
||||||
|
SequentialWithInc { next: f64, inc: f64 },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
@ -507,9 +532,10 @@ pub enum StringValue {
|
||||||
Sequential(Arc<str>, u64),
|
Sequential(Arc<str>, u64),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub enum BooleanValue {
|
pub enum BooleanValue {
|
||||||
Random(SmallRng),
|
Random,
|
||||||
|
Toggle(bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ByteCounter<W> {
|
struct ByteCounter<W> {
|
||||||
|
@ -722,6 +748,7 @@ pub struct Output {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use chrono::TimeZone;
|
use chrono::TimeZone;
|
||||||
|
use rand::{SeedableRng, rngs::SmallRng};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::specification::{FieldSpec, TagSpec};
|
use crate::specification::{FieldSpec, TagSpec};
|
||||||
|
|
|
@ -130,6 +130,8 @@ pub struct FieldSpec {
|
||||||
pub enum FieldKind {
|
pub enum FieldKind {
|
||||||
/// generates a random bool for the value of this field
|
/// generates a random bool for the value of this field
|
||||||
Bool(bool),
|
Bool(bool),
|
||||||
|
/// repeatedly toggles a boolean field value with the initial value being `false`
|
||||||
|
BoolToggle,
|
||||||
/// output this string value for every line this field is present
|
/// output this string value for every line this field is present
|
||||||
String(String),
|
String(String),
|
||||||
/// generate a random string of this length for every line this field is present
|
/// generate a random string of this length for every line this field is present
|
||||||
|
@ -147,6 +149,9 @@ pub enum FieldKind {
|
||||||
Float(f64),
|
Float(f64),
|
||||||
/// generate a random float in this range for every line this field is present
|
/// generate a random float in this range for every line this field is present
|
||||||
FloatRange(f64, f64),
|
FloatRange(f64, f64),
|
||||||
|
/// generate sequential floating point numbers with sequential values generated as increments
|
||||||
|
/// of the specified floating point number, starting from 0
|
||||||
|
FloatSeqWithInc(f64),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
|
Loading…
Reference in New Issue