diff --git a/README.md b/README.md index 9878000..32048dd 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,17 @@ provided a dataset will be generated under: * `number`k.spaces.json -- The reference spaces for that dataset * `number`k.objects.json -- The objects randomly generated (`number` features, each with 1000 positions.) -Example to create 3 datasets, of 1, 10 and 100 features respectively: +You can also specify a factor value, which will generate for each feature `factor` times features sharing the same 1000 positions. + +For example: ```sh +# Generate 3 datasets, with 1k, 10k, 100k, random positions and +# 1, 10 & 100 features ids. cargo run --release -- 1 10 100 + +# Generate 3 datasets, with 1k, 10k, 100k, random positions and +# 2, 20, 200 features ids. +cargo run --release -- 1 10 100 -f 2 ``` ## Acknowledgements diff --git a/src/main.rs b/src/main.rs index 39a8de5..848e525 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,8 +77,14 @@ where .unwrap_or_else(|e| panic!("Unable to serialize to '{}': {}", to, e)); } -fn get_point(space_name: &str, rng: &mut ThreadRng, die: &Uniform) -> SpatialObject { +fn get_point( + factor: usize, + space_name: &str, + rng: &mut ThreadRng, + die: &Uniform, +) -> Vec { let mut shapes = Vec::with_capacity(POSITIONS_PER_SHAPE); + let mut v = Vec::with_capacity(factor); for _ in 0..POSITIONS_PER_SHAPE { shapes.push(Shape { @@ -88,22 +94,36 @@ fn get_point(space_name: &str, rng: &mut ThreadRng, die: &Uniform) -> Spati }); } - SpatialObject { + for _ in 0..(factor - 1) { + v.push(SpatialObject { + properties: Properties { + type_name: "Feature".to_string(), + id: format!("oid{}", die.sample(rng)), + }, + shapes: shapes.clone(), + }); + } + + // Last overlaping point can own the vector of position, saves a clone which + // would be simply discarded right away. + v.push(SpatialObject { properties: Properties { type_name: "Feature".to_string(), id: format!("oid{}", die.sample(rng)), }, shapes, - } + }); + + v } -fn get_space(nb_points: usize, rng: &mut ThreadRng, die: &Uniform) { +fn get_space(nb_points: usize, factor: usize, rng: &mut ThreadRng, die: &Uniform) { let space_name = "std"; let mut objects = Vec::with_capacity(nb_points); for _ in 0..nb_points { - objects.push(get_point(&space_name, rng, &die)); + objects.append(&mut get_point(factor, &space_name, rng, &die)); } store(format!("{}k", nb_points).as_str(), objects); @@ -111,6 +131,9 @@ fn get_space(nb_points: usize, rng: &mut ThreadRng, die: &Uniform) { #[derive(StructOpt, Debug)] struct Opt { + /// Number of ids per positions generated + #[structopt(long, short)] + factor: Option, /// List of Number of features to be generated. datasets: Vec, } @@ -118,10 +141,15 @@ struct Opt { fn main() { let opt = Opt::from_args(); + let factor = match opt.factor { + None => 1, + Some(val) => val, + }; + let mut rng = rand::thread_rng(); let die = Uniform::from(0.0..1.0); for dataset in opt.datasets { - get_space(dataset, &mut rng, &die); + get_space(dataset, factor, &mut rng, &die); } }