You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bigtop.apache.org by rn...@apache.org on 2015/08/25 15:48:10 UTC
[10/23] bigtop git commit: BIGTOP-1983. Move BigPetStore data
generator to bigtop-data-generators
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/RouletteWheelSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/RouletteWheelSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/RouletteWheelSampler.java
new file mode 100644
index 0000000..0353708
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/RouletteWheelSampler.java
@@ -0,0 +1,111 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.framework.samplers;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Random;
+
+import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
+import org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs.MultinomialPDF;
+import org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs.ProbabilityDensityFunction;
+import org.apache.commons.lang3.tuple.Pair;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Maps;
+
+public class RouletteWheelSampler<T> implements Sampler<T>
+{
+ Random rng;
+ final ImmutableList<Pair<T, Double>> wheel;
+
+ public static <T> RouletteWheelSampler<T> create(Map<T, Double> domainWeights, SeedFactory factory)
+ {
+ return new RouletteWheelSampler<T>(domainWeights, factory);
+ }
+
+ public static <T> RouletteWheelSampler<T> create(MultinomialPDF<T> pdf, SeedFactory factory)
+ {
+ return new RouletteWheelSampler<T>(pdf.getData(), pdf, factory);
+ }
+
+ public static <T> RouletteWheelSampler<T> create(Collection<T> data, ProbabilityDensityFunction<T> pdf, SeedFactory factory)
+ {
+ return new RouletteWheelSampler<T>(data, pdf, factory);
+ }
+
+ public static <T> RouletteWheelSampler<T> createUniform(Collection<T> data, SeedFactory factory)
+ {
+ Map<T, Double> pdf = Maps.newHashMap();
+ for(T datum : data)
+ {
+ pdf.put(datum, 1.0);
+ }
+
+ return create(pdf, factory);
+ }
+
+ public RouletteWheelSampler(Map<T, Double> domainWeights, SeedFactory factory)
+ {
+ this.rng = new Random(factory.getNextSeed());
+ this.wheel = this.normalize(domainWeights);
+ }
+
+ public RouletteWheelSampler(Collection<T> data, ProbabilityDensityFunction<T> pdf, SeedFactory factory)
+ {
+ this.rng = new Random(factory.getNextSeed());
+
+ Map<T, Double> domainWeights = Maps.newHashMap();
+ for(T datum : data)
+ {
+ double prob = pdf.probability(datum);
+ domainWeights.put(datum, prob);
+ }
+
+ this.wheel = this.normalize(domainWeights);
+ }
+
+ private ImmutableList<Pair<T, Double>> normalize(Map<T, Double> domainWeights)
+ {
+ double weightSum = 0.0;
+ for(Map.Entry<T, Double> entry : domainWeights.entrySet())
+ {
+ weightSum += entry.getValue();
+ }
+
+ double cumProb = 0.0;
+ ImmutableList.Builder<Pair<T, Double>> builder = ImmutableList.builder();
+ for(Map.Entry<T, Double> entry : domainWeights.entrySet())
+ {
+ double prob = entry.getValue() / weightSum;
+ cumProb += prob;
+
+ builder.add(Pair.of(entry.getKey(), cumProb));
+ }
+
+ return builder.build();
+ }
+
+ public T sample()
+ {
+ double r = rng.nextDouble();
+ for(Pair<T, Double> cumProbPair : wheel)
+ if(r < cumProbPair.getValue())
+ return cumProbPair.getKey();
+
+ throw new IllegalStateException("Invalid state -- RouletteWheelSampler should never fail to sample!");
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/Sampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/Sampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/Sampler.java
new file mode 100644
index 0000000..08af7e0
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/Sampler.java
@@ -0,0 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.framework.samplers;
+
+public interface Sampler<T>
+{
+ public T sample() throws Exception;
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/SequenceSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/SequenceSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/SequenceSampler.java
new file mode 100644
index 0000000..a81c846
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/SequenceSampler.java
@@ -0,0 +1,70 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.framework.samplers;
+
+public class SequenceSampler implements Sampler<Integer>
+{
+ Integer start;
+ Integer end;
+ Integer step;
+ Integer next;
+
+ public SequenceSampler()
+ {
+ start = 0;
+ end = null;
+ step = 1;
+ next = start;
+ }
+
+ public SequenceSampler(Integer start)
+ {
+ this.start = start;
+ end = null;
+ step = 1;
+ next = start;
+ }
+
+ public SequenceSampler(Integer start, Integer end)
+ {
+ this.start = start;
+ this.end = end;
+ step = 1;
+ next = start;
+ }
+
+ public SequenceSampler(Integer start, Integer end, Integer step)
+ {
+ this.start = start;
+ this.end = end;
+ this.step = step;
+ next = start;
+ }
+
+ public Integer sample() throws Exception
+ {
+ if(end == null || next < end)
+ {
+ Integer current = next;
+ next = current + step;
+ return current;
+ }
+
+ throw new Exception("All values have been sampled");
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/StatefulMonteCarloSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/StatefulMonteCarloSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/StatefulMonteCarloSampler.java
new file mode 100644
index 0000000..c447692
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/StatefulMonteCarloSampler.java
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.framework.samplers;
+
+import java.util.Random;
+
+import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
+import org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs.ConditionalProbabilityDensityFunction;
+
+
+public class StatefulMonteCarloSampler<T> implements Sampler<T>
+{
+ private final Sampler<T> stateSampler;
+ private final Random rng;
+ private final ConditionalProbabilityDensityFunction<T, T> acceptancePDF;
+ private T currentState;
+
+ public StatefulMonteCarloSampler(Sampler<T> stateGenerator,
+ ConditionalProbabilityDensityFunction<T, T> acceptancePDF,
+ T initialState,
+ SeedFactory seedFactory)
+ {
+ this.acceptancePDF = acceptancePDF;
+ this.stateSampler = stateGenerator;
+
+ rng = new Random(seedFactory.getNextSeed());
+
+ this.currentState = initialState;
+ }
+
+ public T sample() throws Exception
+ {
+ while(true)
+ {
+ T proposedState = this.stateSampler.sample();
+ double probability = acceptancePDF.probability(proposedState, currentState);
+ double r = rng.nextDouble();
+
+ if(r < probability)
+ {
+ this.currentState = proposedState;
+ return proposedState;
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/UniformIntSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/UniformIntSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/UniformIntSampler.java
new file mode 100644
index 0000000..3fdf550
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/UniformIntSampler.java
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.framework.samplers;
+
+import java.util.Random;
+
+import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
+
+public class UniformIntSampler implements Sampler<Integer>
+{
+ int lowerbound;
+ int upperbound;
+ Random rng;
+
+ /*
+ * Upperbound is inclusive
+ */
+ public UniformIntSampler(int lowerbound, int upperbound, SeedFactory seedFactory)
+ {
+ this.lowerbound = lowerbound;
+ this.upperbound = upperbound;
+ rng = new Random(seedFactory.getNextSeed());
+ }
+
+ public Integer sample()
+ {
+ int range = upperbound + 1 - lowerbound;
+ return rng.nextInt(range) + lowerbound;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/UniformSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/UniformSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/UniformSampler.java
new file mode 100644
index 0000000..3f78471
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/UniformSampler.java
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.framework.samplers;
+
+import java.util.Random;
+
+import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
+
+public class UniformSampler implements Sampler<Double>
+{
+ final Random rng;
+ final double lowerbound;
+ final double upperbound;
+
+ public UniformSampler(SeedFactory seedFactory)
+ {
+ rng = new Random(seedFactory.getNextSeed());
+ lowerbound = 0.0;
+ upperbound = 1.0;
+ }
+
+ public UniformSampler(double lowerbound, double upperbound, SeedFactory seedFactory)
+ {
+ rng = new Random(seedFactory.getNextSeed());
+ this.lowerbound = lowerbound;
+ this.upperbound = upperbound;
+ }
+
+ public Double sample()
+ {
+ return (upperbound - lowerbound) * rng.nextDouble() + lowerbound;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/wfs/ConditionalWeightFunction.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/wfs/ConditionalWeightFunction.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/wfs/ConditionalWeightFunction.java
new file mode 100644
index 0000000..603e5e9
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/wfs/ConditionalWeightFunction.java
@@ -0,0 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.framework.wfs;
+
+public interface ConditionalWeightFunction<T, S>
+{
+ public double weight(T datum, S given);
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/wfs/WeightFunction.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/wfs/WeightFunction.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/wfs/WeightFunction.java
new file mode 100644
index 0000000..1145043
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/wfs/WeightFunction.java
@@ -0,0 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.framework.wfs;
+
+public interface WeightFunction<T>
+{
+ public double weight(T datum);
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerLocationPDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerLocationPDF.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerLocationPDF.java
new file mode 100644
index 0000000..bb97a60
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerLocationPDF.java
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.generators.customer;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Store;
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord;
+import org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs.ProbabilityDensityFunction;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+
+public class CustomerLocationPDF implements ProbabilityDensityFunction<ZipcodeRecord>
+{
+ private final Map<ZipcodeRecord, Double> pdf;
+
+ public CustomerLocationPDF(List<ZipcodeRecord> zipcodes, Store store, double averageDistance)
+ {
+ this.pdf = build(zipcodes, store, averageDistance);
+ }
+
+ protected ImmutableMap<ZipcodeRecord, Double> build(List<ZipcodeRecord> zipcodeTable,
+ Store store, double averageDistance)
+ {
+ double lambda = 1.0 / averageDistance;
+
+ Map<ZipcodeRecord, Double> zipcodeWeights = Maps.newHashMap();
+ double totalWeight = 0.0;
+ for(ZipcodeRecord record : zipcodeTable)
+ {
+ double dist = record.distance(store.getLocation());
+
+ double weight = lambda * Math.exp(-1.0 * lambda * dist);
+ totalWeight += weight;
+ zipcodeWeights.put(record, weight);
+ }
+
+ Map<ZipcodeRecord, Double> pdf = Maps.newHashMap();
+ for(ZipcodeRecord record : zipcodeTable)
+ {
+ pdf.put(record, zipcodeWeights.get(record) / totalWeight);
+ }
+
+ return ImmutableMap.copyOf(pdf);
+ }
+
+ public double probability(ZipcodeRecord record)
+ {
+ if(!this.pdf.containsKey(record))
+ return 0.0;
+
+ return this.pdf.get(record);
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerSampler.java
new file mode 100644
index 0000000..8ef96f0
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerSampler.java
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.generators.customer;
+
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Customer;
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Store;
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord;
+import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.ConditionalSampler;
+import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
+import org.apache.commons.lang3.tuple.Pair;
+
+public class CustomerSampler implements Sampler<Customer>
+{
+ private final Sampler<Integer> idSampler;
+ private final Sampler<String> firstNameSampler;
+ private final Sampler<String> lastNameSampler;
+ private final Sampler<Store> storeSampler;
+ private final ConditionalSampler<ZipcodeRecord, Store> locationSampler;
+
+
+ public CustomerSampler(Sampler<Integer> idSampler, Sampler<String> firstNameSampler,
+ Sampler<String> lastNameSampler, Sampler<Store> storeSampler,
+ ConditionalSampler<ZipcodeRecord, Store> locationSampler)
+ {
+ this.idSampler = idSampler;
+ this.firstNameSampler = firstNameSampler;
+ this.lastNameSampler = lastNameSampler;
+ this.storeSampler = storeSampler;
+ this.locationSampler = locationSampler;
+ }
+
+ public Customer sample() throws Exception
+ {
+ Integer id = idSampler.sample();
+ Pair<String, String> name = Pair.of(firstNameSampler.sample(),
+ lastNameSampler.sample());
+ Store store = storeSampler.sample();
+ ZipcodeRecord location = locationSampler.sample(store);
+
+ return new Customer(id, name, store, location);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerSamplerBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerSamplerBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerSamplerBuilder.java
new file mode 100644
index 0000000..4b449e8
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerSamplerBuilder.java
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.generators.customer;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.bigtop.bigpetstore.datagenerator.Constants;
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Customer;
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Store;
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.InputData;
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord;
+import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
+import org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs.ProbabilityDensityFunction;
+import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.ConditionalSampler;
+import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.RouletteWheelSampler;
+import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
+import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.SequenceSampler;
+
+import com.google.common.collect.Maps;
+
+public class CustomerSamplerBuilder
+{
+ private final List<Store> stores;
+ private final InputData inputData;
+ private final SeedFactory seedFactory;
+
+ public CustomerSamplerBuilder(List<Store> stores, InputData inputData, SeedFactory seedFactory)
+ {
+ this.stores = stores;
+ this.seedFactory = seedFactory;
+ this.inputData = inputData;
+ }
+
+ protected ConditionalSampler<ZipcodeRecord, Store> buildLocationSampler()
+ {
+ final Map<Store, Sampler<ZipcodeRecord>> locationSamplers = Maps.newHashMap();
+ for(Store store : stores)
+ {
+ ProbabilityDensityFunction<ZipcodeRecord> locationPDF = new CustomerLocationPDF(inputData.getZipcodeTable(),
+ store, Constants.AVERAGE_CUSTOMER_STORE_DISTANCE);
+ Sampler<ZipcodeRecord> locationSampler = RouletteWheelSampler.create(inputData.getZipcodeTable(), locationPDF, seedFactory);
+ locationSamplers.put(store, locationSampler);
+ }
+
+ return new ConditionalSampler<ZipcodeRecord, Store>()
+ {
+ public ZipcodeRecord sample(Store store) throws Exception
+ {
+ return locationSamplers.get(store).sample();
+ }
+ };
+ }
+
+ public Sampler<Customer> build()
+ {
+ ProbabilityDensityFunction<Store> storePDF = new CustomerStorePDF(stores);
+
+ Sampler<Integer> idSampler = new SequenceSampler();
+ Sampler<String> firstNameSampler = RouletteWheelSampler.create(inputData.getNames().getFirstNames(), seedFactory);
+ Sampler<String> lastNameSampler = RouletteWheelSampler.create(inputData.getNames().getLastNames(), seedFactory);
+ Sampler<Store> storeSampler = RouletteWheelSampler.create(stores, storePDF, seedFactory);
+
+ return new CustomerSampler(idSampler, firstNameSampler, lastNameSampler, storeSampler, buildLocationSampler());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerStorePDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerStorePDF.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerStorePDF.java
new file mode 100644
index 0000000..400b02a
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerStorePDF.java
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.generators.customer;
+
+import java.util.List;
+
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Store;
+import org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs.ProbabilityDensityFunction;
+
+public class CustomerStorePDF implements ProbabilityDensityFunction<Store>
+{
+ double populationSum = 0.0;
+
+ public CustomerStorePDF(List<Store> stores)
+ {
+ for(Store store : stores)
+ {
+ populationSum += (double) store.getLocation().getPopulation();
+ }
+ }
+
+ @Override
+ public double probability(Store store)
+ {
+ return ((double) store.getLocation().getPopulation()) / populationSum;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductBuilderIterator.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductBuilderIterator.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductBuilderIterator.java
new file mode 100644
index 0000000..c7dd0ab
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductBuilderIterator.java
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.generators.products;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.bigtop.bigpetstore.datagenerator.Constants;
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
+
+import com.google.common.collect.Maps;
+
+public class ProductBuilderIterator implements Iterator<Product>
+{
+ Iterator<Map<String, ProductFieldValue>> productIterator;
+ double basePrice;
+ String productCategory;
+
+ public ProductBuilderIterator(double basePrice, String productCategory,
+ Iterator<Map<String, ProductFieldValue>> productIterator)
+ {
+ this.productIterator = productIterator;
+ this.basePrice = basePrice;
+ this.productCategory = productCategory;
+ }
+
+ @Override
+ public boolean hasNext()
+ {
+ return productIterator != null && productIterator.hasNext();
+ }
+
+ @Override
+ public Product next()
+ {
+ Map<String, ProductFieldValue> productComponents = productIterator.next();
+
+ double sum = 0.0;
+ double product = 1.0;
+
+ Map<String, Object> productFields = Maps.newHashMap();
+
+ for(Map.Entry<String, ProductFieldValue> entry : productComponents.entrySet())
+ {
+ productFields.put(entry.getKey(), entry.getValue().getValue());
+ sum += entry.getValue().getAdd();
+ product *= entry.getValue().getMultiply();
+ }
+
+ double quantity = (Double) productFields.get(Constants.PRODUCT_QUANTITY);
+ double price = product * (sum + basePrice);
+ double unitPrice = price / quantity;
+
+ productFields.put(Constants.PRODUCT_UNIT_PRICE, unitPrice);
+ productFields.put(Constants.PRODUCT_PRICE, price);
+ productFields.put(Constants.PRODUCT_CATEGORY, productCategory);
+
+ return new Product(productFields);
+ }
+
+ @Override
+ public void remove()
+ {
+ throw new UnsupportedOperationException("ProductBuilder does not support remove()");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductCategoryBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductCategoryBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductCategoryBuilder.java
new file mode 100644
index 0000000..df8ae12
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductCategoryBuilder.java
@@ -0,0 +1,195 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.generators.products;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Vector;
+
+import org.apache.bigtop.bigpetstore.datagenerator.Constants;
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.PetSpecies;
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules.AlwaysTrueRule;
+import org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules.NotRule;
+import org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules.OrRule;
+import org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules.Rule;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+
+public class ProductCategoryBuilder
+{
+ String categoryLabel;
+ Set<PetSpecies> applicableSpecies;
+ Boolean triggerTransaction;
+ Double dailyUsageRate;
+ Double amountUsedPerPetAverage;
+ Double amountUsedPerPetVariance;
+ Double triggerTransactionRate;
+ Double triggerPurchaseRate;
+ List<Rule> exclusionRules;
+ Map<String, Collection<ProductFieldValue>> productFieldValues;
+ Double basePrice;
+ List<Product> products;
+
+ public ProductCategoryBuilder()
+ {
+ applicableSpecies = Sets.newHashSet();
+
+ dailyUsageRate = 0.0;
+ amountUsedPerPetAverage = 0.0;
+ amountUsedPerPetVariance = 0.0;
+ triggerTransactionRate = 0.0;
+ triggerPurchaseRate = 0.0;
+ triggerTransaction = false;
+ categoryLabel = null;
+ exclusionRules = new Vector<Rule>();
+ productFieldValues = Maps.newHashMap();
+ basePrice = 1.0;
+ products = Lists.newArrayList();
+ }
+
+ public void setCategory(String category)
+ {
+ this.categoryLabel = category;
+ }
+
+ public void setTriggerTransaction(Boolean triggerTransaction)
+ {
+ this.triggerTransaction = triggerTransaction;
+ }
+
+ public void setDailyUsageRate(Double dailyUsageRate)
+ {
+ this.dailyUsageRate = dailyUsageRate;
+ }
+
+ public void setAmountUsedPetPetAverage(Double baseAmountUsedAverage)
+ {
+ this.amountUsedPerPetAverage = baseAmountUsedAverage;
+ }
+
+ public void setAmountUsedPetPetVariance(Double baseAmountUsedVariance)
+ {
+ this.amountUsedPerPetVariance = baseAmountUsedVariance;
+ }
+
+ public void setTriggerTransactionRate(Double triggerTransactionRate)
+ {
+ this.triggerTransactionRate = triggerTransactionRate;
+ }
+
+ public void setTriggerPurchaseRate(Double triggerPurchaseRate)
+ {
+ this.triggerPurchaseRate = triggerPurchaseRate;
+ }
+
+ public void addApplicableSpecies(PetSpecies species)
+ {
+ this.applicableSpecies.add(species);
+ }
+
+ public void addProduct(Product product)
+ {
+ products.add(product);
+ }
+
+ public void addExclusionRule(Rule rule)
+ {
+ this.exclusionRules.add(rule);
+ }
+
+ public void addPropertyValues(String fieldName, ProductFieldValue ... values)
+ {
+ this.productFieldValues.put(fieldName, Arrays.asList(values));
+ }
+
+ public void setBasePrice(double basePrice)
+ {
+ this.basePrice = basePrice;
+ }
+
+
+ protected List<Product> generateProducts()
+ {
+ Rule combinedRules = new NotRule(new AlwaysTrueRule());
+ if(exclusionRules.size() == 1)
+ {
+ combinedRules = exclusionRules.get(0);
+ }
+ else if(exclusionRules.size() > 1)
+ {
+ combinedRules = new OrRule(exclusionRules.toArray(new Rule[] {}));
+ }
+
+ Iterator<Product> productIterator = new ProductIterator(productFieldValues, combinedRules,
+ basePrice, categoryLabel);
+
+ while(productIterator.hasNext())
+ {
+ products.add(productIterator.next());
+ }
+
+ return products;
+ }
+
+ public void validateProducts()
+ {
+ for(Product product : products)
+ {
+ if(!product.getFieldNames().contains(Constants.PRODUCT_CATEGORY))
+ {
+ throw new IllegalStateException("Product must have field " + Constants.PRODUCT_CATEGORY);
+ }
+
+ if(!product.getFieldNames().contains(Constants.PRODUCT_QUANTITY))
+ {
+ throw new IllegalStateException("Product must have field " + Constants.PRODUCT_QUANTITY);
+ }
+
+ if(!product.getFieldNames().contains(Constants.PRODUCT_PRICE))
+ {
+ throw new IllegalStateException("Product must have field " + Constants.PRODUCT_PRICE);
+ }
+
+ if(!product.getFieldNames().contains(Constants.PRODUCT_UNIT_PRICE))
+ {
+ throw new IllegalStateException("Product must have field " + Constants.PRODUCT_UNIT_PRICE);
+ }
+ }
+ }
+
+ public ProductCategory build()
+ {
+ List<Product> products = generateProducts();
+
+ Set<String> fieldNames = Sets.newHashSet();
+ for(Product product : products)
+ {
+ fieldNames.addAll(product.getFieldNames());
+ }
+
+ return new ProductCategory(categoryLabel, applicableSpecies, fieldNames, triggerTransaction,
+ dailyUsageRate, amountUsedPerPetAverage, amountUsedPerPetVariance, triggerTransactionRate,
+ triggerPurchaseRate, products);
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductFieldValue.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductFieldValue.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductFieldValue.java
new file mode 100644
index 0000000..fe4d7fa
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductFieldValue.java
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.generators.products;
+
+public class ProductFieldValue
+{
+ Object value;
+ double add;
+ double multiply;
+
+ public ProductFieldValue(Object value, double add, double multiply)
+ {
+ this.value = value;
+ this.add = add;
+ this.multiply = multiply;
+ }
+
+ public Object getValue()
+ {
+ return value;
+ }
+
+ public double getAdd()
+ {
+ return add;
+ }
+
+ public double getMultiply()
+ {
+ return multiply;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductFilterIterator.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductFilterIterator.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductFilterIterator.java
new file mode 100644
index 0000000..c0e285d
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductFilterIterator.java
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.generators.products;
+
+import java.util.Iterator;
+
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
+import org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules.Rule;
+
+public class ProductFilterIterator implements Iterator<Product>
+{
+ Rule rule;
+ Iterator<Product> products;
+ Product buffer;
+
+ public ProductFilterIterator(Rule rule, Iterator<Product> products)
+ {
+ this.rule = rule;
+ this.products = products;
+ this.buffer = getNext();
+ }
+
+ private Product getNext()
+ {
+ while(products.hasNext())
+ {
+ Product product = products.next();
+
+ if(!rule.ruleMatches(product))
+ {
+ return product;
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public boolean hasNext()
+ {
+ return buffer != null;
+ }
+
+ @Override
+ public Product next()
+ {
+ Product previous = buffer;
+ buffer = getNext();
+
+ return previous;
+ }
+
+ @Override
+ public void remove()
+ {
+ throw new UnsupportedOperationException("ProductFilter does not support remove()");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductIterator.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductIterator.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductIterator.java
new file mode 100644
index 0000000..ccfef56
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductIterator.java
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.generators.products;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
+import org.apache.bigtop.bigpetstore.datagenerator.generators.products.cartesian.CartesianProduct;
+import org.apache.bigtop.bigpetstore.datagenerator.generators.products.cartesian.CartesianProductBase;
+import org.apache.bigtop.bigpetstore.datagenerator.generators.products.cartesian.CartesianProductField;
+import org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules.Rule;
+
+public class ProductIterator implements Iterator<Product>
+{
+
+ Iterator<Product> productIterator;
+
+ public ProductIterator(Map<String, Collection<ProductFieldValue>> fieldValues, Rule matcher,
+ double basePrice, String productCategory)
+ {
+ productIterator = new ProductFilterIterator(matcher,
+ new ProductBuilderIterator(basePrice, productCategory,
+ buildCartesianProductIterator(fieldValues)));
+ }
+
+ public Iterator<Map<String, ProductFieldValue>>
+ buildCartesianProductIterator(Map<String, Collection<ProductFieldValue>> fieldValues)
+ {
+ CartesianProduct<ProductFieldValue> product = null;
+ for(Map.Entry<String, Collection<ProductFieldValue>> pair : fieldValues.entrySet())
+ {
+ if(product == null)
+ {
+ product = new CartesianProductBase<ProductFieldValue>(pair.getKey(), pair.getValue());
+ } else
+ {
+ product = new CartesianProductField<ProductFieldValue>(pair.getKey(), pair.getValue(), product);
+ }
+
+ }
+
+ return product;
+ }
+
+ @Override
+ public boolean hasNext()
+ {
+ return productIterator.hasNext();
+ }
+
+ @Override
+ public Product next()
+ {
+ return productIterator.next();
+ }
+
+ @Override
+ public void remove()
+ {
+ throw new UnsupportedOperationException("ProductIterator does not support remove()");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/CartesianProduct.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/CartesianProduct.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/CartesianProduct.java
new file mode 100644
index 0000000..f688980
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/CartesianProduct.java
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.generators.products.cartesian;
+
+import java.util.Iterator;
+import java.util.Map;
+
+public interface CartesianProduct<T> extends Iterator<Map<String, T>>
+{
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/CartesianProductBase.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/CartesianProductBase.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/CartesianProductBase.java
new file mode 100644
index 0000000..7b0934c
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/CartesianProductBase.java
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.generators.products.cartesian;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+
+public class CartesianProductBase<T> implements CartesianProduct<T>
+{
+ String fieldName;
+ Iterator<T> fieldValues;
+
+ public CartesianProductBase(String fieldName, Collection<T> fieldValues)
+ {
+ this.fieldName = fieldName;
+ this.fieldValues = fieldValues.iterator();
+ }
+
+
+ @Override
+ public boolean hasNext()
+ {
+ return fieldValues.hasNext();
+ }
+
+ @Override
+ public Map<String, T> next()
+ {
+ Map<String, T> map = new HashMap<String, T>();
+ map.put(fieldName, fieldValues.next());
+
+ return map;
+ }
+
+ @Override
+ public void remove()
+ {
+ throw new UnsupportedOperationException("CartesianProductBase does not support remove()");
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/CartesianProductField.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/CartesianProductField.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/CartesianProductField.java
new file mode 100644
index 0000000..166efc8
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/CartesianProductField.java
@@ -0,0 +1,79 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.generators.products.cartesian;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+public class CartesianProductField<T> implements CartesianProduct<T>
+{
+ String fieldName;
+ Iterator<T> fieldValuesIterator;
+ Collection<T> fieldValues;
+ CartesianProduct<T> previous;
+ Map<String, T> baseValue;
+
+ public CartesianProductField(String fieldName, Collection<T> fieldValues, CartesianProduct<T> previous)
+ {
+ this.fieldValues = fieldValues;
+ this.fieldName = fieldName;
+ this.previous = previous;
+ }
+
+ @Override
+ public boolean hasNext()
+ {
+ return previous.hasNext() || (fieldValuesIterator != null && fieldValuesIterator.hasNext());
+ }
+
+ @Override
+ public Map<String, T> next()
+ {
+ if(fieldValuesIterator != null)
+ {
+ Map<String, T> map = new HashMap<String, T>(baseValue);
+ map.put(fieldName, fieldValuesIterator.next());
+
+ if(!fieldValuesIterator.hasNext())
+ {
+ fieldValuesIterator = null;
+ }
+
+ return map;
+ } else if(previous.hasNext())
+ {
+ baseValue = previous.next();
+ fieldValuesIterator = fieldValues.iterator();
+
+ Map<String, T> map = new HashMap<String, T>(baseValue);
+ map.put(fieldName, fieldValuesIterator.next());
+
+ return map;
+ }
+
+ throw new NoSuchElementException();
+ }
+
+ @Override
+ public void remove()
+ {
+ throw new UnsupportedOperationException("CartesianProductBase does not support remove()");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/collections/MediumProductCollection.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/collections/MediumProductCollection.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/collections/MediumProductCollection.java
new file mode 100644
index 0000000..2ec72d1
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/collections/MediumProductCollection.java
@@ -0,0 +1,275 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.generators.products.collections;
+
+import java.util.List;
+
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.PetSpecies;
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.bigpetstore.datagenerator.generators.products.ProductCategoryBuilder;
+import org.apache.bigtop.bigpetstore.datagenerator.generators.products.ProductFieldValue;
+import org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules.AndRule;
+import org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules.FieldPredicate;
+import org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules.NotRule;
+import org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules.OrRule;
+
+import com.google.common.collect.Lists;
+
+public class MediumProductCollection
+{
+ private ProductCategory createDogFood()
+ {
+ ProductCategoryBuilder builder = new ProductCategoryBuilder();
+
+ builder.addApplicableSpecies(PetSpecies.DOG);
+ builder.setCategory("dry dog food");
+ builder.setTriggerTransaction(true);
+ builder.setDailyUsageRate(2.0);
+ builder.setAmountUsedPetPetAverage(0.25);
+ builder.setAmountUsedPetPetVariance(0.1);
+ builder.setTriggerTransactionRate(2.0);
+ builder.setTriggerPurchaseRate(7.0);
+ builder.setBasePrice(2.0);
+
+ builder.addPropertyValues("brand",
+ new ProductFieldValue("Wellfed", 0.67, 1.0),
+ new ProductFieldValue("Happy Pup", 0.67, 1.0),
+ new ProductFieldValue("Dog Days", 1.0, 1.0),
+ new ProductFieldValue("Chef Corgi", 0.0, 1.0));
+
+ builder.addPropertyValues("meat",
+ new ProductFieldValue("Chicken", 0.0, 1.0),
+ new ProductFieldValue("Pork", 0.0, 1.0),
+ new ProductFieldValue("Lamb", 0.1, 1.0),
+ new ProductFieldValue("Salmon", 0.25, 1.0),
+ new ProductFieldValue("Venison", 0.5, 1.0),
+ new ProductFieldValue("Rabbit", 0.5, 1.0),
+ new ProductFieldValue("Vegetarian", 0.0, 1.0));
+
+ builder.addPropertyValues("grain",
+ new ProductFieldValue("Corn", 0.0, 1.0),
+ new ProductFieldValue("Potatoes", 0.1, 1.0),
+ new ProductFieldValue("Barley", 0.1, 1.0),
+ new ProductFieldValue("Rice", 0.0, 1.0),
+ new ProductFieldValue("Soy", 0.1, 1.0));
+
+ builder.addPropertyValues("lifestage",
+ new ProductFieldValue("Senior", 0.0, 1.0),
+ new ProductFieldValue("Puppy", 0.0, 1.0),
+ new ProductFieldValue("Adult", 0.0, 1.0));
+
+ builder.addPropertyValues("organic",
+ new ProductFieldValue("false", 0.0, 1.0),
+ new ProductFieldValue("true", 0.0, 1.1));
+
+ builder.addPropertyValues("quantity",
+ new ProductFieldValue(4.5, 0.0, 4.5),
+ new ProductFieldValue(15.0, 0.0, 15.0),
+ new ProductFieldValue(30.0, 0.0, 30.0));
+
+ builder.addExclusionRule(new AndRule(
+ new FieldPredicate("brand", "Chef Corgi"),
+ new FieldPredicate("organic", "true")));
+
+ builder.addExclusionRule(new AndRule(
+ new FieldPredicate("brand", "Chef Corgi"),
+ new FieldPredicate("meat", "Vegetarian")));
+
+ builder.addExclusionRule(new AndRule(
+ new FieldPredicate("brand", "Dog Days"),
+ new FieldPredicate("organic", "false")));
+
+ builder.addExclusionRule(new AndRule(
+ new FieldPredicate("grain", "Corn"),
+ new OrRule(
+ new FieldPredicate("organic", "true"),
+ new FieldPredicate("meat", "Venison"),
+ new FieldPredicate("meat", "Rabbit"),
+ new FieldPredicate("meat", "Lamb"),
+ new FieldPredicate("meat", "Salmon"))));
+
+ builder.addExclusionRule(new AndRule(
+ new FieldPredicate("organic", "true"),
+ new FieldPredicate("meat", "Pork")));
+
+ builder.addExclusionRule(new AndRule(
+ new NotRule(new FieldPredicate("grain", "Corn")),
+ new FieldPredicate("meat", "Pork")));
+
+ builder.addExclusionRule(new AndRule(
+ new OrRule(
+ new FieldPredicate("brand", "Chef Corgi"),
+ new FieldPredicate("brand", "Happy Pup")),
+ new OrRule(
+ new FieldPredicate("meat", "Rabbit"),
+ new FieldPredicate("meat", "Venison"))
+ ));
+
+ return builder.build();
+ }
+
+ private ProductCategory createCatFood()
+ {
+ ProductCategoryBuilder builder = new ProductCategoryBuilder();
+
+ builder.addApplicableSpecies(PetSpecies.CAT);
+ builder.setCategory("dry cat food");
+ builder.setTriggerTransaction(true);
+ builder.setDailyUsageRate(2.0);
+ builder.setAmountUsedPetPetAverage(0.1);
+ builder.setAmountUsedPetPetVariance(0.05);
+ builder.setTriggerTransactionRate(2.0);
+ builder.setTriggerPurchaseRate(7.0);
+ builder.setBasePrice(2.14);
+
+ builder.addPropertyValues("brand",
+ new ProductFieldValue("Wellfed", 0.67, 1.0),
+ new ProductFieldValue("Feisty Feline", 0.72, 1.0),
+ new ProductFieldValue("Pretty Cat", 0.0, 1.0));
+
+ builder.addPropertyValues("meat",
+ new ProductFieldValue("Tuna", 0.0, 1.0),
+ new ProductFieldValue("Chicken", 0.0, 1.0),
+ new ProductFieldValue("Turkey", 0.0, 1.0),
+ new ProductFieldValue("Salmon", 0.1, 1.0));
+
+ builder.addPropertyValues("lifestyle",
+ new ProductFieldValue("Indoor", 0.0, 1.0),
+ new ProductFieldValue("Outdoor", 0.0, 1.0),
+ new ProductFieldValue("Weight Management", 0.1, 1.0));
+
+ builder.addPropertyValues("lifestage",
+ new ProductFieldValue("Senior", 0.0, 1.0),
+ new ProductFieldValue("Kitten", 0.0, 1.0),
+ new ProductFieldValue("Adult", 0.0, 1.0));
+
+ builder.addPropertyValues("organic",
+ new ProductFieldValue("true", 0.0, 1.1),
+ new ProductFieldValue("false", 0.0, 1.0));
+
+ builder.addPropertyValues("quantity",
+ new ProductFieldValue(7.0, 0.0, 7.0),
+ new ProductFieldValue(15.0, 0.0, 15.0));
+
+ builder.addPropertyValues("hairball management",
+ new ProductFieldValue("true", 0.1, 1.0),
+ new ProductFieldValue("false", 0.0, 1.0));
+
+ builder.addExclusionRule(new AndRule(
+ new FieldPredicate("brand", "Pretty Cat"),
+ new FieldPredicate("organic", "true")));
+
+ builder.addExclusionRule(new AndRule(
+ new FieldPredicate("brand", "Feisty Feline"),
+ new FieldPredicate("organic", "false")));
+
+ return builder.build();
+ }
+
+ private ProductCategory createKittyLitter()
+ {
+ ProductCategoryBuilder builder = new ProductCategoryBuilder();
+
+ builder.addApplicableSpecies(PetSpecies.CAT);
+ builder.setCategory("kitty litter");
+ builder.setTriggerTransaction(true);
+ builder.setDailyUsageRate(1.0);
+ builder.setAmountUsedPetPetAverage(0.1);
+ builder.setAmountUsedPetPetVariance(0.05);
+ builder.setTriggerTransactionRate(2.0);
+ builder.setTriggerPurchaseRate(7.0);
+ builder.setBasePrice(1.43);
+
+ builder.addPropertyValues("brand",
+ new ProductFieldValue("Pretty Cat", 0.0, 1.0),
+ new ProductFieldValue("Feisty Feline", 0.1, 1.0));
+
+ builder.addPropertyValues("material",
+ new ProductFieldValue("clay", 0.0, 1.0),
+ new ProductFieldValue("pellets", 0.1, 1.0));
+
+ builder.addPropertyValues("clumping",
+ new ProductFieldValue("true", 0.0, 1.0),
+ new ProductFieldValue("false", 0.0, 1.0));
+
+ builder.addPropertyValues("odor control",
+ new ProductFieldValue("true", 0.1, 1.0),
+ new ProductFieldValue("false", 0.0, 1.0));
+
+ builder.addPropertyValues("quantity",
+ new ProductFieldValue(7.0, 0.0, 7.0),
+ new ProductFieldValue(14.0, 0.0, 14.0),
+ new ProductFieldValue(28.0, 0.0, 28.0));
+
+ return builder.build();
+ }
+
+ private ProductCategory createPoopBags()
+ {
+ ProductCategoryBuilder builder = new ProductCategoryBuilder();
+
+ builder.addApplicableSpecies(PetSpecies.DOG);
+ builder.setCategory("poop bags");
+ builder.setTriggerTransaction(true);
+ builder.setDailyUsageRate(2.0);
+ builder.setAmountUsedPetPetAverage(1.0);
+ builder.setAmountUsedPetPetVariance(0.5);
+ builder.setTriggerTransactionRate(2.0);
+ builder.setTriggerPurchaseRate(7.0);
+ builder.setBasePrice(0.17);
+
+ builder.addPropertyValues("brand",
+ new ProductFieldValue("Chef Corgi", 0.0, 1.0),
+ new ProductFieldValue("Happy Pup", 0.67, 1.0),
+ new ProductFieldValue("Dog Days", 1.0, 1.0));
+
+ builder.addPropertyValues("color",
+ new ProductFieldValue("blue", 0.0, 1.0),
+ new ProductFieldValue("multicolor (pastels)", 0.0, 1.0),
+ new ProductFieldValue("multicolor (solids)", 0.0, 1.0),
+ new ProductFieldValue("designs", 0.0, 1.0));
+
+ builder.addPropertyValues("recycled material",
+ new ProductFieldValue("false", 0.0, 60.0),
+ new ProductFieldValue("true", 0.1, 120.0));
+
+ builder.addPropertyValues("quantity",
+ new ProductFieldValue(60.0, 0.0, 60.0),
+ new ProductFieldValue(120.0, 0.0, 120.0));
+
+ builder.addExclusionRule(new AndRule(
+ new FieldPredicate("brand", "Chef Corgi"),
+ new FieldPredicate("recycled material", "true")));
+
+ builder.addExclusionRule(new AndRule(
+ new FieldPredicate("brand", "Dog Days"),
+ new FieldPredicate("recycled material", "false")));
+
+ return builder.build();
+ }
+
+ public List<ProductCategory> generateProductCategory()
+ {
+ List<ProductCategory> productCategories = Lists.newArrayList();
+
+ productCategories.add(this.createDogFood());
+ productCategories.add(this.createCatFood());
+ productCategories.add(this.createKittyLitter());
+ productCategories.add(this.createPoopBags());
+
+ return productCategories;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/collections/SmallProductCollection.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/collections/SmallProductCollection.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/collections/SmallProductCollection.java
new file mode 100644
index 0000000..8ca71ef
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/collections/SmallProductCollection.java
@@ -0,0 +1,162 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.generators.products.collections;
+
+import java.util.List;
+
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.PetSpecies;
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.bigpetstore.datagenerator.generators.products.ProductCategoryBuilder;
+import org.apache.bigtop.bigpetstore.datagenerator.generators.products.ProductFieldValue;
+
+import com.google.common.collect.Lists;
+
+public class SmallProductCollection
+{
+ private ProductCategory createDogFood()
+ {
+ ProductCategoryBuilder builder = new ProductCategoryBuilder();
+
+ builder.addApplicableSpecies(PetSpecies.DOG);
+ builder.setCategory("dry dog food");
+ builder.setTriggerTransaction(true);
+ builder.setDailyUsageRate(2.0);
+ builder.setAmountUsedPetPetAverage(0.25);
+ builder.setAmountUsedPetPetVariance(0.1);
+ builder.setTriggerTransactionRate(2.0);
+ builder.setTriggerPurchaseRate(7.0);
+ builder.setBasePrice(2.0);
+
+ builder.addPropertyValues("brand",
+ new ProductFieldValue("Wellfed", 0.0, 1.0),
+ new ProductFieldValue("Happy Pup", 0.67, 1.0),
+ new ProductFieldValue("Dog Days", 1.0, 1.0));
+
+ builder.addPropertyValues("flavor",
+ new ProductFieldValue("Chicken", 0.0, 1.0),
+ new ProductFieldValue("Pork", 0.0, 1.0),
+ new ProductFieldValue("Lamb & Rice", 0.0, 1.0),
+ new ProductFieldValue("Fish & Potato", 0.0, 1.0));
+
+ builder.addPropertyValues("quantity",
+ new ProductFieldValue(4.5, 0.0, 4.5),
+ new ProductFieldValue(15.0, 0.0, 15.0),
+ new ProductFieldValue(30.0, 0.0, 30.0));
+
+ return builder.build();
+ }
+
+ private ProductCategory createCatFood()
+ {
+ ProductCategoryBuilder builder = new ProductCategoryBuilder();
+
+ builder.addApplicableSpecies(PetSpecies.CAT);
+ builder.setCategory("dry cat food");
+ builder.setTriggerTransaction(true);
+ builder.setDailyUsageRate(2.0);
+ builder.setAmountUsedPetPetAverage(0.1);
+ builder.setAmountUsedPetPetVariance(0.05);
+ builder.setTriggerTransactionRate(2.0);
+ builder.setTriggerPurchaseRate(7.0);
+ builder.setBasePrice(2.14);
+
+ builder.addPropertyValues("brand",
+ new ProductFieldValue("Wellfed", 0.0, 1.0),
+ new ProductFieldValue("Pretty Cat", 0.72, 1.0),
+ new ProductFieldValue("Feisty Feline", 0.0, 1.0));
+
+ builder.addPropertyValues("flavor",
+ new ProductFieldValue("Tuna", 0.0, 1.0),
+ new ProductFieldValue("Chicken & Rice", 0.0, 1.0));
+
+ builder.addPropertyValues("quantity",
+ new ProductFieldValue(7.0, 0.0, 7.0),
+ new ProductFieldValue(15.0, 0.0, 15.0));
+
+ builder.addPropertyValues("hairball management",
+ new ProductFieldValue("true", 0.0, 1.0),
+ new ProductFieldValue("false", 0.0, 1.0));
+
+ return builder.build();
+ }
+
+ private ProductCategory createKittyLitter()
+ {
+ ProductCategoryBuilder builder = new ProductCategoryBuilder();
+
+ builder.addApplicableSpecies(PetSpecies.CAT);
+ builder.setCategory("kitty litter");
+ builder.setTriggerTransaction(true);
+ builder.setDailyUsageRate(1.0);
+ builder.setAmountUsedPetPetAverage(0.1);
+ builder.setAmountUsedPetPetVariance(0.05);
+ builder.setTriggerTransactionRate(2.0);
+ builder.setTriggerPurchaseRate(7.0);
+ builder.setBasePrice(1.43);
+
+ builder.addPropertyValues("brand",
+ new ProductFieldValue("Pretty Cat", 0.0, 1.0),
+ new ProductFieldValue("Feisty Feline", 0.07, 1.0));
+
+ builder.addPropertyValues("quantity",
+ new ProductFieldValue(7.0, 0.0, 7.0),
+ new ProductFieldValue(14.0, 0.0, 14.0),
+ new ProductFieldValue(28.0, 0.0, 28.0));
+
+ return builder.build();
+ }
+
+ private ProductCategory createPoopBags()
+ {
+ ProductCategoryBuilder builder = new ProductCategoryBuilder();
+
+ builder.addApplicableSpecies(PetSpecies.DOG);
+ builder.setCategory("poop bags");
+ builder.setTriggerTransaction(true);
+ builder.setDailyUsageRate(2.0);
+ builder.setAmountUsedPetPetAverage(1.0);
+ builder.setAmountUsedPetPetVariance(0.5);
+ builder.setTriggerTransactionRate(2.0);
+ builder.setTriggerPurchaseRate(7.0);
+ builder.setBasePrice(0.17);
+
+ builder.addPropertyValues("brand",
+ new ProductFieldValue("Happy Pup", 0.0, 1.0),
+ new ProductFieldValue("Dog Days", 0.04, 1.0));
+
+ builder.addPropertyValues("color",
+ new ProductFieldValue("blue", 0.0, 1.0),
+ new ProductFieldValue("multicolor", 0.0, 1.0));
+
+ builder.addPropertyValues("quantity",
+ new ProductFieldValue(60.0, 0.0, 60.0),
+ new ProductFieldValue(120.0, 0.0, 120.0));
+
+ return builder.build();
+ }
+
+ public List<ProductCategory> generateProductCategory()
+ {
+ List<ProductCategory> productCategories = Lists.newArrayList();
+
+ productCategories.add(this.createDogFood());
+ productCategories.add(this.createCatFood());
+ productCategories.add(this.createKittyLitter());
+ productCategories.add(this.createPoopBags());
+
+ return productCategories;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/AlwaysTrueRule.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/AlwaysTrueRule.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/AlwaysTrueRule.java
new file mode 100644
index 0000000..d973346
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/AlwaysTrueRule.java
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules;
+
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
+
+public class AlwaysTrueRule implements Rule
+{
+
+ @Override
+ public boolean ruleMatches(Product product) throws IllegalArgumentException
+ {
+ return true;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/AndRule.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/AndRule.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/AndRule.java
new file mode 100644
index 0000000..4be89be
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/AndRule.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules;
+
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
+
+public class AndRule implements Rule
+{
+ List<Rule> rules;
+
+ public AndRule(Rule rule1, Rule rule2, Rule ... rules)
+ {
+ this.rules = new LinkedList<Rule>(Arrays.asList(rules));
+ this.rules.add(rule1);
+ this.rules.add(rule2);
+ }
+
+ @Override
+ public boolean ruleMatches(Product product) throws IllegalArgumentException
+ {
+ boolean matches = true;
+ for(Rule rule : rules)
+ {
+ if(! rule.ruleMatches(product))
+ {
+ matches = false;
+ }
+ }
+
+ return matches;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/FieldPredicate.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/FieldPredicate.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/FieldPredicate.java
new file mode 100644
index 0000000..37e7c12
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/FieldPredicate.java
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
+
+public class FieldPredicate implements Rule
+{
+ String fieldName;
+ Collection<String> allowedValues;
+
+ public FieldPredicate(String fieldName, String ... allowedValues)
+ {
+ this.fieldName = fieldName;
+ this.allowedValues = Arrays.asList(allowedValues);
+ }
+
+ @Override
+ public boolean ruleMatches(Product product)
+ {
+ if(! product.getFieldNames().contains(fieldName))
+ {
+ throw new IllegalArgumentException("Product (" + product.toString() +
+ ") does not contain field name (" + fieldName + ")");
+ }
+
+ Object seenValue = product.getFieldValue(fieldName);
+
+ return allowedValues.contains(seenValue);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/NotRule.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/NotRule.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/NotRule.java
new file mode 100644
index 0000000..ffac751
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/NotRule.java
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules;
+
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
+
+public class NotRule implements Rule
+{
+ Rule rule;
+
+ public NotRule(Rule rule)
+ {
+ this.rule = rule;
+ }
+
+
+ @Override
+ public boolean ruleMatches(Product product) throws IllegalArgumentException
+ {
+ return ! rule.ruleMatches(product);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/OrRule.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/OrRule.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/OrRule.java
new file mode 100644
index 0000000..c3ed549
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/OrRule.java
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules;
+
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
+
+public class OrRule implements Rule
+{
+ Rule[] rules;
+
+ public OrRule(Rule ... rules)
+ {
+ this.rules = rules;
+ }
+
+ @Override
+ public boolean ruleMatches(Product product) throws IllegalArgumentException
+ {
+ for(Rule rule : rules)
+ {
+ if(rule.ruleMatches(product))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+}