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 influxdb3_client::{Client, Precision};
|
||||
use rand::distributions::Alphanumeric;
|
||||
use rand::rngs::SmallRng;
|
||||
use rand::{Rng, RngCore, SeedableRng};
|
||||
use rand::{Rng, RngCore};
|
||||
use std::collections::HashMap;
|
||||
use std::io::Write;
|
||||
use std::ops::Add;
|
||||
|
@ -133,9 +132,15 @@ fn create_measurement<'a>(
|
|||
key: Arc::clone(&key),
|
||||
copy_id,
|
||||
null_probability,
|
||||
field_value: FieldValue::Boolean(BooleanValue::Random(
|
||||
SmallRng::from_entropy(),
|
||||
)),
|
||||
field_value: FieldValue::Boolean(BooleanValue::Random),
|
||||
});
|
||||
}
|
||||
FieldKind::BoolToggle => {
|
||||
fields.push(Field {
|
||||
key: Arc::clone(&key),
|
||||
copy_id,
|
||||
null_probability,
|
||||
field_value: FieldValue::Boolean(BooleanValue::Toggle(false)),
|
||||
});
|
||||
}
|
||||
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());
|
||||
write!(w, "{:.3}", v)?;
|
||||
}
|
||||
FloatValue::SequentialWithInc { next, inc } => {
|
||||
write!(w, "{}", next)?;
|
||||
*next += *inc;
|
||||
}
|
||||
},
|
||||
FieldValue::String(s) => match s {
|
||||
StringValue::Fixed(v) => write!(w, "\"{}\"", v)?,
|
||||
|
@ -476,10 +496,14 @@ impl Field {
|
|||
}
|
||||
},
|
||||
FieldValue::Boolean(f) => match f {
|
||||
BooleanValue::Random(rng) => {
|
||||
BooleanValue::Random => {
|
||||
let v: bool = rng.r#gen();
|
||||
write!(w, "{}", v)?;
|
||||
}
|
||||
BooleanValue::Toggle(current) => {
|
||||
write!(w, "{current}")?;
|
||||
*current = !*current;
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -498,6 +522,7 @@ pub enum IntegerValue {
|
|||
pub enum FloatValue {
|
||||
Fixed(f64),
|
||||
Random(Range<f64>),
|
||||
SequentialWithInc { next: f64, inc: f64 },
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -507,9 +532,10 @@ pub enum StringValue {
|
|||
Sequential(Arc<str>, u64),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum BooleanValue {
|
||||
Random(SmallRng),
|
||||
Random,
|
||||
Toggle(bool),
|
||||
}
|
||||
|
||||
struct ByteCounter<W> {
|
||||
|
@ -722,6 +748,7 @@ pub struct Output {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use chrono::TimeZone;
|
||||
use rand::{SeedableRng, rngs::SmallRng};
|
||||
|
||||
use super::*;
|
||||
use crate::specification::{FieldSpec, TagSpec};
|
||||
|
|
|
@ -130,6 +130,8 @@ pub struct FieldSpec {
|
|||
pub enum FieldKind {
|
||||
/// generates a random bool for the value of this field
|
||||
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
|
||||
String(String),
|
||||
/// generate a random string of this length for every line this field is present
|
||||
|
@ -147,6 +149,9 @@ pub enum FieldKind {
|
|||
Float(f64),
|
||||
/// generate a random float in this range for every line this field is present
|
||||
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)]
|
||||
|
|
Loading…
Reference in New Issue