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 16:21:35 UTC
[01/11] bigtop git commit: BIGTOP-1984. Extract samplers library from
BigPetStore data generator
Repository: bigtop
Updated Branches:
refs/heads/master 3bbbb557a -> 15af83ebd
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/markovmodels/TestMarkovModelBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/markovmodels/TestMarkovModelBuilder.java b/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/markovmodels/TestMarkovModelBuilder.java
new file mode 100644
index 0000000..6aa6a6a
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/markovmodels/TestMarkovModelBuilder.java
@@ -0,0 +1,76 @@
+/**
+ * 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.datagenerators.samplers.markovmodels;
+
+import org.apache.bigtop.datagenerators.samplers.markovmodels.MarkovModel;
+import org.apache.bigtop.datagenerators.samplers.markovmodels.MarkovModelBuilder;
+import org.junit.Test;
+
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.matchers.JUnitMatchers.*;
+
+public class TestMarkovModelBuilder
+{
+
+ @Test
+ public void testAddStateState()
+ {
+ MarkovModelBuilder<String> builder = MarkovModelBuilder.create();
+
+ builder.addStartState("a", 1.0);
+
+ MarkovModel<String> msm = builder.build();
+
+ assertThat(msm.getStartWeights().keySet(), hasItem("a"));
+ assertEquals((double) msm.getStartWeights().get("a"), (double) 1.0, 0.000001);
+
+ }
+
+ @Test
+ public void testAddEdgeTransition()
+ {
+ MarkovModelBuilder<String> builder = MarkovModelBuilder.create();
+
+ builder.addTransition("a", "b", 1.0);
+
+ MarkovModel<String> msm = builder.build();
+
+ assertThat(msm.getTransitionWeights().keySet(), hasItem("a"));
+ assertThat(msm.getTransitionWeights().get("a").keySet(), hasItem("b"));
+ assertEquals((double) msm.getTransitionWeights().get("a").get("b"), (double) 1.0, 0.000001);
+ }
+
+ @Test
+ public void testBuildMSM()
+ {
+ MarkovModelBuilder<String> builder = MarkovModelBuilder.create();
+
+ builder.addStartState("a", 1.0);
+ builder.addTransition("a", "b", 1.0);
+ builder.addTransition("a", "c", 1.0);
+
+ MarkovModel<String> msm = builder.build();
+
+ assertThat(msm.getStartWeights().keySet(), hasItem("a"));
+ assertThat(msm.getTransitionWeights().keySet(), hasItem("a"));
+ assertThat(msm.getTransitionWeights().get("a").keySet(), hasItem("b"));
+ assertThat(msm.getTransitionWeights().get("a").keySet(), hasItem("c"));
+ assertEquals((double) msm.getTransitionWeights().get("a").get("b"), (double) 1.0, 0.000001);
+ assertEquals((double) msm.getTransitionWeights().get("a").get("c"), (double) 1.0, 0.000001);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/markovmodels/TestMarkovProcess.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/markovmodels/TestMarkovProcess.java b/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/markovmodels/TestMarkovProcess.java
new file mode 100644
index 0000000..a26f31c
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/markovmodels/TestMarkovProcess.java
@@ -0,0 +1,53 @@
+/**
+ * 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.datagenerators.samplers.markovmodels;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.hasItem;
+
+import java.util.Arrays;
+
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.markovmodels.MarkovModel;
+import org.apache.bigtop.datagenerators.samplers.markovmodels.MarkovModelBuilder;
+import org.apache.bigtop.datagenerators.samplers.markovmodels.MarkovProcess;
+import org.junit.Test;
+
+public class TestMarkovProcess
+{
+
+ @Test
+ public void test() throws Exception
+ {
+ SeedFactory factory = new SeedFactory(1245);
+ MarkovModelBuilder<String> builder = MarkovModelBuilder.create();
+
+ builder.addStartState("a", 1.0);
+ builder.addTransition("a", "b", 1.0);
+ builder.addTransition("a", "c", 1.0);
+
+ MarkovModel<String> msm = builder.build();
+ MarkovProcess<String> process = MarkovProcess.create(msm, factory);
+
+ String firstState = process.sample();
+ assertEquals(firstState, "a");
+
+ String secondState = process.sample();
+ assertThat(Arrays.asList("b", "c"), hasItem(secondState));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/pdfs/TestMultinomialPDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/pdfs/TestMultinomialPDF.java b/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/pdfs/TestMultinomialPDF.java
new file mode 100644
index 0000000..17e1d5e
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/pdfs/TestMultinomialPDF.java
@@ -0,0 +1,42 @@
+/**
+ * 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.datagenerators.samplers.pdfs;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.bigtop.datagenerators.samplers.pdfs.MultinomialPDF;
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Sets;
+
+public class TestMultinomialPDF
+{
+
+ @Test
+ public void testToString()
+ {
+ Map<String, Double> objects = ImmutableMap.of("A", 0.1, "B", 0.3, "C", 0.5);
+ MultinomialPDF<String> pdf = new MultinomialPDF<String>(objects);
+ String string = pdf.toString();
+ Set<String> observed = Sets.newHashSet(string.split("\n"));
+ Set<String> expected = Sets.newHashSet("0.1,A", "0.3,B", "0.5,C");
+
+ Assert.assertEquals(expected, observed);
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/samplers/TestBoundedMultiModalGaussianSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/samplers/TestBoundedMultiModalGaussianSampler.java b/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/samplers/TestBoundedMultiModalGaussianSampler.java
new file mode 100644
index 0000000..54d9e41
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/samplers/TestBoundedMultiModalGaussianSampler.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.datagenerators.samplers.samplers;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.BoundedMultiModalGaussianSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.apache.commons.lang3.tuple.Pair;
+import org.junit.Test;
+
+import com.google.common.collect.Lists;
+
+public class TestBoundedMultiModalGaussianSampler
+{
+
+ @Test
+ public void testSample() throws Exception
+ {
+ double upperbound = 10.0;
+ double lowerbound = 1.0;
+
+ List<Pair<Double, Double>> distributions = Lists.newArrayList(Pair.of(2.0, 2.0), Pair.of(7.5, 2.0));
+
+ SeedFactory seedFactory = new SeedFactory(1234);
+
+ Sampler<Double> sampler = new BoundedMultiModalGaussianSampler(distributions, lowerbound, upperbound, seedFactory);
+
+ Double result = sampler.sample();
+
+ assertTrue(result >= lowerbound);
+ assertTrue(result <= upperbound);
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/samplers/TestExponentialSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/samplers/TestExponentialSampler.java b/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/samplers/TestExponentialSampler.java
new file mode 100644
index 0000000..b04015a
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/samplers/TestExponentialSampler.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.datagenerators.samplers.samplers;
+
+import static org.junit.Assert.assertTrue;
+
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.ExponentialSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.junit.Test;
+
+public class TestExponentialSampler
+{
+
+ @Test
+ public void testSample() throws Exception
+ {
+ double lambda = 1.0 / 2.0;
+
+ SeedFactory seedFactory = new SeedFactory(1234);
+
+ Sampler<Double> sampler = new ExponentialSampler(lambda, seedFactory);
+
+ Double result = sampler.sample();
+
+ assertTrue(result >= 0.0);
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/samplers/TestGaussianSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/samplers/TestGaussianSampler.java b/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/samplers/TestGaussianSampler.java
new file mode 100644
index 0000000..9c816b5
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/samplers/TestGaussianSampler.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.datagenerators.samplers.samplers;
+
+import static org.junit.Assert.assertTrue;
+
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.GaussianSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.junit.Test;
+
+public class TestGaussianSampler
+{
+
+ @Test
+ public void testSample() throws Exception
+ {
+ double mean = 2.0;
+ double var = 1.0;
+
+ SeedFactory seedFactory = new SeedFactory(1234);
+
+ Sampler<Double> sampler = new GaussianSampler(mean, var, seedFactory);
+
+ Double result = sampler.sample();
+
+ assertTrue(result >= -10);
+ assertTrue(result <= 10);
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/samplers/TestRouletteWheelSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/samplers/TestRouletteWheelSampler.java b/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/samplers/TestRouletteWheelSampler.java
new file mode 100644
index 0000000..0c4cc05
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/samplers/TestRouletteWheelSampler.java
@@ -0,0 +1,71 @@
+/**
+ * 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.datagenerators.samplers.samplers;
+
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.hasItem;
+
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.RouletteWheelSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+public class TestRouletteWheelSampler
+{
+
+ @Test
+ public void testSample() throws Exception
+ {
+ Map<String, Double> dataPoints = ImmutableMap.of(
+ "a", 0.25,
+ "b", 0.25,
+ "c", 0.25,
+ "d", 0.25
+ );
+
+ SeedFactory seedFactory = new SeedFactory(1234);
+
+ Sampler<String> sampler = new RouletteWheelSampler<String>(dataPoints, seedFactory);
+
+ String result = sampler.sample();
+
+ assertThat(dataPoints.keySet(), hasItem(result));
+ }
+
+ @Test
+ public void testSampleUnnormalized() throws Exception
+ {
+ Map<String, Double> dataPoints = ImmutableMap.of(
+ "a", 1.0,
+ "b", 1.0,
+ "c", 1.0,
+ "d", 1.0
+ );
+
+ SeedFactory seedFactory = new SeedFactory(1234);
+
+ Sampler<String> sampler = new RouletteWheelSampler<String>(dataPoints, seedFactory);
+
+ String result = sampler.sample();
+
+ assertThat(dataPoints.keySet(), hasItem(result));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/samplers/TestSequenceSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/samplers/TestSequenceSampler.java b/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/samplers/TestSequenceSampler.java
new file mode 100644
index 0000000..84e9ab8
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/samplers/TestSequenceSampler.java
@@ -0,0 +1,38 @@
+/**
+ * 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.datagenerators.samplers.samplers;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.SequenceSampler;
+import org.junit.Test;
+
+public class TestSequenceSampler
+{
+
+ @Test
+ public void testSample() throws Exception
+ {
+ Sampler<Integer> sampler = new SequenceSampler(0, 10, 1);
+
+ for(int i = 0; i < 10; i++)
+ {
+ Integer value = sampler.sample();
+ assertEquals( (int) value, i);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/samplers/TestUniformIntSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/samplers/TestUniformIntSampler.java b/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/samplers/TestUniformIntSampler.java
new file mode 100644
index 0000000..6ab51b8
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/test/java/org/apache/bigtop/datagenerators/samplers/samplers/TestUniformIntSampler.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.datagenerators.samplers.samplers;
+
+import static org.junit.Assert.assertTrue;
+
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.UniformIntSampler;
+import org.junit.Test;
+
+public class TestUniformIntSampler
+{
+
+ @Test
+ public void testSample() throws Exception
+ {
+ int upperbound = 10;
+ int lowerbound = 1;
+
+ SeedFactory seedFactory = new SeedFactory(1234);
+
+ Sampler<Integer> sampler = new UniformIntSampler(lowerbound, upperbound, seedFactory);
+
+ Integer result = sampler.sample();
+
+ assertTrue(result >= lowerbound);
+ assertTrue(result <= upperbound);
+ }
+
+ @Test
+ public void testSampleInclusive() throws Exception
+ {
+ int upperbound = 2;
+ int lowerbound = 1;
+
+ SeedFactory seedFactory = new SeedFactory(1234);
+
+ Sampler<Integer> sampler = new UniformIntSampler(lowerbound, upperbound, seedFactory);
+
+ Integer result = sampler.sample();
+
+ assertTrue(result >= lowerbound);
+ assertTrue(result <= upperbound);
+ }
+
+}
[03/11] bigtop git commit: BIGTOP-1984. Extract samplers library from
BigPetStore data generator
Posted by rn...@apache.org.
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/TestProduct.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/TestProduct.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/TestProduct.java
new file mode 100644
index 0000000..313b725
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/TestProduct.java
@@ -0,0 +1,77 @@
+/**
+ * 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.datagenerators.bigpetstore.datamodels;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.bigpetstore.Constants;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.junit.Test;
+
+import com.google.common.collect.Maps;
+
+public class TestProduct
+{
+
+ @Test
+ public void testString()
+ {
+ Map<String, Object> fields = Maps.newHashMap();
+ fields.put(Constants.PRODUCT_CATEGORY, "poop bags");
+ fields.put(Constants.PRODUCT_QUANTITY, 120);
+ fields.put("price", 12.80);
+
+ Product product = new Product(fields);
+
+ assertEquals(product.getFieldValueAsString(Constants.PRODUCT_CATEGORY), "poop bags");
+ assertEquals(product.getFieldValueAsString("price"), "12.8");
+ assertEquals(product.getFieldValueAsString(Constants.PRODUCT_QUANTITY), "120");
+ }
+
+ @Test
+ public void testDouble()
+ {
+ Map<String, Object> fields = Maps.newHashMap();
+ fields.put(Constants.PRODUCT_CATEGORY, "poop bags");
+ fields.put(Constants.PRODUCT_QUANTITY, 120);
+ fields.put("price", 12.80);
+
+ Product product = new Product(fields);
+
+ assertNull(product.getFieldValueAsDouble(Constants.PRODUCT_CATEGORY));
+ assertEquals(product.getFieldValueAsDouble("price"), 12.80, 1e-5);
+ assertNull(product.getFieldValueAsDouble(Constants.PRODUCT_QUANTITY));
+ }
+
+ @Test
+ public void testLong()
+ {
+ Map<String, Object> fields = Maps.newHashMap();
+ fields.put(Constants.PRODUCT_CATEGORY, "poop bags");
+ fields.put(Constants.PRODUCT_QUANTITY, 120);
+ fields.put("price", 12.80);
+
+ Product product = new Product(fields);
+
+ assertNull(product.getFieldValueAsLong(Constants.PRODUCT_CATEGORY));
+ assertNull(product.getFieldValueAsLong("price"));
+ assertEquals((long) product.getFieldValueAsLong(Constants.PRODUCT_QUANTITY), 120L);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/customer/TestCustomerLocationPDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/customer/TestCustomerLocationPDF.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/customer/TestCustomerLocationPDF.java
new file mode 100644
index 0000000..60733a9
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/customer/TestCustomerLocationPDF.java
@@ -0,0 +1,58 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.customer;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.bigtop.datagenerators.bigpetstore.Constants;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Store;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ZipcodeRecord;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.customer.CustomerLocationPDF;
+import org.apache.commons.lang3.tuple.Pair;
+import org.junit.Test;
+
+public class TestCustomerLocationPDF
+{
+
+ @Test
+ public void testProbability() throws Exception
+ {
+ List<ZipcodeRecord> zipcodes = Arrays.asList(new ZipcodeRecord[] {
+ new ZipcodeRecord("11111", Pair.of(1.0, 1.0), "AZ", "Tempte", 30000.0, 100),
+ new ZipcodeRecord("22222", Pair.of(2.0, 2.0), "AZ", "Phoenix", 45000.0, 200),
+ new ZipcodeRecord("33333", Pair.of(3.0, 3.0), "AZ", "Flagstaff", 60000.0, 300)
+ });
+
+ List<Store> stores = new ArrayList<Store>();
+ for(int i = 0; i < zipcodes.size(); i++)
+ {
+ Store store = new Store(i, "Store_" + i, zipcodes.get(i));
+ stores.add(store);
+ }
+
+ CustomerLocationPDF customerLocationPDF = new CustomerLocationPDF(zipcodes, stores.get(0),
+ Constants.AVERAGE_CUSTOMER_STORE_DISTANCE);
+
+ double prob = customerLocationPDF.probability(zipcodes.get(0));
+
+ assertTrue(prob > 0.0);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/customer/TestCustomerSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/customer/TestCustomerSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/customer/TestCustomerSampler.java
new file mode 100644
index 0000000..8bb3c87
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/customer/TestCustomerSampler.java
@@ -0,0 +1,108 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.customer;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.bigpetstore.Constants;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Customer;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Store;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ZipcodeRecord;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.customer.CustomerLocationPDF;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.customer.CustomerSampler;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.pdfs.ProbabilityDensityFunction;
+import org.apache.bigtop.datagenerators.samplers.samplers.ConditionalSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.RouletteWheelSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.SequenceSampler;
+import org.apache.commons.lang3.tuple.Pair;
+import org.junit.Test;
+
+import com.google.common.collect.Maps;
+
+public class TestCustomerSampler
+{
+ protected ConditionalSampler<ZipcodeRecord, Store> buildLocationSampler(List<Store> stores, List<ZipcodeRecord> records,
+ SeedFactory factory)
+ {
+ final Map<Store, Sampler<ZipcodeRecord>> locationSamplers = Maps.newHashMap();
+ for(Store store : stores)
+ {
+ ProbabilityDensityFunction<ZipcodeRecord> locationPDF = new CustomerLocationPDF(records,
+ store, Constants.AVERAGE_CUSTOMER_STORE_DISTANCE);
+ Sampler<ZipcodeRecord> locationSampler = RouletteWheelSampler.create(records, locationPDF, factory);
+ locationSamplers.put(store, locationSampler);
+ }
+
+ return new ConditionalSampler<ZipcodeRecord, Store>()
+ {
+ public ZipcodeRecord sample(Store store) throws Exception
+ {
+ return locationSamplers.get(store).sample();
+ }
+ };
+ }
+
+ @Test
+ public void testBuild() throws Exception
+ {
+ SeedFactory factory = new SeedFactory(1234);
+
+ Collection<String> nameList = Arrays.asList(new String[] {"Fred", "Gary", "George", "Fiona"});
+ List<ZipcodeRecord> zipcodes = Arrays.asList(new ZipcodeRecord[] {
+ new ZipcodeRecord("11111", Pair.of(1.0, 1.0), "AZ", "Tempte", 30000.0, 100),
+ new ZipcodeRecord("22222", Pair.of(2.0, 2.0), "AZ", "Phoenix", 45000.0, 200),
+ new ZipcodeRecord("33333", Pair.of(3.0, 3.0), "AZ", "Flagstaff", 60000.0, 300)
+ });
+
+ List<Store> stores = new ArrayList<Store>();
+ for(int i = 0; i < zipcodes.size(); i++)
+ {
+ Store store = new Store(i, "Store_" + i, zipcodes.get(i));
+ stores.add(store);
+ }
+
+
+ Sampler<Integer> idSampler = new SequenceSampler();
+ Sampler<String> nameSampler = RouletteWheelSampler.createUniform(nameList, factory);
+ Sampler<Store> storeSampler = RouletteWheelSampler.createUniform(stores, factory);
+ ConditionalSampler<ZipcodeRecord, Store> zipcodeSampler = buildLocationSampler(stores, zipcodes, factory);
+
+ Sampler<Customer> sampler = new CustomerSampler(idSampler, nameSampler, nameSampler, storeSampler, zipcodeSampler);
+
+ Customer customer = sampler.sample();
+
+ assertNotNull(customer);
+ assertTrue(customer.getId() >= 0);
+ assertNotNull(customer.getName());
+ assertNotNull(customer.getName().getLeft());
+ assertTrue(nameList.contains(customer.getName().getLeft()));
+ assertNotNull(customer.getName().getRight());
+ assertTrue(nameList.contains(customer.getName().getRight()));
+ assertNotNull(customer.getLocation());
+ assertTrue(zipcodes.contains(customer.getLocation()));
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/customer/TestCustomerSamplerBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/customer/TestCustomerSamplerBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/customer/TestCustomerSamplerBuilder.java
new file mode 100644
index 0000000..786c7fc
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/customer/TestCustomerSamplerBuilder.java
@@ -0,0 +1,77 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.customer;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Customer;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Store;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.InputData;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.Names;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ZipcodeRecord;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.customer.CustomerSamplerBuilder;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.apache.commons.lang3.tuple.Pair;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+public class TestCustomerSamplerBuilder
+{
+
+ @Test
+ public void testSample() throws Exception
+ {
+ Map<String, Double> nameList = ImmutableMap.of("Fred", 1.0, "George", 1.0, "Gary", 1.0, "Fiona", 1.0);
+ List<ZipcodeRecord> zipcodes = Arrays.asList(new ZipcodeRecord[] {
+ new ZipcodeRecord("11111", Pair.of(1.0, 1.0), "AZ", "Tempte", 30000.0, 100),
+ new ZipcodeRecord("22222", Pair.of(2.0, 2.0), "AZ", "Phoenix", 45000.0, 200),
+ new ZipcodeRecord("33333", Pair.of(3.0, 3.0), "AZ", "Flagstaff", 60000.0, 300)
+ });
+
+ Names names = new Names(nameList, nameList);
+
+ // don't need product categories for building customers
+ InputData inputData = new InputData(zipcodes, names);
+
+ List<Store> stores = Arrays.asList(new Store(0, "Store_0", zipcodes.get(0)),
+ new Store(1, "Store_1", zipcodes.get(1)),
+ new Store(2, "Store_2", zipcodes.get(2))
+ );
+
+ SeedFactory factory = new SeedFactory(1234);
+
+ CustomerSamplerBuilder builder = new CustomerSamplerBuilder(stores, inputData, factory);
+ Sampler<Customer> sampler = builder.build();
+
+ Customer customer = sampler.sample();
+
+ assertNotNull(customer);
+ assertTrue(customer.getId() >= 0);
+ assertNotNull(customer.getName());
+ assertNotNull(customer.getName().getLeft());
+ assertNotNull(customer.getName().getRight());
+ assertNotNull(customer.getLocation());
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/cartesian/TestCartesianProductBase.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/cartesian/TestCartesianProductBase.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/cartesian/TestCartesianProductBase.java
new file mode 100644
index 0000000..6393b67
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/cartesian/TestCartesianProductBase.java
@@ -0,0 +1,57 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.products.cartesian;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.cartesian.CartesianProductBase;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestCartesianProductBase
+{
+ @Test
+ public void testNext()
+ {
+ Iterator<Map<String, Double>> iter = new CartesianProductBase<Double>("count",
+ Arrays.asList(1.0, 2.0, 3.0));
+
+ Assert.assertTrue(iter.hasNext());
+
+ Map<String, Double> map = iter.next();
+ Assert.assertEquals(1, map.size());
+ Assert.assertTrue(map.containsKey("count"));
+ Assert.assertEquals( (double) map.get("count"), (double) 1.0, 0.0001);
+
+ Assert.assertTrue(iter.hasNext());
+
+ map = iter.next();
+ Assert.assertEquals(1, map.size());
+ Assert.assertTrue(map.containsKey("count"));
+ Assert.assertEquals( (double) map.get("count"), (double) 2.0, 0.0001);
+
+ Assert.assertTrue(iter.hasNext());
+
+ map = iter.next();
+ Assert.assertEquals(1, map.size());
+ Assert.assertTrue(map.containsKey("count"));
+ Assert.assertEquals( (double) map.get("count"), (double) 3.0, 0.0001);
+
+ Assert.assertFalse(iter.hasNext());
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/cartesian/TestCartesianProductField.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/cartesian/TestCartesianProductField.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/cartesian/TestCartesianProductField.java
new file mode 100644
index 0000000..b4a74f3
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/cartesian/TestCartesianProductField.java
@@ -0,0 +1,74 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.products.cartesian;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.cartesian.CartesianProductBase;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.cartesian.CartesianProductField;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestCartesianProductField
+{
+
+ @Test
+ public void testTwoLevels()
+ {
+ Iterator<Map<String, String>> iter = new CartesianProductField<String>(
+ "children", Arrays.asList("1", "2"),
+ new CartesianProductBase<String>(
+ "animal", Arrays.asList("cat", "dog")));
+
+ Assert.assertEquals(iter.hasNext(), true);
+ Map<String, String> map = iter.next();
+ Assert.assertEquals(map.size(), 2);
+ Assert.assertTrue(map.containsKey("animal"));
+ Assert.assertTrue(map.containsKey("children"));
+ Assert.assertEquals(map.get("animal"), "cat");
+ Assert.assertEquals(map.get("children"), "1");
+
+ Assert.assertEquals(iter.hasNext(), true);
+ map = iter.next();
+ Assert.assertEquals(map.size(), 2);
+ Assert.assertTrue(map.containsKey("animal"));
+ Assert.assertTrue(map.containsKey("children"));
+ Assert.assertEquals(map.get("animal"), "cat");
+ Assert.assertEquals(map.get("children"), "2");
+
+ Assert.assertEquals(iter.hasNext(), true);
+ map = iter.next();
+ Assert.assertEquals(map.size(), 2);
+ Assert.assertTrue(map.containsKey("animal"));
+ Assert.assertTrue(map.containsKey("children"));
+ Assert.assertEquals(map.get("animal"), "dog");
+ Assert.assertEquals(map.get("children"), "1");
+
+ Assert.assertEquals(iter.hasNext(), true);
+ map = iter.next();
+ Assert.assertEquals(map.size(), 2);
+ Assert.assertTrue(map.containsKey("animal"));
+ Assert.assertTrue(map.containsKey("children"));
+ Assert.assertEquals(map.get("animal"), "dog");
+ Assert.assertEquals(map.get("children"), "2");
+
+ Assert.assertFalse(iter.hasNext());
+ Assert.assertFalse(iter.hasNext());
+ Assert.assertFalse(iter.hasNext());
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/TestAlwaysTrueRule.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/TestAlwaysTrueRule.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/TestAlwaysTrueRule.java
new file mode 100644
index 0000000..2738456
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/TestAlwaysTrueRule.java
@@ -0,0 +1,32 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.products.rules;
+
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.rules.AlwaysTrueRule;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.rules.Rule;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestAlwaysTrueRule
+{
+
+ @Test
+ public void testRuleMatches()
+ {
+ Rule rule = new AlwaysTrueRule();
+ Assert.assertTrue(rule.ruleMatches(null));
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/TestAndRule.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/TestAndRule.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/TestAndRule.java
new file mode 100644
index 0000000..7757048
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/TestAndRule.java
@@ -0,0 +1,55 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.products.rules;
+
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.rules.AlwaysTrueRule;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.rules.AndRule;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.rules.NotRule;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.rules.Rule;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestAndRule
+{
+
+ @Test
+ public void testRuleMatches()
+ {
+ Rule rule = new AndRule(
+ new AlwaysTrueRule(),
+ new AlwaysTrueRule());
+ Assert.assertTrue(rule.ruleMatches(null));
+
+ rule = new AndRule(
+ new AlwaysTrueRule(),
+ new NotRule(
+ new AlwaysTrueRule()));
+ Assert.assertFalse(rule.ruleMatches(null));
+
+ rule = new AndRule(
+ new NotRule(
+ new AlwaysTrueRule()),
+ new AlwaysTrueRule());
+ Assert.assertFalse(rule.ruleMatches(null));
+
+ rule = new AndRule(
+ new NotRule(
+ new AlwaysTrueRule()),
+ new NotRule(
+ new AlwaysTrueRule()));
+ Assert.assertFalse(rule.ruleMatches(null));
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/TestFieldPredicate.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/TestFieldPredicate.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/TestFieldPredicate.java
new file mode 100644
index 0000000..1139f16
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/TestFieldPredicate.java
@@ -0,0 +1,44 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.products.rules;
+
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.rules.FieldPredicate;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.rules.Rule;
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+public class TestFieldPredicate
+{
+
+ @Test
+ public void testRuleMatches()
+ {
+ Map<String, Object> fields = ImmutableMap.of("brand", (Object) "Chef Corgi",
+ "flavor", (Object) "chicken");
+ Product product = new Product(fields);
+
+ Rule rule = new FieldPredicate("brand", "Chef Corgi");
+ Assert.assertTrue(rule.ruleMatches(product));
+
+ rule = new FieldPredicate("brand", "Happy Pup");
+ Assert.assertFalse(rule.ruleMatches(product));
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/TestNotRule.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/TestNotRule.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/TestNotRule.java
new file mode 100644
index 0000000..44b5aaa
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/TestNotRule.java
@@ -0,0 +1,39 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.products.rules;
+
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.rules.AlwaysTrueRule;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.rules.NotRule;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.rules.Rule;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestNotRule
+{
+
+ @Test
+ public void testRuleMatches()
+ {
+ Rule rule = new NotRule(
+ new AlwaysTrueRule());
+ Assert.assertFalse(rule.ruleMatches(null));
+
+ rule = new NotRule(
+ new NotRule(
+ new AlwaysTrueRule()));
+ Assert.assertTrue(rule.ruleMatches(null));
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/TestOrRule.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/TestOrRule.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/TestOrRule.java
new file mode 100644
index 0000000..c9e7ec7
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/TestOrRule.java
@@ -0,0 +1,55 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.products.rules;
+
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.rules.AlwaysTrueRule;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.rules.NotRule;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.rules.OrRule;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.rules.Rule;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestOrRule
+{
+
+ @Test
+ public void testRuleMatches()
+ {
+ Rule rule = new OrRule(
+ new AlwaysTrueRule(),
+ new AlwaysTrueRule());
+ Assert.assertTrue(rule.ruleMatches(null));
+
+ rule = new OrRule(
+ new AlwaysTrueRule(),
+ new NotRule(
+ new AlwaysTrueRule()));
+ Assert.assertTrue(rule.ruleMatches(null));
+
+ rule = new OrRule(
+ new NotRule(
+ new AlwaysTrueRule()),
+ new AlwaysTrueRule());
+ Assert.assertTrue(rule.ruleMatches(null));
+
+ rule = new OrRule(
+ new NotRule(
+ new AlwaysTrueRule()),
+ new NotRule(
+ new AlwaysTrueRule()));
+ Assert.assertFalse(rule.ruleMatches(null));
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/TestProductCategoryMarkovModelSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/TestProductCategoryMarkovModelSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/TestProductCategoryMarkovModelSampler.java
new file mode 100644
index 0000000..0453eec
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/TestProductCategoryMarkovModelSampler.java
@@ -0,0 +1,108 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.purchase;
+
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.bigtop.datagenerators.bigpetstore.Constants;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.PetSpecies;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.ProductCategoryBuilder;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.purchase.MarkovModelProductCategorySampler;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.markovmodels.MarkovModel;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.UniformSampler;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+public class TestProductCategoryMarkovModelSampler
+{
+
+ private List<ProductCategory> createProducts()
+ {
+ List<ProductCategory> productCategories = Lists.newArrayList();
+
+ ProductCategoryBuilder foodBuilder = new ProductCategoryBuilder();
+ foodBuilder.addApplicableSpecies(PetSpecies.DOG);
+ foodBuilder.setAmountUsedPetPetAverage(1.0);
+ foodBuilder.setAmountUsedPetPetVariance(1.0);
+ foodBuilder.setDailyUsageRate(2.0);
+ foodBuilder.setCategory("dogFood");
+ foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood",
+ Constants.PRODUCT_QUANTITY, (Object) 60.0, "Flavor", "Fish & Potato")));
+ foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood",
+ Constants.PRODUCT_QUANTITY, (Object) 30.0, "Flavor", "Chicken & Rice")));
+ foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood",
+ Constants.PRODUCT_QUANTITY, (Object) 15.0, "Flavor", "Lamb & Barley")));
+ productCategories.add(foodBuilder.build());
+
+ ProductCategoryBuilder bagBuilder = new ProductCategoryBuilder();
+ bagBuilder.addApplicableSpecies(PetSpecies.DOG);
+ bagBuilder.setAmountUsedPetPetAverage(1.0);
+ bagBuilder.setAmountUsedPetPetVariance(1.0);
+ bagBuilder.setDailyUsageRate(2.0);
+ bagBuilder.setCategory("Poop Bags");
+ bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags",
+ Constants.PRODUCT_QUANTITY, (Object) 60.0, "Color", "Blue")));
+ bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags",
+ Constants.PRODUCT_QUANTITY, (Object) 30.0, "Color", "Red")));
+ bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags",
+ Constants.PRODUCT_QUANTITY, (Object) 120.0, "Flavor", "Multicolor")));
+ productCategories.add(bagBuilder.build());
+
+ return productCategories;
+ }
+
+ @Test
+ public void testSample() throws Exception
+ {
+ SeedFactory seedFactory = new SeedFactory(1245);
+
+ List<ProductCategory> productCategories = createProducts();
+
+ ProductCategory productCategory = productCategories.get(0);
+
+ Sampler<Double> fieldWeightSampler = new UniformSampler(seedFactory);
+
+ Map<String, Double> fieldWeights = Maps.newHashMap();
+ for(String fieldName : productCategory.getFieldNames())
+ {
+ fieldWeights.put(fieldName, fieldWeightSampler.sample());
+ }
+
+ MarkovModelProductCategorySampler generator = new MarkovModelProductCategorySampler(productCategory,
+ fieldWeights, new UniformSampler(seedFactory), new UniformSampler(seedFactory)
+ );
+
+ MarkovModel<Product> model = generator.sample();
+
+ assertNotNull(model);
+ assertNotNull(model.getStartWeights());
+ assertNotNull(model.getTransitionWeights());
+ assertTrue(model.getStartWeights().size() > 0);
+ assertTrue(model.getTransitionWeights().size() > 0);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/TestPurchasingModelSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/TestPurchasingModelSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/TestPurchasingModelSampler.java
new file mode 100644
index 0000000..25a43ed
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/TestPurchasingModelSampler.java
@@ -0,0 +1,100 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.purchase;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.apache.bigtop.datagenerators.bigpetstore.Constants;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.PetSpecies;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.ProductCategoryBuilder;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.purchase.MarkovPurchasingModel;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.purchase.PurchasingModelSamplerBuilder;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+
+public class TestPurchasingModelSampler
+{
+
+ private List<ProductCategory> createProducts()
+ {
+ List<ProductCategory> productCategories = Lists.newArrayList();
+
+ ProductCategoryBuilder foodBuilder = new ProductCategoryBuilder();
+ foodBuilder.addApplicableSpecies(PetSpecies.DOG);
+ foodBuilder.setAmountUsedPetPetAverage(1.0);
+ foodBuilder.setAmountUsedPetPetVariance(1.0);
+ foodBuilder.setDailyUsageRate(2.0);
+ foodBuilder.setCategory("dogFood");
+ foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood",
+ Constants.PRODUCT_QUANTITY, (Object) 60.0, "Flavor", "Fish & Potato")));
+ foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood",
+ Constants.PRODUCT_QUANTITY, (Object) 30.0, "Flavor", "Chicken & Rice")));
+ foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood",
+ Constants.PRODUCT_QUANTITY, (Object) 15.0, "Flavor", "Lamb & Barley")));
+ productCategories.add(foodBuilder.build());
+
+ ProductCategoryBuilder bagBuilder = new ProductCategoryBuilder();
+ bagBuilder.addApplicableSpecies(PetSpecies.DOG);
+ bagBuilder.setAmountUsedPetPetAverage(1.0);
+ bagBuilder.setAmountUsedPetPetVariance(1.0);
+ bagBuilder.setDailyUsageRate(2.0);
+ bagBuilder.setCategory("Poop Bags");
+ bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags",
+ Constants.PRODUCT_QUANTITY, (Object) 60.0, "Color", "Blue")));
+ bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags",
+ Constants.PRODUCT_QUANTITY, (Object) 30.0, "Color", "Red")));
+ bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags",
+ Constants.PRODUCT_QUANTITY, (Object) 120.0, "Color", "Multicolor")));
+ productCategories.add(bagBuilder.build());
+
+ return productCategories;
+ }
+
+ @Test
+ public void testSample() throws Exception
+ {
+ SeedFactory seedFactory = new SeedFactory(1245);
+
+ List<ProductCategory> productCategories = createProducts();
+
+ PurchasingModelSamplerBuilder builder = new PurchasingModelSamplerBuilder(productCategories, seedFactory);
+ Sampler<MarkovPurchasingModel> sampler = builder.buildMarkovPurchasingModel();
+ MarkovPurchasingModel profile = sampler.sample();
+
+ assertNotNull(profile);
+ assertNotNull(profile.getProductCategories());
+ assertTrue(profile.getProductCategories().size() > 0);
+
+ for(String label : profile.getProductCategories())
+ {
+ assertNotNull(profile.getProfile(label));
+ assertNotNull(profile.getProfile(label).getStartWeights());
+ assertTrue(profile.getProfile(label).getStartWeights().size() > 0);
+ assertNotNull(profile.getProfile(label).getTransitionWeights());
+ assertTrue(profile.getProfile(label).getTransitionWeights().size() > 0);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/TestPurchasingModelSamplerBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/TestPurchasingModelSamplerBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/TestPurchasingModelSamplerBuilder.java
new file mode 100644
index 0000000..79d9821
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/TestPurchasingModelSamplerBuilder.java
@@ -0,0 +1,100 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.purchase;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.apache.bigtop.datagenerators.bigpetstore.Constants;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.PetSpecies;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.ProductCategoryBuilder;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.purchase.MarkovPurchasingModel;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.purchase.PurchasingModelSamplerBuilder;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+
+public class TestPurchasingModelSamplerBuilder
+{
+
+ private List<ProductCategory> createProducts()
+ {
+ List<ProductCategory> productCategories = Lists.newArrayList();
+
+ ProductCategoryBuilder foodBuilder = new ProductCategoryBuilder();
+ foodBuilder.addApplicableSpecies(PetSpecies.DOG);
+ foodBuilder.setAmountUsedPetPetAverage(1.0);
+ foodBuilder.setAmountUsedPetPetVariance(1.0);
+ foodBuilder.setDailyUsageRate(2.0);
+ foodBuilder.setCategory("dogFood");
+ foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood",
+ Constants.PRODUCT_QUANTITY, (Object) 60.0, "Flavor", "Fish & Potato")));
+ foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood",
+ Constants.PRODUCT_QUANTITY, (Object) 30.0, "Flavor", "Chicken & Rice")));
+ foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood",
+ Constants.PRODUCT_QUANTITY, (Object) 15.0, "Flavor", "Lamb & Barley")));
+ productCategories.add(foodBuilder.build());
+
+ ProductCategoryBuilder bagBuilder = new ProductCategoryBuilder();
+ bagBuilder.addApplicableSpecies(PetSpecies.DOG);
+ bagBuilder.setAmountUsedPetPetAverage(1.0);
+ bagBuilder.setAmountUsedPetPetVariance(1.0);
+ bagBuilder.setDailyUsageRate(2.0);
+ bagBuilder.setCategory("Poop Bags");
+ bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags",
+ Constants.PRODUCT_QUANTITY, (Object) 60.0, "Color", "Blue")));
+ bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags",
+ Constants.PRODUCT_QUANTITY, (Object) 30.0, "Color", "Red")));
+ bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags",
+ Constants.PRODUCT_QUANTITY, (Object) 120.0, "Color", "Multicolor")));
+ productCategories.add(bagBuilder.build());
+
+ return productCategories;
+ }
+
+ @Test
+ public void testBuild() throws Exception
+ {
+ SeedFactory seedFactory = new SeedFactory(1245);
+
+ List<ProductCategory> productCategories = createProducts();
+
+ PurchasingModelSamplerBuilder builder = new PurchasingModelSamplerBuilder(productCategories, seedFactory);
+ Sampler<MarkovPurchasingModel> sampler = builder.buildMarkovPurchasingModel();
+ MarkovPurchasingModel profile = sampler.sample();
+
+ assertNotNull(profile);
+ assertNotNull(profile.getProductCategories());
+ assertTrue(profile.getProductCategories().size() > 0);
+
+ for(String label : profile.getProductCategories())
+ {
+ assertNotNull(profile.getProfile(label));
+ assertNotNull(profile.getProfile(label).getStartWeights());
+ assertTrue(profile.getProfile(label).getStartWeights().size() > 0);
+ assertNotNull(profile.getProfile(label).getTransitionWeights());
+ assertTrue(profile.getProfile(label).getTransitionWeights().size() > 0);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/TestPurchasingProcesses.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/TestPurchasingProcesses.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/TestPurchasingProcesses.java
new file mode 100644
index 0000000..eadc61d
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/TestPurchasingProcesses.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.datagenerators.bigpetstore.generators.purchase;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.bigpetstore.Constants;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.purchase.PurchasingProcesses;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.RouletteWheelSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.junit.Test;
+
+import com.google.common.collect.Maps;
+
+public class TestPurchasingProcesses
+{
+
+ @Test
+ public void testSimulatePurchase() throws Exception
+ {
+ Map<Product, Double> productPDF = Maps.newHashMap();
+
+ for(int i = 0; i < 10; i++)
+ {
+ Map<String, Object> fields = Maps.newHashMap();
+ fields.put(Constants.PRODUCT_CATEGORY, "dog food");
+ fields.put(Constants.PRODUCT_QUANTITY, (double) (i + 1));
+ Product product = new Product(fields);
+ productPDF.put(product, 0.1);
+ }
+
+ SeedFactory seedFactory = new SeedFactory(1234);
+ Sampler<Product> sampler = RouletteWheelSampler.create(productPDF, seedFactory);
+
+
+ Map<String, Sampler<Product>> processesMap = Maps.newHashMap();
+ processesMap.put("dog food", sampler);
+ PurchasingProcesses processes = new PurchasingProcesses(processesMap);
+
+ Product product = processes.sample("dog food");
+
+ assertNotNull(product);
+ assertNotNull(product.getFieldValue(Constants.PRODUCT_CATEGORY));
+ assertNotNull(product.getFieldValue(Constants.PRODUCT_QUANTITY));
+
+ product = processes.sample("dog food");
+
+ assertNotNull(product);
+ assertNotNull(product.getFieldValue(Constants.PRODUCT_CATEGORY));
+ assertNotNull(product.getFieldValue(Constants.PRODUCT_QUANTITY));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/TestStoreLocationIncomePDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/TestStoreLocationIncomePDF.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/TestStoreLocationIncomePDF.java
new file mode 100644
index 0000000..b194c3a
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/TestStoreLocationIncomePDF.java
@@ -0,0 +1,49 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.store;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ZipcodeRecord;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.store.StoreLocationIncomePDF;
+import org.apache.commons.lang3.tuple.Pair;
+import org.junit.Test;
+
+public class TestStoreLocationIncomePDF
+{
+
+ @Test
+ public void testProbability() throws Exception
+ {
+ List<ZipcodeRecord> zipcodes = Arrays.asList(new ZipcodeRecord[] {
+ new ZipcodeRecord("11111", Pair.of(1.0, 1.0), "AZ", "Tempte", 30000.0, 100),
+ new ZipcodeRecord("22222", Pair.of(2.0, 2.0), "AZ", "Phoenix", 45000.0, 200),
+ new ZipcodeRecord("33333", Pair.of(3.0, 3.0), "AZ", "Flagstaff", 60000.0, 300)
+ });
+
+ StoreLocationIncomePDF pdf = new StoreLocationIncomePDF(zipcodes, 100.0);
+
+ for(ZipcodeRecord record : zipcodes)
+ {
+ assertTrue(pdf.probability(record) > 0.0);
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/TestStoreLocationPopulationPDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/TestStoreLocationPopulationPDF.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/TestStoreLocationPopulationPDF.java
new file mode 100644
index 0000000..002e14f
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/TestStoreLocationPopulationPDF.java
@@ -0,0 +1,49 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.store;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ZipcodeRecord;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.store.StoreLocationPopulationPDF;
+import org.apache.commons.lang3.tuple.Pair;
+import org.junit.Test;
+
+public class TestStoreLocationPopulationPDF
+{
+
+ @Test
+ public void testProbability() throws Exception
+ {
+ List<ZipcodeRecord> zipcodes = Arrays.asList(new ZipcodeRecord[] {
+ new ZipcodeRecord("11111", Pair.of(1.0, 1.0), "AZ", "Tempte", 30000.0, 100),
+ new ZipcodeRecord("22222", Pair.of(2.0, 2.0), "AZ", "Phoenix", 45000.0, 200),
+ new ZipcodeRecord("33333", Pair.of(3.0, 3.0), "AZ", "Flagstaff", 60000.0, 300)
+ });
+
+ StoreLocationPopulationPDF pdf = new StoreLocationPopulationPDF(zipcodes);
+
+ for(ZipcodeRecord record : zipcodes)
+ {
+ assertTrue(pdf.probability(record) > 0.0);
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/TestStoreSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/TestStoreSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/TestStoreSampler.java
new file mode 100644
index 0000000..2594509
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/TestStoreSampler.java
@@ -0,0 +1,59 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.store;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Store;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ZipcodeRecord;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.store.StoreSampler;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.RouletteWheelSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.SequenceSampler;
+import org.apache.commons.lang3.tuple.Pair;
+import org.junit.Test;
+
+public class TestStoreSampler
+{
+
+ @Test
+ public void testSampler() throws Exception
+ {
+ Collection<ZipcodeRecord> zipcodes = Arrays.asList(new ZipcodeRecord[] {
+ new ZipcodeRecord("11111", Pair.of(1.0, 1.0), "AZ", "Tempte", 30000.0, 100),
+ new ZipcodeRecord("22222", Pair.of(2.0, 2.0), "AZ", "Phoenix", 45000.0, 200),
+ new ZipcodeRecord("33333", Pair.of(3.0, 3.0), "AZ", "Flagstaff", 60000.0, 300)
+ });
+
+ SeedFactory factory = new SeedFactory(1234);
+
+ Sampler<Store> sampler = new StoreSampler(new SequenceSampler(),
+ RouletteWheelSampler.createUniform(zipcodes, factory));
+
+ Store store = sampler.sample();
+ assertNotNull(store);
+ assertTrue(store.getId() >= 0);
+ assertNotNull(store.getName());
+ assertNotNull(store.getLocation());
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/TestStoreSamplerBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/TestStoreSamplerBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/TestStoreSamplerBuilder.java
new file mode 100644
index 0000000..f440ff6
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/TestStoreSamplerBuilder.java
@@ -0,0 +1,59 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.store;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Store;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ZipcodeRecord;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.store.StoreSamplerBuilder;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.apache.commons.lang3.tuple.Pair;
+import org.junit.Test;
+
+public class TestStoreSamplerBuilder
+{
+
+ @Test
+ public void testBuild() throws Exception
+ {
+ List<ZipcodeRecord> zipcodes = Arrays.asList(new ZipcodeRecord[] {
+ new ZipcodeRecord("11111", Pair.of(1.0, 1.0), "AZ", "Tempte", 30000.0, 100),
+ new ZipcodeRecord("22222", Pair.of(2.0, 2.0), "AZ", "Phoenix", 45000.0, 200),
+ new ZipcodeRecord("33333", Pair.of(3.0, 3.0), "AZ", "Flagstaff", 60000.0, 300)
+ });
+
+ assertTrue(zipcodes.size() > 0);
+
+ SeedFactory factory = new SeedFactory(1234);
+
+ StoreSamplerBuilder builder = new StoreSamplerBuilder(zipcodes, factory);
+ Sampler<Store> sampler = builder.build();
+
+ Store store = sampler.sample();
+ assertNotNull(store);
+ assertTrue(store.getId() >= 0);
+ assertNotNull(store.getName());
+ assertNotNull(store.getLocation());
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestCustomerInventory.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestCustomerInventory.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestCustomerInventory.java
new file mode 100644
index 0000000..1d0ded4
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestCustomerInventory.java
@@ -0,0 +1,94 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.transaction;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.bigpetstore.Constants;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.PetSpecies;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.ProductCategoryBuilder;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.CustomerInventory;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.CustomerTransactionParameters;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.CustomerTransactionParametersSamplerBuilder;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.ProductCategoryInventory;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.junit.Test;
+
+import com.google.common.collect.Maps;
+
+public class TestCustomerInventory
+{
+
+ @Test
+ public void testPurchase() throws Exception
+ {
+ SeedFactory seedFactory = new SeedFactory(1234);
+
+ CustomerTransactionParametersSamplerBuilder transParamsBuilder = new CustomerTransactionParametersSamplerBuilder(seedFactory);
+ Sampler<CustomerTransactionParameters> sampler = transParamsBuilder.build();
+
+ CustomerTransactionParameters parameters = sampler.sample();
+
+ ProductCategoryBuilder builder = new ProductCategoryBuilder();
+ builder.addApplicableSpecies(PetSpecies.DOG);
+ builder.setAmountUsedPetPetAverage(1.0);
+ builder.setAmountUsedPetPetVariance(1.0);
+ builder.setDailyUsageRate(2.0);
+ builder.setCategory("dog food");
+
+
+ ProductCategory category = builder.build();
+
+ ProductCategoryInventory productInventory = new ProductCategoryInventory(category, parameters, seedFactory);
+
+ Map<String, ProductCategoryInventory> inventories = Maps.newHashMap();
+ inventories.put("dog food", productInventory);
+
+ CustomerInventory inventory = new CustomerInventory(inventories);
+
+ for(Map.Entry<String, Double> entry : inventory.getExhaustionTimes().entrySet())
+ {
+ assertEquals(entry.getValue(), 0.0, 0.0001);
+ }
+
+ for(Map.Entry<String, Double> entry : inventory.getInventoryAmounts(0.0).entrySet())
+ {
+ assertEquals(entry.getValue(), 0.0, 0.0001);
+ }
+
+ Map<String, Object> fields = Maps.newHashMap();
+ fields.put(Constants.PRODUCT_CATEGORY, "dog food");
+ fields.put(Constants.PRODUCT_QUANTITY, 30.0);
+ Product product = new Product(fields);
+
+ inventory.simulatePurchase(1.0, product);
+
+ Map<String, Double> exhaustionTimes = inventory.getExhaustionTimes();
+ assertTrue(exhaustionTimes.containsKey("dog food"));
+ assertTrue(exhaustionTimes.get("dog food") > 0.0);
+
+ Map<String, Double> amounts = inventory.getInventoryAmounts(2.0);
+ assertTrue(amounts.containsKey("dog food"));
+ assertTrue(amounts.get("dog food") > 0.0);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestCustomerInventoryBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestCustomerInventoryBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestCustomerInventoryBuilder.java
new file mode 100644
index 0000000..85aa000
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestCustomerInventoryBuilder.java
@@ -0,0 +1,91 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.transaction;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.bigpetstore.Constants;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.PetSpecies;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.ProductCategoryBuilder;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.CustomerInventory;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.CustomerInventoryBuilder;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.CustomerTransactionParameters;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.CustomerTransactionParametersSamplerBuilder;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.junit.Test;
+
+import com.google.common.collect.Maps;
+
+public class TestCustomerInventoryBuilder
+{
+
+ @Test
+ public void testBuild() throws Exception
+ {
+ SeedFactory seedFactory = new SeedFactory(1234);
+
+ CustomerTransactionParametersSamplerBuilder transParamsBuilder = new CustomerTransactionParametersSamplerBuilder(seedFactory);
+ Sampler<CustomerTransactionParameters> sampler = transParamsBuilder.build();
+
+ CustomerTransactionParameters parameters = sampler.sample();
+
+ ProductCategoryBuilder builder = new ProductCategoryBuilder();
+ builder.addApplicableSpecies(PetSpecies.DOG);
+ builder.setAmountUsedPetPetAverage(1.0);
+ builder.setAmountUsedPetPetVariance(1.0);
+ builder.setDailyUsageRate(2.0);
+ builder.setCategory("dog food");
+
+ ProductCategory category = builder.build();
+
+ CustomerInventoryBuilder inventoryBuilder = new CustomerInventoryBuilder(parameters, seedFactory);
+ inventoryBuilder.addProductCategory(category);
+
+ CustomerInventory inventory = inventoryBuilder.build();
+
+ for(Map.Entry<String, Double> entry : inventory.getExhaustionTimes().entrySet())
+ {
+ assertEquals(entry.getValue(), 0.0, 0.0001);
+ }
+
+ for(Map.Entry<String, Double> entry : inventory.getInventoryAmounts(0.0).entrySet())
+ {
+ assertEquals(entry.getValue(), 0.0, 0.0001);
+ }
+
+ Map<String, Object> fields = Maps.newHashMap();
+ fields.put(Constants.PRODUCT_CATEGORY, "dog food");
+ fields.put(Constants.PRODUCT_QUANTITY, 30.0);
+ Product product = new Product(fields);
+
+ inventory.simulatePurchase(1.0, product);
+
+ Map<String, Double> exhaustionTimes = inventory.getExhaustionTimes();
+ assertTrue(exhaustionTimes.containsKey("dog food"));
+ assertTrue(exhaustionTimes.get("dog food") > 0.0);
+
+ Map<String, Double> amounts = inventory.getInventoryAmounts(2.0);
+ assertTrue(amounts.containsKey("dog food"));
+ assertTrue(amounts.get("dog food") > 0.0);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestCustomerTransactionParameters.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestCustomerTransactionParameters.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestCustomerTransactionParameters.java
new file mode 100644
index 0000000..06b0881
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestCustomerTransactionParameters.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.datagenerators.bigpetstore.generators.transaction;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.PetSpecies;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.CustomerTransactionParameters;
+import org.junit.Test;
+
+import com.google.common.collect.HashMultiset;
+import com.google.common.collect.Multiset;
+
+public class TestCustomerTransactionParameters
+{
+
+ @Test
+ public void testCountPetsBySpecies() throws Exception
+ {
+ Multiset<PetSpecies> petCounts = HashMultiset.create();
+
+ petCounts.add(PetSpecies.CAT);
+ petCounts.add(PetSpecies.CAT);
+ petCounts.add(PetSpecies.CAT);
+
+
+ CustomerTransactionParameters transParams = new CustomerTransactionParameters(
+ petCounts, 0.0, 0.0);
+
+
+ assertEquals(transParams.countPetsBySpecies(PetSpecies.CAT), 3);
+ assertEquals(transParams.countPetsBySpecies(PetSpecies.DOG), 0);
+ assertEquals(transParams.countPets(), 3);
+ }
+
+ @Test
+ public void testCountPetsByMultipleSpecies() throws Exception
+ {
+ Multiset<PetSpecies> petCounts = HashMultiset.create();
+
+ petCounts.add(PetSpecies.CAT);
+ petCounts.add(PetSpecies.CAT);
+ petCounts.add(PetSpecies.DOG);
+
+
+ CustomerTransactionParameters transParams = new CustomerTransactionParameters(
+ petCounts, 0.0, 0.0);
+
+
+ assertEquals(transParams.countPetsBySpecies(Arrays.asList(PetSpecies.values())), 3);
+ assertEquals(transParams.countPets(), 3);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestCustomerTransactionParametersBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestCustomerTransactionParametersBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestCustomerTransactionParametersBuilder.java
new file mode 100644
index 0000000..45245d5
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestCustomerTransactionParametersBuilder.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.datagenerators.bigpetstore.generators.transaction;
+
+import static org.junit.Assert.assertTrue;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.PetSpecies;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.CustomerTransactionParameters;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.CustomerTransactionParametersBuilder;
+import org.junit.Test;
+
+public class TestCustomerTransactionParametersBuilder
+{
+
+ @Test
+ public void testBuild() throws Exception
+ {
+ CustomerTransactionParametersBuilder builder = new CustomerTransactionParametersBuilder();
+
+ builder.addPet(PetSpecies.DOG);
+ builder.addPet(PetSpecies.DOG);
+ builder.addPet(PetSpecies.DOG);
+
+ builder.setAveragePurchaseTriggerTime(1.0);
+ builder.setAverageTransactionTriggerTime(2.0);
+
+ CustomerTransactionParameters transParams = builder.build();
+
+ assertTrue(transParams.countPetsBySpecies(PetSpecies.DOG) == 3);
+ assertTrue(transParams.countPetsBySpecies(PetSpecies.CAT) == 0);
+ assertTrue(transParams.getAveragePurchaseTriggerTime() == 1.0);
+ assertTrue(transParams.getAverageTransactionTriggerTime() == 2.0);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestCustomerTransactionParametersSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestCustomerTransactionParametersSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestCustomerTransactionParametersSampler.java
new file mode 100644
index 0000000..0f4513b
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestCustomerTransactionParametersSampler.java
@@ -0,0 +1,47 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.transaction;
+
+import static org.junit.Assert.assertTrue;
+
+import org.apache.bigtop.datagenerators.bigpetstore.Constants;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.CustomerTransactionParameters;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.CustomerTransactionParametersSamplerBuilder;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.junit.Test;
+
+public class TestCustomerTransactionParametersSampler
+{
+
+ @Test
+ public void testSample() throws Exception
+ {
+ SeedFactory seedFactory = new SeedFactory(1234);
+ CustomerTransactionParametersSamplerBuilder builder = new CustomerTransactionParametersSamplerBuilder(seedFactory);
+ Sampler<CustomerTransactionParameters> sampler = builder.build();
+
+ CustomerTransactionParameters transParams = sampler.sample();
+
+ assertTrue(transParams.countPets() >= Constants.MIN_PETS);
+ assertTrue(transParams.countPets() <= Constants.MAX_PETS);
+ assertTrue(transParams.getAveragePurchaseTriggerTime() >= Constants.PURCHASE_TRIGGER_TIME_MIN);
+ assertTrue(transParams.getAveragePurchaseTriggerTime() <= Constants.PURCHASE_TRIGGER_TIME_MAX);
+ assertTrue(transParams.getAverageTransactionTriggerTime() >= Constants.TRANSACTION_TRIGGER_TIME_MIN);
+ assertTrue(transParams.getAverageTransactionTriggerTime() <= Constants.TRANSACTION_TRIGGER_TIME_MAX);
+ }
+
+}
[11/11] bigtop git commit: BIGTOP-1984. Extract samplers library from
BigPetStore data generator
Posted by rn...@apache.org.
BIGTOP-1984. Extract samplers library from BigPetStore data generator
Project: http://git-wip-us.apache.org/repos/asf/bigtop/repo
Commit: http://git-wip-us.apache.org/repos/asf/bigtop/commit/15af83eb
Tree: http://git-wip-us.apache.org/repos/asf/bigtop/tree/15af83eb
Diff: http://git-wip-us.apache.org/repos/asf/bigtop/diff/15af83eb
Branch: refs/heads/master
Commit: 15af83ebdf9f3e039b15daa0352e802165c55bb4
Parents: 3bbbb55
Author: RJ Nowling <rn...@gmail.com>
Authored: Tue Aug 25 09:21:19 2015 -0500
Committer: RJ Nowling <rn...@gmail.com>
Committed: Tue Aug 25 09:21:19 2015 -0500
----------------------------------------------------------------------
.../bigpetstore-data-generator/build.gradle | 5 +-
.../bigpetstore/datagenerator/Constants.java | 99 ------
.../datagenerator/CustomerGenerator.java | 41 ---
.../bigpetstore/datagenerator/DataLoader.java | 57 ----
.../datagenerator/ProductGenerator.java | 50 ---
.../datagenerator/PurchasingModelGenerator.java | 40 ---
.../datagenerator/StoreGenerator.java | 38 ---
.../datagenerator/TransactionGenerator.java | 43 ---
.../bigpetstore/datagenerator/cli/Driver.java | 315 -------------------
.../datagenerator/cli/Simulation.java | 188 -----------
.../datagenerator/datamodels/Customer.java | 59 ----
.../datagenerator/datamodels/PetSpecies.java | 22 --
.../datagenerator/datamodels/Product.java | 96 ------
.../datagenerator/datamodels/Store.java | 51 ---
.../datagenerator/datamodels/Transaction.java | 68 ----
.../datamodels/inputs/InputData.java | 45 ---
.../datagenerator/datamodels/inputs/Names.java | 46 ---
.../datamodels/inputs/ProductCategory.java | 108 -------
.../datamodels/inputs/ZipcodeRecord.java | 90 ------
.../datagenerator/datareaders/NameReader.java | 62 ----
.../datareaders/ZipcodeReader.java | 193 ------------
.../datagenerator/framework/SeedFactory.java | 38 ---
.../framework/markovmodels/MarkovModel.java | 50 ---
.../markovmodels/MarkovModelBuilder.java | 53 ----
.../framework/markovmodels/MarkovProcess.java | 68 ----
.../ConditionalProbabilityDensityFunction.java | 21 --
.../framework/pdfs/ExponentialPDF.java | 31 --
.../framework/pdfs/GaussianPDF.java | 37 ---
.../datagenerator/framework/pdfs/JointPDF.java | 49 ---
.../framework/pdfs/MultinomialPDF.java | 57 ----
.../pdfs/ProbabilityDensityFunction.java | 21 --
.../framework/pdfs/UniformPDF.java | 36 ---
.../BoundedMultiModalGaussianSampler.java | 61 ----
.../framework/samplers/ConditionalSampler.java | 21 --
.../samplers/DoubleSequenceSampler.java | 70 -----
.../framework/samplers/ExponentialSampler.java | 37 ---
.../framework/samplers/GaussianSampler.java | 39 ---
.../framework/samplers/MonteCarloSampler.java | 55 ----
.../samplers/RouletteWheelSampler.java | 111 -------
.../framework/samplers/Sampler.java | 21 --
.../framework/samplers/SequenceSampler.java | 70 -----
.../samplers/StatefulMonteCarloSampler.java | 60 ----
.../framework/samplers/UniformIntSampler.java | 43 ---
.../framework/samplers/UniformSampler.java | 46 ---
.../wfs/ConditionalWeightFunction.java | 21 --
.../framework/wfs/WeightFunction.java | 21 --
.../customer/CustomerLocationPDF.java | 69 ----
.../generators/customer/CustomerSampler.java | 56 ----
.../customer/CustomerSamplerBuilder.java | 80 -----
.../generators/customer/CustomerStorePDF.java | 41 ---
.../products/ProductBuilderIterator.java | 80 -----
.../products/ProductCategoryBuilder.java | 195 ------------
.../generators/products/ProductFieldValue.java | 45 ---
.../products/ProductFilterIterator.java | 72 -----
.../generators/products/ProductIterator.java | 78 -----
.../products/cartesian/CartesianProduct.java | 24 --
.../cartesian/CartesianProductBase.java | 56 ----
.../cartesian/CartesianProductField.java | 79 -----
.../collections/MediumProductCollection.java | 275 ----------------
.../collections/SmallProductCollection.java | 162 ----------
.../products/rules/AlwaysTrueRule.java | 29 --
.../generators/products/rules/AndRule.java | 50 ---
.../products/rules/FieldPredicate.java | 48 ---
.../generators/products/rules/NotRule.java | 36 ---
.../generators/products/rules/OrRule.java | 43 ---
.../generators/products/rules/Rule.java | 23 --
.../MarkovModelProductCategorySampler.java | 119 -------
.../purchase/MarkovPurchasingModel.java | 65 ----
.../purchase/MarkovPurchasingModelSampler.java | 47 ---
.../purchase/MultinomialPurchasingModel.java | 67 ----
.../MultinomialPurchasingModelSampler.java | 143 ---------
.../generators/purchase/PurchasingModel.java | 31 --
.../purchase/PurchasingModelSamplerBuilder.java | 108 -------
.../purchase/PurchasingProcesses.java | 39 ---
.../store/StoreLocationIncomePDF.java | 65 ----
.../store/StoreLocationPopulationPDF.java | 43 ---
.../generators/store/StoreSampler.java | 45 ---
.../generators/store/StoreSamplerBuilder.java | 57 ----
.../transaction/CategoryWeightFunction.java | 39 ---
.../transaction/CustomerInventory.java | 65 ----
.../transaction/CustomerInventoryBuilder.java | 69 ----
.../CustomerTransactionParameters.java | 73 -----
.../CustomerTransactionParametersBuilder.java | 58 ----
.../CustomerTransactionParametersSampler.java | 61 ----
...omerTransactionParametersSamplerBuilder.java | 55 ----
.../transaction/ProductCategoryInventory.java | 58 ----
.../ProductCategoryUsageSimulator.java | 72 -----
.../ProductCategoryUsageTrajectory.java | 74 -----
.../ProposedPurchaseTimeSampler.java | 49 ---
.../TransactionPurchasesHiddenMarkovModel.java | 108 -------
.../TransactionPurchasesSamplerBuilder.java | 70 -----
.../transaction/TransactionSampler.java | 56 ----
.../transaction/TransactionSamplerBuilder.java | 95 ------
.../transaction/TransactionTimePDF.java | 31 --
.../TransactionTimeSamplerBuilder.java | 56 ----
.../datagenerators/bigpetstore/Constants.java | 99 ++++++
.../bigpetstore/CustomerGenerator.java | 41 +++
.../datagenerators/bigpetstore/DataLoader.java | 57 ++++
.../bigpetstore/ProductGenerator.java | 50 +++
.../bigpetstore/PurchasingModelGenerator.java | 40 +++
.../bigpetstore/StoreGenerator.java | 38 +++
.../bigpetstore/TransactionGenerator.java | 43 +++
.../datagenerators/bigpetstore/cli/Driver.java | 315 +++++++++++++++++++
.../bigpetstore/cli/Simulation.java | 188 +++++++++++
.../bigpetstore/datamodels/Customer.java | 59 ++++
.../bigpetstore/datamodels/PetSpecies.java | 22 ++
.../bigpetstore/datamodels/Product.java | 96 ++++++
.../bigpetstore/datamodels/Store.java | 51 +++
.../bigpetstore/datamodels/Transaction.java | 68 ++++
.../datamodels/inputs/InputData.java | 45 +++
.../bigpetstore/datamodels/inputs/Names.java | 46 +++
.../datamodels/inputs/ProductCategory.java | 108 +++++++
.../datamodels/inputs/ZipcodeRecord.java | 90 ++++++
.../bigpetstore/datareaders/NameReader.java | 62 ++++
.../bigpetstore/datareaders/ZipcodeReader.java | 193 ++++++++++++
.../customer/CustomerLocationPDF.java | 69 ++++
.../generators/customer/CustomerSampler.java | 56 ++++
.../customer/CustomerSamplerBuilder.java | 80 +++++
.../generators/customer/CustomerStorePDF.java | 41 +++
.../products/ProductBuilderIterator.java | 80 +++++
.../products/ProductCategoryBuilder.java | 195 ++++++++++++
.../generators/products/ProductFieldValue.java | 45 +++
.../products/ProductFilterIterator.java | 72 +++++
.../generators/products/ProductIterator.java | 78 +++++
.../products/cartesian/CartesianProduct.java | 24 ++
.../cartesian/CartesianProductBase.java | 56 ++++
.../cartesian/CartesianProductField.java | 79 +++++
.../collections/MediumProductCollection.java | 275 ++++++++++++++++
.../collections/SmallProductCollection.java | 162 ++++++++++
.../products/rules/AlwaysTrueRule.java | 29 ++
.../generators/products/rules/AndRule.java | 50 +++
.../products/rules/FieldPredicate.java | 48 +++
.../generators/products/rules/NotRule.java | 36 +++
.../generators/products/rules/OrRule.java | 43 +++
.../generators/products/rules/Rule.java | 23 ++
.../MarkovModelProductCategorySampler.java | 119 +++++++
.../purchase/MarkovPurchasingModel.java | 65 ++++
.../purchase/MarkovPurchasingModelSampler.java | 47 +++
.../purchase/MultinomialPurchasingModel.java | 67 ++++
.../MultinomialPurchasingModelSampler.java | 143 +++++++++
.../generators/purchase/PurchasingModel.java | 31 ++
.../purchase/PurchasingModelSamplerBuilder.java | 108 +++++++
.../purchase/PurchasingProcesses.java | 39 +++
.../store/StoreLocationIncomePDF.java | 65 ++++
.../store/StoreLocationPopulationPDF.java | 43 +++
.../generators/store/StoreSampler.java | 45 +++
.../generators/store/StoreSamplerBuilder.java | 57 ++++
.../transaction/CategoryWeightFunction.java | 39 +++
.../transaction/CustomerInventory.java | 65 ++++
.../transaction/CustomerInventoryBuilder.java | 67 ++++
.../CustomerTransactionParameters.java | 73 +++++
.../CustomerTransactionParametersBuilder.java | 58 ++++
.../CustomerTransactionParametersSampler.java | 61 ++++
...omerTransactionParametersSamplerBuilder.java | 55 ++++
.../transaction/ProductCategoryInventory.java | 58 ++++
.../ProductCategoryUsageSimulator.java | 72 +++++
.../ProductCategoryUsageTrajectory.java | 74 +++++
.../ProposedPurchaseTimeSampler.java | 49 +++
.../TransactionPurchasesHiddenMarkovModel.java | 108 +++++++
.../TransactionPurchasesSamplerBuilder.java | 70 +++++
.../transaction/TransactionSampler.java | 56 ++++
.../transaction/TransactionSamplerBuilder.java | 95 ++++++
.../transaction/TransactionTimePDF.java | 31 ++
.../TransactionTimeSamplerBuilder.java | 56 ++++
.../datagenerator/datamodels/TestProduct.java | 77 -----
.../markovmodels/TestMarkovModelBuilder.java | 76 -----
.../markovmodels/TestMarkovProcess.java | 53 ----
.../framework/pdfs/TestMultinomialPDF.java | 41 ---
.../TestBoundedMultiModalGaussianSampler.java | 48 ---
.../samplers/TestExponentialSampler.java | 41 ---
.../framework/samplers/TestGaussianSampler.java | 43 ---
.../samplers/TestRouletteWheelSampler.java | 71 -----
.../framework/samplers/TestSequenceSampler.java | 38 ---
.../samplers/TestUniformIntSampler.java | 60 ----
.../customer/TestCustomerLocationPDF.java | 57 ----
.../customer/TestCustomerSampler.java | 106 -------
.../customer/TestCustomerSamplerBuilder.java | 76 -----
.../cartesian/TestCartesianProductBase.java | 56 ----
.../cartesian/TestCartesianProductField.java | 72 -----
.../products/rules/TestAlwaysTrueRule.java | 30 --
.../generators/products/rules/TestAndRule.java | 51 ---
.../products/rules/TestFieldPredicate.java | 42 ---
.../generators/products/rules/TestNotRule.java | 36 ---
.../generators/products/rules/TestOrRule.java | 51 ---
.../TestProductCategoryMarkovModelSampler.java | 108 -------
.../purchase/TestPurchasingModelSampler.java | 100 ------
.../TestPurchasingModelSamplerBuilder.java | 100 ------
.../purchase/TestPurchasingProcesses.java | 70 -----
.../store/TestStoreLocationIncomePDF.java | 48 ---
.../store/TestStoreLocationPopulationPDF.java | 48 ---
.../generators/store/TestStoreSampler.java | 58 ----
.../store/TestStoreSamplerBuilder.java | 58 ----
.../transaction/TestCustomerInventory.java | 94 ------
.../TestCustomerInventoryBuilder.java | 91 ------
.../TestCustomerTransactionParameters.java | 69 ----
...estCustomerTransactionParametersBuilder.java | 48 ---
...estCustomerTransactionParametersSampler.java | 47 ---
...omerTransactionParametersSamplerBuilder.java | 47 ---
.../TestProductCategoryInventory.java | 75 -----
.../TestProductCategoryUsageSimulator.java | 51 ---
.../TestProductCategoryUsageTrajectory.java | 69 ----
...stTransactionPurchasesHiddenMarkovModel.java | 205 ------------
.../transaction/TestTransactionTimePDF.java | 35 ---
.../bigpetstore/datamodels/TestProduct.java | 77 +++++
.../customer/TestCustomerLocationPDF.java | 58 ++++
.../customer/TestCustomerSampler.java | 108 +++++++
.../customer/TestCustomerSamplerBuilder.java | 77 +++++
.../cartesian/TestCartesianProductBase.java | 57 ++++
.../cartesian/TestCartesianProductField.java | 74 +++++
.../products/rules/TestAlwaysTrueRule.java | 32 ++
.../generators/products/rules/TestAndRule.java | 55 ++++
.../products/rules/TestFieldPredicate.java | 44 +++
.../generators/products/rules/TestNotRule.java | 39 +++
.../generators/products/rules/TestOrRule.java | 55 ++++
.../TestProductCategoryMarkovModelSampler.java | 108 +++++++
.../purchase/TestPurchasingModelSampler.java | 100 ++++++
.../TestPurchasingModelSamplerBuilder.java | 100 ++++++
.../purchase/TestPurchasingProcesses.java | 70 +++++
.../store/TestStoreLocationIncomePDF.java | 49 +++
.../store/TestStoreLocationPopulationPDF.java | 49 +++
.../generators/store/TestStoreSampler.java | 59 ++++
.../store/TestStoreSamplerBuilder.java | 59 ++++
.../transaction/TestCustomerInventory.java | 94 ++++++
.../TestCustomerInventoryBuilder.java | 91 ++++++
.../TestCustomerTransactionParameters.java | 69 ++++
...estCustomerTransactionParametersBuilder.java | 48 +++
...estCustomerTransactionParametersSampler.java | 47 +++
...omerTransactionParametersSamplerBuilder.java | 47 +++
.../TestProductCategoryInventory.java | 75 +++++
.../TestProductCategoryUsageSimulator.java | 53 ++++
.../TestProductCategoryUsageTrajectory.java | 70 +++++
...stTransactionPurchasesHiddenMarkovModel.java | 205 ++++++++++++
.../transaction/TestTransactionTimePDF.java | 35 +++
.../bigtop-samplers/README.md | 49 +++
.../bigtop-samplers/build.gradle | 64 ++++
.../bigtop-samplers/settings.gradle | 16 +
.../datagenerators/samplers/SeedFactory.java | 38 +++
.../samplers/markovmodels/MarkovModel.java | 50 +++
.../markovmodels/MarkovModelBuilder.java | 53 ++++
.../samplers/markovmodels/MarkovProcess.java | 68 ++++
.../ConditionalProbabilityDensityFunction.java | 21 ++
.../samplers/pdfs/ExponentialPDF.java | 31 ++
.../samplers/pdfs/GaussianPDF.java | 37 +++
.../datagenerators/samplers/pdfs/JointPDF.java | 49 +++
.../samplers/pdfs/MultinomialPDF.java | 57 ++++
.../pdfs/ProbabilityDensityFunction.java | 21 ++
.../samplers/pdfs/UniformPDF.java | 36 +++
.../BoundedMultiModalGaussianSampler.java | 61 ++++
.../samplers/samplers/ConditionalSampler.java | 21 ++
.../samplers/DoubleSequenceSampler.java | 70 +++++
.../samplers/samplers/ExponentialSampler.java | 37 +++
.../samplers/samplers/GaussianSampler.java | 39 +++
.../samplers/samplers/MonteCarloSampler.java | 55 ++++
.../samplers/samplers/RouletteWheelSampler.java | 111 +++++++
.../samplers/samplers/Sampler.java | 21 ++
.../samplers/samplers/SequenceSampler.java | 70 +++++
.../samplers/StatefulMonteCarloSampler.java | 60 ++++
.../samplers/samplers/UniformIntSampler.java | 43 +++
.../samplers/samplers/UniformSampler.java | 46 +++
.../samplers/wfs/ConditionalWeightFunction.java | 21 ++
.../samplers/wfs/WeightFunction.java | 21 ++
.../markovmodels/TestMarkovModelBuilder.java | 76 +++++
.../markovmodels/TestMarkovProcess.java | 53 ++++
.../samplers/pdfs/TestMultinomialPDF.java | 42 +++
.../TestBoundedMultiModalGaussianSampler.java | 50 +++
.../samplers/TestExponentialSampler.java | 41 +++
.../samplers/samplers/TestGaussianSampler.java | 43 +++
.../samplers/TestRouletteWheelSampler.java | 71 +++++
.../samplers/samplers/TestSequenceSampler.java | 38 +++
.../samplers/TestUniformIntSampler.java | 60 ++++
270 files changed, 9015 insertions(+), 8855 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/build.gradle
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/build.gradle b/bigtop-data-generators/bigpetstore-data-generator/build.gradle
index 8c2ea57..d18cac5 100644
--- a/bigtop-data-generators/bigpetstore-data-generator/build.gradle
+++ b/bigtop-data-generators/bigpetstore-data-generator/build.gradle
@@ -18,7 +18,7 @@ apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'maven'
group = 'org.apache.bigtop'
-version = '0.9.0-SNAPSHOT'
+version = '1.1.0-SNAPSHOT'
jar {
@@ -30,7 +30,7 @@ jar {
manifest {
attributes 'Title': 'BigPetStore Data Generator', 'Version': version
- attributes 'Main-Class': 'org.apache.bigtop.bigpetstore.datagenerator.cli.Driver'
+ attributes 'Main-Class': 'org.apache.bigtop.datagenerators.bigpetstore.cli.Driver'
}
}
@@ -59,6 +59,7 @@ dependencies {
compile 'com.google.guava:guava:18.0'
compile 'com.google.code.gson:gson:2.3'
compile 'org.apache.commons:commons-lang3:3.4'
+ compile 'org.apache.bigtop:bigtop-samplers:1.1.0-SNAPSHOT'
testCompile 'junit:junit:4.+'
}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/Constants.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/Constants.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/Constants.java
deleted file mode 100644
index ff87c2e..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/Constants.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * 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;
-
-import java.io.File;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.commons.lang3.tuple.Pair;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-
-public class Constants
-{
- public static enum PurchasingModelType
- {
- MULTINOMIAL,
- MARKOV;
- }
-
- public static enum ProductsCollectionSize
- {
- SMALL,
- MEDIUM;
- }
-
- public static final File COORDINATES_FILE = new File("zips.csv");
- public static final File INCOMES_FILE = new File("ACS_12_5YR_S1903/ACS_12_5YR_S1903_with_ann.csv");
- public static final File POPULATION_FILE = new File("population_data.csv");
-
- public static final File NAMEDB_FILE = new File("namedb/data/data.dat");
-
- public static final ProductsCollectionSize PRODUCTS_COLLECTION = ProductsCollectionSize.MEDIUM;
-
- public static final double INCOME_SCALING_FACTOR = 100.0;
-
- public static final int MIN_PETS = 1;
- public static final int MAX_PETS = 10;
-
- public static final List<Pair<Double, Double>> TRANSACTION_TRIGGER_TIME_GAUSSIANS = ImmutableList.of(Pair.of(5.0, 2.0));
- public static final List<Pair<Double, Double>> PURCHASE_TRIGGER_TIME_GAUSSIANS = ImmutableList.of(Pair.of(10.0, 4.0));
-
- public static final double TRANSACTION_TRIGGER_TIME_MAX = 10.0;
- public static final double TRANSACTION_TRIGGER_TIME_MIN = 1.0;
-
- public static final double PURCHASE_TRIGGER_TIME_MAX = 20.0;
- public static final double PURCHASE_TRIGGER_TIME_MIN = 1.0;
-
- public static final double AVERAGE_CUSTOMER_STORE_DISTANCE = 5.0; // miles
-
- public static final PurchasingModelType PURCHASING_MODEL_TYPE = PurchasingModelType.MULTINOMIAL;
-
- public static final List<Pair<Double, Double>> PRODUCT_MSM_FIELD_WEIGHT_GAUSSIANS = ImmutableList.of(Pair.of(0.15, 0.1), Pair.of(0.85, 0.1));
- public static final double PRODUCT_MSM_FIELD_WEIGHT_LOWERBOUND = 0.05;
- public static final double PRODUCT_MSM_FIELD_WEIGHT_UPPERBOUND = 0.95;
-
- public static final List<Pair<Double, Double>> PRODUCT_MSM_FIELD_SIMILARITY_WEIGHT_GAUSSIANS = ImmutableList.of(Pair.of(0.15, 0.1), Pair.of(0.85, 0.1));
- public static final double PRODUCT_MSM_FIELD_SIMILARITY_WEIGHT_LOWERBOUND = 0.05;
- public static final double PRODUCT_MSM_FIELD_SIMILARITY_WEIGHT_UPPERBOUND = 0.95;
-
- public static final List<Pair<Double, Double>> PRODUCT_MSM_LOOPBACK_WEIGHT_GAUSSIANS = ImmutableList.of(Pair.of(0.25, 0.1), Pair.of(0.75, 0.1));
- public static final double PRODUCT_MSM_LOOPBACK_WEIGHT_LOWERBOUND = 0.05;
- public static final double PRODUCT_MSM_LOOPBACK_WEIGHT_UPPERBOUND = 0.95;
-
- public static final double PRODUCT_MULTINOMIAL_POSITIVE_WEIGHT = 10.0;
- public static final double PRODUCT_MULTINOMIAL_NEUTRAL_WEIGHT = 1.0;
- public static final double PRODUCT_MULTINOMIAL_NEGATIVE_WEIGHT = 0.1;
- public static final int PRODUCT_MULTINOMIAL_POSITIVE_COUNT_MIN = 1;
- public static final double PRODUCT_MULTINOMIAL_POSITIVE_FREQUENCY = 0.1; // 10%
-
- public static final String PRODUCT_QUANTITY = "quantity";
- public static final String PRODUCT_CATEGORY = "category";
- public static final String PRODUCT_UNIT_PRICE = "unitPrice";
- public static final String PRODUCT_PRICE = "price";
-
- /*
- * Until we have a more intelligent way (e.g., based on range) of dealing with prices,
- * let's exclude them.
- */
- public static final Set<String> PRODUCT_MODEL_EXCLUDED_FIELDS = ImmutableSet.of(PRODUCT_CATEGORY,
- PRODUCT_UNIT_PRICE,
- PRODUCT_PRICE);
-
- public static final double STOP_CATEGORY_WEIGHT = 0.01;
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/CustomerGenerator.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/CustomerGenerator.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/CustomerGenerator.java
deleted file mode 100644
index 799b2e3..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/CustomerGenerator.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * 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;
-
-import java.util.List;
-
-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.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.customer.CustomerSamplerBuilder;
-
-public class CustomerGenerator
-{
- final Sampler<Customer> sampler;
-
- public CustomerGenerator(InputData inputData, List<Store> stores, SeedFactory seedFactory)
- {
- CustomerSamplerBuilder builder = new CustomerSamplerBuilder(stores, inputData, seedFactory);
- sampler = builder.build();
- }
-
- public Customer generate() throws Exception
- {
- return sampler.sample();
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/DataLoader.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/DataLoader.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/DataLoader.java
deleted file mode 100644
index a67acd7..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/DataLoader.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * 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;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.InputStream;
-import java.util.List;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.InputData;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.Names;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord;
-import org.apache.bigtop.bigpetstore.datagenerator.datareaders.NameReader;
-import org.apache.bigtop.bigpetstore.datagenerator.datareaders.ZipcodeReader;
-
-public class DataLoader
-{
- private InputStream getResource(File filename) throws Exception
- {
- InputStream stream = getClass().getResourceAsStream("/input_data/" + filename);
- return new BufferedInputStream(stream);
- }
-
- public InputData loadData() throws Exception
- {
-
- System.out.println("Reading zipcode data");
- ZipcodeReader zipcodeReader = new ZipcodeReader();
- zipcodeReader.setCoordinatesFile(getResource(Constants.COORDINATES_FILE));
- zipcodeReader.setIncomesFile(getResource(Constants.INCOMES_FILE));
- zipcodeReader.setPopulationFile(getResource(Constants.POPULATION_FILE));
- List<ZipcodeRecord> zipcodeTable = zipcodeReader.readData();
- System.out.println("Read " + zipcodeTable.size() + " zipcode entries");
-
- System.out.println("Reading name data");
- NameReader nameReader = new NameReader(getResource(Constants.NAMEDB_FILE));
- Names names = nameReader.readData();
- System.out.println("Read " + names.getFirstNames().size() + " first names and " + names.getLastNames().size() + " last names");
-
- InputData inputData = new InputData(zipcodeTable, names);
-
- return inputData;
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/ProductGenerator.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/ProductGenerator.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/ProductGenerator.java
deleted file mode 100644
index cd008ac..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/ProductGenerator.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * 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;
-
-import java.util.List;
-
-import org.apache.bigtop.bigpetstore.datagenerator.Constants.ProductsCollectionSize;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.products.collections.MediumProductCollection;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.products.collections.SmallProductCollection;
-
-public class ProductGenerator
-{
- ProductsCollectionSize collection;
-
- public ProductGenerator(ProductsCollectionSize collection)
- {
- this.collection = collection;
- }
-
- public List<ProductCategory> generate()
- {
- List<ProductCategory> categories;
-
- if(collection.equals(ProductsCollectionSize.SMALL))
- {
- SmallProductCollection collection = new SmallProductCollection();
- categories = collection.generateProductCategory();
- } else
- {
- MediumProductCollection collection = new MediumProductCollection();
- categories = collection.generateProductCategory();
- }
-
- return categories;
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/PurchasingModelGenerator.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/PurchasingModelGenerator.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/PurchasingModelGenerator.java
deleted file mode 100644
index 6994d9e..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/PurchasingModelGenerator.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * 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;
-
-import java.util.Collection;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.PurchasingModel;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.PurchasingModelSamplerBuilder;
-
-public class PurchasingModelGenerator
-{
- final Sampler<? extends PurchasingModel> sampler;
-
- public PurchasingModelGenerator(Collection<ProductCategory> productCategories, SeedFactory seedFactory) throws Exception
- {
- PurchasingModelSamplerBuilder builder = new PurchasingModelSamplerBuilder(productCategories, seedFactory);
- sampler = builder.build();
- }
-
- public PurchasingModel generate() throws Exception
- {
- return sampler.sample();
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/StoreGenerator.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/StoreGenerator.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/StoreGenerator.java
deleted file mode 100644
index df6d759..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/StoreGenerator.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Store;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.InputData;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.store.StoreSamplerBuilder;
-
-public class StoreGenerator
-{
- final Sampler<Store> sampler;
-
- public StoreGenerator(InputData inputData, SeedFactory seedFactory)
- {
- StoreSamplerBuilder builder = new StoreSamplerBuilder(inputData.getZipcodeTable(), seedFactory);
- sampler = builder.build();
- }
-
- public Store generate() throws Exception
- {
- return sampler.sample();
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/TransactionGenerator.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/TransactionGenerator.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/TransactionGenerator.java
deleted file mode 100644
index 8f78bb7..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/TransactionGenerator.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * 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;
-
-import java.util.Collection;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Customer;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Transaction;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.PurchasingModel;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.TransactionSamplerBuilder;
-
-public class TransactionGenerator
-{
- Sampler<Transaction> sampler;
-
- public TransactionGenerator(Customer customer, PurchasingModel profile,
- Collection<ProductCategory> productCategories, SeedFactory seedFactory) throws Exception
- {
- sampler = new TransactionSamplerBuilder(productCategories,
- customer, profile, seedFactory).build();
- }
-
- public Transaction generate() throws Exception
- {
- return sampler.sample();
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/cli/Driver.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/cli/Driver.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/cli/Driver.java
deleted file mode 100644
index 3fdef68..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/cli/Driver.java
+++ /dev/null
@@ -1,315 +0,0 @@
-/**
- * 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.cli;
-
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.OutputStream;
-import java.util.Collection;
-import java.util.List;
-
-import org.apache.bigtop.bigpetstore.datagenerator.DataLoader;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Customer;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Store;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Transaction;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.InputData;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.PurchasingModel;
-import org.apache.commons.lang3.tuple.Pair;
-
-
-public class Driver
-{
- int nStores;
- int nCustomers;
- int nPurchasingModels;
- double simulationTime;
- long seed;
- File outputDir;
-
- static final int NPARAMS = 6;
-
- private void printUsage()
- {
- String usage = "BigPetStore Data Generator\n" +
- "\n" +
- "Usage: java -jar bps-data-generator-v0.2.java outputDir nStores nCustomers nPurchasingModels simulationLength seed\n" +
- "\n" +
- "outputDir - (string) directory to write files\n" +
- "nStores - (int) number of stores to generate\n" +
- "nCustomers - (int) number of customers to generate\n" +
- "nPurchasingModels - (int) number of purchasing models to generate\n" +
- "simulationLength - (float) number of days to simulate\n" +
- "seed - (long) seed for RNG. If not given, one is reandomly generated.\n";
-
- System.out.println(usage);
- }
-
- public void parseArgs(String[] args)
- {
- if(args.length != NPARAMS && args.length != (NPARAMS - 1))
- {
- printUsage();
- System.exit(1);
- }
-
- int i = -1;
-
- outputDir = new File(args[++i]);
- if(! outputDir.exists())
- {
- System.err.println("Given path (" + args[i] + ") does not exist.\n");
- printUsage();
- System.exit(1);
- }
-
- if(! outputDir.isDirectory())
- {
- System.err.println("Given path (" + args[i] + ") is not a directory.\n");
- printUsage();
- System.exit(1);
- }
-
- try
- {
- nStores = Integer.parseInt(args[++i]);
- }
- catch(Exception e)
- {
- System.err.println("Unable to parse '" + args[i] + "' as an integer for nStores.\n");
- printUsage();
- System.exit(1);
- }
-
- try
- {
- nCustomers = Integer.parseInt(args[++i]);
- }
- catch(Exception e)
- {
- System.err.println("Unable to parse '" + args[i] + "' as an integer for nCustomers.\n");
- printUsage();
- System.exit(1);
- }
-
- try
- {
- nPurchasingModels = Integer.parseInt(args[++i]);
- }
- catch(Exception e)
- {
- System.err.println("Unable to parse '" + args[i] + "' as an integer for nPurchasingModels.\n");
- printUsage();
- System.exit(1);
- }
-
- try
- {
- simulationTime = Double.parseDouble(args[++i]);
- }
- catch(Exception e)
- {
- System.err.println("Unable to parse '" + args[i] + "' as a float for simulationLength.\n");
- printUsage();
- System.exit(1);
- }
-
- try
- {
- seed = Long.parseLong(args[++i]);
- }
- catch(Exception e)
- {
- System.err.println("Unable to parse '" + args[i] + "' as a long for the seed.\n");
- printUsage();
- System.exit(1);
- }
- }
-
- private void writeTransactions(Collection<Transaction> transactions) throws Exception
- {
- File outputFile = new File(outputDir.toString() + File.separator + "transactions.txt");
- System.out.println(outputFile.toString());
- OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
-
- for(Transaction transaction : transactions)
- {
- for(Product product : transaction.getProducts())
- {
- String record = transaction.getId() + ",";
- record += transaction.getDateTime() + ",";
- record += transaction.getStore().getId() + ",";
- record += transaction.getStore().getLocation().getZipcode() + ",";
- record += transaction.getStore().getLocation().getCity() + ",";
- record += transaction.getStore().getLocation().getState() + ",";
- record += transaction.getCustomer().getId() + ",";
- Pair<String, String> name = transaction.getCustomer().getName();
- record += name.getLeft() + " " + name.getRight() + ",";
- record += transaction.getCustomer().getLocation().getZipcode() + ",";
- record += transaction.getCustomer().getLocation().getCity() + ",";
- record += transaction.getCustomer().getLocation().getState() + ",";
- record += product.toString() + "\n";
-
- outputStream.write(record.getBytes());
- }
- }
-
- outputStream.close();
- }
-
- private void writeCustomers(Collection<Customer> customers) throws Exception
- {
- File outputFile = new File(outputDir.toString() + File.separator + "customers.txt");
- System.out.println(outputFile.toString());
- OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
-
- for(Customer customer : customers)
- {
- String record = customer.getId() + ",";
- Pair<String, String> name = customer.getName();
- record += name.getLeft() + "," + name.getRight() + ",";
- record += customer.getLocation().getZipcode() + ",";
- record += customer.getLocation().getCity() + ",";
- record += customer.getLocation().getState() + "\n";
-
- outputStream.write(record.getBytes());
- }
-
- outputStream.close();
- }
-
- private void writeStores(Collection<Store> stores) throws Exception
- {
- File outputFile = new File(outputDir.toString() + File.separator + "stores.txt");
- System.out.println(outputFile.toString());
- OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
-
- for(Store store : stores)
- {
- String record = store.getId() + ",";
- record += store.getLocation().getZipcode() + ",";
- record += store.getLocation().getCity() + ",";
- record += store.getLocation().getState() + "\n";
-
- outputStream.write(record.getBytes());
- }
-
- outputStream.close();
- }
-
- private void writeProducts(Collection<ProductCategory> productCategories) throws Exception
- {
- File outputFile = new File(outputDir.toString() + File.separator + "products.txt");
- System.out.println(outputFile.toString());
- OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
-
- for(ProductCategory category : productCategories)
- {
-
- for(Product product : category.getProducts())
- {
- String record = category.getCategoryLabel() + ",";
- record += product.toString() + "\n";
-
- outputStream.write(record.getBytes());
- }
- }
-
- outputStream.close();
- }
-
- private void writePurchasingProfiles(List<ProductCategory> productCategories, List<PurchasingModel> profiles) throws Exception
- {
- File outputFile = new File(outputDir.toString() + File.separator + "purchasing_profiles.txt");
- System.out.println(outputFile.toString());
- OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
-
- for(ProductCategory category : productCategories)
- {
- int i = 0;
- for(PurchasingModel model : profiles)
- {
- Object productModel = model.getProfile(category.getCategoryLabel());
- String record = productModel.toString();
-
- outputStream.write(record.getBytes());
-
- i += 1;
- }
- }
-
- outputStream.close();
- }
-
- public Simulation buildSimulation(InputData inputData)
- {
- return new Simulation(inputData, nStores, nCustomers, nPurchasingModels, simulationTime, seed);
- }
-
- private void run(InputData inputData) throws Exception
- {
- Simulation simulation = buildSimulation(inputData);
-
- simulation.simulate();
-
- writeStores(simulation.getStores());
- writeCustomers(simulation.getCustomers());
- writeProducts(simulation.getProductCategories());
- writePurchasingProfiles(simulation.getProductCategories(), simulation.getPurchasingProfiles());
- writeTransactions(simulation.getTransactions());
- }
- public void run(String[] args) throws Exception
- {
- parseArgs(args);
-
- InputData inputData = (new DataLoader()).loadData();
-
- run(inputData);
- }
-
- public static void main(String[] args) throws Exception
- {
- Driver driver = new Driver();
- driver.run(args);
- }
-
- public Double getSimulationLength()
- {
- return simulationTime;
- }
-
- public int getNCustomers()
- {
- return nCustomers;
- }
-
- public long getSeed()
- {
- return seed;
- }
-
- public int getNStores()
- {
- return nStores;
- }
-
- public File getOutputDir()
- {
- return outputDir;
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/cli/Simulation.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/cli/Simulation.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/cli/Simulation.java
deleted file mode 100644
index 4b9b500..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/cli/Simulation.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/**
- * 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.cli;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Vector;
-
-import org.apache.bigtop.bigpetstore.datagenerator.Constants;
-import org.apache.bigtop.bigpetstore.datagenerator.CustomerGenerator;
-import org.apache.bigtop.bigpetstore.datagenerator.ProductGenerator;
-import org.apache.bigtop.bigpetstore.datagenerator.PurchasingModelGenerator;
-import org.apache.bigtop.bigpetstore.datagenerator.StoreGenerator;
-import org.apache.bigtop.bigpetstore.datagenerator.TransactionGenerator;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Customer;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Store;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Transaction;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.InputData;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.RouletteWheelSampler;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.PurchasingModel;
-
-import com.google.common.collect.Lists;
-
-public class Simulation
-{
- InputData inputData;
- SeedFactory seedFactory;
- int nStores;
- int nCustomers;
- int nPurchasingModels;
- double simulationTime;
-
- List<Store> stores;
- List<Customer> customers;
- Sampler<PurchasingModel> purchasingModelSampler;
- List<PurchasingModel> purchasingProfiles;
- List<Transaction> transactions;
- List<ProductCategory> productCategories;
-
- public Simulation(InputData inputData, int nStores, int nCustomers, int nPurchasingModels, double simulationTime, long seed)
- {
- this.inputData = inputData;
- this.nStores = nStores;
- this.nCustomers = nCustomers;
- this.nPurchasingModels = nPurchasingModels;
- this.simulationTime = simulationTime;
- seedFactory = new SeedFactory(seed);
- }
-
- public void generateStores() throws Exception
- {
- System.out.println("Generating stores");
- StoreGenerator storeGenerator = new StoreGenerator(inputData, seedFactory);
-
- stores = new Vector<Store>();
- for(int i = 0; i < nStores; i++)
- {
- Store store = storeGenerator.generate();
- stores.add(store);
- }
-
- stores = Collections.unmodifiableList(stores);
-
- System.out.println("Generated " + stores.size() + " stores");
- }
-
- public void generateCustomers() throws Exception
- {
- System.out.println("Generating customers");
- CustomerGenerator generator = new CustomerGenerator(inputData, stores, seedFactory);
-
- customers = new Vector<Customer>();
- for(int i = 0; i < nCustomers; i++)
- {
- Customer customer = generator.generate();
- customers.add(customer);
- }
-
- customers = Collections.unmodifiableList(customers);
-
- System.out.println("Generated " + customers.size() + " customers");
- }
-
- public void generateProducts()
- {
- System.out.println("Generating products");
- ProductGenerator generator = new ProductGenerator(Constants.PRODUCTS_COLLECTION);
- productCategories = generator.generate();
- }
-
- public void generatePurchasingProfiles() throws Exception
- {
- System.out.println("Generating purchasing profiles");
- PurchasingModelGenerator generator = new PurchasingModelGenerator(productCategories, seedFactory);
-
- purchasingProfiles = new Vector<PurchasingModel>();
- for(int i = 0; i < nPurchasingModels; i++)
- {
- PurchasingModel profile = generator.generate();
- purchasingProfiles.add(profile);
- }
-
- System.out.println("Generated " + purchasingProfiles.size() + " purchasing profiles");
-
- purchasingModelSampler = RouletteWheelSampler.createUniform(purchasingProfiles, seedFactory);
- }
-
- public void generateTransactions() throws Exception
- {
- System.out.println("Generating transactions");
- transactions = Lists.newArrayList();
-
- for(int i = 0; i < nCustomers; i++)
- {
- Customer customer = customers.get(i);
- PurchasingModel profile = purchasingModelSampler.sample();
-
- TransactionGenerator generator = new TransactionGenerator(customer,
- profile, productCategories, seedFactory);
-
- while(true)
- {
- Transaction transaction = generator.generate();
-
- if(transaction.getDateTime() > simulationTime)
- break;
- transactions.add(transaction);
- }
- }
-
- System.out.println("Generated " + transactions.size() + " transactions");
- }
-
- public void simulate() throws Exception
- {
- generateStores();
- generateCustomers();
- generateProducts();
- generatePurchasingProfiles();
- generateTransactions();
- }
-
- public List<Store> getStores()
- {
- return stores;
- }
-
- public List<Customer> getCustomers()
- {
- return customers;
- }
-
- public List<Transaction> getTransactions()
- {
- return transactions;
- }
-
- public InputData getInputData()
- {
- return inputData;
- }
-
- public List<ProductCategory> getProductCategories()
- {
- return this.productCategories;
- }
-
- public List<PurchasingModel> getPurchasingProfiles()
- {
- return this.purchasingProfiles;
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/Customer.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/Customer.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/Customer.java
deleted file mode 100644
index 704c965..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/Customer.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * 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.datamodels;
-
-import java.io.Serializable;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord;
-import org.apache.commons.lang3.tuple.Pair;
-
-public class Customer implements Serializable
-{
- private static final long serialVersionUID = 5739806281335931258L;
-
- int id;
- Pair<String, String> name;
- ZipcodeRecord location;
- Store store;
-
- public Customer(int id, Pair<String, String> name, Store store, ZipcodeRecord location)
- {
- this.id = id;
- this.name = name;
- this.location = location;
- this.store = store;
- }
-
- public int getId()
- {
- return id;
- }
-
- public Pair<String, String> getName()
- {
- return name;
- }
-
- public ZipcodeRecord getLocation()
- {
- return location;
- }
-
- public Store getStore()
- {
- return store;
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/PetSpecies.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/PetSpecies.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/PetSpecies.java
deleted file mode 100644
index d4bab79..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/PetSpecies.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/**
- * 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.datamodels;
-
-public enum PetSpecies
-{
- DOG,
- CAT;
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/Product.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/Product.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/Product.java
deleted file mode 100644
index 1d4e074..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/Product.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/**
- * 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.datamodels;
-
-import java.io.Serializable;
-import java.util.Map;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-
-public class Product implements Serializable
-{
- private static final long serialVersionUID = 4519472063058037956L;
-
- ImmutableMap<String, Object> fields;
-
- public Product(Map<String, Object> fields)
- {
- this.fields = ImmutableMap.copyOf(fields);
- }
-
- public ImmutableSet<String> getFieldNames()
- {
- return fields.keySet();
- }
-
- public Object getFieldValue(String fieldName)
- {
- return fields.get(fieldName);
- }
-
- public String getFieldValueAsString(String fieldName)
- {
- return fields.get(fieldName).toString();
- }
-
- public Double getFieldValueAsDouble(String fieldName)
- {
- Object value = getFieldValue(fieldName);
- try
- {
- Double doubleValue = (Double) value;
- return doubleValue;
- }
- catch(ClassCastException e)
- {
- return null;
- }
- }
-
- public Long getFieldValueAsLong(String fieldName)
- {
- Object value = getFieldValue(fieldName);
- try
- {
- Long longValue = (Long) value;
- return longValue;
- }
- catch(ClassCastException e)
- {
- try
- {
- Integer intValue = (Integer) value;
- return new Long(intValue);
- }
- catch(ClassCastException f)
- {
- return null;
- }
- }
- }
-
- public String toString()
- {
- String str = "";
- for(Map.Entry<String, Object> entry : fields.entrySet())
- {
- str += entry.getKey() + "=" + entry.getValue() + ";";
- }
-
- return str;
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/Store.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/Store.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/Store.java
deleted file mode 100644
index 50e333a..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/Store.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * 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.datamodels;
-
-import java.io.Serializable;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord;
-
-public class Store implements Serializable
-{
- private static final long serialVersionUID = 2347066623022747969L;
-
- int id;
- String name;
- ZipcodeRecord location;
-
- public Store(int id, String name, ZipcodeRecord location)
- {
- this.id = id;
- this.name = name;
- this.location = location;
- }
-
- public int getId()
- {
- return id;
- }
-
- public String getName()
- {
- return name;
- }
-
- public ZipcodeRecord getLocation()
- {
- return location;
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/Transaction.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/Transaction.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/Transaction.java
deleted file mode 100644
index 6a78e44..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/Transaction.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * 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.datamodels;
-
-import java.io.Serializable;
-import java.util.List;
-
-import com.google.common.collect.ImmutableList;
-
-public class Transaction implements Serializable
-{
- private static final long serialVersionUID = 103133601154354349L;
-
- final int id;
- final Customer customer;
- final Store store;
- final Double dateTime;
- final ImmutableList<Product> products;
-
- public Transaction(int id, Customer customer, Store store, Double dateTime, List<Product> products)
- {
- this.id = id;
- this.customer = customer;
- this.store = store;
- this.dateTime = dateTime;
- this.products = ImmutableList.copyOf(products);
- }
-
- public int getId()
- {
- return id;
- }
-
- public Customer getCustomer()
- {
- return customer;
- }
-
- public Store getStore()
- {
- return store;
- }
-
- public Double getDateTime()
- {
- return dateTime;
- }
-
- public ImmutableList<Product> getProducts()
- {
- return products;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/InputData.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/InputData.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/InputData.java
deleted file mode 100644
index 4fad219..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/InputData.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * 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.datamodels.inputs;
-
-import java.io.Serializable;
-import java.util.Collections;
-import java.util.List;
-
-public class InputData implements Serializable
-{
- private static final long serialVersionUID = 9078989799806707788L;
-
- List<ZipcodeRecord> zipcodeTable;
- Names names;
-
- public InputData(List<ZipcodeRecord> zipcodeTable,
- Names names)
- {
- this.zipcodeTable = Collections.unmodifiableList(zipcodeTable);
- this.names = names;
- }
-
- public List<ZipcodeRecord> getZipcodeTable()
- {
- return zipcodeTable;
- }
-
- public Names getNames()
- {
- return names;
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/Names.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/Names.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/Names.java
deleted file mode 100644
index 9402e02..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/Names.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * 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.datamodels.inputs;
-
-import java.io.Serializable;
-import java.util.Map;
-
-import com.google.common.collect.ImmutableMap;
-
-public class Names implements Serializable
-{
- private static final long serialVersionUID = 2731634747628534453L;
-
- final ImmutableMap<String, Double> firstNames;
- final ImmutableMap<String, Double> lastNames;
-
- public Names(Map<String, Double> firstNames,
- Map<String, Double> lastNames)
- {
- this.firstNames = ImmutableMap.copyOf(firstNames);
- this.lastNames = ImmutableMap.copyOf(lastNames);
- }
-
- public ImmutableMap<String, Double> getFirstNames()
- {
- return firstNames;
- }
-
- public ImmutableMap<String, Double> getLastNames()
- {
- return lastNames;
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/ProductCategory.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/ProductCategory.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/ProductCategory.java
deleted file mode 100644
index 6fb0572..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/ProductCategory.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
- * 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.datamodels.inputs;
-
-import java.io.Serializable;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.PetSpecies;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-
-public class ProductCategory implements Serializable
-{
- private static final long serialVersionUID = -7638076590334497836L;
-
- String categoryLabel;
- ImmutableSet<PetSpecies> applicableSpecies;
- ImmutableSet<String> fieldNames;
- boolean triggerTransaction;
- double dailyUsageRate;
- double amountUsedPerPetAverage;
- double amountUsedPerPetVariance;
- double triggerTransactionRate;
- double triggerPurchaseRate;
- ImmutableList<Product> products;
-
- public ProductCategory(String categoryLabel, Set<PetSpecies> species, Set<String> fieldNames,
- boolean triggerTransaction, double dailyUsageRate, double amountUsedPerPetAverage,
- double amountUsedPerPetVariance, double triggerTransactionRate,
- double triggerPurchaseRate, List<Product> products)
- {
- this.categoryLabel = categoryLabel;
- this.applicableSpecies = ImmutableSet.copyOf(species);
- this.fieldNames = ImmutableSet.copyOf(fieldNames);
- this.triggerTransaction = triggerTransaction;
- this.dailyUsageRate = dailyUsageRate;
- this.amountUsedPerPetAverage = amountUsedPerPetAverage;
- this.amountUsedPerPetVariance = amountUsedPerPetVariance;
- this.triggerTransactionRate = triggerTransactionRate;
- this.triggerPurchaseRate = triggerPurchaseRate;
- this.products = ImmutableList.copyOf(products);
- }
-
- public String getCategoryLabel()
- {
- return categoryLabel;
- }
-
- public ImmutableSet<PetSpecies> getApplicableSpecies()
- {
- return applicableSpecies;
- }
-
- public ImmutableSet<String> getFieldNames()
- {
- return fieldNames;
- }
- public Boolean getTriggerTransaction()
- {
- return triggerTransaction;
- }
-
- public Double getDailyUsageRate()
- {
- return dailyUsageRate;
- }
-
- public Double getBaseAmountUsedAverage()
- {
- return amountUsedPerPetAverage;
- }
-
- public Double getBaseAmountUsedVariance()
- {
- return amountUsedPerPetVariance;
- }
-
- public Double getTransactionTriggerRate()
- {
- return triggerTransactionRate;
- }
-
- public Double getPurchaseTriggerRate()
- {
- return triggerPurchaseRate;
- }
-
- public ImmutableList<Product> getProducts()
- {
- return products;
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/ZipcodeRecord.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/ZipcodeRecord.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/ZipcodeRecord.java
deleted file mode 100644
index ef54712..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/ZipcodeRecord.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/**
- * 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.datamodels.inputs;
-
-import java.io.Serializable;
-
-import org.apache.commons.lang3.tuple.Pair;
-
-public class ZipcodeRecord implements Serializable
-{
- private static final long serialVersionUID = 1769986686070108470L;
-
- final String zipcode;
- final Pair<Double, Double> coordinates;
- final String city;
- final String state;
- final double medianHouseholdIncome;
- final long population;
-
- public ZipcodeRecord(String zipcode, Pair<Double, Double> coordinates,
- String city, String state, double medianHouseholdIncome, long population)
- {
- this.city = city;
- this.state = state;
- this.zipcode = zipcode;
- this.coordinates = coordinates;
- this.medianHouseholdIncome = medianHouseholdIncome;
- this.population = population;
- }
-
- public String getZipcode()
- {
- return zipcode;
- }
-
- public Pair<Double, Double> getCoordinates()
- {
- return coordinates;
- }
-
- public double getMedianHouseholdIncome()
- {
- return medianHouseholdIncome;
- }
-
- public long getPopulation()
- {
- return population;
- }
-
- public double distance(ZipcodeRecord other)
- {
- if(other.getZipcode().equals(zipcode))
- return 0.0;
-
- Pair<Double, Double> otherCoords = other.getCoordinates();
-
- double dist = Math.sin(Math.toRadians(coordinates.getLeft())) *
- Math.sin(Math.toRadians(otherCoords.getLeft())) +
- Math.cos(Math.toRadians(coordinates.getLeft())) *
- Math.cos(Math.toRadians(otherCoords.getLeft())) *
- Math.cos(Math.toRadians(coordinates.getRight() - otherCoords.getRight()));
- dist = Math.toDegrees(Math.acos(dist)) * 69.09;
-
- return dist;
- }
-
- public String getCity()
- {
- return city;
- }
-
- public String getState()
- {
- return state;
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datareaders/NameReader.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datareaders/NameReader.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datareaders/NameReader.java
deleted file mode 100644
index 5a847ea..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datareaders/NameReader.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- * 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.datareaders;
-
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.util.Map;
-import java.util.Scanner;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.Names;
-
-import com.google.common.collect.Maps;
-
-public class NameReader
-{
- InputStream path;
-
- public NameReader(InputStream path)
- {
- this.path = path;
- }
-
- public Names readData() throws FileNotFoundException
- {
- Scanner scanner = new Scanner(path);
-
- Map<String, Double> firstNames = Maps.newHashMap();
- Map<String, Double> lastNames = Maps.newHashMap();
-
- while(scanner.hasNextLine())
- {
- String line = scanner.nextLine();
- String[] cols = line.trim().split(",");
-
- String name = cols[0];
- double weight = Double.parseDouble(cols[5]);
-
- if(cols[4].equals("1"))
- firstNames.put(name, weight);
- if(cols[3].equals("1"))
- lastNames.put(name, weight);
- }
-
- scanner.close();
-
- return new Names(firstNames, lastNames);
-
- }
-}
[06/11] bigtop git commit: BIGTOP-1984. Extract samplers library from
BigPetStore data generator
Posted by rn...@apache.org.
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/collections/MediumProductCollection.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/collections/MediumProductCollection.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/collections/MediumProductCollection.java
new file mode 100644
index 0000000..c9683bc
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/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.datagenerators.bigpetstore.generators.products.collections;
+
+import java.util.List;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.PetSpecies;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.ProductCategoryBuilder;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.ProductFieldValue;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.rules.AndRule;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.rules.FieldPredicate;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.rules.NotRule;
+import org.apache.bigtop.datagenerators.bigpetstore.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/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/collections/SmallProductCollection.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/collections/SmallProductCollection.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/collections/SmallProductCollection.java
new file mode 100644
index 0000000..40edf78
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/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.datagenerators.bigpetstore.generators.products.collections;
+
+import java.util.List;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.PetSpecies;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.ProductCategoryBuilder;
+import org.apache.bigtop.datagenerators.bigpetstore.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/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/AlwaysTrueRule.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/AlwaysTrueRule.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/AlwaysTrueRule.java
new file mode 100644
index 0000000..a89022e
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/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.datagenerators.bigpetstore.generators.products.rules;
+
+import org.apache.bigtop.datagenerators.bigpetstore.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/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/AndRule.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/AndRule.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/AndRule.java
new file mode 100644
index 0000000..5186423
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/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.datagenerators.bigpetstore.generators.products.rules;
+
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.bigtop.datagenerators.bigpetstore.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/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/FieldPredicate.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/FieldPredicate.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/FieldPredicate.java
new file mode 100644
index 0000000..bd96ccd
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/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.datagenerators.bigpetstore.generators.products.rules;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.bigtop.datagenerators.bigpetstore.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/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/NotRule.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/NotRule.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/NotRule.java
new file mode 100644
index 0000000..bed11fa
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/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.datagenerators.bigpetstore.generators.products.rules;
+
+import org.apache.bigtop.datagenerators.bigpetstore.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/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/OrRule.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/OrRule.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/OrRule.java
new file mode 100644
index 0000000..c979e02
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/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.datagenerators.bigpetstore.generators.products.rules;
+
+import org.apache.bigtop.datagenerators.bigpetstore.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;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/Rule.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/Rule.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/Rule.java
new file mode 100644
index 0000000..c3ad6f3
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/rules/Rule.java
@@ -0,0 +1,23 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.products.rules;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+
+public interface Rule
+{
+ public boolean ruleMatches(Product product) throws IllegalArgumentException;
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/MarkovModelProductCategorySampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/MarkovModelProductCategorySampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/MarkovModelProductCategorySampler.java
new file mode 100644
index 0000000..e2549f7
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/MarkovModelProductCategorySampler.java
@@ -0,0 +1,119 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.purchase;
+
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.datagenerators.samplers.markovmodels.MarkovModel;
+import org.apache.bigtop.datagenerators.samplers.markovmodels.MarkovModelBuilder;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+
+import com.google.common.collect.Maps;
+
+public class MarkovModelProductCategorySampler implements Sampler<MarkovModel<Product>>
+{
+ final ProductCategory productCategory;
+ final Sampler<Double> fieldSimilarityWeightSampler;
+ final Sampler<Double> loopbackWeightSampler;
+
+ final Map<String, Double> fieldWeights;
+ Map<String, Double> fieldSimilarityWeights;
+ double loopbackWeight;
+
+ public MarkovModelProductCategorySampler(ProductCategory productCategory,
+ Map<String, Double> fieldWeights, Sampler<Double> fieldSimilarityWeightSampler,
+ Sampler<Double> loopbackWeightSampler)
+ {
+ this.productCategory = productCategory;
+
+ this.fieldSimilarityWeightSampler = fieldSimilarityWeightSampler;
+ this.fieldWeights = fieldWeights;
+ this.loopbackWeightSampler = loopbackWeightSampler;
+ }
+
+ protected void generateWeights() throws Exception
+ {
+ fieldSimilarityWeights = Maps.newHashMap();
+
+ for(String fieldName : productCategory.getFieldNames())
+ {
+ fieldSimilarityWeights.put(fieldName,fieldSimilarityWeightSampler.sample());
+ }
+
+ loopbackWeight = loopbackWeightSampler.sample();
+ }
+
+ protected double productPairWeight(Product product1, Product product2)
+ {
+ double weightSum = 0.0;
+ for(String fieldName : productCategory.getFieldNames())
+ {
+ double fieldWeight = this.fieldWeights.get(fieldName);
+
+ if(product1.getFieldValue(fieldName).equals(product2.getFieldValue(fieldName)))
+ {
+ fieldWeight *= this.fieldSimilarityWeights.get(fieldName);
+ }
+ else
+ {
+ fieldWeight *= (1.0 - this.fieldSimilarityWeights.get(fieldName));
+ }
+
+ weightSum += fieldWeight;
+ }
+ return weightSum;
+ }
+
+ public MarkovModel<Product> sample() throws Exception
+ {
+ generateWeights();
+
+ MarkovModelBuilder<Product> builder = new MarkovModelBuilder<Product>();
+
+ for(Product product1 : productCategory.getProducts())
+ {
+ builder.addStartState(product1, 1.0);
+
+ double weightSum = 0.0;
+ for(Product product2 : productCategory.getProducts())
+ {
+ if(!product1.equals(product2))
+ {
+ weightSum += productPairWeight(product1, product2);
+ }
+ }
+
+ for(Product product2 : productCategory.getProducts())
+ {
+ double weight = 0.0;
+ if(!product1.equals(product2))
+ {
+ weight = (1.0 - loopbackWeight) * productPairWeight(product1, product2) / weightSum;
+ }
+ else
+ { weight = loopbackWeight;
+
+ }
+
+ builder.addTransition(product1, product2, weight);
+ }
+ }
+
+ return builder.build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/MarkovPurchasingModel.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/MarkovPurchasingModel.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/MarkovPurchasingModel.java
new file mode 100644
index 0000000..6855aa8
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/MarkovPurchasingModel.java
@@ -0,0 +1,65 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.purchase;
+
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.markovmodels.MarkovModel;
+import org.apache.bigtop.datagenerators.samplers.markovmodels.MarkovProcess;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Maps;
+
+public class MarkovPurchasingModel implements PurchasingModel<MarkovModel<Product>>
+{
+
+ private static final long serialVersionUID = 3098355461347511619L;
+ ImmutableMap<String, MarkovModel<Product>> productCategoryProfiles;
+
+ public MarkovPurchasingModel(Map<String, MarkovModel<Product>> productCategoryProfiles)
+ {
+ this.productCategoryProfiles = ImmutableMap.copyOf(productCategoryProfiles);
+ }
+
+ @Override
+ public ImmutableSet<String> getProductCategories()
+ {
+ return productCategoryProfiles.keySet();
+ }
+
+ @Override
+ public MarkovModel<Product> getProfile(String productCategory)
+ {
+ return productCategoryProfiles.get(productCategory);
+ }
+
+ @Override
+ public PurchasingProcesses buildProcesses(SeedFactory seedFactory)
+ {
+ Map<String, Sampler<Product>> processes = Maps.newHashMap();
+ for(String category : getProductCategories())
+ {
+ MarkovModel<Product> model = getProfile(category);
+ processes.put(category, new MarkovProcess<Product>(model, seedFactory));
+ }
+
+ return new PurchasingProcesses(processes);
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/MarkovPurchasingModelSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/MarkovPurchasingModelSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/MarkovPurchasingModelSampler.java
new file mode 100644
index 0000000..7beb634
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/MarkovPurchasingModelSampler.java
@@ -0,0 +1,47 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.purchase;
+
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.datagenerators.samplers.markovmodels.MarkovModel;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+
+import com.google.common.collect.Maps;
+
+public class MarkovPurchasingModelSampler implements Sampler<MarkovPurchasingModel>
+{
+ final Map<ProductCategory, Sampler<MarkovModel<Product>>> categorySamplers;
+
+ public MarkovPurchasingModelSampler(Map<ProductCategory, Sampler<MarkovModel<Product>>> categorySamplers)
+ {
+ this.categorySamplers = categorySamplers;
+ }
+
+ public MarkovPurchasingModel sample() throws Exception
+ {
+ Map<String, MarkovModel<Product>> markovModels = Maps.newHashMap();
+ for(ProductCategory productCategory : categorySamplers.keySet())
+ {
+ Sampler<MarkovModel<Product>> sampler = categorySamplers.get(productCategory);
+ markovModels.put(productCategory.getCategoryLabel(), sampler.sample());
+ }
+
+ return new MarkovPurchasingModel(markovModels);
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/MultinomialPurchasingModel.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/MultinomialPurchasingModel.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/MultinomialPurchasingModel.java
new file mode 100644
index 0000000..f0c90fe
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/MultinomialPurchasingModel.java
@@ -0,0 +1,67 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.purchase;
+
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.pdfs.MultinomialPDF;
+import org.apache.bigtop.datagenerators.samplers.samplers.RouletteWheelSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Maps;
+
+public class MultinomialPurchasingModel implements PurchasingModel<MultinomialPDF<Product>>
+{
+
+ private static final long serialVersionUID = 5863830733003282570L;
+
+ private final ImmutableMap<String, MultinomialPDF<Product>> productPDFs;
+
+ public MultinomialPurchasingModel(Map<String, MultinomialPDF<Product>> productPDFs)
+ {
+ this.productPDFs = ImmutableMap.copyOf(productPDFs);
+ }
+
+ @Override
+ public ImmutableSet<String> getProductCategories()
+ {
+ return productPDFs.keySet();
+ }
+
+ @Override
+ public MultinomialPDF<Product> getProfile(String category)
+ {
+ return productPDFs.get(category);
+ }
+
+ @Override
+ public PurchasingProcesses buildProcesses(SeedFactory seedFactory)
+ {
+ Map<String, Sampler<Product>> processes = Maps.newHashMap();
+ for(String category : getProductCategories())
+ {
+ MultinomialPDF<Product> pdf = productPDFs.get(category);
+ processes.put(category, RouletteWheelSampler.create(pdf, seedFactory));
+ }
+
+ return new PurchasingProcesses(processes);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/MultinomialPurchasingModelSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/MultinomialPurchasingModelSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/MultinomialPurchasingModelSampler.java
new file mode 100644
index 0000000..b190cb1
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/MultinomialPurchasingModelSampler.java
@@ -0,0 +1,143 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.purchase;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+import org.apache.bigtop.datagenerators.bigpetstore.Constants;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.pdfs.MultinomialPDF;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.UniformIntSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.UniformSampler;
+import org.apache.commons.lang3.tuple.Pair;
+
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Multimap;
+
+public class MultinomialPurchasingModelSampler implements Sampler<MultinomialPurchasingModel>
+{
+ private final SeedFactory seedFactory;
+ private final Collection<ProductCategory> productCategories;
+
+ public MultinomialPurchasingModelSampler(Collection<ProductCategory> productCategories, SeedFactory seedFactory)
+ {
+ this.seedFactory = seedFactory;
+ this.productCategories = productCategories;
+ }
+
+ protected <T> List<T> shuffle(Collection<T> input) throws Exception
+ {
+ Vector<T> shuffled = new Vector<>(input);
+ for(int i = 0; i < input.size() - 1; i++)
+ {
+ int swapIdx = new UniformIntSampler(i, input.size() - 1, seedFactory).sample();
+ T tmp = shuffled.get(i);
+ shuffled.set(i, shuffled.get(swapIdx));
+ shuffled.set(swapIdx, tmp);
+ }
+
+ return shuffled;
+ }
+
+ protected Map<Pair<String, Object>, Double> generateFieldValueWeights(ProductCategory productCategory) throws Exception
+ {
+ // Get all values for each field by iterating over all products
+ Multimap<String, Object> allFieldValues = HashMultimap.create();
+ for(String fieldName : productCategory.getFieldNames())
+ {
+ if(!Constants.PRODUCT_MODEL_EXCLUDED_FIELDS.contains(fieldName))
+ {
+ for(Product p : productCategory.getProducts())
+ {
+ Object fieldValue = p.getFieldValue(fieldName);
+ allFieldValues.put(fieldName, fieldValue);
+ }
+ }
+ }
+
+ Sampler<Double> sampler = new UniformSampler(seedFactory);
+
+ // shuffle field values
+ Map<Pair<String, Object>, Double> fieldValueWeights = Maps.newHashMap();
+ for(Map.Entry<String, Collection<Object>> entry : allFieldValues.asMap().entrySet())
+ {
+ String fieldName = entry.getKey();
+ List<Object> shuffled = shuffle(entry.getValue());
+
+ for(int i = 0; i < shuffled.size(); i++)
+ {
+ double weight = Constants.PRODUCT_MULTINOMIAL_POSITIVE_WEIGHT;
+ if ((i + 1) > Constants.PRODUCT_MULTINOMIAL_POSITIVE_COUNT_MIN)
+ {
+ double r = sampler.sample();
+ if (r >= Constants.PRODUCT_MULTINOMIAL_POSITIVE_FREQUENCY)
+ {
+ weight = Constants.PRODUCT_MULTINOMIAL_NEGATIVE_WEIGHT;
+ }
+ }
+
+ Object fieldValue = shuffled.get(i);
+ fieldValueWeights.put(Pair.of(fieldName, fieldValue), weight);
+ }
+ }
+
+
+ return ImmutableMap.copyOf(fieldValueWeights);
+ }
+
+ protected Map<Product, Double> generateProductWeights(Map<Pair<String, Object>, Double> fieldValueWeights,
+ ProductCategory productCategory) throws Exception
+ {
+ Map<Product, Double> productWeights = Maps.newHashMap();
+ for(Product p : productCategory.getProducts())
+ {
+ double weight = 1.0;
+ for(String fieldName : productCategory.getFieldNames())
+ {
+ if(!Constants.PRODUCT_MODEL_EXCLUDED_FIELDS.contains(fieldName))
+ {
+ Object fieldValue = p.getFieldValue(fieldName);
+ Pair<String, Object> key = Pair.of(fieldName, fieldValue);
+ weight *= fieldValueWeights.get(key);
+ }
+ }
+ productWeights.put(p, weight);
+ }
+
+ return productWeights;
+ }
+
+ public MultinomialPurchasingModel sample() throws Exception
+ {
+ Map<String, MultinomialPDF<Product>> pdfs = Maps.newHashMap();
+ for(ProductCategory productCategory : productCategories)
+ {
+ Map<Pair<String, Object>, Double> fieldWeights = this.generateFieldValueWeights(productCategory);
+ Map<Product, Double> productWeights = this.generateProductWeights(fieldWeights, productCategory);
+ pdfs.put(productCategory.getCategoryLabel(), new MultinomialPDF<Product>(productWeights));
+ }
+
+ return new MultinomialPurchasingModel(pdfs);
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/PurchasingModel.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/PurchasingModel.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/PurchasingModel.java
new file mode 100644
index 0000000..eddc0a0
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/PurchasingModel.java
@@ -0,0 +1,31 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.purchase;
+
+import java.io.Serializable;
+
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+
+import com.google.common.collect.ImmutableSet;
+
+public interface PurchasingModel<T> extends Serializable
+{
+ public ImmutableSet<String> getProductCategories();
+
+ public T getProfile(String category);
+
+ public PurchasingProcesses buildProcesses(SeedFactory seedFactory);
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/PurchasingModelSamplerBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/PurchasingModelSamplerBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/PurchasingModelSamplerBuilder.java
new file mode 100644
index 0000000..2a22487
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/PurchasingModelSamplerBuilder.java
@@ -0,0 +1,108 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.purchase;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.bigtop.datagenerators.bigpetstore.Constants;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.markovmodels.MarkovModel;
+import org.apache.bigtop.datagenerators.samplers.samplers.BoundedMultiModalGaussianSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Maps;
+
+public class PurchasingModelSamplerBuilder
+{
+ final ImmutableList<ProductCategory> productCategories;
+ final SeedFactory seedFactory;
+
+ public PurchasingModelSamplerBuilder(Collection<ProductCategory> productCategories, SeedFactory seedFactory)
+ {
+ this.productCategories = ImmutableList.copyOf(productCategories);
+ this.seedFactory = seedFactory;
+ }
+
+ protected Map<String, Double> generateFieldWeights(Sampler<Double> fieldWeightSampler) throws Exception
+ {
+ Set<String> fieldNames = new HashSet<String>();
+ for(ProductCategory pc : productCategories)
+ {
+ for(String fieldName : pc.getFieldNames())
+ {
+ fieldNames.add(fieldName);
+ }
+ }
+
+ Map<String, Double> fieldWeights = Maps.newHashMap();
+ for(String fieldName : fieldNames)
+ {
+ double weight = fieldWeightSampler.sample();
+ fieldWeights.put(fieldName, weight);
+ }
+
+ return fieldWeights;
+ }
+
+ public Sampler<MarkovPurchasingModel> buildMarkovPurchasingModel() throws Exception
+ {
+
+ Sampler<Double> fieldWeightSampler = new BoundedMultiModalGaussianSampler(Constants.PRODUCT_MSM_FIELD_WEIGHT_GAUSSIANS,
+ Constants.PRODUCT_MSM_FIELD_WEIGHT_LOWERBOUND,
+ Constants.PRODUCT_MSM_FIELD_WEIGHT_UPPERBOUND,
+ seedFactory);
+
+ Sampler<Double> fieldSimilarityWeightSampler = new BoundedMultiModalGaussianSampler(Constants.PRODUCT_MSM_FIELD_SIMILARITY_WEIGHT_GAUSSIANS,
+ Constants.PRODUCT_MSM_FIELD_SIMILARITY_WEIGHT_LOWERBOUND,
+ Constants.PRODUCT_MSM_FIELD_SIMILARITY_WEIGHT_UPPERBOUND,
+ seedFactory);
+
+ Sampler<Double> loopbackWeightSampler = new BoundedMultiModalGaussianSampler(Constants.PRODUCT_MSM_LOOPBACK_WEIGHT_GAUSSIANS,
+ Constants.PRODUCT_MSM_LOOPBACK_WEIGHT_LOWERBOUND,
+ Constants.PRODUCT_MSM_LOOPBACK_WEIGHT_UPPERBOUND,
+ seedFactory);
+
+ Map<String, Double> fieldWeights = generateFieldWeights(fieldWeightSampler);
+
+ Map<ProductCategory, Sampler<MarkovModel<Product>>> categorySamplers = Maps.newHashMap();
+ for(ProductCategory productCategory : productCategories)
+ {
+ MarkovModelProductCategorySampler sampler = new MarkovModelProductCategorySampler(productCategory,
+ fieldWeights, fieldSimilarityWeightSampler, loopbackWeightSampler);
+ categorySamplers.put(productCategory, sampler);
+ }
+
+ return new MarkovPurchasingModelSampler(categorySamplers);
+ }
+
+ public Sampler<? extends PurchasingModel> build() throws Exception
+ {
+ if(Constants.PURCHASING_MODEL_TYPE.equals(Constants.PurchasingModelType.MARKOV))
+ {
+ return buildMarkovPurchasingModel();
+ }
+ else
+ {
+ return new MultinomialPurchasingModelSampler(productCategories, seedFactory);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/PurchasingProcesses.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/PurchasingProcesses.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/PurchasingProcesses.java
new file mode 100644
index 0000000..99516d7
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/purchase/PurchasingProcesses.java
@@ -0,0 +1,39 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.purchase;
+
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.samplers.samplers.ConditionalSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+
+import com.google.common.collect.ImmutableMap;
+
+public class PurchasingProcesses implements ConditionalSampler<Product, String>
+{
+ ImmutableMap<String, Sampler<Product>> processes;
+
+ public PurchasingProcesses(Map<String, Sampler<Product>> processes)
+ {
+ this.processes = ImmutableMap.copyOf(processes);
+ }
+
+ public Product sample(String productCategory) throws Exception
+ {
+ return this.processes.get(productCategory).sample();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/StoreLocationIncomePDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/StoreLocationIncomePDF.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/StoreLocationIncomePDF.java
new file mode 100644
index 0000000..7e56462
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/StoreLocationIncomePDF.java
@@ -0,0 +1,65 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.store;
+
+import java.util.List;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ZipcodeRecord;
+import org.apache.bigtop.datagenerators.samplers.pdfs.ProbabilityDensityFunction;
+
+public class StoreLocationIncomePDF implements ProbabilityDensityFunction<ZipcodeRecord>
+{
+ double incomeNormalizationFactor;
+ double minIncome;
+ double k;
+
+ public StoreLocationIncomePDF(List<ZipcodeRecord> zipcodeTable, double incomeScalingFactor)
+ {
+
+ double maxIncome = 0.0;
+ minIncome = Double.MAX_VALUE;
+
+ for(ZipcodeRecord record : zipcodeTable)
+ {
+ maxIncome = Math.max(maxIncome, record.getMedianHouseholdIncome());
+ minIncome = Math.min(minIncome, record.getMedianHouseholdIncome());
+ }
+
+ k = Math.log(incomeScalingFactor) / (maxIncome - minIncome);
+
+ incomeNormalizationFactor = 0.0d;
+ for(ZipcodeRecord record : zipcodeTable)
+ {
+ double weight = incomeWeight(record);
+ incomeNormalizationFactor += weight;
+ }
+ }
+
+ private double incomeWeight(ZipcodeRecord record)
+ {
+ return Math.exp(k * (record.getMedianHouseholdIncome() - minIncome));
+ }
+
+
+ @Override
+ public double probability(ZipcodeRecord datum)
+ {
+ double weight = incomeWeight(datum);
+
+ return weight / this.incomeNormalizationFactor;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/StoreLocationPopulationPDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/StoreLocationPopulationPDF.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/StoreLocationPopulationPDF.java
new file mode 100644
index 0000000..2623bb5
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/StoreLocationPopulationPDF.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.datagenerators.bigpetstore.generators.store;
+
+import java.util.List;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ZipcodeRecord;
+import org.apache.bigtop.datagenerators.samplers.pdfs.ProbabilityDensityFunction;
+
+public class StoreLocationPopulationPDF implements ProbabilityDensityFunction<ZipcodeRecord>
+{
+ double populationSum = 0.0;
+
+ public StoreLocationPopulationPDF(List<ZipcodeRecord> zipcodeTable)
+ {
+ long populationSum = 0L;
+ for(ZipcodeRecord record : zipcodeTable)
+ {
+ populationSum += record.getPopulation();
+ }
+
+ this.populationSum = ((double) populationSum);
+ }
+
+ public double probability(ZipcodeRecord record)
+ {
+ return ((double) record.getPopulation()) / populationSum;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/StoreSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/StoreSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/StoreSampler.java
new file mode 100644
index 0000000..7b981c4
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/StoreSampler.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.datagenerators.bigpetstore.generators.store;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Store;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ZipcodeRecord;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+
+public class StoreSampler implements Sampler<Store>
+{
+
+ private final Sampler<ZipcodeRecord> locationSampler;
+ private final Sampler<Integer> idSampler;
+
+ public StoreSampler(Sampler<Integer> idSampler, Sampler<ZipcodeRecord> locationSampler)
+ {
+ this.locationSampler = locationSampler;
+ this.idSampler = idSampler;
+ }
+
+ public Store sample() throws Exception
+ {
+ Integer id = idSampler.sample();
+ String name = "Store_" + id;
+ ZipcodeRecord location = locationSampler.sample();
+
+ Store store = new Store(id, name, location);
+
+ return store;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/StoreSamplerBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/StoreSamplerBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/StoreSamplerBuilder.java
new file mode 100644
index 0000000..74f6698
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/store/StoreSamplerBuilder.java
@@ -0,0 +1,57 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.store;
+
+import java.util.List;
+
+import org.apache.bigtop.datagenerators.bigpetstore.Constants;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Store;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ZipcodeRecord;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.pdfs.JointPDF;
+import org.apache.bigtop.datagenerators.samplers.pdfs.ProbabilityDensityFunction;
+import org.apache.bigtop.datagenerators.samplers.samplers.RouletteWheelSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.SequenceSampler;
+
+public class StoreSamplerBuilder
+{
+ private final List<ZipcodeRecord> zipcodeTable;
+ private final SeedFactory seedFactory;
+
+ public StoreSamplerBuilder(List<ZipcodeRecord> zipcodeTable, SeedFactory seedFactory)
+ {
+ this.zipcodeTable = zipcodeTable;
+ this.seedFactory = seedFactory;
+ }
+
+ public Sampler<Store> build()
+ {
+ Sampler<Integer> idSampler = new SequenceSampler();
+
+ ProbabilityDensityFunction<ZipcodeRecord> locationPopulationPDF =
+ new StoreLocationPopulationPDF(zipcodeTable);
+ ProbabilityDensityFunction<ZipcodeRecord> locationIncomePDF =
+ new StoreLocationIncomePDF(zipcodeTable, Constants.INCOME_SCALING_FACTOR);
+ ProbabilityDensityFunction<ZipcodeRecord> locationJointPDF =
+ new JointPDF<ZipcodeRecord>(zipcodeTable, locationPopulationPDF, locationIncomePDF);
+
+ Sampler<ZipcodeRecord> locationSampler = RouletteWheelSampler.create(zipcodeTable, locationJointPDF, seedFactory);
+
+ return new StoreSampler(idSampler, locationSampler);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CategoryWeightFunction.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CategoryWeightFunction.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CategoryWeightFunction.java
new file mode 100644
index 0000000..c576812
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CategoryWeightFunction.java
@@ -0,0 +1,39 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.transaction;
+
+import org.apache.bigtop.datagenerators.samplers.pdfs.ExponentialPDF;
+import org.apache.bigtop.datagenerators.samplers.pdfs.ProbabilityDensityFunction;
+import org.apache.bigtop.datagenerators.samplers.wfs.ConditionalWeightFunction;
+import org.apache.bigtop.datagenerators.samplers.wfs.WeightFunction;
+
+public class CategoryWeightFunction implements ConditionalWeightFunction<Double, Double>
+{
+ private final ProbabilityDensityFunction<Double> pdf;
+
+ public CategoryWeightFunction(double averagePurchaseTriggerTime)
+ {
+ double lambda = 1.0 / averagePurchaseTriggerTime;
+ pdf = new ExponentialPDF(lambda);
+ }
+
+ @Override
+ public double weight(Double exhaustionTime, Double transactionTime)
+ {
+ double remainingTime = Math.max(0.0, exhaustionTime - transactionTime);
+ return pdf.probability(remainingTime);
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CustomerInventory.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CustomerInventory.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CustomerInventory.java
new file mode 100644
index 0000000..3798532
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CustomerInventory.java
@@ -0,0 +1,65 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.transaction;
+
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.bigpetstore.Constants;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+
+public class CustomerInventory
+{
+ final private ImmutableMap<String, ProductCategoryInventory> productCategoryInventories;
+
+ public CustomerInventory(Map<String, ProductCategoryInventory> productCategoryInventories)
+ {
+ this.productCategoryInventories = ImmutableMap.copyOf(productCategoryInventories);
+ }
+
+ public void simulatePurchase(double time, Product product) throws Exception
+ {
+ String category = product.getFieldValueAsString(Constants.PRODUCT_CATEGORY);
+ ProductCategoryInventory inventory = productCategoryInventories.get(category);
+ inventory.simulatePurchase(time, product);
+ }
+
+ public ImmutableMap<String, Double> getInventoryAmounts(double time)
+ {
+ Map<String, Double> amounts = Maps.newHashMap();
+ for(String category : productCategoryInventories.keySet())
+ {
+ double amount = productCategoryInventories.get(category).findRemainingAmount(time);
+ amounts.put(category, amount);
+ }
+
+ return ImmutableMap.copyOf(amounts);
+ }
+
+ public ImmutableMap<String, Double> getExhaustionTimes()
+ {
+ Map<String, Double> times = Maps.newHashMap();
+ for(String category : productCategoryInventories.keySet())
+ {
+ double time = productCategoryInventories.get(category).findExhaustionTime();
+ times.put(category, time);
+ }
+
+ return ImmutableMap.copyOf(times);
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CustomerInventoryBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CustomerInventoryBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CustomerInventoryBuilder.java
new file mode 100644
index 0000000..f1793a4
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CustomerInventoryBuilder.java
@@ -0,0 +1,67 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.transaction;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+public class CustomerInventoryBuilder
+{
+ final private List<ProductCategory> productCategories;
+ final private SeedFactory seedFactory;
+ final private CustomerTransactionParameters parameters;
+
+ public CustomerInventoryBuilder(CustomerTransactionParameters parameters,
+ SeedFactory seedFactory)
+ {
+ productCategories = Lists.newArrayList();
+ this.seedFactory = seedFactory;
+ this.parameters = parameters;
+ }
+
+ public void addProductCategory(ProductCategory productCategory)
+ {
+ this.productCategories.add(productCategory);
+ }
+
+ public void addAllProductCategories(Collection<ProductCategory> productCategories)
+ {
+ this.productCategories.addAll(productCategories);
+ }
+
+ public CustomerInventory build()
+ {
+ Map<String, ProductCategoryInventory> inventories = Maps.newHashMap();
+ for(ProductCategory productCategory : productCategories)
+ {
+ if(parameters.countPetsBySpecies(productCategory.getApplicableSpecies()) > 0)
+ {
+ ProductCategoryInventory inventory = new ProductCategoryInventory(productCategory,
+ parameters, seedFactory);
+ inventories.put(productCategory.getCategoryLabel(), inventory);
+ }
+ }
+
+ return new CustomerInventory(inventories);
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CustomerTransactionParameters.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CustomerTransactionParameters.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CustomerTransactionParameters.java
new file mode 100644
index 0000000..dbceb04
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CustomerTransactionParameters.java
@@ -0,0 +1,73 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.transaction;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.PetSpecies;
+
+import com.google.common.collect.ImmutableMultiset;
+import com.google.common.collect.Multiset;
+import com.google.common.collect.Sets;
+
+public class CustomerTransactionParameters
+{
+ final ImmutableMultiset<PetSpecies> petCounts;
+ final double averageTransactionTriggerTime;
+ final double averagePurchaseTriggerTime;
+
+ public CustomerTransactionParameters(Multiset<PetSpecies> petCounts,
+ double averageTransactionTriggerTime, double averagePurchaseTriggerTime)
+ {
+ this.petCounts = ImmutableMultiset.copyOf(petCounts);
+ this.averageTransactionTriggerTime = averageTransactionTriggerTime;
+ this.averagePurchaseTriggerTime = averagePurchaseTriggerTime;
+ }
+
+ public double getAverageTransactionTriggerTime()
+ {
+ return averageTransactionTriggerTime;
+ }
+
+ public double getAveragePurchaseTriggerTime()
+ {
+ return averagePurchaseTriggerTime;
+ }
+
+ public int countPetsBySpecies(PetSpecies species)
+ {
+ return petCounts.count(species);
+ }
+
+ public int countPetsBySpecies(Collection<PetSpecies> allSpecies)
+ {
+ int count = 0;
+ Set<PetSpecies> speciesSet = Sets.newHashSet(allSpecies);
+ for(PetSpecies species : speciesSet)
+ {
+ count += countPetsBySpecies(species);
+ }
+
+ return count;
+ }
+
+ public int countPets()
+ {
+ return petCounts.size();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CustomerTransactionParametersBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CustomerTransactionParametersBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CustomerTransactionParametersBuilder.java
new file mode 100644
index 0000000..97a73e7
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CustomerTransactionParametersBuilder.java
@@ -0,0 +1,58 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.transaction;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.PetSpecies;
+
+import com.google.common.collect.HashMultiset;
+import com.google.common.collect.Multiset;
+
+public class CustomerTransactionParametersBuilder
+{
+ private Multiset<PetSpecies> petCounts;
+ private double averageTransactionTriggerTime;
+ private double averagePurchaseTriggerTime;
+
+ public CustomerTransactionParametersBuilder()
+ {
+ this.petCounts = HashMultiset.create();
+ this.averagePurchaseTriggerTime = 0.0;
+ this.averageTransactionTriggerTime = 0.0;
+ }
+
+ public void addPet(PetSpecies species)
+ {
+ this.petCounts.add(species);
+ }
+
+ public void setAverageTransactionTriggerTime(
+ double averageTransactionTriggerTime)
+ {
+ this.averageTransactionTriggerTime = averageTransactionTriggerTime;
+ }
+
+ public void setAveragePurchaseTriggerTime(double averagePurchaseTriggerTime)
+ {
+ this.averagePurchaseTriggerTime = averagePurchaseTriggerTime;
+ }
+
+ public CustomerTransactionParameters build()
+ {
+ return new CustomerTransactionParameters(this.petCounts,
+ this.averageTransactionTriggerTime,
+ this.averagePurchaseTriggerTime);
+ }
+}
[08/11] bigtop git commit: BIGTOP-1984. Extract samplers library from
BigPetStore data generator
Posted by rn...@apache.org.
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CategoryWeightFunction.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CategoryWeightFunction.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CategoryWeightFunction.java
deleted file mode 100644
index 09b7327..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CategoryWeightFunction.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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.transaction;
-
-import org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs.ExponentialPDF;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs.ProbabilityDensityFunction;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.wfs.ConditionalWeightFunction;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.wfs.WeightFunction;
-
-public class CategoryWeightFunction implements ConditionalWeightFunction<Double, Double>
-{
- private final ProbabilityDensityFunction<Double> pdf;
-
- public CategoryWeightFunction(double averagePurchaseTriggerTime)
- {
- double lambda = 1.0 / averagePurchaseTriggerTime;
- pdf = new ExponentialPDF(lambda);
- }
-
- @Override
- public double weight(Double exhaustionTime, Double transactionTime)
- {
- double remainingTime = Math.max(0.0, exhaustionTime - transactionTime);
- return pdf.probability(remainingTime);
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CustomerInventory.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CustomerInventory.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CustomerInventory.java
deleted file mode 100644
index f0f538a..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CustomerInventory.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * 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.transaction;
-
-import java.util.Map;
-
-import org.apache.bigtop.bigpetstore.datagenerator.Constants;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-
-public class CustomerInventory
-{
- final private ImmutableMap<String, ProductCategoryInventory> productCategoryInventories;
-
- public CustomerInventory(Map<String, ProductCategoryInventory> productCategoryInventories)
- {
- this.productCategoryInventories = ImmutableMap.copyOf(productCategoryInventories);
- }
-
- public void simulatePurchase(double time, Product product) throws Exception
- {
- String category = product.getFieldValueAsString(Constants.PRODUCT_CATEGORY);
- ProductCategoryInventory inventory = productCategoryInventories.get(category);
- inventory.simulatePurchase(time, product);
- }
-
- public ImmutableMap<String, Double> getInventoryAmounts(double time)
- {
- Map<String, Double> amounts = Maps.newHashMap();
- for(String category : productCategoryInventories.keySet())
- {
- double amount = productCategoryInventories.get(category).findRemainingAmount(time);
- amounts.put(category, amount);
- }
-
- return ImmutableMap.copyOf(amounts);
- }
-
- public ImmutableMap<String, Double> getExhaustionTimes()
- {
- Map<String, Double> times = Maps.newHashMap();
- for(String category : productCategoryInventories.keySet())
- {
- double time = productCategoryInventories.get(category).findExhaustionTime();
- times.put(category, time);
- }
-
- return ImmutableMap.copyOf(times);
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CustomerInventoryBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CustomerInventoryBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CustomerInventoryBuilder.java
deleted file mode 100644
index 80ed944..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CustomerInventoryBuilder.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * 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.transaction;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-
-public class CustomerInventoryBuilder
-{
- final private List<ProductCategory> productCategories;
- final private SeedFactory seedFactory;
- final private CustomerTransactionParameters parameters;
-
- public CustomerInventoryBuilder(CustomerTransactionParameters parameters,
- SeedFactory seedFactory)
- {
- productCategories = Lists.newArrayList();
- this.seedFactory = seedFactory;
- this.parameters = parameters;
- }
-
- public void addProductCategory(ProductCategory productCategory)
- {
- this.productCategories.add(productCategory);
- }
-
- public void addAllProductCategories(Collection<ProductCategory> productCategories)
- {
- this.productCategories.addAll(productCategories);
- }
-
- public CustomerInventory build()
- {
- Map<String, ProductCategoryInventory> inventories = Maps.newHashMap();
- for(ProductCategory productCategory : productCategories)
- {
- if(parameters.countPetsBySpecies(productCategory.getApplicableSpecies()) > 0)
- {
- ProductCategoryInventory inventory = new ProductCategoryInventory(productCategory,
- parameters, seedFactory);
- inventories.put(productCategory.getCategoryLabel(), inventory);
- }
- }
-
- return new CustomerInventory(inventories);
- }
-}
-
-
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CustomerTransactionParameters.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CustomerTransactionParameters.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CustomerTransactionParameters.java
deleted file mode 100644
index 9267635..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CustomerTransactionParameters.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/**
- * 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.transaction;
-
-import java.util.Collection;
-import java.util.Set;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.PetSpecies;
-
-import com.google.common.collect.ImmutableMultiset;
-import com.google.common.collect.Multiset;
-import com.google.common.collect.Sets;
-
-public class CustomerTransactionParameters
-{
- final ImmutableMultiset<PetSpecies> petCounts;
- final double averageTransactionTriggerTime;
- final double averagePurchaseTriggerTime;
-
- public CustomerTransactionParameters(Multiset<PetSpecies> petCounts,
- double averageTransactionTriggerTime, double averagePurchaseTriggerTime)
- {
- this.petCounts = ImmutableMultiset.copyOf(petCounts);
- this.averageTransactionTriggerTime = averageTransactionTriggerTime;
- this.averagePurchaseTriggerTime = averagePurchaseTriggerTime;
- }
-
- public double getAverageTransactionTriggerTime()
- {
- return averageTransactionTriggerTime;
- }
-
- public double getAveragePurchaseTriggerTime()
- {
- return averagePurchaseTriggerTime;
- }
-
- public int countPetsBySpecies(PetSpecies species)
- {
- return petCounts.count(species);
- }
-
- public int countPetsBySpecies(Collection<PetSpecies> allSpecies)
- {
- int count = 0;
- Set<PetSpecies> speciesSet = Sets.newHashSet(allSpecies);
- for(PetSpecies species : speciesSet)
- {
- count += countPetsBySpecies(species);
- }
-
- return count;
- }
-
- public int countPets()
- {
- return petCounts.size();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CustomerTransactionParametersBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CustomerTransactionParametersBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CustomerTransactionParametersBuilder.java
deleted file mode 100644
index 9adfa4c..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CustomerTransactionParametersBuilder.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * 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.transaction;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.PetSpecies;
-
-import com.google.common.collect.HashMultiset;
-import com.google.common.collect.Multiset;
-
-public class CustomerTransactionParametersBuilder
-{
- private Multiset<PetSpecies> petCounts;
- private double averageTransactionTriggerTime;
- private double averagePurchaseTriggerTime;
-
- public CustomerTransactionParametersBuilder()
- {
- this.petCounts = HashMultiset.create();
- this.averagePurchaseTriggerTime = 0.0;
- this.averageTransactionTriggerTime = 0.0;
- }
-
- public void addPet(PetSpecies species)
- {
- this.petCounts.add(species);
- }
-
- public void setAverageTransactionTriggerTime(
- double averageTransactionTriggerTime)
- {
- this.averageTransactionTriggerTime = averageTransactionTriggerTime;
- }
-
- public void setAveragePurchaseTriggerTime(double averagePurchaseTriggerTime)
- {
- this.averagePurchaseTriggerTime = averagePurchaseTriggerTime;
- }
-
- public CustomerTransactionParameters build()
- {
- return new CustomerTransactionParameters(this.petCounts,
- this.averageTransactionTriggerTime,
- this.averagePurchaseTriggerTime);
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CustomerTransactionParametersSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CustomerTransactionParametersSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CustomerTransactionParametersSampler.java
deleted file mode 100644
index 8495fd9..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CustomerTransactionParametersSampler.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * 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.transaction;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.PetSpecies;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-
-public class CustomerTransactionParametersSampler implements Sampler<CustomerTransactionParameters>
-{
- final private Sampler<Integer> nPetsSampler;
- final private Sampler<PetSpecies> petSpeciesSampler;
- final private Sampler<Double> purchaseTriggerTimeSampler;
- final private Sampler<Double> transactionTriggerTimeSampler;
-
- public CustomerTransactionParametersSampler(Sampler<Integer> nPetsSampler,
- Sampler<PetSpecies> petSpeciesSampler,
- Sampler<Double> purchaseTriggerTimeSampler,
- Sampler<Double> transactionTriggerTimeSampler)
- {
-
- this.nPetsSampler = nPetsSampler;
- this.petSpeciesSampler = petSpeciesSampler;
- this.purchaseTriggerTimeSampler = purchaseTriggerTimeSampler;
- this.transactionTriggerTimeSampler = transactionTriggerTimeSampler;
- }
-
- protected void generatePets(CustomerTransactionParametersBuilder builder) throws Exception
- {
- int nPets = this.nPetsSampler.sample();
-
- for(int i = 0; i < nPets; i++)
- {
- PetSpecies species = this.petSpeciesSampler.sample();
- builder.addPet(species);
- }
- }
-
- public CustomerTransactionParameters sample() throws Exception
- {
- CustomerTransactionParametersBuilder builder = new CustomerTransactionParametersBuilder();
-
- this.generatePets(builder);
- builder.setAveragePurchaseTriggerTime(this.purchaseTriggerTimeSampler.sample());
- builder.setAverageTransactionTriggerTime(this.transactionTriggerTimeSampler.sample());
-
- return builder.build();
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CustomerTransactionParametersSamplerBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CustomerTransactionParametersSamplerBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CustomerTransactionParametersSamplerBuilder.java
deleted file mode 100644
index 249a456..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/CustomerTransactionParametersSamplerBuilder.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * 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.transaction;
-
-import java.util.Arrays;
-
-import org.apache.bigtop.bigpetstore.datagenerator.Constants;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.PetSpecies;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.BoundedMultiModalGaussianSampler;
-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.UniformIntSampler;
-
-public class CustomerTransactionParametersSamplerBuilder
-{
- final private SeedFactory seedFactory;
-
- public CustomerTransactionParametersSamplerBuilder(SeedFactory seedFactory)
- {
- this.seedFactory = seedFactory;
- }
-
- public Sampler<CustomerTransactionParameters> build()
- {
- Sampler<Integer> nPetsSampler = new UniformIntSampler(Constants.MIN_PETS, Constants.MAX_PETS, seedFactory);
-
- Sampler<PetSpecies> petSpeciesSampler = RouletteWheelSampler.createUniform(Arrays.asList(PetSpecies.values()), seedFactory);
-
- Sampler<Double> transactionTriggerTimeSampler = new BoundedMultiModalGaussianSampler(Constants.TRANSACTION_TRIGGER_TIME_GAUSSIANS,
- Constants.TRANSACTION_TRIGGER_TIME_MIN, Constants.TRANSACTION_TRIGGER_TIME_MAX,
- seedFactory);
-
- Sampler<Double> purchaseTriggerTimeSampler = new BoundedMultiModalGaussianSampler(Constants.PURCHASE_TRIGGER_TIME_GAUSSIANS,
- Constants.PURCHASE_TRIGGER_TIME_MIN, Constants.PURCHASE_TRIGGER_TIME_MAX,
- seedFactory);
-
- return new CustomerTransactionParametersSampler(nPetsSampler, petSpeciesSampler,
- transactionTriggerTimeSampler, purchaseTriggerTimeSampler);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/ProductCategoryInventory.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/ProductCategoryInventory.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/ProductCategoryInventory.java
deleted file mode 100644
index 8d43b82..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/ProductCategoryInventory.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * 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.transaction;
-
-import org.apache.bigtop.bigpetstore.datagenerator.Constants;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-
-public class ProductCategoryInventory
-{
- private ProductCategoryUsageTrajectory trajectory;
- private ProductCategoryUsageSimulator simulator;
-
- public ProductCategoryInventory(ProductCategory productCategory, CustomerTransactionParameters parameters,
- SeedFactory seedFactory)
- {
-
- double amountUsedAverage = productCategory.getBaseAmountUsedAverage() * parameters.countPetsBySpecies(productCategory.getApplicableSpecies());
- double amountUsedVariance = productCategory.getBaseAmountUsedVariance() * parameters.countPetsBySpecies(productCategory.getApplicableSpecies());
-
- trajectory = new ProductCategoryUsageTrajectory(0.0, 0.0);
- simulator = new ProductCategoryUsageSimulator(productCategory.getDailyUsageRate(),
- amountUsedAverage, amountUsedVariance, seedFactory);
- }
-
- public void simulatePurchase(double time, Product product) throws Exception
- {
- double amountPurchased = product.getFieldValueAsDouble(Constants.PRODUCT_QUANTITY);
-
- double amountRemainingBeforePurchase = trajectory.amountAtTime(time);
-
- trajectory = simulator.simulate(time, amountRemainingBeforePurchase + amountPurchased);
- }
-
- public double findExhaustionTime()
- {
- return trajectory.getLastTime();
- }
-
- public double findRemainingAmount(double time)
- {
- return trajectory.amountAtTime(time);
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/ProductCategoryUsageSimulator.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/ProductCategoryUsageSimulator.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/ProductCategoryUsageSimulator.java
deleted file mode 100644
index b09d395..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/ProductCategoryUsageSimulator.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * 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.transaction;
-
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.ExponentialSampler;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.GaussianSampler;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-
-public class ProductCategoryUsageSimulator
-{
- final private double amountUsedAverage;
- final private double amountUsedVariance;
-
- final private Sampler<Double> timestepSampler;
- final private Sampler<Double> R;
-
- public ProductCategoryUsageSimulator(double dailyUsageRate, double amountUsedAverage,
- double amountUsedVariance, SeedFactory seedFactory)
- {
- this.amountUsedAverage = amountUsedAverage;
- this.amountUsedVariance = amountUsedVariance;
-
- timestepSampler = new ExponentialSampler(dailyUsageRate, seedFactory);
- R = new GaussianSampler(0.0, 1.0, seedFactory);
- }
-
- private void step(ProductCategoryUsageTrajectory trajectory) throws Exception
- {
- // given in days since last usage
- double timestep = timestepSampler.sample();
-
- double r = R.sample();
-
- // given in units per day
- double usageAmount = this.amountUsedAverage * timestep +
- Math.sqrt(this.amountUsedVariance * timestep) * r;
-
- // can't use a negative amount
- usageAmount = Math.max(usageAmount, 0.0);
-
- double remainingAmount = Math.max(0.0, trajectory.getLastAmount() - usageAmount);
- double time = trajectory.getLastTime() + timestep;
-
- trajectory.append(time, remainingAmount);
- }
-
- public ProductCategoryUsageTrajectory simulate(double initialTime, double initialAmount) throws Exception
- {
- ProductCategoryUsageTrajectory trajectory = new ProductCategoryUsageTrajectory(initialTime, initialAmount);
-
- while(trajectory.getLastAmount() > 0.0)
- {
- step(trajectory);
- }
-
- return trajectory;
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/ProductCategoryUsageTrajectory.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/ProductCategoryUsageTrajectory.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/ProductCategoryUsageTrajectory.java
deleted file mode 100644
index f3c20c7..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/ProductCategoryUsageTrajectory.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/**
- * 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.transaction;
-
-import java.util.List;
-
-import org.apache.commons.lang3.tuple.Pair;
-
-import com.google.common.collect.Lists;
-
-public class ProductCategoryUsageTrajectory
-{
- final private List<Pair<Double, Double>> trajectory;
-
- public ProductCategoryUsageTrajectory(double initialTime, double initialAmount)
- {
- trajectory = Lists.newArrayList();
- this.append(initialTime, initialAmount);
- }
-
- public void append(double time, double amount)
- {
- trajectory.add(Pair.of(time, amount));
- }
-
- public double getLastAmount()
- {
- return trajectory.get(trajectory.size() - 1).getValue();
- }
-
- public double getLastTime()
- {
- return trajectory.get(trajectory.size() - 1).getKey();
- }
-
- public double amountAtTime(double time)
- {
- Pair<Double, Double> previous = null;
- for(Pair<Double, Double> entry : trajectory)
- {
- if(entry.getKey() > time)
- break;
- previous = entry;
- }
-
- if(previous == null)
- return 0.0;
-
- return previous.getValue();
- }
-
- public Pair<Double, Double> getStep(int idx)
- {
- return trajectory.get(idx);
- }
-
- public int size()
- {
- return trajectory.size();
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/ProposedPurchaseTimeSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/ProposedPurchaseTimeSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/ProposedPurchaseTimeSampler.java
deleted file mode 100644
index 3fa2ef9..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/ProposedPurchaseTimeSampler.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * 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.transaction;
-
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-
-public class ProposedPurchaseTimeSampler implements Sampler<Double>
-{
- final CustomerInventory customerInventory;
- final Sampler<Double> arrivalTimeSampler;
-
- public ProposedPurchaseTimeSampler(CustomerInventory customerInventory,
- Sampler<Double> arrivalTimeSampler)
- {
- this.customerInventory = customerInventory;
- this.arrivalTimeSampler = arrivalTimeSampler;
- }
-
- protected double categoryProposedTime(double exhaustionTime) throws Exception
- {
- return Math.max(exhaustionTime - arrivalTimeSampler.sample(), 0.0);
- }
-
- public Double sample() throws Exception
- {
- double minProposedTime = Double.MAX_VALUE;
- for(Double exhaustionTime : this.customerInventory.getExhaustionTimes().values())
- {
- double proposedTime = this.categoryProposedTime(exhaustionTime);
- minProposedTime = Math.min(proposedTime, minProposedTime);
- }
-
- return minProposedTime;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TransactionPurchasesHiddenMarkovModel.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TransactionPurchasesHiddenMarkovModel.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TransactionPurchasesHiddenMarkovModel.java
deleted file mode 100644
index 83924e3..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TransactionPurchasesHiddenMarkovModel.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
- * 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.transaction;
-
-import java.util.List;
-import java.util.Map;
-
-import org.apache.bigtop.bigpetstore.datagenerator.Constants;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-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.wfs.ConditionalWeightFunction;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-
-public class TransactionPurchasesHiddenMarkovModel implements ConditionalSampler<List<Product>, Double>
-{
-
- protected final static String STOP_STATE = "STOP";
-
- final ConditionalSampler<Product, String> purchasingProcesses;
- final ConditionalWeightFunction<Double, Double> categoryWF;
- final CustomerInventory inventory;
-
- final SeedFactory seedFactory;
-
- public TransactionPurchasesHiddenMarkovModel(ConditionalSampler<Product, String> purchasingProcesses,
- ConditionalWeightFunction<Double, Double> categoryWF, CustomerInventory inventory,
- SeedFactory seedFactory)
- {
- this.purchasingProcesses = purchasingProcesses;
- this.inventory = inventory;
- this.categoryWF = categoryWF;
-
- this.seedFactory = seedFactory;
- }
-
- protected String chooseCategory(double transactionTime, int numPurchases) throws Exception
- {
- ImmutableMap<String, Double> exhaustionTimes = this.inventory.getExhaustionTimes();
- Map<String, Double> weights = Maps.newHashMap();
-
- for(Map.Entry<String, Double> entry : exhaustionTimes.entrySet())
- {
- String category = entry.getKey();
- double weight = this.categoryWF.weight(entry.getValue(), transactionTime);
- weights.put(category, weight);
- }
-
- if(numPurchases > 0)
- {
- weights.put(STOP_STATE, Constants.STOP_CATEGORY_WEIGHT);
- }
-
- Sampler<String> sampler = RouletteWheelSampler.create(weights, seedFactory);
-
- return sampler.sample();
- }
-
- protected Product chooseProduct(String category) throws Exception
- {
- return this.purchasingProcesses.sample(category);
- }
-
- public List<Product> sample(Double transactionTime) throws Exception
- {
- int numPurchases = 0;
-
- List<Product> purchasedProducts = Lists.newArrayList();
-
- String category;
- while(true)
- {
- category = this.chooseCategory(transactionTime, numPurchases);
-
- if(category.equals(STOP_STATE))
- {
- break;
- }
-
- Product product = this.chooseProduct(category);
-
- purchasedProducts.add(product);
-
- this.inventory.simulatePurchase(transactionTime, product);
- numPurchases += 1;
- }
-
- return purchasedProducts;
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TransactionPurchasesSamplerBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TransactionPurchasesSamplerBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TransactionPurchasesSamplerBuilder.java
deleted file mode 100644
index 4400151..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TransactionPurchasesSamplerBuilder.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * 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.transaction;
-
-import java.util.Collection;
-import java.util.List;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.ConditionalSampler;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.wfs.ConditionalWeightFunction;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.PurchasingModel;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.PurchasingProcesses;
-
-public class TransactionPurchasesSamplerBuilder
-{
- final SeedFactory seedFactory;
- final Collection<ProductCategory> productCategories;
- final PurchasingModel purchasingProfile;
-
- protected CustomerTransactionParameters transactionParameters;
- protected CustomerInventory inventory;
-
- public TransactionPurchasesSamplerBuilder(Collection<ProductCategory> productCategories,
- PurchasingModel purchasingProfile,
- SeedFactory seedFactory)
- {
- this.seedFactory = seedFactory;
- this.productCategories = productCategories;
- this.purchasingProfile = purchasingProfile;
- }
-
- public void setTransactionParameters(
- CustomerTransactionParameters transactionParameters)
- {
- this.transactionParameters = transactionParameters;
- }
-
- public void setInventory(CustomerInventory inventory)
- {
- this.inventory = inventory;
- }
-
- public ConditionalSampler<List<Product>, Double> build() throws Exception
- {
- PurchasingProcesses processes = purchasingProfile.buildProcesses(seedFactory);
-
- ConditionalWeightFunction<Double, Double> categoryWF =
- new CategoryWeightFunction(transactionParameters.getAveragePurchaseTriggerTime());
-
- ConditionalSampler<List<Product>, Double> sampler = new TransactionPurchasesHiddenMarkovModel(processes,
- categoryWF, inventory, this.seedFactory);
-
- return sampler;
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TransactionSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TransactionSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TransactionSampler.java
deleted file mode 100644
index b19ae38..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TransactionSampler.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * 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.transaction;
-
-import java.util.List;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Customer;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Transaction;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.ConditionalSampler;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-
-public class TransactionSampler implements Sampler<Transaction>
-{
- private final Sampler<Double> timeSampler;
- private final ConditionalSampler<List<Product>, Double> purchasesSampler;
- private final Sampler<Integer> idSampler;
- private final Customer customer;
-
- public TransactionSampler(Customer customer, Sampler<Double> timeSampler,
- ConditionalSampler<List<Product>, Double> purchasesSampler,
- Sampler<Integer> idSampler)
- {
- this.timeSampler = timeSampler;
- this.customer = customer;
- this.purchasesSampler = purchasesSampler;
- this.idSampler = idSampler;
- }
-
-
- public Transaction sample() throws Exception
- {
- Double transactionTime = timeSampler.sample();
- List<Product> purchase = purchasesSampler.sample(transactionTime);
- Integer id = idSampler.sample();
-
- Transaction transaction = new Transaction(id, customer, customer.getStore(),
- transactionTime, purchase);
-
- return transaction;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TransactionSamplerBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TransactionSamplerBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TransactionSamplerBuilder.java
deleted file mode 100644
index 748b4db..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TransactionSamplerBuilder.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/**
- * 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.transaction;
-
-import java.util.Collection;
-import java.util.List;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Customer;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Transaction;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.ConditionalSampler;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.SequenceSampler;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.PurchasingModel;
-
-public class TransactionSamplerBuilder
-{
- private final Collection<ProductCategory> productCategories;
- private final Customer customer;
- private final PurchasingModel purchasingProfile;
- private final SeedFactory seedFactory;
-
- CustomerTransactionParameters parameters;
- CustomerInventory inventory;
-
- public TransactionSamplerBuilder(Collection<ProductCategory> productCategories,
- Customer customer,
- PurchasingModel purchasingProfile,
- SeedFactory seedFactory) throws Exception
- {
- this.customer = customer;
- this.seedFactory = seedFactory;
- this.purchasingProfile = purchasingProfile;
- this.productCategories = productCategories;
- }
-
- protected void buildParameters() throws Exception
- {
- CustomerTransactionParametersSamplerBuilder builder = new CustomerTransactionParametersSamplerBuilder(seedFactory);
- parameters = builder.build().sample();
- }
-
- protected ConditionalSampler<List<Product>, Double> buildPurchasesSampler() throws Exception
- {
- TransactionPurchasesSamplerBuilder builder = new TransactionPurchasesSamplerBuilder(productCategories,
- purchasingProfile, seedFactory);
-
- builder.setTransactionParameters(parameters);
- builder.setInventory(inventory);
-
- return builder.build();
- }
-
- protected Sampler<Double> buildTimeSampler()
- {
- TransactionTimeSamplerBuilder builder = new TransactionTimeSamplerBuilder(seedFactory);
- builder.setCustomerTransactionParameters(parameters);
- builder.setCustomerInventory(inventory);
-
- return builder.build();
- }
-
- protected void buildCustomerInventory()
- {
- CustomerInventoryBuilder inventoryBuilder = new CustomerInventoryBuilder(parameters,
- seedFactory);
- inventoryBuilder.addAllProductCategories(productCategories);
- inventory = inventoryBuilder.build();
- }
-
- public Sampler<Transaction> build() throws Exception
- {
- buildParameters();
- buildCustomerInventory();
-
- Sampler<Double> timeSampler = buildTimeSampler();
-
- return new TransactionSampler(customer, timeSampler, buildPurchasesSampler(), new SequenceSampler());
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TransactionTimePDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TransactionTimePDF.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TransactionTimePDF.java
deleted file mode 100644
index b2b284f..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TransactionTimePDF.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * 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.transaction;
-
-import org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs.ConditionalProbabilityDensityFunction;
-
-public class TransactionTimePDF implements ConditionalProbabilityDensityFunction<Double, Double>
-{
- public double probability(Double proposedTime, Double lastTransactionTime)
- {
- if(proposedTime >= lastTransactionTime)
- {
- return 1.0;
- }
-
- return 0.0;
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TransactionTimeSamplerBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TransactionTimeSamplerBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TransactionTimeSamplerBuilder.java
deleted file mode 100644
index 261d5a3..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TransactionTimeSamplerBuilder.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * 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.transaction;
-
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.ExponentialSampler;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.StatefulMonteCarloSampler;
-
-public class TransactionTimeSamplerBuilder
-{
- private final SeedFactory seedFactory;
- private CustomerInventory customerInventory;
- private CustomerTransactionParameters transactionParameters;
-
- public TransactionTimeSamplerBuilder(SeedFactory seedFactory)
- {
- this.seedFactory = seedFactory;
- }
-
- public void setCustomerInventory(CustomerInventory inventory)
- {
- this.customerInventory = inventory;
- }
-
- public void setCustomerTransactionParameters(CustomerTransactionParameters parameters)
- {
- this.transactionParameters = parameters;
- }
-
- public Sampler<Double> build()
- {
- double lambda = 1.0 / transactionParameters.getAverageTransactionTriggerTime();
- Sampler<Double> arrivalTimeSampler = new ExponentialSampler(lambda, seedFactory);
- Sampler<Double> proposedTimeSampler = new ProposedPurchaseTimeSampler(customerInventory,
- arrivalTimeSampler);
-
- return new StatefulMonteCarloSampler<Double>(proposedTimeSampler,
- new TransactionTimePDF(),
- 0.0,
- seedFactory);
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/Constants.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/Constants.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/Constants.java
new file mode 100644
index 0000000..21827d5
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/Constants.java
@@ -0,0 +1,99 @@
+/**
+ * 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.datagenerators.bigpetstore;
+
+import java.io.File;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.lang3.tuple.Pair;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+
+public class Constants
+{
+ public static enum PurchasingModelType
+ {
+ MULTINOMIAL,
+ MARKOV;
+ }
+
+ public static enum ProductsCollectionSize
+ {
+ SMALL,
+ MEDIUM;
+ }
+
+ public static final File COORDINATES_FILE = new File("zips.csv");
+ public static final File INCOMES_FILE = new File("ACS_12_5YR_S1903/ACS_12_5YR_S1903_with_ann.csv");
+ public static final File POPULATION_FILE = new File("population_data.csv");
+
+ public static final File NAMEDB_FILE = new File("namedb/data/data.dat");
+
+ public static final ProductsCollectionSize PRODUCTS_COLLECTION = ProductsCollectionSize.MEDIUM;
+
+ public static final double INCOME_SCALING_FACTOR = 100.0;
+
+ public static final int MIN_PETS = 1;
+ public static final int MAX_PETS = 10;
+
+ public static final List<Pair<Double, Double>> TRANSACTION_TRIGGER_TIME_GAUSSIANS = ImmutableList.of(Pair.of(5.0, 2.0));
+ public static final List<Pair<Double, Double>> PURCHASE_TRIGGER_TIME_GAUSSIANS = ImmutableList.of(Pair.of(10.0, 4.0));
+
+ public static final double TRANSACTION_TRIGGER_TIME_MAX = 10.0;
+ public static final double TRANSACTION_TRIGGER_TIME_MIN = 1.0;
+
+ public static final double PURCHASE_TRIGGER_TIME_MAX = 20.0;
+ public static final double PURCHASE_TRIGGER_TIME_MIN = 1.0;
+
+ public static final double AVERAGE_CUSTOMER_STORE_DISTANCE = 5.0; // miles
+
+ public static final PurchasingModelType PURCHASING_MODEL_TYPE = PurchasingModelType.MULTINOMIAL;
+
+ public static final List<Pair<Double, Double>> PRODUCT_MSM_FIELD_WEIGHT_GAUSSIANS = ImmutableList.of(Pair.of(0.15, 0.1), Pair.of(0.85, 0.1));
+ public static final double PRODUCT_MSM_FIELD_WEIGHT_LOWERBOUND = 0.05;
+ public static final double PRODUCT_MSM_FIELD_WEIGHT_UPPERBOUND = 0.95;
+
+ public static final List<Pair<Double, Double>> PRODUCT_MSM_FIELD_SIMILARITY_WEIGHT_GAUSSIANS = ImmutableList.of(Pair.of(0.15, 0.1), Pair.of(0.85, 0.1));
+ public static final double PRODUCT_MSM_FIELD_SIMILARITY_WEIGHT_LOWERBOUND = 0.05;
+ public static final double PRODUCT_MSM_FIELD_SIMILARITY_WEIGHT_UPPERBOUND = 0.95;
+
+ public static final List<Pair<Double, Double>> PRODUCT_MSM_LOOPBACK_WEIGHT_GAUSSIANS = ImmutableList.of(Pair.of(0.25, 0.1), Pair.of(0.75, 0.1));
+ public static final double PRODUCT_MSM_LOOPBACK_WEIGHT_LOWERBOUND = 0.05;
+ public static final double PRODUCT_MSM_LOOPBACK_WEIGHT_UPPERBOUND = 0.95;
+
+ public static final double PRODUCT_MULTINOMIAL_POSITIVE_WEIGHT = 10.0;
+ public static final double PRODUCT_MULTINOMIAL_NEUTRAL_WEIGHT = 1.0;
+ public static final double PRODUCT_MULTINOMIAL_NEGATIVE_WEIGHT = 0.1;
+ public static final int PRODUCT_MULTINOMIAL_POSITIVE_COUNT_MIN = 1;
+ public static final double PRODUCT_MULTINOMIAL_POSITIVE_FREQUENCY = 0.1; // 10%
+
+ public static final String PRODUCT_QUANTITY = "quantity";
+ public static final String PRODUCT_CATEGORY = "category";
+ public static final String PRODUCT_UNIT_PRICE = "unitPrice";
+ public static final String PRODUCT_PRICE = "price";
+
+ /*
+ * Until we have a more intelligent way (e.g., based on range) of dealing with prices,
+ * let's exclude them.
+ */
+ public static final Set<String> PRODUCT_MODEL_EXCLUDED_FIELDS = ImmutableSet.of(PRODUCT_CATEGORY,
+ PRODUCT_UNIT_PRICE,
+ PRODUCT_PRICE);
+
+ public static final double STOP_CATEGORY_WEIGHT = 0.01;
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/CustomerGenerator.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/CustomerGenerator.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/CustomerGenerator.java
new file mode 100644
index 0000000..7fc2cbe
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/CustomerGenerator.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.datagenerators.bigpetstore;
+
+import java.util.List;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Customer;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Store;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.InputData;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.customer.CustomerSamplerBuilder;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+
+public class CustomerGenerator
+{
+ final Sampler<Customer> sampler;
+
+ public CustomerGenerator(InputData inputData, List<Store> stores, SeedFactory seedFactory)
+ {
+ CustomerSamplerBuilder builder = new CustomerSamplerBuilder(stores, inputData, seedFactory);
+ sampler = builder.build();
+ }
+
+ public Customer generate() throws Exception
+ {
+ return sampler.sample();
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/DataLoader.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/DataLoader.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/DataLoader.java
new file mode 100644
index 0000000..d3393fe
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/DataLoader.java
@@ -0,0 +1,57 @@
+/**
+ * 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.datagenerators.bigpetstore;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.util.List;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.InputData;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.Names;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ZipcodeRecord;
+import org.apache.bigtop.datagenerators.bigpetstore.datareaders.NameReader;
+import org.apache.bigtop.datagenerators.bigpetstore.datareaders.ZipcodeReader;
+
+public class DataLoader
+{
+ private InputStream getResource(File filename) throws Exception
+ {
+ InputStream stream = getClass().getResourceAsStream("/input_data/" + filename);
+ return new BufferedInputStream(stream);
+ }
+
+ public InputData loadData() throws Exception
+ {
+
+ System.out.println("Reading zipcode data");
+ ZipcodeReader zipcodeReader = new ZipcodeReader();
+ zipcodeReader.setCoordinatesFile(getResource(Constants.COORDINATES_FILE));
+ zipcodeReader.setIncomesFile(getResource(Constants.INCOMES_FILE));
+ zipcodeReader.setPopulationFile(getResource(Constants.POPULATION_FILE));
+ List<ZipcodeRecord> zipcodeTable = zipcodeReader.readData();
+ System.out.println("Read " + zipcodeTable.size() + " zipcode entries");
+
+ System.out.println("Reading name data");
+ NameReader nameReader = new NameReader(getResource(Constants.NAMEDB_FILE));
+ Names names = nameReader.readData();
+ System.out.println("Read " + names.getFirstNames().size() + " first names and " + names.getLastNames().size() + " last names");
+
+ InputData inputData = new InputData(zipcodeTable, names);
+
+ return inputData;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/ProductGenerator.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/ProductGenerator.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/ProductGenerator.java
new file mode 100644
index 0000000..d6a0412
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/ProductGenerator.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.datagenerators.bigpetstore;
+
+import java.util.List;
+
+import org.apache.bigtop.datagenerators.bigpetstore.Constants.ProductsCollectionSize;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.collections.MediumProductCollection;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.collections.SmallProductCollection;
+
+public class ProductGenerator
+{
+ ProductsCollectionSize collection;
+
+ public ProductGenerator(ProductsCollectionSize collection)
+ {
+ this.collection = collection;
+ }
+
+ public List<ProductCategory> generate()
+ {
+ List<ProductCategory> categories;
+
+ if(collection.equals(ProductsCollectionSize.SMALL))
+ {
+ SmallProductCollection collection = new SmallProductCollection();
+ categories = collection.generateProductCategory();
+ } else
+ {
+ MediumProductCollection collection = new MediumProductCollection();
+ categories = collection.generateProductCategory();
+ }
+
+ return categories;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/PurchasingModelGenerator.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/PurchasingModelGenerator.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/PurchasingModelGenerator.java
new file mode 100644
index 0000000..21f82a5
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/PurchasingModelGenerator.java
@@ -0,0 +1,40 @@
+/**
+ * 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.datagenerators.bigpetstore;
+
+import java.util.Collection;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.purchase.PurchasingModel;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.purchase.PurchasingModelSamplerBuilder;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+
+public class PurchasingModelGenerator
+{
+ final Sampler<? extends PurchasingModel> sampler;
+
+ public PurchasingModelGenerator(Collection<ProductCategory> productCategories, SeedFactory seedFactory) throws Exception
+ {
+ PurchasingModelSamplerBuilder builder = new PurchasingModelSamplerBuilder(productCategories, seedFactory);
+ sampler = builder.build();
+ }
+
+ public PurchasingModel generate() throws Exception
+ {
+ return sampler.sample();
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/StoreGenerator.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/StoreGenerator.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/StoreGenerator.java
new file mode 100644
index 0000000..60a150e
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/StoreGenerator.java
@@ -0,0 +1,38 @@
+/**
+ * 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.datagenerators.bigpetstore;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Store;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.InputData;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.store.StoreSamplerBuilder;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+
+public class StoreGenerator
+{
+ final Sampler<Store> sampler;
+
+ public StoreGenerator(InputData inputData, SeedFactory seedFactory)
+ {
+ StoreSamplerBuilder builder = new StoreSamplerBuilder(inputData.getZipcodeTable(), seedFactory);
+ sampler = builder.build();
+ }
+
+ public Store generate() throws Exception
+ {
+ return sampler.sample();
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/TransactionGenerator.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/TransactionGenerator.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/TransactionGenerator.java
new file mode 100644
index 0000000..7f56093
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/TransactionGenerator.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.datagenerators.bigpetstore;
+
+import java.util.Collection;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Customer;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Transaction;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.purchase.PurchasingModel;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.TransactionSamplerBuilder;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+
+public class TransactionGenerator
+{
+ Sampler<Transaction> sampler;
+
+ public TransactionGenerator(Customer customer, PurchasingModel profile,
+ Collection<ProductCategory> productCategories, SeedFactory seedFactory) throws Exception
+ {
+ sampler = new TransactionSamplerBuilder(productCategories,
+ customer, profile, seedFactory).build();
+ }
+
+ public Transaction generate() throws Exception
+ {
+ return sampler.sample();
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/cli/Driver.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/cli/Driver.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/cli/Driver.java
new file mode 100644
index 0000000..623b947
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/cli/Driver.java
@@ -0,0 +1,315 @@
+/**
+ * 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.datagenerators.bigpetstore.cli;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.bigtop.datagenerators.bigpetstore.DataLoader;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Customer;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Store;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Transaction;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.InputData;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.purchase.PurchasingModel;
+import org.apache.commons.lang3.tuple.Pair;
+
+
+public class Driver
+{
+ int nStores;
+ int nCustomers;
+ int nPurchasingModels;
+ double simulationTime;
+ long seed;
+ File outputDir;
+
+ static final int NPARAMS = 6;
+
+ private void printUsage()
+ {
+ String usage = "BigPetStore Data Generator\n" +
+ "\n" +
+ "Usage: java -jar bps-data-generator-v0.2.java outputDir nStores nCustomers nPurchasingModels simulationLength seed\n" +
+ "\n" +
+ "outputDir - (string) directory to write files\n" +
+ "nStores - (int) number of stores to generate\n" +
+ "nCustomers - (int) number of customers to generate\n" +
+ "nPurchasingModels - (int) number of purchasing models to generate\n" +
+ "simulationLength - (float) number of days to simulate\n" +
+ "seed - (long) seed for RNG. If not given, one is reandomly generated.\n";
+
+ System.out.println(usage);
+ }
+
+ public void parseArgs(String[] args)
+ {
+ if(args.length != NPARAMS && args.length != (NPARAMS - 1))
+ {
+ printUsage();
+ System.exit(1);
+ }
+
+ int i = -1;
+
+ outputDir = new File(args[++i]);
+ if(! outputDir.exists())
+ {
+ System.err.println("Given path (" + args[i] + ") does not exist.\n");
+ printUsage();
+ System.exit(1);
+ }
+
+ if(! outputDir.isDirectory())
+ {
+ System.err.println("Given path (" + args[i] + ") is not a directory.\n");
+ printUsage();
+ System.exit(1);
+ }
+
+ try
+ {
+ nStores = Integer.parseInt(args[++i]);
+ }
+ catch(Exception e)
+ {
+ System.err.println("Unable to parse '" + args[i] + "' as an integer for nStores.\n");
+ printUsage();
+ System.exit(1);
+ }
+
+ try
+ {
+ nCustomers = Integer.parseInt(args[++i]);
+ }
+ catch(Exception e)
+ {
+ System.err.println("Unable to parse '" + args[i] + "' as an integer for nCustomers.\n");
+ printUsage();
+ System.exit(1);
+ }
+
+ try
+ {
+ nPurchasingModels = Integer.parseInt(args[++i]);
+ }
+ catch(Exception e)
+ {
+ System.err.println("Unable to parse '" + args[i] + "' as an integer for nPurchasingModels.\n");
+ printUsage();
+ System.exit(1);
+ }
+
+ try
+ {
+ simulationTime = Double.parseDouble(args[++i]);
+ }
+ catch(Exception e)
+ {
+ System.err.println("Unable to parse '" + args[i] + "' as a float for simulationLength.\n");
+ printUsage();
+ System.exit(1);
+ }
+
+ try
+ {
+ seed = Long.parseLong(args[++i]);
+ }
+ catch(Exception e)
+ {
+ System.err.println("Unable to parse '" + args[i] + "' as a long for the seed.\n");
+ printUsage();
+ System.exit(1);
+ }
+ }
+
+ private void writeTransactions(Collection<Transaction> transactions) throws Exception
+ {
+ File outputFile = new File(outputDir.toString() + File.separator + "transactions.txt");
+ System.out.println(outputFile.toString());
+ OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
+
+ for(Transaction transaction : transactions)
+ {
+ for(Product product : transaction.getProducts())
+ {
+ String record = transaction.getId() + ",";
+ record += transaction.getDateTime() + ",";
+ record += transaction.getStore().getId() + ",";
+ record += transaction.getStore().getLocation().getZipcode() + ",";
+ record += transaction.getStore().getLocation().getCity() + ",";
+ record += transaction.getStore().getLocation().getState() + ",";
+ record += transaction.getCustomer().getId() + ",";
+ Pair<String, String> name = transaction.getCustomer().getName();
+ record += name.getLeft() + " " + name.getRight() + ",";
+ record += transaction.getCustomer().getLocation().getZipcode() + ",";
+ record += transaction.getCustomer().getLocation().getCity() + ",";
+ record += transaction.getCustomer().getLocation().getState() + ",";
+ record += product.toString() + "\n";
+
+ outputStream.write(record.getBytes());
+ }
+ }
+
+ outputStream.close();
+ }
+
+ private void writeCustomers(Collection<Customer> customers) throws Exception
+ {
+ File outputFile = new File(outputDir.toString() + File.separator + "customers.txt");
+ System.out.println(outputFile.toString());
+ OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
+
+ for(Customer customer : customers)
+ {
+ String record = customer.getId() + ",";
+ Pair<String, String> name = customer.getName();
+ record += name.getLeft() + "," + name.getRight() + ",";
+ record += customer.getLocation().getZipcode() + ",";
+ record += customer.getLocation().getCity() + ",";
+ record += customer.getLocation().getState() + "\n";
+
+ outputStream.write(record.getBytes());
+ }
+
+ outputStream.close();
+ }
+
+ private void writeStores(Collection<Store> stores) throws Exception
+ {
+ File outputFile = new File(outputDir.toString() + File.separator + "stores.txt");
+ System.out.println(outputFile.toString());
+ OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
+
+ for(Store store : stores)
+ {
+ String record = store.getId() + ",";
+ record += store.getLocation().getZipcode() + ",";
+ record += store.getLocation().getCity() + ",";
+ record += store.getLocation().getState() + "\n";
+
+ outputStream.write(record.getBytes());
+ }
+
+ outputStream.close();
+ }
+
+ private void writeProducts(Collection<ProductCategory> productCategories) throws Exception
+ {
+ File outputFile = new File(outputDir.toString() + File.separator + "products.txt");
+ System.out.println(outputFile.toString());
+ OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
+
+ for(ProductCategory category : productCategories)
+ {
+
+ for(Product product : category.getProducts())
+ {
+ String record = category.getCategoryLabel() + ",";
+ record += product.toString() + "\n";
+
+ outputStream.write(record.getBytes());
+ }
+ }
+
+ outputStream.close();
+ }
+
+ private void writePurchasingProfiles(List<ProductCategory> productCategories, List<PurchasingModel> profiles) throws Exception
+ {
+ File outputFile = new File(outputDir.toString() + File.separator + "purchasing_profiles.txt");
+ System.out.println(outputFile.toString());
+ OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
+
+ for(ProductCategory category : productCategories)
+ {
+ int i = 0;
+ for(PurchasingModel model : profiles)
+ {
+ Object productModel = model.getProfile(category.getCategoryLabel());
+ String record = productModel.toString();
+
+ outputStream.write(record.getBytes());
+
+ i += 1;
+ }
+ }
+
+ outputStream.close();
+ }
+
+ public Simulation buildSimulation(InputData inputData)
+ {
+ return new Simulation(inputData, nStores, nCustomers, nPurchasingModels, simulationTime, seed);
+ }
+
+ private void run(InputData inputData) throws Exception
+ {
+ Simulation simulation = buildSimulation(inputData);
+
+ simulation.simulate();
+
+ writeStores(simulation.getStores());
+ writeCustomers(simulation.getCustomers());
+ writeProducts(simulation.getProductCategories());
+ writePurchasingProfiles(simulation.getProductCategories(), simulation.getPurchasingProfiles());
+ writeTransactions(simulation.getTransactions());
+ }
+ public void run(String[] args) throws Exception
+ {
+ parseArgs(args);
+
+ InputData inputData = (new DataLoader()).loadData();
+
+ run(inputData);
+ }
+
+ public static void main(String[] args) throws Exception
+ {
+ Driver driver = new Driver();
+ driver.run(args);
+ }
+
+ public Double getSimulationLength()
+ {
+ return simulationTime;
+ }
+
+ public int getNCustomers()
+ {
+ return nCustomers;
+ }
+
+ public long getSeed()
+ {
+ return seed;
+ }
+
+ public int getNStores()
+ {
+ return nStores;
+ }
+
+ public File getOutputDir()
+ {
+ return outputDir;
+ }
+}
[05/11] bigtop git commit: BIGTOP-1984. Extract samplers library from
BigPetStore data generator
Posted by rn...@apache.org.
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CustomerTransactionParametersSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CustomerTransactionParametersSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CustomerTransactionParametersSampler.java
new file mode 100644
index 0000000..4b746b2
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CustomerTransactionParametersSampler.java
@@ -0,0 +1,61 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.transaction;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.PetSpecies;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+
+public class CustomerTransactionParametersSampler implements Sampler<CustomerTransactionParameters>
+{
+ final private Sampler<Integer> nPetsSampler;
+ final private Sampler<PetSpecies> petSpeciesSampler;
+ final private Sampler<Double> purchaseTriggerTimeSampler;
+ final private Sampler<Double> transactionTriggerTimeSampler;
+
+ public CustomerTransactionParametersSampler(Sampler<Integer> nPetsSampler,
+ Sampler<PetSpecies> petSpeciesSampler,
+ Sampler<Double> purchaseTriggerTimeSampler,
+ Sampler<Double> transactionTriggerTimeSampler)
+ {
+
+ this.nPetsSampler = nPetsSampler;
+ this.petSpeciesSampler = petSpeciesSampler;
+ this.purchaseTriggerTimeSampler = purchaseTriggerTimeSampler;
+ this.transactionTriggerTimeSampler = transactionTriggerTimeSampler;
+ }
+
+ protected void generatePets(CustomerTransactionParametersBuilder builder) throws Exception
+ {
+ int nPets = this.nPetsSampler.sample();
+
+ for(int i = 0; i < nPets; i++)
+ {
+ PetSpecies species = this.petSpeciesSampler.sample();
+ builder.addPet(species);
+ }
+ }
+
+ public CustomerTransactionParameters sample() throws Exception
+ {
+ CustomerTransactionParametersBuilder builder = new CustomerTransactionParametersBuilder();
+
+ this.generatePets(builder);
+ builder.setAveragePurchaseTriggerTime(this.purchaseTriggerTimeSampler.sample());
+ builder.setAverageTransactionTriggerTime(this.transactionTriggerTimeSampler.sample());
+
+ return builder.build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CustomerTransactionParametersSamplerBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CustomerTransactionParametersSamplerBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CustomerTransactionParametersSamplerBuilder.java
new file mode 100644
index 0000000..88b1d1f
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/CustomerTransactionParametersSamplerBuilder.java
@@ -0,0 +1,55 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.transaction;
+
+import java.util.Arrays;
+
+import org.apache.bigtop.datagenerators.bigpetstore.Constants;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.PetSpecies;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.BoundedMultiModalGaussianSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.RouletteWheelSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.UniformIntSampler;
+
+public class CustomerTransactionParametersSamplerBuilder
+{
+ final private SeedFactory seedFactory;
+
+ public CustomerTransactionParametersSamplerBuilder(SeedFactory seedFactory)
+ {
+ this.seedFactory = seedFactory;
+ }
+
+ public Sampler<CustomerTransactionParameters> build()
+ {
+ Sampler<Integer> nPetsSampler = new UniformIntSampler(Constants.MIN_PETS, Constants.MAX_PETS, seedFactory);
+
+ Sampler<PetSpecies> petSpeciesSampler = RouletteWheelSampler.createUniform(Arrays.asList(PetSpecies.values()), seedFactory);
+
+ Sampler<Double> transactionTriggerTimeSampler = new BoundedMultiModalGaussianSampler(Constants.TRANSACTION_TRIGGER_TIME_GAUSSIANS,
+ Constants.TRANSACTION_TRIGGER_TIME_MIN, Constants.TRANSACTION_TRIGGER_TIME_MAX,
+ seedFactory);
+
+ Sampler<Double> purchaseTriggerTimeSampler = new BoundedMultiModalGaussianSampler(Constants.PURCHASE_TRIGGER_TIME_GAUSSIANS,
+ Constants.PURCHASE_TRIGGER_TIME_MIN, Constants.PURCHASE_TRIGGER_TIME_MAX,
+ seedFactory);
+
+ return new CustomerTransactionParametersSampler(nPetsSampler, petSpeciesSampler,
+ transactionTriggerTimeSampler, purchaseTriggerTimeSampler);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/ProductCategoryInventory.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/ProductCategoryInventory.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/ProductCategoryInventory.java
new file mode 100644
index 0000000..3fdacbd
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/ProductCategoryInventory.java
@@ -0,0 +1,58 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.transaction;
+
+import org.apache.bigtop.datagenerators.bigpetstore.Constants;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+
+public class ProductCategoryInventory
+{
+ private ProductCategoryUsageTrajectory trajectory;
+ private ProductCategoryUsageSimulator simulator;
+
+ public ProductCategoryInventory(ProductCategory productCategory, CustomerTransactionParameters parameters,
+ SeedFactory seedFactory)
+ {
+
+ double amountUsedAverage = productCategory.getBaseAmountUsedAverage() * parameters.countPetsBySpecies(productCategory.getApplicableSpecies());
+ double amountUsedVariance = productCategory.getBaseAmountUsedVariance() * parameters.countPetsBySpecies(productCategory.getApplicableSpecies());
+
+ trajectory = new ProductCategoryUsageTrajectory(0.0, 0.0);
+ simulator = new ProductCategoryUsageSimulator(productCategory.getDailyUsageRate(),
+ amountUsedAverage, amountUsedVariance, seedFactory);
+ }
+
+ public void simulatePurchase(double time, Product product) throws Exception
+ {
+ double amountPurchased = product.getFieldValueAsDouble(Constants.PRODUCT_QUANTITY);
+
+ double amountRemainingBeforePurchase = trajectory.amountAtTime(time);
+
+ trajectory = simulator.simulate(time, amountRemainingBeforePurchase + amountPurchased);
+ }
+
+ public double findExhaustionTime()
+ {
+ return trajectory.getLastTime();
+ }
+
+ public double findRemainingAmount(double time)
+ {
+ return trajectory.amountAtTime(time);
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/ProductCategoryUsageSimulator.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/ProductCategoryUsageSimulator.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/ProductCategoryUsageSimulator.java
new file mode 100644
index 0000000..cfefa16
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/ProductCategoryUsageSimulator.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.datagenerators.bigpetstore.generators.transaction;
+
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.ExponentialSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.GaussianSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+
+public class ProductCategoryUsageSimulator
+{
+ final private double amountUsedAverage;
+ final private double amountUsedVariance;
+
+ final private Sampler<Double> timestepSampler;
+ final private Sampler<Double> R;
+
+ public ProductCategoryUsageSimulator(double dailyUsageRate, double amountUsedAverage,
+ double amountUsedVariance, SeedFactory seedFactory)
+ {
+ this.amountUsedAverage = amountUsedAverage;
+ this.amountUsedVariance = amountUsedVariance;
+
+ timestepSampler = new ExponentialSampler(dailyUsageRate, seedFactory);
+ R = new GaussianSampler(0.0, 1.0, seedFactory);
+ }
+
+ private void step(ProductCategoryUsageTrajectory trajectory) throws Exception
+ {
+ // given in days since last usage
+ double timestep = timestepSampler.sample();
+
+ double r = R.sample();
+
+ // given in units per day
+ double usageAmount = this.amountUsedAverage * timestep +
+ Math.sqrt(this.amountUsedVariance * timestep) * r;
+
+ // can't use a negative amount
+ usageAmount = Math.max(usageAmount, 0.0);
+
+ double remainingAmount = Math.max(0.0, trajectory.getLastAmount() - usageAmount);
+ double time = trajectory.getLastTime() + timestep;
+
+ trajectory.append(time, remainingAmount);
+ }
+
+ public ProductCategoryUsageTrajectory simulate(double initialTime, double initialAmount) throws Exception
+ {
+ ProductCategoryUsageTrajectory trajectory = new ProductCategoryUsageTrajectory(initialTime, initialAmount);
+
+ while(trajectory.getLastAmount() > 0.0)
+ {
+ step(trajectory);
+ }
+
+ return trajectory;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/ProductCategoryUsageTrajectory.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/ProductCategoryUsageTrajectory.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/ProductCategoryUsageTrajectory.java
new file mode 100644
index 0000000..45cdbc9
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/ProductCategoryUsageTrajectory.java
@@ -0,0 +1,74 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.transaction;
+
+import java.util.List;
+
+import org.apache.commons.lang3.tuple.Pair;
+
+import com.google.common.collect.Lists;
+
+public class ProductCategoryUsageTrajectory
+{
+ final private List<Pair<Double, Double>> trajectory;
+
+ public ProductCategoryUsageTrajectory(double initialTime, double initialAmount)
+ {
+ trajectory = Lists.newArrayList();
+ this.append(initialTime, initialAmount);
+ }
+
+ public void append(double time, double amount)
+ {
+ trajectory.add(Pair.of(time, amount));
+ }
+
+ public double getLastAmount()
+ {
+ return trajectory.get(trajectory.size() - 1).getValue();
+ }
+
+ public double getLastTime()
+ {
+ return trajectory.get(trajectory.size() - 1).getKey();
+ }
+
+ public double amountAtTime(double time)
+ {
+ Pair<Double, Double> previous = null;
+ for(Pair<Double, Double> entry : trajectory)
+ {
+ if(entry.getKey() > time)
+ break;
+ previous = entry;
+ }
+
+ if(previous == null)
+ return 0.0;
+
+ return previous.getValue();
+ }
+
+ public Pair<Double, Double> getStep(int idx)
+ {
+ return trajectory.get(idx);
+ }
+
+ public int size()
+ {
+ return trajectory.size();
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/ProposedPurchaseTimeSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/ProposedPurchaseTimeSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/ProposedPurchaseTimeSampler.java
new file mode 100644
index 0000000..e4380fc
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/ProposedPurchaseTimeSampler.java
@@ -0,0 +1,49 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.transaction;
+
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+
+public class ProposedPurchaseTimeSampler implements Sampler<Double>
+{
+ final CustomerInventory customerInventory;
+ final Sampler<Double> arrivalTimeSampler;
+
+ public ProposedPurchaseTimeSampler(CustomerInventory customerInventory,
+ Sampler<Double> arrivalTimeSampler)
+ {
+ this.customerInventory = customerInventory;
+ this.arrivalTimeSampler = arrivalTimeSampler;
+ }
+
+ protected double categoryProposedTime(double exhaustionTime) throws Exception
+ {
+ return Math.max(exhaustionTime - arrivalTimeSampler.sample(), 0.0);
+ }
+
+ public Double sample() throws Exception
+ {
+ double minProposedTime = Double.MAX_VALUE;
+ for(Double exhaustionTime : this.customerInventory.getExhaustionTimes().values())
+ {
+ double proposedTime = this.categoryProposedTime(exhaustionTime);
+ minProposedTime = Math.min(proposedTime, minProposedTime);
+ }
+
+ return minProposedTime;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TransactionPurchasesHiddenMarkovModel.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TransactionPurchasesHiddenMarkovModel.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TransactionPurchasesHiddenMarkovModel.java
new file mode 100644
index 0000000..0ae2f2c
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TransactionPurchasesHiddenMarkovModel.java
@@ -0,0 +1,108 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.transaction;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.bigpetstore.Constants;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.ConditionalSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.RouletteWheelSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.apache.bigtop.datagenerators.samplers.wfs.ConditionalWeightFunction;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+public class TransactionPurchasesHiddenMarkovModel implements ConditionalSampler<List<Product>, Double>
+{
+
+ protected final static String STOP_STATE = "STOP";
+
+ final ConditionalSampler<Product, String> purchasingProcesses;
+ final ConditionalWeightFunction<Double, Double> categoryWF;
+ final CustomerInventory inventory;
+
+ final SeedFactory seedFactory;
+
+ public TransactionPurchasesHiddenMarkovModel(ConditionalSampler<Product, String> purchasingProcesses,
+ ConditionalWeightFunction<Double, Double> categoryWF, CustomerInventory inventory,
+ SeedFactory seedFactory)
+ {
+ this.purchasingProcesses = purchasingProcesses;
+ this.inventory = inventory;
+ this.categoryWF = categoryWF;
+
+ this.seedFactory = seedFactory;
+ }
+
+ protected String chooseCategory(double transactionTime, int numPurchases) throws Exception
+ {
+ ImmutableMap<String, Double> exhaustionTimes = this.inventory.getExhaustionTimes();
+ Map<String, Double> weights = Maps.newHashMap();
+
+ for(Map.Entry<String, Double> entry : exhaustionTimes.entrySet())
+ {
+ String category = entry.getKey();
+ double weight = this.categoryWF.weight(entry.getValue(), transactionTime);
+ weights.put(category, weight);
+ }
+
+ if(numPurchases > 0)
+ {
+ weights.put(STOP_STATE, Constants.STOP_CATEGORY_WEIGHT);
+ }
+
+ Sampler<String> sampler = RouletteWheelSampler.create(weights, seedFactory);
+
+ return sampler.sample();
+ }
+
+ protected Product chooseProduct(String category) throws Exception
+ {
+ return this.purchasingProcesses.sample(category);
+ }
+
+ public List<Product> sample(Double transactionTime) throws Exception
+ {
+ int numPurchases = 0;
+
+ List<Product> purchasedProducts = Lists.newArrayList();
+
+ String category;
+ while(true)
+ {
+ category = this.chooseCategory(transactionTime, numPurchases);
+
+ if(category.equals(STOP_STATE))
+ {
+ break;
+ }
+
+ Product product = this.chooseProduct(category);
+
+ purchasedProducts.add(product);
+
+ this.inventory.simulatePurchase(transactionTime, product);
+ numPurchases += 1;
+ }
+
+ return purchasedProducts;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TransactionPurchasesSamplerBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TransactionPurchasesSamplerBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TransactionPurchasesSamplerBuilder.java
new file mode 100644
index 0000000..678c292
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TransactionPurchasesSamplerBuilder.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.datagenerators.bigpetstore.generators.transaction;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.purchase.PurchasingModel;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.purchase.PurchasingProcesses;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.ConditionalSampler;
+import org.apache.bigtop.datagenerators.samplers.wfs.ConditionalWeightFunction;
+
+public class TransactionPurchasesSamplerBuilder
+{
+ final SeedFactory seedFactory;
+ final Collection<ProductCategory> productCategories;
+ final PurchasingModel purchasingProfile;
+
+ protected CustomerTransactionParameters transactionParameters;
+ protected CustomerInventory inventory;
+
+ public TransactionPurchasesSamplerBuilder(Collection<ProductCategory> productCategories,
+ PurchasingModel purchasingProfile,
+ SeedFactory seedFactory)
+ {
+ this.seedFactory = seedFactory;
+ this.productCategories = productCategories;
+ this.purchasingProfile = purchasingProfile;
+ }
+
+ public void setTransactionParameters(
+ CustomerTransactionParameters transactionParameters)
+ {
+ this.transactionParameters = transactionParameters;
+ }
+
+ public void setInventory(CustomerInventory inventory)
+ {
+ this.inventory = inventory;
+ }
+
+ public ConditionalSampler<List<Product>, Double> build() throws Exception
+ {
+ PurchasingProcesses processes = purchasingProfile.buildProcesses(seedFactory);
+
+ ConditionalWeightFunction<Double, Double> categoryWF =
+ new CategoryWeightFunction(transactionParameters.getAveragePurchaseTriggerTime());
+
+ ConditionalSampler<List<Product>, Double> sampler = new TransactionPurchasesHiddenMarkovModel(processes,
+ categoryWF, inventory, this.seedFactory);
+
+ return sampler;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TransactionSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TransactionSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TransactionSampler.java
new file mode 100644
index 0000000..06b479b
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TransactionSampler.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.datagenerators.bigpetstore.generators.transaction;
+
+import java.util.List;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Customer;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Transaction;
+import org.apache.bigtop.datagenerators.samplers.samplers.ConditionalSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+
+public class TransactionSampler implements Sampler<Transaction>
+{
+ private final Sampler<Double> timeSampler;
+ private final ConditionalSampler<List<Product>, Double> purchasesSampler;
+ private final Sampler<Integer> idSampler;
+ private final Customer customer;
+
+ public TransactionSampler(Customer customer, Sampler<Double> timeSampler,
+ ConditionalSampler<List<Product>, Double> purchasesSampler,
+ Sampler<Integer> idSampler)
+ {
+ this.timeSampler = timeSampler;
+ this.customer = customer;
+ this.purchasesSampler = purchasesSampler;
+ this.idSampler = idSampler;
+ }
+
+
+ public Transaction sample() throws Exception
+ {
+ Double transactionTime = timeSampler.sample();
+ List<Product> purchase = purchasesSampler.sample(transactionTime);
+ Integer id = idSampler.sample();
+
+ Transaction transaction = new Transaction(id, customer, customer.getStore(),
+ transactionTime, purchase);
+
+ return transaction;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TransactionSamplerBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TransactionSamplerBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TransactionSamplerBuilder.java
new file mode 100644
index 0000000..80f336f
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TransactionSamplerBuilder.java
@@ -0,0 +1,95 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.transaction;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Customer;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Transaction;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.purchase.PurchasingModel;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.ConditionalSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.SequenceSampler;
+
+public class TransactionSamplerBuilder
+{
+ private final Collection<ProductCategory> productCategories;
+ private final Customer customer;
+ private final PurchasingModel purchasingProfile;
+ private final SeedFactory seedFactory;
+
+ CustomerTransactionParameters parameters;
+ CustomerInventory inventory;
+
+ public TransactionSamplerBuilder(Collection<ProductCategory> productCategories,
+ Customer customer,
+ PurchasingModel purchasingProfile,
+ SeedFactory seedFactory) throws Exception
+ {
+ this.customer = customer;
+ this.seedFactory = seedFactory;
+ this.purchasingProfile = purchasingProfile;
+ this.productCategories = productCategories;
+ }
+
+ protected void buildParameters() throws Exception
+ {
+ CustomerTransactionParametersSamplerBuilder builder = new CustomerTransactionParametersSamplerBuilder(seedFactory);
+ parameters = builder.build().sample();
+ }
+
+ protected ConditionalSampler<List<Product>, Double> buildPurchasesSampler() throws Exception
+ {
+ TransactionPurchasesSamplerBuilder builder = new TransactionPurchasesSamplerBuilder(productCategories,
+ purchasingProfile, seedFactory);
+
+ builder.setTransactionParameters(parameters);
+ builder.setInventory(inventory);
+
+ return builder.build();
+ }
+
+ protected Sampler<Double> buildTimeSampler()
+ {
+ TransactionTimeSamplerBuilder builder = new TransactionTimeSamplerBuilder(seedFactory);
+ builder.setCustomerTransactionParameters(parameters);
+ builder.setCustomerInventory(inventory);
+
+ return builder.build();
+ }
+
+ protected void buildCustomerInventory()
+ {
+ CustomerInventoryBuilder inventoryBuilder = new CustomerInventoryBuilder(parameters,
+ seedFactory);
+ inventoryBuilder.addAllProductCategories(productCategories);
+ inventory = inventoryBuilder.build();
+ }
+
+ public Sampler<Transaction> build() throws Exception
+ {
+ buildParameters();
+ buildCustomerInventory();
+
+ Sampler<Double> timeSampler = buildTimeSampler();
+
+ return new TransactionSampler(customer, timeSampler, buildPurchasesSampler(), new SequenceSampler());
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TransactionTimePDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TransactionTimePDF.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TransactionTimePDF.java
new file mode 100644
index 0000000..8e7369b
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TransactionTimePDF.java
@@ -0,0 +1,31 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.transaction;
+
+import org.apache.bigtop.datagenerators.samplers.pdfs.ConditionalProbabilityDensityFunction;
+
+public class TransactionTimePDF implements ConditionalProbabilityDensityFunction<Double, Double>
+{
+ public double probability(Double proposedTime, Double lastTransactionTime)
+ {
+ if(proposedTime >= lastTransactionTime)
+ {
+ return 1.0;
+ }
+
+ return 0.0;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TransactionTimeSamplerBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TransactionTimeSamplerBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TransactionTimeSamplerBuilder.java
new file mode 100644
index 0000000..41fd984
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TransactionTimeSamplerBuilder.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.datagenerators.bigpetstore.generators.transaction;
+
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.ExponentialSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.StatefulMonteCarloSampler;
+
+public class TransactionTimeSamplerBuilder
+{
+ private final SeedFactory seedFactory;
+ private CustomerInventory customerInventory;
+ private CustomerTransactionParameters transactionParameters;
+
+ public TransactionTimeSamplerBuilder(SeedFactory seedFactory)
+ {
+ this.seedFactory = seedFactory;
+ }
+
+ public void setCustomerInventory(CustomerInventory inventory)
+ {
+ this.customerInventory = inventory;
+ }
+
+ public void setCustomerTransactionParameters(CustomerTransactionParameters parameters)
+ {
+ this.transactionParameters = parameters;
+ }
+
+ public Sampler<Double> build()
+ {
+ double lambda = 1.0 / transactionParameters.getAverageTransactionTriggerTime();
+ Sampler<Double> arrivalTimeSampler = new ExponentialSampler(lambda, seedFactory);
+ Sampler<Double> proposedTimeSampler = new ProposedPurchaseTimeSampler(customerInventory,
+ arrivalTimeSampler);
+
+ return new StatefulMonteCarloSampler<Double>(proposedTimeSampler,
+ new TransactionTimePDF(),
+ 0.0,
+ seedFactory);
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/TestProduct.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/TestProduct.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/TestProduct.java
deleted file mode 100644
index f1e835a..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/TestProduct.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * 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.datamodels;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-import java.util.Map;
-
-import org.apache.bigtop.bigpetstore.datagenerator.Constants;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
-import org.junit.Test;
-
-import com.google.common.collect.Maps;
-
-public class TestProduct
-{
-
- @Test
- public void testString()
- {
- Map<String, Object> fields = Maps.newHashMap();
- fields.put(Constants.PRODUCT_CATEGORY, "poop bags");
- fields.put(Constants.PRODUCT_QUANTITY, 120);
- fields.put("price", 12.80);
-
- Product product = new Product(fields);
-
- assertEquals(product.getFieldValueAsString(Constants.PRODUCT_CATEGORY), "poop bags");
- assertEquals(product.getFieldValueAsString("price"), "12.8");
- assertEquals(product.getFieldValueAsString(Constants.PRODUCT_QUANTITY), "120");
- }
-
- @Test
- public void testDouble()
- {
- Map<String, Object> fields = Maps.newHashMap();
- fields.put(Constants.PRODUCT_CATEGORY, "poop bags");
- fields.put(Constants.PRODUCT_QUANTITY, 120);
- fields.put("price", 12.80);
-
- Product product = new Product(fields);
-
- assertNull(product.getFieldValueAsDouble(Constants.PRODUCT_CATEGORY));
- assertEquals(product.getFieldValueAsDouble("price"), 12.80, 1e-5);
- assertNull(product.getFieldValueAsDouble(Constants.PRODUCT_QUANTITY));
- }
-
- @Test
- public void testLong()
- {
- Map<String, Object> fields = Maps.newHashMap();
- fields.put(Constants.PRODUCT_CATEGORY, "poop bags");
- fields.put(Constants.PRODUCT_QUANTITY, 120);
- fields.put("price", 12.80);
-
- Product product = new Product(fields);
-
- assertNull(product.getFieldValueAsLong(Constants.PRODUCT_CATEGORY));
- assertNull(product.getFieldValueAsLong("price"));
- assertEquals((long) product.getFieldValueAsLong(Constants.PRODUCT_QUANTITY), 120L);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/TestMarkovModelBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/TestMarkovModelBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/TestMarkovModelBuilder.java
deleted file mode 100644
index b9e63f2..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/TestMarkovModelBuilder.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/**
- * 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.markovmodels;
-
-import org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels.MarkovModel;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels.MarkovModelBuilder;
-import org.junit.Test;
-
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.matchers.JUnitMatchers.*;
-
-public class TestMarkovModelBuilder
-{
-
- @Test
- public void testAddStateState()
- {
- MarkovModelBuilder<String> builder = MarkovModelBuilder.create();
-
- builder.addStartState("a", 1.0);
-
- MarkovModel<String> msm = builder.build();
-
- assertThat(msm.getStartWeights().keySet(), hasItem("a"));
- assertEquals((double) msm.getStartWeights().get("a"), (double) 1.0, 0.000001);
-
- }
-
- @Test
- public void testAddEdgeTransition()
- {
- MarkovModelBuilder<String> builder = MarkovModelBuilder.create();
-
- builder.addTransition("a", "b", 1.0);
-
- MarkovModel<String> msm = builder.build();
-
- assertThat(msm.getTransitionWeights().keySet(), hasItem("a"));
- assertThat(msm.getTransitionWeights().get("a").keySet(), hasItem("b"));
- assertEquals((double) msm.getTransitionWeights().get("a").get("b"), (double) 1.0, 0.000001);
- }
-
- @Test
- public void testBuildMSM()
- {
- MarkovModelBuilder<String> builder = MarkovModelBuilder.create();
-
- builder.addStartState("a", 1.0);
- builder.addTransition("a", "b", 1.0);
- builder.addTransition("a", "c", 1.0);
-
- MarkovModel<String> msm = builder.build();
-
- assertThat(msm.getStartWeights().keySet(), hasItem("a"));
- assertThat(msm.getTransitionWeights().keySet(), hasItem("a"));
- assertThat(msm.getTransitionWeights().get("a").keySet(), hasItem("b"));
- assertThat(msm.getTransitionWeights().get("a").keySet(), hasItem("c"));
- assertEquals((double) msm.getTransitionWeights().get("a").get("b"), (double) 1.0, 0.000001);
- assertEquals((double) msm.getTransitionWeights().get("a").get("c"), (double) 1.0, 0.000001);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/TestMarkovProcess.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/TestMarkovProcess.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/TestMarkovProcess.java
deleted file mode 100644
index e2ff4d5..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/TestMarkovProcess.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * 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.markovmodels;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.junit.matchers.JUnitMatchers.hasItem;
-
-import java.util.Arrays;
-
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels.MarkovModel;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels.MarkovModelBuilder;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels.MarkovProcess;
-import org.junit.Test;
-
-public class TestMarkovProcess
-{
-
- @Test
- public void test() throws Exception
- {
- SeedFactory factory = new SeedFactory(1245);
- MarkovModelBuilder<String> builder = MarkovModelBuilder.create();
-
- builder.addStartState("a", 1.0);
- builder.addTransition("a", "b", 1.0);
- builder.addTransition("a", "c", 1.0);
-
- MarkovModel<String> msm = builder.build();
- MarkovProcess<String> process = MarkovProcess.create(msm, factory);
-
- String firstState = process.sample();
- assertEquals(firstState, "a");
-
- String secondState = process.sample();
- assertThat(Arrays.asList("b", "c"), hasItem(secondState));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/TestMultinomialPDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/TestMultinomialPDF.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/TestMultinomialPDF.java
deleted file mode 100644
index 8952389..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/TestMultinomialPDF.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * 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.pdfs;
-
-import java.util.Map;
-import java.util.Set;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Sets;
-
-public class TestMultinomialPDF
-{
-
- @Test
- public void testToString()
- {
- Map<String, Double> objects = ImmutableMap.of("A", 0.1, "B", 0.3, "C", 0.5);
- MultinomialPDF<String> pdf = new MultinomialPDF<String>(objects);
- String string = pdf.toString();
- Set<String> observed = Sets.newHashSet(string.split("\n"));
- Set<String> expected = Sets.newHashSet("0.1,A", "0.3,B", "0.5,C");
-
- Assert.assertEquals(expected, observed);
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestBoundedMultiModalGaussianSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestBoundedMultiModalGaussianSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestBoundedMultiModalGaussianSampler.java
deleted file mode 100644
index 9300d08..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestBoundedMultiModalGaussianSampler.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * 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 static org.junit.Assert.assertTrue;
-
-import java.util.List;
-
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.commons.lang3.tuple.Pair;
-import org.junit.Test;
-
-import com.google.common.collect.Lists;
-
-public class TestBoundedMultiModalGaussianSampler
-{
-
- @Test
- public void testSample() throws Exception
- {
- double upperbound = 10.0;
- double lowerbound = 1.0;
-
- List<Pair<Double, Double>> distributions = Lists.newArrayList(Pair.of(2.0, 2.0), Pair.of(7.5, 2.0));
-
- SeedFactory seedFactory = new SeedFactory(1234);
-
- Sampler<Double> sampler = new BoundedMultiModalGaussianSampler(distributions, lowerbound, upperbound, seedFactory);
-
- Double result = sampler.sample();
-
- assertTrue(result >= lowerbound);
- assertTrue(result <= upperbound);
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestExponentialSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestExponentialSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestExponentialSampler.java
deleted file mode 100644
index 228b97d..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestExponentialSampler.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * 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 static org.junit.Assert.assertTrue;
-
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.ExponentialSampler;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.junit.Test;
-
-public class TestExponentialSampler
-{
-
- @Test
- public void testSample() throws Exception
- {
- double lambda = 1.0 / 2.0;
-
- SeedFactory seedFactory = new SeedFactory(1234);
-
- Sampler<Double> sampler = new ExponentialSampler(lambda, seedFactory);
-
- Double result = sampler.sample();
-
- assertTrue(result >= 0.0);
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestGaussianSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestGaussianSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestGaussianSampler.java
deleted file mode 100644
index fbe8c18..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestGaussianSampler.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * 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 static org.junit.Assert.assertTrue;
-
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.GaussianSampler;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.junit.Test;
-
-public class TestGaussianSampler
-{
-
- @Test
- public void testSample() throws Exception
- {
- double mean = 2.0;
- double var = 1.0;
-
- SeedFactory seedFactory = new SeedFactory(1234);
-
- Sampler<Double> sampler = new GaussianSampler(mean, var, seedFactory);
-
- Double result = sampler.sample();
-
- assertTrue(result >= -10);
- assertTrue(result <= 10);
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestRouletteWheelSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestRouletteWheelSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestRouletteWheelSampler.java
deleted file mode 100644
index f1152c5..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestRouletteWheelSampler.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * 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 static org.junit.Assert.assertThat;
-import static org.junit.matchers.JUnitMatchers.hasItem;
-
-import java.util.Map;
-
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.RouletteWheelSampler;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.junit.Test;
-
-import com.google.common.collect.ImmutableMap;
-
-public class TestRouletteWheelSampler
-{
-
- @Test
- public void testSample() throws Exception
- {
- Map<String, Double> dataPoints = ImmutableMap.of(
- "a", 0.25,
- "b", 0.25,
- "c", 0.25,
- "d", 0.25
- );
-
- SeedFactory seedFactory = new SeedFactory(1234);
-
- Sampler<String> sampler = new RouletteWheelSampler<String>(dataPoints, seedFactory);
-
- String result = sampler.sample();
-
- assertThat(dataPoints.keySet(), hasItem(result));
- }
-
- @Test
- public void testSampleUnnormalized() throws Exception
- {
- Map<String, Double> dataPoints = ImmutableMap.of(
- "a", 1.0,
- "b", 1.0,
- "c", 1.0,
- "d", 1.0
- );
-
- SeedFactory seedFactory = new SeedFactory(1234);
-
- Sampler<String> sampler = new RouletteWheelSampler<String>(dataPoints, seedFactory);
-
- String result = sampler.sample();
-
- assertThat(dataPoints.keySet(), hasItem(result));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestSequenceSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestSequenceSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestSequenceSampler.java
deleted file mode 100644
index 6684773..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestSequenceSampler.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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 static org.junit.Assert.assertEquals;
-
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.SequenceSampler;
-import org.junit.Test;
-
-public class TestSequenceSampler
-{
-
- @Test
- public void testSample() throws Exception
- {
- Sampler<Integer> sampler = new SequenceSampler(0, 10, 1);
-
- for(int i = 0; i < 10; i++)
- {
- Integer value = sampler.sample();
- assertEquals( (int) value, i);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestUniformIntSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestUniformIntSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestUniformIntSampler.java
deleted file mode 100644
index a700cdf..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestUniformIntSampler.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * 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 static org.junit.Assert.assertTrue;
-
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.UniformIntSampler;
-import org.junit.Test;
-
-public class TestUniformIntSampler
-{
-
- @Test
- public void testSample() throws Exception
- {
- int upperbound = 10;
- int lowerbound = 1;
-
- SeedFactory seedFactory = new SeedFactory(1234);
-
- Sampler<Integer> sampler = new UniformIntSampler(lowerbound, upperbound, seedFactory);
-
- Integer result = sampler.sample();
-
- assertTrue(result >= lowerbound);
- assertTrue(result <= upperbound);
- }
-
- @Test
- public void testSampleInclusive() throws Exception
- {
- int upperbound = 2;
- int lowerbound = 1;
-
- SeedFactory seedFactory = new SeedFactory(1234);
-
- Sampler<Integer> sampler = new UniformIntSampler(lowerbound, upperbound, seedFactory);
-
- Integer result = sampler.sample();
-
- assertTrue(result >= lowerbound);
- assertTrue(result <= upperbound);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerLocationPDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerLocationPDF.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerLocationPDF.java
deleted file mode 100644
index 0800c58..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerLocationPDF.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * 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 static org.junit.Assert.assertTrue;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.bigtop.bigpetstore.datagenerator.Constants;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Store;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord;
-import org.apache.commons.lang3.tuple.Pair;
-import org.junit.Test;
-
-public class TestCustomerLocationPDF
-{
-
- @Test
- public void testProbability() throws Exception
- {
- List<ZipcodeRecord> zipcodes = Arrays.asList(new ZipcodeRecord[] {
- new ZipcodeRecord("11111", Pair.of(1.0, 1.0), "AZ", "Tempte", 30000.0, 100),
- new ZipcodeRecord("22222", Pair.of(2.0, 2.0), "AZ", "Phoenix", 45000.0, 200),
- new ZipcodeRecord("33333", Pair.of(3.0, 3.0), "AZ", "Flagstaff", 60000.0, 300)
- });
-
- List<Store> stores = new ArrayList<Store>();
- for(int i = 0; i < zipcodes.size(); i++)
- {
- Store store = new Store(i, "Store_" + i, zipcodes.get(i));
- stores.add(store);
- }
-
- CustomerLocationPDF customerLocationPDF = new CustomerLocationPDF(zipcodes, stores.get(0),
- Constants.AVERAGE_CUSTOMER_STORE_DISTANCE);
-
- double prob = customerLocationPDF.probability(zipcodes.get(0));
-
- assertTrue(prob > 0.0);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerSampler.java
deleted file mode 100644
index 639b2af..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerSampler.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/**
- * 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 static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-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.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 org.apache.commons.lang3.tuple.Pair;
-import org.junit.Test;
-
-import com.google.common.collect.Maps;
-
-public class TestCustomerSampler
-{
- protected ConditionalSampler<ZipcodeRecord, Store> buildLocationSampler(List<Store> stores, List<ZipcodeRecord> records,
- SeedFactory factory)
- {
- final Map<Store, Sampler<ZipcodeRecord>> locationSamplers = Maps.newHashMap();
- for(Store store : stores)
- {
- ProbabilityDensityFunction<ZipcodeRecord> locationPDF = new CustomerLocationPDF(records,
- store, Constants.AVERAGE_CUSTOMER_STORE_DISTANCE);
- Sampler<ZipcodeRecord> locationSampler = RouletteWheelSampler.create(records, locationPDF, factory);
- locationSamplers.put(store, locationSampler);
- }
-
- return new ConditionalSampler<ZipcodeRecord, Store>()
- {
- public ZipcodeRecord sample(Store store) throws Exception
- {
- return locationSamplers.get(store).sample();
- }
- };
- }
-
- @Test
- public void testBuild() throws Exception
- {
- SeedFactory factory = new SeedFactory(1234);
-
- Collection<String> nameList = Arrays.asList(new String[] {"Fred", "Gary", "George", "Fiona"});
- List<ZipcodeRecord> zipcodes = Arrays.asList(new ZipcodeRecord[] {
- new ZipcodeRecord("11111", Pair.of(1.0, 1.0), "AZ", "Tempte", 30000.0, 100),
- new ZipcodeRecord("22222", Pair.of(2.0, 2.0), "AZ", "Phoenix", 45000.0, 200),
- new ZipcodeRecord("33333", Pair.of(3.0, 3.0), "AZ", "Flagstaff", 60000.0, 300)
- });
-
- List<Store> stores = new ArrayList<Store>();
- for(int i = 0; i < zipcodes.size(); i++)
- {
- Store store = new Store(i, "Store_" + i, zipcodes.get(i));
- stores.add(store);
- }
-
-
- Sampler<Integer> idSampler = new SequenceSampler();
- Sampler<String> nameSampler = RouletteWheelSampler.createUniform(nameList, factory);
- Sampler<Store> storeSampler = RouletteWheelSampler.createUniform(stores, factory);
- ConditionalSampler<ZipcodeRecord, Store> zipcodeSampler = buildLocationSampler(stores, zipcodes, factory);
-
- Sampler<Customer> sampler = new CustomerSampler(idSampler, nameSampler, nameSampler, storeSampler, zipcodeSampler);
-
- Customer customer = sampler.sample();
-
- assertNotNull(customer);
- assertTrue(customer.getId() >= 0);
- assertNotNull(customer.getName());
- assertNotNull(customer.getName().getLeft());
- assertTrue(nameList.contains(customer.getName().getLeft()));
- assertNotNull(customer.getName().getRight());
- assertTrue(nameList.contains(customer.getName().getRight()));
- assertNotNull(customer.getLocation());
- assertTrue(zipcodes.contains(customer.getLocation()));
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerSamplerBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerSamplerBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerSamplerBuilder.java
deleted file mode 100644
index 74c8348..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerSamplerBuilder.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/**
- * 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 static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-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.Names;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.apache.commons.lang3.tuple.Pair;
-import org.junit.Test;
-
-import com.google.common.collect.ImmutableMap;
-
-public class TestCustomerSamplerBuilder
-{
-
- @Test
- public void testSample() throws Exception
- {
- Map<String, Double> nameList = ImmutableMap.of("Fred", 1.0, "George", 1.0, "Gary", 1.0, "Fiona", 1.0);
- List<ZipcodeRecord> zipcodes = Arrays.asList(new ZipcodeRecord[] {
- new ZipcodeRecord("11111", Pair.of(1.0, 1.0), "AZ", "Tempte", 30000.0, 100),
- new ZipcodeRecord("22222", Pair.of(2.0, 2.0), "AZ", "Phoenix", 45000.0, 200),
- new ZipcodeRecord("33333", Pair.of(3.0, 3.0), "AZ", "Flagstaff", 60000.0, 300)
- });
-
- Names names = new Names(nameList, nameList);
-
- // don't need product categories for building customers
- InputData inputData = new InputData(zipcodes, names);
-
- List<Store> stores = Arrays.asList(new Store(0, "Store_0", zipcodes.get(0)),
- new Store(1, "Store_1", zipcodes.get(1)),
- new Store(2, "Store_2", zipcodes.get(2))
- );
-
- SeedFactory factory = new SeedFactory(1234);
-
- CustomerSamplerBuilder builder = new CustomerSamplerBuilder(stores, inputData, factory);
- Sampler<Customer> sampler = builder.build();
-
- Customer customer = sampler.sample();
-
- assertNotNull(customer);
- assertTrue(customer.getId() >= 0);
- assertNotNull(customer.getName());
- assertNotNull(customer.getName().getLeft());
- assertNotNull(customer.getName().getRight());
- assertNotNull(customer.getLocation());
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/TestCartesianProductBase.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/TestCartesianProductBase.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/TestCartesianProductBase.java
deleted file mode 100644
index 3b7c2e8..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/TestCartesianProductBase.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * 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.Arrays;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-public class TestCartesianProductBase
-{
- @Test
- public void testNext()
- {
- Iterator<Map<String, Double>> iter = new CartesianProductBase<Double>("count",
- Arrays.asList(1.0, 2.0, 3.0));
-
- Assert.assertTrue(iter.hasNext());
-
- Map<String, Double> map = iter.next();
- Assert.assertEquals(1, map.size());
- Assert.assertTrue(map.containsKey("count"));
- Assert.assertEquals( (double) map.get("count"), (double) 1.0, 0.0001);
-
- Assert.assertTrue(iter.hasNext());
-
- map = iter.next();
- Assert.assertEquals(1, map.size());
- Assert.assertTrue(map.containsKey("count"));
- Assert.assertEquals( (double) map.get("count"), (double) 2.0, 0.0001);
-
- Assert.assertTrue(iter.hasNext());
-
- map = iter.next();
- Assert.assertEquals(1, map.size());
- Assert.assertTrue(map.containsKey("count"));
- Assert.assertEquals( (double) map.get("count"), (double) 3.0, 0.0001);
-
- Assert.assertFalse(iter.hasNext());
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/TestCartesianProductField.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/TestCartesianProductField.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/TestCartesianProductField.java
deleted file mode 100644
index 5071a54..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/TestCartesianProductField.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * 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.Arrays;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-public class TestCartesianProductField
-{
-
- @Test
- public void testTwoLevels()
- {
- Iterator<Map<String, String>> iter = new CartesianProductField<String>(
- "children", Arrays.asList("1", "2"),
- new CartesianProductBase<String>(
- "animal", Arrays.asList("cat", "dog")));
-
- Assert.assertEquals(iter.hasNext(), true);
- Map<String, String> map = iter.next();
- Assert.assertEquals(map.size(), 2);
- Assert.assertTrue(map.containsKey("animal"));
- Assert.assertTrue(map.containsKey("children"));
- Assert.assertEquals(map.get("animal"), "cat");
- Assert.assertEquals(map.get("children"), "1");
-
- Assert.assertEquals(iter.hasNext(), true);
- map = iter.next();
- Assert.assertEquals(map.size(), 2);
- Assert.assertTrue(map.containsKey("animal"));
- Assert.assertTrue(map.containsKey("children"));
- Assert.assertEquals(map.get("animal"), "cat");
- Assert.assertEquals(map.get("children"), "2");
-
- Assert.assertEquals(iter.hasNext(), true);
- map = iter.next();
- Assert.assertEquals(map.size(), 2);
- Assert.assertTrue(map.containsKey("animal"));
- Assert.assertTrue(map.containsKey("children"));
- Assert.assertEquals(map.get("animal"), "dog");
- Assert.assertEquals(map.get("children"), "1");
-
- Assert.assertEquals(iter.hasNext(), true);
- map = iter.next();
- Assert.assertEquals(map.size(), 2);
- Assert.assertTrue(map.containsKey("animal"));
- Assert.assertTrue(map.containsKey("children"));
- Assert.assertEquals(map.get("animal"), "dog");
- Assert.assertEquals(map.get("children"), "2");
-
- Assert.assertFalse(iter.hasNext());
- Assert.assertFalse(iter.hasNext());
- Assert.assertFalse(iter.hasNext());
- }
-}
[10/11] bigtop git commit: BIGTOP-1984. Extract samplers library from
BigPetStore data generator
Posted by rn...@apache.org.
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datareaders/ZipcodeReader.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datareaders/ZipcodeReader.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datareaders/ZipcodeReader.java
deleted file mode 100644
index 1612a92..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datareaders/ZipcodeReader.java
+++ /dev/null
@@ -1,193 +0,0 @@
-/**
- * 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.datareaders;
-
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Scanner;
-import java.util.Set;
-import java.util.Vector;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord;
-import org.apache.commons.lang3.tuple.Pair;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-
-public class ZipcodeReader
-{
- private static class ZipcodeLocationRecord
- {
- public final Pair<Double, Double> coordinates;
- public final String state;
- public final String city;
-
- public ZipcodeLocationRecord(Pair<Double, Double> coordinates,
- String city, String state)
- {
- this.coordinates = coordinates;
- this.city = city;
- this.state = state;
- }
- }
-
- InputStream zipcodeIncomesFile = null;
- InputStream zipcodePopulationFile = null;
- InputStream zipcodeCoordinatesFile = null;
-
- public void setIncomesFile(InputStream path)
- {
- this.zipcodeIncomesFile = path;
- }
-
- public void setPopulationFile(InputStream path)
- {
- this.zipcodePopulationFile = path;
- }
-
- public void setCoordinatesFile(InputStream path)
- {
- this.zipcodeCoordinatesFile = path;
- }
-
- private ImmutableMap<String, Double> readIncomeData(InputStream path) throws FileNotFoundException
- {
- Scanner scanner = new Scanner(path);
-
- // skip headers
- scanner.nextLine();
- scanner.nextLine();
-
- Map<String, Double> entries = Maps.newHashMap();
- while(scanner.hasNextLine())
- {
- String line = scanner.nextLine().trim();
- String[] cols = line.split(",");
- // zipcodes are in the form "ZCTA5 XXXXX"
- String zipcode = cols[2].split(" ")[1].trim();
- try
- {
- double medianHouseholdIncome = Integer.parseInt(cols[5].trim());
- entries.put(zipcode, medianHouseholdIncome);
- }
- catch(NumberFormatException e)
- {
-
- }
- }
-
- scanner.close();
-
- return ImmutableMap.copyOf(entries);
- }
-
- private ImmutableMap<String, Long> readPopulationData(InputStream path) throws FileNotFoundException
- {
- Scanner scanner = new Scanner(path);
-
- // skip header
- scanner.nextLine();
-
- Map<String, Long> entries = Maps.newHashMap();
- while(scanner.hasNextLine())
- {
- String line = scanner.nextLine().trim();
-
- if(line.length() == 0)
- continue;
-
- String[] cols = line.split(",");
-
- String zipcode = cols[0].trim();
- Long population = Long.parseLong(cols[1].trim());
-
- if(entries.containsKey(zipcode))
- {
- entries.put(zipcode, Math.max(entries.get(zipcode), population));
- }
- else
- {
- entries.put(zipcode, population);
- }
- }
-
- scanner.close();
-
- return ImmutableMap.copyOf(entries);
- }
-
- private ImmutableMap<String, ZipcodeLocationRecord> readCoordinates(InputStream path) throws FileNotFoundException
- {
- Scanner scanner = new Scanner(path);
-
- // skip header
- scanner.nextLine();
-
- Map<String, ZipcodeLocationRecord> entries = Maps.newHashMap();
- while(scanner.hasNextLine())
- {
- String line = scanner.nextLine().trim();
-
- String[] cols = line.split(", ");
-
- // remove quote marks
- String zipcode = cols[0].substring(1, cols[0].length() - 1);
- String state = cols[1].substring(1, cols[1].length() - 1);
- Double latitude = Double.parseDouble(cols[2].substring(1, cols[2].length() - 1));
- Double longitude = Double.parseDouble(cols[3].substring(1, cols[3].length() - 1));
- String city = cols[4].substring(1, cols[4].length() - 1);
-
- Pair<Double, Double> coords = Pair.of(latitude, longitude);
-
- ZipcodeLocationRecord record = new ZipcodeLocationRecord(coords, city, state);
-
- entries.put(zipcode, record);
- }
-
- scanner.close();
-
- return ImmutableMap.copyOf(entries);
- }
-
- public ImmutableList<ZipcodeRecord> readData() throws FileNotFoundException
- {
- ImmutableMap<String, Double> incomes = readIncomeData(this.zipcodeIncomesFile);
- ImmutableMap<String, Long> populations = readPopulationData(this.zipcodePopulationFile);
- ImmutableMap<String, ZipcodeLocationRecord> coordinates = readCoordinates(this.zipcodeCoordinatesFile);
-
- Set<String> zipcodeSubset = new HashSet<String>(incomes.keySet());
- zipcodeSubset.retainAll(populations.keySet());
- zipcodeSubset.retainAll(coordinates.keySet());
-
- List<ZipcodeRecord> table = new Vector<ZipcodeRecord>();
- for(String zipcode : zipcodeSubset)
- {
- ZipcodeRecord record = new ZipcodeRecord(zipcode,
- coordinates.get(zipcode).coordinates,
- coordinates.get(zipcode).city,
- coordinates.get(zipcode).state,
- incomes.get(zipcode),
- populations.get(zipcode));
- table.add(record);
- }
-
- return ImmutableList.copyOf(table);
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/SeedFactory.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/SeedFactory.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/SeedFactory.java
deleted file mode 100644
index aea004e..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/SeedFactory.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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;
-
-import java.util.Random;
-
-public class SeedFactory
-{
- Random rng;
-
- public SeedFactory()
- {
- rng = new Random();
- }
-
- public SeedFactory(long seed)
- {
- rng = new Random(seed);
- }
-
- public long getNextSeed()
- {
- return rng.nextLong();
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/MarkovModel.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/MarkovModel.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/MarkovModel.java
deleted file mode 100644
index 0b90e2b..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/MarkovModel.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * 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.markovmodels;
-
-import java.io.Serializable;
-import java.util.Map;
-
-public class MarkovModel<T> implements Serializable
-{
- private static final long serialVersionUID = 8378109656005603192L;
-
- final Map<T, Map<T, Double>> transitionWeights;
- final Map<T, Double> startWeights;
-
- public MarkovModel(Map<T, Map<T, Double>> transitionWeights, Map<T, Double> startWeights)
- {
- this.transitionWeights = transitionWeights;
- this.startWeights = startWeights;
- }
-
- public Map<T, Map<T, Double>> getTransitionWeights()
- {
- return transitionWeights;
- }
-
- public Map<T, Double> getStartWeights()
- {
- return startWeights;
- }
-
- @Override
- public String toString()
- {
- return "MarkModel(" + startWeights + "," + transitionWeights + ")";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/MarkovModelBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/MarkovModelBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/MarkovModelBuilder.java
deleted file mode 100644
index 861c0ef..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/MarkovModelBuilder.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * 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.markovmodels;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableTable;
-
-public class MarkovModelBuilder<S>
-{
- ImmutableTable.Builder<S, S, Double> transitionWeights;
- ImmutableMap.Builder<S, Double> startWeights;
-
- public MarkovModelBuilder()
- {
- transitionWeights = ImmutableTable.builder();
- startWeights = ImmutableMap.builder();
- }
-
- public static <T> MarkovModelBuilder<T> create()
- {
- return new MarkovModelBuilder<T>();
- }
-
- public void addStartState(S state, double weight)
- {
- startWeights.put(state, weight);
- }
-
- public void addTransition(S state1, S state2, double weight)
- {
- transitionWeights.put(state1, state2, weight);
- }
-
- public MarkovModel<S> build()
- {
- return new MarkovModel<S>(transitionWeights.build().rowMap(), startWeights.build());
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/MarkovProcess.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/MarkovProcess.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/MarkovProcess.java
deleted file mode 100644
index d0bd6c5..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/MarkovProcess.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * 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.markovmodels;
-
-import java.util.Map;
-
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.RouletteWheelSampler;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-
-import com.google.common.collect.ImmutableMap;
-
-public class MarkovProcess<T> implements Sampler<T>
-{
- final ImmutableMap<T, Sampler<T>> transitionSamplers;
- final Sampler<T> startStateSampler;
-
- T currentState;
-
-
- public MarkovProcess(MarkovModel<T> model, SeedFactory factory)
- {
- Map<T, Map<T, Double>> transitionTable = model.getTransitionWeights();
-
- startStateSampler = RouletteWheelSampler.create(model.getStartWeights(), factory);
-
- ImmutableMap.Builder<T, Sampler<T>> builder = ImmutableMap.builder();
- for(Map.Entry<T, Map<T, Double>> entry : transitionTable.entrySet())
- {
- builder.put(entry.getKey(), RouletteWheelSampler.create(entry.getValue(), factory));
- }
-
-
- this.transitionSamplers = builder.build();
-
- currentState = null;
- }
-
- public static <T> MarkovProcess<T> create(MarkovModel<T> model, SeedFactory factory)
- {
- return new MarkovProcess<T>(model, factory);
- }
-
- public T sample() throws Exception
- {
- if(currentState == null)
- {
- currentState = startStateSampler.sample();
- return currentState;
- }
-
- currentState = transitionSamplers.get(currentState).sample();
- return currentState;
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/ConditionalProbabilityDensityFunction.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/ConditionalProbabilityDensityFunction.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/ConditionalProbabilityDensityFunction.java
deleted file mode 100644
index 5161761..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/ConditionalProbabilityDensityFunction.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/**
- * 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.pdfs;
-
-public interface ConditionalProbabilityDensityFunction<T, S>
-{
- public double probability(T datum, S conditionalDatum);
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/ExponentialPDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/ExponentialPDF.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/ExponentialPDF.java
deleted file mode 100644
index dcc1278..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/ExponentialPDF.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * 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.pdfs;
-
-public class ExponentialPDF implements ProbabilityDensityFunction<Double>
-{
- private final double lambda;
-
- public ExponentialPDF(double lambda)
- {
- this.lambda = lambda;
- }
-
- public double probability(Double value)
- {
- return lambda * Math.exp(-1.0 * value * lambda);
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/GaussianPDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/GaussianPDF.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/GaussianPDF.java
deleted file mode 100644
index 55ebc93..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/GaussianPDF.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * 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.pdfs;
-
-public class GaussianPDF implements ProbabilityDensityFunction<Double>
-{
- private double mean;
- private double std;
-
- public GaussianPDF(double mean, double std)
- {
- this.mean = mean;
- this.std = std;
- }
-
- public double probability(Double value)
- {
- double diff = (mean - value) * (mean - value);
- double var = std * std;
- double exp = Math.exp(-1.0 * diff / (2.0 * var));
-
- return exp / (std * Math.sqrt(2.0 * Math.PI));
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/JointPDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/JointPDF.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/JointPDF.java
deleted file mode 100644
index fdf2db0..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/JointPDF.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * 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.pdfs;
-
-import java.util.List;
-
-public class JointPDF<T> implements ProbabilityDensityFunction<T>
-{
-
- double normalizationFactor;
- ProbabilityDensityFunction<T>[] pdfs;
-
- public JointPDF(List<T> data, ProbabilityDensityFunction<T> ... pdfs)
- {
- this.pdfs = pdfs;
-
- normalizationFactor = 0.0d;
- for(T datum : data)
- {
- double prob = 1.0;
- for(ProbabilityDensityFunction<T> pdf : pdfs)
- prob *= pdf.probability(datum);
- normalizationFactor += prob;
- }
-
- }
-
- public double probability(T datum)
- {
- double weight = 1.0;
- for(ProbabilityDensityFunction<T> pdf : pdfs)
- weight *= pdf.probability(datum);
-
- return weight / normalizationFactor;
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/MultinomialPDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/MultinomialPDF.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/MultinomialPDF.java
deleted file mode 100644
index 7605156..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/MultinomialPDF.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * 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.pdfs;
-
-import java.util.Map;
-import java.util.Set;
-
-import com.google.common.collect.ImmutableMap;
-
-public class MultinomialPDF<T> implements ProbabilityDensityFunction<T>
-{
- private final ImmutableMap<T, Double> probabilities;
-
- public MultinomialPDF(Map<T, Double> probabilities)
- {
- this.probabilities = ImmutableMap.copyOf(probabilities);
- }
-
- public Set<T> getData()
- {
- return probabilities.keySet();
- }
-
- public double probability(T value)
- {
- if(probabilities.containsKey(value))
- {
- return probabilities.get(value);
- }
-
- return 0.0;
- }
-
- @Override
- public String toString()
- {
- String str = "";
- for(Map.Entry<T, Double> entry: probabilities.entrySet())
- {
- str += entry.getValue() + "," + entry.getKey() + "\n";
- }
- return str;
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/ProbabilityDensityFunction.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/ProbabilityDensityFunction.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/ProbabilityDensityFunction.java
deleted file mode 100644
index 1b691ca..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/ProbabilityDensityFunction.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/**
- * 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.pdfs;
-
-public interface ProbabilityDensityFunction<T>
-{
- public double probability(T datum);
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/UniformPDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/UniformPDF.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/UniformPDF.java
deleted file mode 100644
index ea8e77e..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/UniformPDF.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * 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.pdfs;
-
-public class UniformPDF<T> implements ProbabilityDensityFunction<T>
-{
- private final double probability;
-
- public UniformPDF(long count)
- {
- probability = 1.0 / ((double) count);
- }
-
- public UniformPDF(double probability)
- {
- this.probability = probability;
- }
-
- public double probability(T datum)
- {
- return probability;
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/BoundedMultiModalGaussianSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/BoundedMultiModalGaussianSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/BoundedMultiModalGaussianSampler.java
deleted file mode 100644
index 348f080..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/BoundedMultiModalGaussianSampler.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * 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.List;
-import java.util.Random;
-
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.commons.lang3.tuple.Pair;
-
-import com.google.common.collect.ImmutableList;
-
-public class BoundedMultiModalGaussianSampler implements Sampler<Double>
-{
- ImmutableList<Pair<Double, Double>> distributions;
-
- double min;
- double max;
- Random rng;
-
- public BoundedMultiModalGaussianSampler(List<Pair<Double, Double>> distributions, double min, double max, SeedFactory seedFactory)
- {
- rng = new Random(seedFactory.getNextSeed());
- this.distributions = ImmutableList.copyOf(distributions);
-
- this.min = min;
- this.max = max;
- }
-
- public Double sample()
- {
- while(true)
- {
- int idx = rng.nextInt(distributions.size());
-
- double mean = distributions.get(idx).getLeft();
- double std = distributions.get(idx).getRight();
-
- double value = mean + rng.nextGaussian() * std;
-
- if (value >= this.min && value <= this.max)
- {
- return value;
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/ConditionalSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/ConditionalSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/ConditionalSampler.java
deleted file mode 100644
index c521333..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/ConditionalSampler.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/**
- * 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 ConditionalSampler<T, S>
-{
- public T sample(S conditional) throws Exception;
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/DoubleSequenceSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/DoubleSequenceSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/DoubleSequenceSampler.java
deleted file mode 100644
index 82e4d2d..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/DoubleSequenceSampler.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * 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 DoubleSequenceSampler implements Sampler<Double>
-{
- Double start;
- Double end;
- Double step;
- Double next;
-
- public DoubleSequenceSampler()
- {
- start = 0.0;
- end = null;
- step = 1.0;
- next = start;
- }
-
- public DoubleSequenceSampler(Double start)
- {
- this.start = start;
- end = null;
- step = 1.0;
- next = start;
- }
-
- public DoubleSequenceSampler(Double start, Double end)
- {
- this.start = start;
- this.end = end;
- step = 1.0;
- next = start;
- }
-
- public DoubleSequenceSampler(Double start, Double end, Double step)
- {
- this.start = start;
- this.end = end;
- this.step = step;
- next = start;
- }
-
- public Double sample() throws Exception
- {
- if(end == null || next < end)
- {
- Double 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/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/ExponentialSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/ExponentialSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/ExponentialSampler.java
deleted file mode 100644
index 082f3ac..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/ExponentialSampler.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * 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 ExponentialSampler implements Sampler<Double>
-{
- final private Random rng;
- final private double lambda;
-
- public ExponentialSampler(double lambda, SeedFactory seedFactory)
- {
- rng = new Random(seedFactory.getNextSeed());
- this.lambda = lambda;
- }
-
- public Double sample()
- {
- return - Math.log(1.0 - rng.nextDouble()) / lambda;
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/GaussianSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/GaussianSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/GaussianSampler.java
deleted file mode 100644
index ed40cc8..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/GaussianSampler.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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 GaussianSampler implements Sampler<Double>
-{
- double mean;
- double std;
- Random rng;
-
- public GaussianSampler(double mean, double std, SeedFactory seedFactory)
- {
- rng = new Random(seedFactory.getNextSeed());
- this.mean = mean;
- this.std = std;
- }
-
- public Double sample()
- {
- return rng.nextGaussian() * std + mean;
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/MonteCarloSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/MonteCarloSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/MonteCarloSampler.java
deleted file mode 100644
index 0db8200..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/MonteCarloSampler.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * 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.ProbabilityDensityFunction;
-
-
-public class MonteCarloSampler<T> implements Sampler<T>
-{
- private final Sampler<T> stateSampler;
- private final Random rng;
- private final ProbabilityDensityFunction<T> acceptancePDF;
-
- public MonteCarloSampler(Sampler<T> stateGenerator,
- ProbabilityDensityFunction<T> acceptancePDF,
- SeedFactory seedFactory)
- {
- this.acceptancePDF = acceptancePDF;
- this.stateSampler = stateGenerator;
-
- rng = new Random(seedFactory.getNextSeed());
- }
-
- public T sample() throws Exception
- {
- while(true)
- {
- T proposedState = this.stateSampler.sample();
- double probability = acceptancePDF.probability(proposedState);
- double r = rng.nextDouble();
-
- if(r < probability)
- {
- return proposedState;
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/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
deleted file mode 100644
index 0353708..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/RouletteWheelSampler.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index 08af7e0..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/Sampler.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index a81c846..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/SequenceSampler.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index c447692..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/StatefulMonteCarloSampler.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index 3fdf550..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/UniformIntSampler.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index 3f78471..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/UniformSampler.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index 603e5e9..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/wfs/ConditionalWeightFunction.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index 1145043..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/wfs/WeightFunction.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index bb97a60..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerLocationPDF.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index 8ef96f0..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerSampler.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index 4b449e8..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerSamplerBuilder.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index 400b02a..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerStorePDF.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index c7dd0ab..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductBuilderIterator.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index df8ae12..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductCategoryBuilder.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/**
- * 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);
- }
-}
[09/11] bigtop git commit: BIGTOP-1984. Extract samplers library from
BigPetStore data generator
Posted by rn...@apache.org.
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/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
deleted file mode 100644
index fe4d7fa..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductFieldValue.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index c0e285d..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductFilterIterator.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index ccfef56..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductIterator.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index f688980..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/CartesianProduct.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index 7b0934c..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/CartesianProductBase.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index 166efc8..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/CartesianProductField.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index 2ec72d1..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/collections/MediumProductCollection.java
+++ /dev/null
@@ -1,275 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index 8ca71ef..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/collections/SmallProductCollection.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index d973346..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/AlwaysTrueRule.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index 4be89be..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/AndRule.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index 37e7c12..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/FieldPredicate.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index ffac751..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/NotRule.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * 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/15af83eb/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
deleted file mode 100644
index c3ed549..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/OrRule.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * 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;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/Rule.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/Rule.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/Rule.java
deleted file mode 100644
index 4aa7945..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/Rule.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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 interface Rule
-{
- public boolean ruleMatches(Product product) throws IllegalArgumentException;
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/MarkovModelProductCategorySampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/MarkovModelProductCategorySampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/MarkovModelProductCategorySampler.java
deleted file mode 100644
index c842ff1..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/MarkovModelProductCategorySampler.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/**
- * 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.purchase;
-
-import java.util.Map;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels.MarkovModel;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels.MarkovModelBuilder;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-
-import com.google.common.collect.Maps;
-
-public class MarkovModelProductCategorySampler implements Sampler<MarkovModel<Product>>
-{
- final ProductCategory productCategory;
- final Sampler<Double> fieldSimilarityWeightSampler;
- final Sampler<Double> loopbackWeightSampler;
-
- final Map<String, Double> fieldWeights;
- Map<String, Double> fieldSimilarityWeights;
- double loopbackWeight;
-
- public MarkovModelProductCategorySampler(ProductCategory productCategory,
- Map<String, Double> fieldWeights, Sampler<Double> fieldSimilarityWeightSampler,
- Sampler<Double> loopbackWeightSampler)
- {
- this.productCategory = productCategory;
-
- this.fieldSimilarityWeightSampler = fieldSimilarityWeightSampler;
- this.fieldWeights = fieldWeights;
- this.loopbackWeightSampler = loopbackWeightSampler;
- }
-
- protected void generateWeights() throws Exception
- {
- fieldSimilarityWeights = Maps.newHashMap();
-
- for(String fieldName : productCategory.getFieldNames())
- {
- fieldSimilarityWeights.put(fieldName,fieldSimilarityWeightSampler.sample());
- }
-
- loopbackWeight = loopbackWeightSampler.sample();
- }
-
- protected double productPairWeight(Product product1, Product product2)
- {
- double weightSum = 0.0;
- for(String fieldName : productCategory.getFieldNames())
- {
- double fieldWeight = this.fieldWeights.get(fieldName);
-
- if(product1.getFieldValue(fieldName).equals(product2.getFieldValue(fieldName)))
- {
- fieldWeight *= this.fieldSimilarityWeights.get(fieldName);
- }
- else
- {
- fieldWeight *= (1.0 - this.fieldSimilarityWeights.get(fieldName));
- }
-
- weightSum += fieldWeight;
- }
- return weightSum;
- }
-
- public MarkovModel<Product> sample() throws Exception
- {
- generateWeights();
-
- MarkovModelBuilder<Product> builder = new MarkovModelBuilder<Product>();
-
- for(Product product1 : productCategory.getProducts())
- {
- builder.addStartState(product1, 1.0);
-
- double weightSum = 0.0;
- for(Product product2 : productCategory.getProducts())
- {
- if(!product1.equals(product2))
- {
- weightSum += productPairWeight(product1, product2);
- }
- }
-
- for(Product product2 : productCategory.getProducts())
- {
- double weight = 0.0;
- if(!product1.equals(product2))
- {
- weight = (1.0 - loopbackWeight) * productPairWeight(product1, product2) / weightSum;
- }
- else
- { weight = loopbackWeight;
-
- }
-
- builder.addTransition(product1, product2, weight);
- }
- }
-
- return builder.build();
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/MarkovPurchasingModel.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/MarkovPurchasingModel.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/MarkovPurchasingModel.java
deleted file mode 100644
index 8b22660..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/MarkovPurchasingModel.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * 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.purchase;
-
-import java.util.Map;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels.MarkovModel;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels.MarkovProcess;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Maps;
-
-public class MarkovPurchasingModel implements PurchasingModel<MarkovModel<Product>>
-{
-
- private static final long serialVersionUID = 3098355461347511619L;
- ImmutableMap<String, MarkovModel<Product>> productCategoryProfiles;
-
- public MarkovPurchasingModel(Map<String, MarkovModel<Product>> productCategoryProfiles)
- {
- this.productCategoryProfiles = ImmutableMap.copyOf(productCategoryProfiles);
- }
-
- @Override
- public ImmutableSet<String> getProductCategories()
- {
- return productCategoryProfiles.keySet();
- }
-
- @Override
- public MarkovModel<Product> getProfile(String productCategory)
- {
- return productCategoryProfiles.get(productCategory);
- }
-
- @Override
- public PurchasingProcesses buildProcesses(SeedFactory seedFactory)
- {
- Map<String, Sampler<Product>> processes = Maps.newHashMap();
- for(String category : getProductCategories())
- {
- MarkovModel<Product> model = getProfile(category);
- processes.put(category, new MarkovProcess<Product>(model, seedFactory));
- }
-
- return new PurchasingProcesses(processes);
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/MarkovPurchasingModelSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/MarkovPurchasingModelSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/MarkovPurchasingModelSampler.java
deleted file mode 100644
index 6291213..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/MarkovPurchasingModelSampler.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * 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.purchase;
-
-import java.util.Map;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels.MarkovModel;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-
-import com.google.common.collect.Maps;
-
-public class MarkovPurchasingModelSampler implements Sampler<MarkovPurchasingModel>
-{
- final Map<ProductCategory, Sampler<MarkovModel<Product>>> categorySamplers;
-
- public MarkovPurchasingModelSampler(Map<ProductCategory, Sampler<MarkovModel<Product>>> categorySamplers)
- {
- this.categorySamplers = categorySamplers;
- }
-
- public MarkovPurchasingModel sample() throws Exception
- {
- Map<String, MarkovModel<Product>> markovModels = Maps.newHashMap();
- for(ProductCategory productCategory : categorySamplers.keySet())
- {
- Sampler<MarkovModel<Product>> sampler = categorySamplers.get(productCategory);
- markovModels.put(productCategory.getCategoryLabel(), sampler.sample());
- }
-
- return new MarkovPurchasingModel(markovModels);
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/MultinomialPurchasingModel.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/MultinomialPurchasingModel.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/MultinomialPurchasingModel.java
deleted file mode 100644
index 336a898..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/MultinomialPurchasingModel.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
- * 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.purchase;
-
-import java.util.Map;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs.MultinomialPDF;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.RouletteWheelSampler;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Maps;
-
-public class MultinomialPurchasingModel implements PurchasingModel<MultinomialPDF<Product>>
-{
-
- private static final long serialVersionUID = 5863830733003282570L;
-
- private final ImmutableMap<String, MultinomialPDF<Product>> productPDFs;
-
- public MultinomialPurchasingModel(Map<String, MultinomialPDF<Product>> productPDFs)
- {
- this.productPDFs = ImmutableMap.copyOf(productPDFs);
- }
-
- @Override
- public ImmutableSet<String> getProductCategories()
- {
- return productPDFs.keySet();
- }
-
- @Override
- public MultinomialPDF<Product> getProfile(String category)
- {
- return productPDFs.get(category);
- }
-
- @Override
- public PurchasingProcesses buildProcesses(SeedFactory seedFactory)
- {
- Map<String, Sampler<Product>> processes = Maps.newHashMap();
- for(String category : getProductCategories())
- {
- MultinomialPDF<Product> pdf = productPDFs.get(category);
- processes.put(category, RouletteWheelSampler.create(pdf, seedFactory));
- }
-
- return new PurchasingProcesses(processes);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/MultinomialPurchasingModelSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/MultinomialPurchasingModelSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/MultinomialPurchasingModelSampler.java
deleted file mode 100644
index 7fcfbe5..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/MultinomialPurchasingModelSampler.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/**
- * 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.purchase;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Vector;
-
-import org.apache.bigtop.bigpetstore.datagenerator.Constants;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs.MultinomialPDF;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.UniformIntSampler;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.UniformSampler;
-import org.apache.commons.lang3.tuple.Pair;
-
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Multimap;
-
-public class MultinomialPurchasingModelSampler implements Sampler<MultinomialPurchasingModel>
-{
- private final SeedFactory seedFactory;
- private final Collection<ProductCategory> productCategories;
-
- public MultinomialPurchasingModelSampler(Collection<ProductCategory> productCategories, SeedFactory seedFactory)
- {
- this.seedFactory = seedFactory;
- this.productCategories = productCategories;
- }
-
- protected <T> List<T> shuffle(Collection<T> input) throws Exception
- {
- Vector<T> shuffled = new Vector<>(input);
- for(int i = 0; i < input.size() - 1; i++)
- {
- int swapIdx = new UniformIntSampler(i, input.size() - 1, seedFactory).sample();
- T tmp = shuffled.get(i);
- shuffled.set(i, shuffled.get(swapIdx));
- shuffled.set(swapIdx, tmp);
- }
-
- return shuffled;
- }
-
- protected Map<Pair<String, Object>, Double> generateFieldValueWeights(ProductCategory productCategory) throws Exception
- {
- // Get all values for each field by iterating over all products
- Multimap<String, Object> allFieldValues = HashMultimap.create();
- for(String fieldName : productCategory.getFieldNames())
- {
- if(!Constants.PRODUCT_MODEL_EXCLUDED_FIELDS.contains(fieldName))
- {
- for(Product p : productCategory.getProducts())
- {
- Object fieldValue = p.getFieldValue(fieldName);
- allFieldValues.put(fieldName, fieldValue);
- }
- }
- }
-
- Sampler<Double> sampler = new UniformSampler(seedFactory);
-
- // shuffle field values
- Map<Pair<String, Object>, Double> fieldValueWeights = Maps.newHashMap();
- for(Map.Entry<String, Collection<Object>> entry : allFieldValues.asMap().entrySet())
- {
- String fieldName = entry.getKey();
- List<Object> shuffled = shuffle(entry.getValue());
-
- for(int i = 0; i < shuffled.size(); i++)
- {
- double weight = Constants.PRODUCT_MULTINOMIAL_POSITIVE_WEIGHT;
- if ((i + 1) > Constants.PRODUCT_MULTINOMIAL_POSITIVE_COUNT_MIN)
- {
- double r = sampler.sample();
- if (r >= Constants.PRODUCT_MULTINOMIAL_POSITIVE_FREQUENCY)
- {
- weight = Constants.PRODUCT_MULTINOMIAL_NEGATIVE_WEIGHT;
- }
- }
-
- Object fieldValue = shuffled.get(i);
- fieldValueWeights.put(Pair.of(fieldName, fieldValue), weight);
- }
- }
-
-
- return ImmutableMap.copyOf(fieldValueWeights);
- }
-
- protected Map<Product, Double> generateProductWeights(Map<Pair<String, Object>, Double> fieldValueWeights,
- ProductCategory productCategory) throws Exception
- {
- Map<Product, Double> productWeights = Maps.newHashMap();
- for(Product p : productCategory.getProducts())
- {
- double weight = 1.0;
- for(String fieldName : productCategory.getFieldNames())
- {
- if(!Constants.PRODUCT_MODEL_EXCLUDED_FIELDS.contains(fieldName))
- {
- Object fieldValue = p.getFieldValue(fieldName);
- Pair<String, Object> key = Pair.of(fieldName, fieldValue);
- weight *= fieldValueWeights.get(key);
- }
- }
- productWeights.put(p, weight);
- }
-
- return productWeights;
- }
-
- public MultinomialPurchasingModel sample() throws Exception
- {
- Map<String, MultinomialPDF<Product>> pdfs = Maps.newHashMap();
- for(ProductCategory productCategory : productCategories)
- {
- Map<Pair<String, Object>, Double> fieldWeights = this.generateFieldValueWeights(productCategory);
- Map<Product, Double> productWeights = this.generateProductWeights(fieldWeights, productCategory);
- pdfs.put(productCategory.getCategoryLabel(), new MultinomialPDF<Product>(productWeights));
- }
-
- return new MultinomialPurchasingModel(pdfs);
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/PurchasingModel.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/PurchasingModel.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/PurchasingModel.java
deleted file mode 100644
index d460c3b..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/PurchasingModel.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * 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.purchase;
-
-import java.io.Serializable;
-
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-
-import com.google.common.collect.ImmutableSet;
-
-public interface PurchasingModel<T> extends Serializable
-{
- public ImmutableSet<String> getProductCategories();
-
- public T getProfile(String category);
-
- public PurchasingProcesses buildProcesses(SeedFactory seedFactory);
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/PurchasingModelSamplerBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/PurchasingModelSamplerBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/PurchasingModelSamplerBuilder.java
deleted file mode 100644
index 43808c7..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/PurchasingModelSamplerBuilder.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
- * 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.purchase;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.bigtop.bigpetstore.datagenerator.Constants;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels.MarkovModel;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.BoundedMultiModalGaussianSampler;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Maps;
-
-public class PurchasingModelSamplerBuilder
-{
- final ImmutableList<ProductCategory> productCategories;
- final SeedFactory seedFactory;
-
- public PurchasingModelSamplerBuilder(Collection<ProductCategory> productCategories, SeedFactory seedFactory)
- {
- this.productCategories = ImmutableList.copyOf(productCategories);
- this.seedFactory = seedFactory;
- }
-
- protected Map<String, Double> generateFieldWeights(Sampler<Double> fieldWeightSampler) throws Exception
- {
- Set<String> fieldNames = new HashSet<String>();
- for(ProductCategory pc : productCategories)
- {
- for(String fieldName : pc.getFieldNames())
- {
- fieldNames.add(fieldName);
- }
- }
-
- Map<String, Double> fieldWeights = Maps.newHashMap();
- for(String fieldName : fieldNames)
- {
- double weight = fieldWeightSampler.sample();
- fieldWeights.put(fieldName, weight);
- }
-
- return fieldWeights;
- }
-
- public Sampler<MarkovPurchasingModel> buildMarkovPurchasingModel() throws Exception
- {
-
- Sampler<Double> fieldWeightSampler = new BoundedMultiModalGaussianSampler(Constants.PRODUCT_MSM_FIELD_WEIGHT_GAUSSIANS,
- Constants.PRODUCT_MSM_FIELD_WEIGHT_LOWERBOUND,
- Constants.PRODUCT_MSM_FIELD_WEIGHT_UPPERBOUND,
- seedFactory);
-
- Sampler<Double> fieldSimilarityWeightSampler = new BoundedMultiModalGaussianSampler(Constants.PRODUCT_MSM_FIELD_SIMILARITY_WEIGHT_GAUSSIANS,
- Constants.PRODUCT_MSM_FIELD_SIMILARITY_WEIGHT_LOWERBOUND,
- Constants.PRODUCT_MSM_FIELD_SIMILARITY_WEIGHT_UPPERBOUND,
- seedFactory);
-
- Sampler<Double> loopbackWeightSampler = new BoundedMultiModalGaussianSampler(Constants.PRODUCT_MSM_LOOPBACK_WEIGHT_GAUSSIANS,
- Constants.PRODUCT_MSM_LOOPBACK_WEIGHT_LOWERBOUND,
- Constants.PRODUCT_MSM_LOOPBACK_WEIGHT_UPPERBOUND,
- seedFactory);
-
- Map<String, Double> fieldWeights = generateFieldWeights(fieldWeightSampler);
-
- Map<ProductCategory, Sampler<MarkovModel<Product>>> categorySamplers = Maps.newHashMap();
- for(ProductCategory productCategory : productCategories)
- {
- MarkovModelProductCategorySampler sampler = new MarkovModelProductCategorySampler(productCategory,
- fieldWeights, fieldSimilarityWeightSampler, loopbackWeightSampler);
- categorySamplers.put(productCategory, sampler);
- }
-
- return new MarkovPurchasingModelSampler(categorySamplers);
- }
-
- public Sampler<? extends PurchasingModel> build() throws Exception
- {
- if(Constants.PURCHASING_MODEL_TYPE.equals(Constants.PurchasingModelType.MARKOV))
- {
- return buildMarkovPurchasingModel();
- }
- else
- {
- return new MultinomialPurchasingModelSampler(productCategories, seedFactory);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/PurchasingProcesses.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/PurchasingProcesses.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/PurchasingProcesses.java
deleted file mode 100644
index d9a9849..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/PurchasingProcesses.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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.purchase;
-
-import java.util.Map;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.ConditionalSampler;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-
-import com.google.common.collect.ImmutableMap;
-
-public class PurchasingProcesses implements ConditionalSampler<Product, String>
-{
- ImmutableMap<String, Sampler<Product>> processes;
-
- public PurchasingProcesses(Map<String, Sampler<Product>> processes)
- {
- this.processes = ImmutableMap.copyOf(processes);
- }
-
- public Product sample(String productCategory) throws Exception
- {
- return this.processes.get(productCategory).sample();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/StoreLocationIncomePDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/StoreLocationIncomePDF.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/StoreLocationIncomePDF.java
deleted file mode 100644
index 345956f..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/StoreLocationIncomePDF.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * 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.store;
-
-import java.util.List;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs.ProbabilityDensityFunction;
-
-public class StoreLocationIncomePDF implements ProbabilityDensityFunction<ZipcodeRecord>
-{
- double incomeNormalizationFactor;
- double minIncome;
- double k;
-
- public StoreLocationIncomePDF(List<ZipcodeRecord> zipcodeTable, double incomeScalingFactor)
- {
-
- double maxIncome = 0.0;
- minIncome = Double.MAX_VALUE;
-
- for(ZipcodeRecord record : zipcodeTable)
- {
- maxIncome = Math.max(maxIncome, record.getMedianHouseholdIncome());
- minIncome = Math.min(minIncome, record.getMedianHouseholdIncome());
- }
-
- k = Math.log(incomeScalingFactor) / (maxIncome - minIncome);
-
- incomeNormalizationFactor = 0.0d;
- for(ZipcodeRecord record : zipcodeTable)
- {
- double weight = incomeWeight(record);
- incomeNormalizationFactor += weight;
- }
- }
-
- private double incomeWeight(ZipcodeRecord record)
- {
- return Math.exp(k * (record.getMedianHouseholdIncome() - minIncome));
- }
-
-
- @Override
- public double probability(ZipcodeRecord datum)
- {
- double weight = incomeWeight(datum);
-
- return weight / this.incomeNormalizationFactor;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/StoreLocationPopulationPDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/StoreLocationPopulationPDF.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/StoreLocationPopulationPDF.java
deleted file mode 100644
index 8c6f43c..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/StoreLocationPopulationPDF.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * 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.store;
-
-import java.util.List;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs.ProbabilityDensityFunction;
-
-public class StoreLocationPopulationPDF implements ProbabilityDensityFunction<ZipcodeRecord>
-{
- double populationSum = 0.0;
-
- public StoreLocationPopulationPDF(List<ZipcodeRecord> zipcodeTable)
- {
- long populationSum = 0L;
- for(ZipcodeRecord record : zipcodeTable)
- {
- populationSum += record.getPopulation();
- }
-
- this.populationSum = ((double) populationSum);
- }
-
- public double probability(ZipcodeRecord record)
- {
- return ((double) record.getPopulation()) / populationSum;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/StoreSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/StoreSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/StoreSampler.java
deleted file mode 100644
index d118611..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/StoreSampler.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * 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.store;
-
-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.Sampler;
-
-public class StoreSampler implements Sampler<Store>
-{
-
- private final Sampler<ZipcodeRecord> locationSampler;
- private final Sampler<Integer> idSampler;
-
- public StoreSampler(Sampler<Integer> idSampler, Sampler<ZipcodeRecord> locationSampler)
- {
- this.locationSampler = locationSampler;
- this.idSampler = idSampler;
- }
-
- public Store sample() throws Exception
- {
- Integer id = idSampler.sample();
- String name = "Store_" + id;
- ZipcodeRecord location = locationSampler.sample();
-
- Store store = new Store(id, name, location);
-
- return store;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/StoreSamplerBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/StoreSamplerBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/StoreSamplerBuilder.java
deleted file mode 100644
index 68e4e57..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/StoreSamplerBuilder.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * 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.store;
-
-import java.util.List;
-
-import org.apache.bigtop.bigpetstore.datagenerator.Constants;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Store;
-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.JointPDF;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs.ProbabilityDensityFunction;
-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;
-
-public class StoreSamplerBuilder
-{
- private final List<ZipcodeRecord> zipcodeTable;
- private final SeedFactory seedFactory;
-
- public StoreSamplerBuilder(List<ZipcodeRecord> zipcodeTable, SeedFactory seedFactory)
- {
- this.zipcodeTable = zipcodeTable;
- this.seedFactory = seedFactory;
- }
-
- public Sampler<Store> build()
- {
- Sampler<Integer> idSampler = new SequenceSampler();
-
- ProbabilityDensityFunction<ZipcodeRecord> locationPopulationPDF =
- new StoreLocationPopulationPDF(zipcodeTable);
- ProbabilityDensityFunction<ZipcodeRecord> locationIncomePDF =
- new StoreLocationIncomePDF(zipcodeTable, Constants.INCOME_SCALING_FACTOR);
- ProbabilityDensityFunction<ZipcodeRecord> locationJointPDF =
- new JointPDF<ZipcodeRecord>(zipcodeTable, locationPopulationPDF, locationIncomePDF);
-
- Sampler<ZipcodeRecord> locationSampler = RouletteWheelSampler.create(zipcodeTable, locationJointPDF, seedFactory);
-
- return new StoreSampler(idSampler, locationSampler);
- }
-
-}
[02/11] bigtop git commit: BIGTOP-1984. Extract samplers library from
BigPetStore data generator
Posted by rn...@apache.org.
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestCustomerTransactionParametersSamplerBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestCustomerTransactionParametersSamplerBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestCustomerTransactionParametersSamplerBuilder.java
new file mode 100644
index 0000000..5da4ae3
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestCustomerTransactionParametersSamplerBuilder.java
@@ -0,0 +1,47 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.transaction;
+
+import static org.junit.Assert.assertTrue;
+
+import org.apache.bigtop.datagenerators.bigpetstore.Constants;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.CustomerTransactionParameters;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.CustomerTransactionParametersSamplerBuilder;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.junit.Test;
+
+public class TestCustomerTransactionParametersSamplerBuilder
+{
+
+ @Test
+ public void testBuild() throws Exception
+ {
+ SeedFactory seedFactory = new SeedFactory(1234);
+ CustomerTransactionParametersSamplerBuilder builder = new CustomerTransactionParametersSamplerBuilder(seedFactory);
+ Sampler<CustomerTransactionParameters> sampler = builder.build();
+
+ CustomerTransactionParameters transParams = sampler.sample();
+
+ assertTrue(transParams.countPets() >= Constants.MIN_PETS);
+ assertTrue(transParams.countPets() <= Constants.MAX_PETS);
+ assertTrue(transParams.getAveragePurchaseTriggerTime() >= Constants.PURCHASE_TRIGGER_TIME_MIN);
+ assertTrue(transParams.getAveragePurchaseTriggerTime() <= Constants.PURCHASE_TRIGGER_TIME_MAX);
+ assertTrue(transParams.getAverageTransactionTriggerTime() >= Constants.TRANSACTION_TRIGGER_TIME_MIN);
+ assertTrue(transParams.getAverageTransactionTriggerTime() <= Constants.TRANSACTION_TRIGGER_TIME_MAX);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestProductCategoryInventory.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestProductCategoryInventory.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestProductCategoryInventory.java
new file mode 100644
index 0000000..6b00eca
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestProductCategoryInventory.java
@@ -0,0 +1,75 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.transaction;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.bigpetstore.Constants;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.PetSpecies;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.ProductCategoryBuilder;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.CustomerTransactionParameters;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.CustomerTransactionParametersSamplerBuilder;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.ProductCategoryInventory;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.junit.Test;
+
+import com.google.common.collect.Maps;
+
+public class TestProductCategoryInventory
+{
+
+ @Test
+ public void testPurchase() throws Exception
+ {
+ SeedFactory seedFactory = new SeedFactory(1234);
+
+ CustomerTransactionParametersSamplerBuilder transParamsBuilder = new CustomerTransactionParametersSamplerBuilder(seedFactory);
+ Sampler<CustomerTransactionParameters> sampler = transParamsBuilder.build();
+
+ CustomerTransactionParameters parameters = sampler.sample();
+
+ ProductCategoryBuilder builder = new ProductCategoryBuilder();
+ builder.addApplicableSpecies(PetSpecies.DOG);
+ builder.setAmountUsedPetPetAverage(1.0);
+ builder.setAmountUsedPetPetVariance(1.0);
+ builder.setDailyUsageRate(2.0);
+
+
+ ProductCategory category = builder.build();
+
+ ProductCategoryInventory inventory = new ProductCategoryInventory(category, parameters, seedFactory);
+
+ assertEquals(inventory.findExhaustionTime(), 0.0, 0.0001);
+ assertEquals(inventory.findRemainingAmount(0.0), 0.0, 0.0001);
+
+ Map<String, Object> fields = Maps.newHashMap();
+ fields.put(Constants.PRODUCT_CATEGORY, "dog food");
+ fields.put(Constants.PRODUCT_QUANTITY, 30.0);
+ Product product = new Product(fields);
+
+ inventory.simulatePurchase(1.0, product);
+
+ assertTrue(inventory.findExhaustionTime() > 1.0);
+ assertTrue(inventory.findRemainingAmount(1.0) > 0.0);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestProductCategoryUsageSimulator.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestProductCategoryUsageSimulator.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestProductCategoryUsageSimulator.java
new file mode 100644
index 0000000..22dbfd4
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestProductCategoryUsageSimulator.java
@@ -0,0 +1,53 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.transaction;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.ProductCategoryUsageSimulator;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.ProductCategoryUsageTrajectory;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.commons.lang3.tuple.Pair;
+import org.junit.Test;
+
+public class TestProductCategoryUsageSimulator
+{
+
+ @Test
+ public void testSimulate() throws Exception
+ {
+ SeedFactory seedFactory = new SeedFactory(1234);
+
+ ProductCategoryUsageSimulator simulator = new ProductCategoryUsageSimulator(2.0, 1.0, 1.0, seedFactory);
+
+ ProductCategoryUsageTrajectory trajectory = simulator.simulate(0.0, 30.0);
+
+ assertEquals(0.0, trajectory.getLastAmount(), 0.0001);
+
+ Pair<Double, Double> previousEntry = trajectory.getStep(0);
+ for(int i = 1; i < trajectory.size(); i++)
+ {
+ Pair<Double, Double> entry = trajectory.getStep(i);
+ // time should move forward
+ assertTrue(previousEntry.getLeft() <= entry.getLeft());
+ // remaining amounts should go down
+ assertTrue(previousEntry.getRight() >= entry.getRight());
+ previousEntry = entry;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestProductCategoryUsageTrajectory.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestProductCategoryUsageTrajectory.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestProductCategoryUsageTrajectory.java
new file mode 100644
index 0000000..230f06e
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestProductCategoryUsageTrajectory.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.datagenerators.bigpetstore.generators.transaction;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.ProductCategoryUsageTrajectory;
+import org.apache.commons.lang3.tuple.Pair;
+import org.junit.Test;
+
+public class TestProductCategoryUsageTrajectory
+{
+
+ @Test
+ public void testTrajectory()
+ {
+ double initialAmount = 30.0;
+ double initialTime = 0.0;
+
+ ProductCategoryUsageTrajectory trajectory = new ProductCategoryUsageTrajectory(initialTime, initialAmount);
+
+ assertEquals(trajectory.size(), 1);
+
+ Pair<Double, Double> entry = trajectory.getStep(0);
+ assertEquals(initialTime, entry.getLeft(), 0.0001);
+ assertEquals(initialAmount, entry.getRight(), 0.0001);
+
+ trajectory.append(1.0, 25.0);
+
+ assertEquals(2, trajectory.size());
+
+ entry = trajectory.getStep(1);
+ assertEquals(1.0, entry.getLeft(), 0.0001);
+ assertEquals(25.0, entry.getRight(), 0.0001);
+
+ assertEquals(1.0, trajectory.getLastTime(), 0.0001);
+ assertEquals(25.0, trajectory.getLastAmount(), 0.0001);
+ }
+
+ @Test
+ public void testAmountAtTime()
+ {
+ ProductCategoryUsageTrajectory trajectory = new ProductCategoryUsageTrajectory(0.0, 30.0);
+ trajectory.append(1.0, 25.0);
+ trajectory.append(2.0, 20.0);
+ trajectory.append(3.0, 50.0);
+ trajectory.append(4.0, 40.0);
+ trajectory.append(4.0, 50.0);
+ trajectory.append(5.0, 30.0);
+
+ assertEquals(30.0, trajectory.amountAtTime(0.5), 0.0001);
+ assertEquals(50.0, trajectory.amountAtTime(4.0), 0.0001);
+ assertEquals(30.0, trajectory.amountAtTime(10.0), 0.0001);
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestTransactionPurchasesHiddenMarkovModel.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestTransactionPurchasesHiddenMarkovModel.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestTransactionPurchasesHiddenMarkovModel.java
new file mode 100644
index 0000000..984f796
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestTransactionPurchasesHiddenMarkovModel.java
@@ -0,0 +1,205 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.transaction;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.bigpetstore.Constants;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.PetSpecies;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.ProductCategoryBuilder;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.purchase.MarkovPurchasingModel;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.purchase.PurchasingProcesses;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.CategoryWeightFunction;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.CustomerInventory;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.CustomerInventoryBuilder;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.CustomerTransactionParameters;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.CustomerTransactionParametersSamplerBuilder;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.TransactionPurchasesHiddenMarkovModel;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.markovmodels.MarkovModel;
+import org.apache.bigtop.datagenerators.samplers.markovmodels.MarkovModelBuilder;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.apache.bigtop.datagenerators.samplers.wfs.ConditionalWeightFunction;
+import org.junit.Test;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+public class TestTransactionPurchasesHiddenMarkovModel
+{
+
+ private List<Product> createProducts(String category)
+ {
+ List<Product> products = Lists.newArrayList();
+
+ for(int i = 0; i < 10; i++)
+ {
+ Map<String, Object> fields = Maps.newHashMap();
+ fields.put(Constants.PRODUCT_CATEGORY, category);
+ fields.put(Constants.PRODUCT_QUANTITY, (double) (i + 1));
+ Product product = new Product(fields);
+ products.add(product);
+ }
+
+ return products;
+ }
+
+ private MarkovModel<Product> createMarkovModel(ProductCategory category)
+ {
+ MarkovModelBuilder<Product> markovBuilder = new MarkovModelBuilder<Product>();
+
+ for(Product product1 : category.getProducts())
+ {
+ markovBuilder.addStartState(product1, 1.0);
+ for(Product product2 : category.getProducts())
+ {
+ markovBuilder.addTransition(product1, product2, 1.0);
+ }
+ }
+
+ return markovBuilder.build();
+ }
+
+ protected PurchasingProcesses createProcesses(ProductCategory dogFoodCategory,
+ ProductCategory catFoodCategory, SeedFactory seedFactory)
+ {
+ MarkovModel<Product> dogFoodModel = createMarkovModel(dogFoodCategory);
+ MarkovModel<Product> catFoodModel = createMarkovModel(catFoodCategory);
+
+ Map<String, MarkovModel<Product>> models = Maps.newHashMap();
+ models.put("dog food", dogFoodModel);
+ models.put("cat food", catFoodModel);
+
+ MarkovPurchasingModel profile = new MarkovPurchasingModel(models);
+
+ return profile.buildProcesses(seedFactory);
+ }
+
+ protected ProductCategory createCategory(String category)
+ {
+ List<Product> products = createProducts(category);
+
+ ProductCategoryBuilder builder = new ProductCategoryBuilder();
+
+ if(category.equals("dog food"))
+ {
+ builder.addApplicableSpecies(PetSpecies.DOG);
+ }
+ else
+ {
+ builder.addApplicableSpecies(PetSpecies.CAT);
+ }
+
+ builder.setAmountUsedPetPetAverage(1.0);
+ builder.setAmountUsedPetPetVariance(1.0);
+ builder.setDailyUsageRate(2.0);
+ builder.setCategory(category);
+ builder.setTriggerPurchaseRate(1.0 / 10.0);
+ builder.setTriggerPurchaseRate(1.0 / 10.0);
+
+ for(Product product : products)
+ {
+ builder.addProduct(product);
+ }
+
+ return builder.build();
+ }
+
+ protected TransactionPurchasesHiddenMarkovModel createHMM() throws Exception
+ {
+ SeedFactory seedFactory = new SeedFactory(1234);
+
+ ProductCategory dogFoodCategory = createCategory("dog food");
+ ProductCategory catFoodCategory = createCategory("cat food");
+
+ PurchasingProcesses processes = createProcesses(dogFoodCategory, catFoodCategory, seedFactory);
+
+ CustomerTransactionParametersSamplerBuilder transParamsBuilder = new CustomerTransactionParametersSamplerBuilder(seedFactory);
+ Sampler<CustomerTransactionParameters> sampler = transParamsBuilder.build();
+
+ CustomerTransactionParameters parameters = sampler.sample();
+
+ CustomerInventoryBuilder inventoryBuilder = new CustomerInventoryBuilder(parameters, seedFactory);
+ inventoryBuilder.addProductCategory(dogFoodCategory);
+ inventoryBuilder.addProductCategory(catFoodCategory);
+ CustomerInventory inventory = inventoryBuilder.build();
+
+ ConditionalWeightFunction<Double, Double> categoryWF =
+ new CategoryWeightFunction(parameters.getAveragePurchaseTriggerTime());
+
+ TransactionPurchasesHiddenMarkovModel hmm = new TransactionPurchasesHiddenMarkovModel(processes,
+ categoryWF, inventory, seedFactory);
+
+ return hmm;
+ }
+
+ @Test
+ public void testChooseCategory() throws Exception
+ {
+ TransactionPurchasesHiddenMarkovModel hmm = createHMM();
+
+ String category = hmm.chooseCategory(1.0, 0);
+
+ assertNotNull(category);
+ assertTrue(category.equals(TransactionPurchasesHiddenMarkovModel.STOP_STATE) ||
+ category.equals("dog food") ||
+ category.equals("cat food"));
+ }
+
+ @Test
+ public void testChooseProduct() throws Exception
+ {
+ TransactionPurchasesHiddenMarkovModel hmm = createHMM();
+
+ Product product = hmm.chooseProduct("dog food");
+
+ assertNotNull(product);
+ assertTrue(product.getFieldValue(Constants.PRODUCT_CATEGORY).equals("dog food"));
+
+ product = hmm.chooseProduct("cat food");
+
+ assertNotNull(product);
+ assertTrue(product.getFieldValue(Constants.PRODUCT_CATEGORY).equals("cat food"));
+ }
+
+ @Test
+ public void testSample() throws Exception
+ {
+ TransactionPurchasesHiddenMarkovModel hmm = createHMM();
+
+ List<Product> purchase = hmm.sample(1.0);
+
+ assertTrue(purchase.size() > 0);
+
+ for(int i = 0; i < purchase.size(); i++)
+ {
+ Product product = purchase.get(i);
+
+ // first product should never be null
+ assertNotNull(product);
+ assertTrue(product.getFieldValue(Constants.PRODUCT_CATEGORY).equals("dog food") ||
+ product.getFieldValue(Constants.PRODUCT_CATEGORY).equals("cat food"));
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestTransactionTimePDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestTransactionTimePDF.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestTransactionTimePDF.java
new file mode 100644
index 0000000..5bd0c9f
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/datagenerators/bigpetstore/generators/transaction/TestTransactionTimePDF.java
@@ -0,0 +1,35 @@
+/**
+ * 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.datagenerators.bigpetstore.generators.transaction;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.bigtop.datagenerators.bigpetstore.generators.transaction.TransactionTimePDF;
+import org.junit.Test;
+
+public class TestTransactionTimePDF
+{
+
+ @Test
+ public void testProbability() throws Exception
+ {
+ TransactionTimePDF pdf = new TransactionTimePDF();
+
+ assertEquals(pdf.probability(0.5, 0.75), 0.0, 0.000001);
+ assertEquals(pdf.probability(0.5, 0.5), 1.0, 0.000001);
+ assertEquals(pdf.probability(0.75, 0.5), 1.0, 0.000001);
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/README.md
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/README.md b/bigtop-data-generators/bigtop-samplers/README.md
new file mode 100644
index 0000000..3a91c1b
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/README.md
@@ -0,0 +1,49 @@
+<!--
+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.
+-->
+BigTop Samplers
+===============
+
+Library of interfaces and implementations of probability density
+functions, probability mass functions, weight functions and samplers.
+
+Building and Testing
+--------------------
+We use the Gradle build system for the BPS data generator so you'll need
+to install Gradle on your system.
+Once that's done, you can use gradle to run the included unit tests
+and build the data generator jar.
+
+To build:
+
+ $ gradle build
+
+This will create several directories and a jar located at:
+
+ build/libs/bigtop-samplers-0.9.0-SNAPSHOT.jar
+
+Building automatically runs the included unit tests. If you would prefer
+to just run the unit tests, you can do so by:
+
+ $ gradle test
+
+To clean up the build files, run:
+
+ $ gradle clean
+
+To install a jar into your local maven repository:
+
+ $ gradle install
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/build.gradle
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/build.gradle b/bigtop-data-generators/bigtop-samplers/build.gradle
new file mode 100644
index 0000000..84b5fe0
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/build.gradle
@@ -0,0 +1,64 @@
+/**
+ * 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.
+ */
+apply plugin: 'eclipse'
+apply plugin: 'groovy'
+apply plugin: 'java'
+apply plugin: 'maven'
+group = 'org.apache.bigtop'
+version = '1.1.0-SNAPSHOT'
+
+jar {
+
+ from {
+ configurations.runtime.collect {
+ it.isDirectory() ? it : zipTree(it)
+ }
+ }
+
+ manifest {
+ attributes 'Title': 'BigTop Samplers', 'Version': version
+ }
+}
+
+repositories {
+ mavenLocal()
+ mavenCentral()
+}
+
+test {
+ // show standard out and error on console
+ testLogging.showStandardStreams = true
+
+ // listen to events in the test execution lifecycle
+ beforeTest { descriptor ->
+ logger.lifecycle("Running test: " + descriptor)
+ }
+
+ // listen to standard out and standard error of the test JVM(s)
+ onOutput { descriptor, event ->
+ logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message )
+ }
+
+}
+
+dependencies {
+ compile 'com.google.guava:guava:18.0'
+
+ compile 'org.apache.commons:commons-lang3:3.4'
+ compile 'org.apache.commons:commons-math3:3.5'
+
+ testCompile 'junit:junit:4.+'
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/settings.gradle
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/settings.gradle b/bigtop-data-generators/bigtop-samplers/settings.gradle
new file mode 100644
index 0000000..ef1ce16
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/settings.gradle
@@ -0,0 +1,16 @@
+/**
+ * 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.
+ */
+rootProject.name = "bigtop-samplers"
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/SeedFactory.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/SeedFactory.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/SeedFactory.java
new file mode 100644
index 0000000..678a3dc
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/SeedFactory.java
@@ -0,0 +1,38 @@
+/**
+ * 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.datagenerators.samplers;
+
+import java.util.Random;
+
+public class SeedFactory
+{
+ Random rng;
+
+ public SeedFactory()
+ {
+ rng = new Random();
+ }
+
+ public SeedFactory(long seed)
+ {
+ rng = new Random(seed);
+ }
+
+ public long getNextSeed()
+ {
+ return rng.nextLong();
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/markovmodels/MarkovModel.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/markovmodels/MarkovModel.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/markovmodels/MarkovModel.java
new file mode 100644
index 0000000..ca51e7d
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/markovmodels/MarkovModel.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.datagenerators.samplers.markovmodels;
+
+import java.io.Serializable;
+import java.util.Map;
+
+public class MarkovModel<T> implements Serializable
+{
+ private static final long serialVersionUID = 8378109656005603192L;
+
+ final Map<T, Map<T, Double>> transitionWeights;
+ final Map<T, Double> startWeights;
+
+ public MarkovModel(Map<T, Map<T, Double>> transitionWeights, Map<T, Double> startWeights)
+ {
+ this.transitionWeights = transitionWeights;
+ this.startWeights = startWeights;
+ }
+
+ public Map<T, Map<T, Double>> getTransitionWeights()
+ {
+ return transitionWeights;
+ }
+
+ public Map<T, Double> getStartWeights()
+ {
+ return startWeights;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "MarkModel(" + startWeights + "," + transitionWeights + ")";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/markovmodels/MarkovModelBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/markovmodels/MarkovModelBuilder.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/markovmodels/MarkovModelBuilder.java
new file mode 100644
index 0000000..cf50a9c
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/markovmodels/MarkovModelBuilder.java
@@ -0,0 +1,53 @@
+/**
+ * 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.datagenerators.samplers.markovmodels;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableTable;
+
+public class MarkovModelBuilder<S>
+{
+ ImmutableTable.Builder<S, S, Double> transitionWeights;
+ ImmutableMap.Builder<S, Double> startWeights;
+
+ public MarkovModelBuilder()
+ {
+ transitionWeights = ImmutableTable.builder();
+ startWeights = ImmutableMap.builder();
+ }
+
+ public static <T> MarkovModelBuilder<T> create()
+ {
+ return new MarkovModelBuilder<T>();
+ }
+
+ public void addStartState(S state, double weight)
+ {
+ startWeights.put(state, weight);
+ }
+
+ public void addTransition(S state1, S state2, double weight)
+ {
+ transitionWeights.put(state1, state2, weight);
+ }
+
+ public MarkovModel<S> build()
+ {
+ return new MarkovModel<S>(transitionWeights.build().rowMap(), startWeights.build());
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/markovmodels/MarkovProcess.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/markovmodels/MarkovProcess.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/markovmodels/MarkovProcess.java
new file mode 100644
index 0000000..99bdb15
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/markovmodels/MarkovProcess.java
@@ -0,0 +1,68 @@
+/**
+ * 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.datagenerators.samplers.markovmodels;
+
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.RouletteWheelSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+
+import com.google.common.collect.ImmutableMap;
+
+public class MarkovProcess<T> implements Sampler<T>
+{
+ final ImmutableMap<T, Sampler<T>> transitionSamplers;
+ final Sampler<T> startStateSampler;
+
+ T currentState;
+
+
+ public MarkovProcess(MarkovModel<T> model, SeedFactory factory)
+ {
+ Map<T, Map<T, Double>> transitionTable = model.getTransitionWeights();
+
+ startStateSampler = RouletteWheelSampler.create(model.getStartWeights(), factory);
+
+ ImmutableMap.Builder<T, Sampler<T>> builder = ImmutableMap.builder();
+ for(Map.Entry<T, Map<T, Double>> entry : transitionTable.entrySet())
+ {
+ builder.put(entry.getKey(), RouletteWheelSampler.create(entry.getValue(), factory));
+ }
+
+
+ this.transitionSamplers = builder.build();
+
+ currentState = null;
+ }
+
+ public static <T> MarkovProcess<T> create(MarkovModel<T> model, SeedFactory factory)
+ {
+ return new MarkovProcess<T>(model, factory);
+ }
+
+ public T sample() throws Exception
+ {
+ if(currentState == null)
+ {
+ currentState = startStateSampler.sample();
+ return currentState;
+ }
+
+ currentState = transitionSamplers.get(currentState).sample();
+ return currentState;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/ConditionalProbabilityDensityFunction.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/ConditionalProbabilityDensityFunction.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/ConditionalProbabilityDensityFunction.java
new file mode 100644
index 0000000..7a55b2e
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/ConditionalProbabilityDensityFunction.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.datagenerators.samplers.pdfs;
+
+public interface ConditionalProbabilityDensityFunction<T, S>
+{
+ public double probability(T datum, S conditionalDatum);
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/ExponentialPDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/ExponentialPDF.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/ExponentialPDF.java
new file mode 100644
index 0000000..93042f0
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/ExponentialPDF.java
@@ -0,0 +1,31 @@
+/**
+ * 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.datagenerators.samplers.pdfs;
+
+public class ExponentialPDF implements ProbabilityDensityFunction<Double>
+{
+ private final double lambda;
+
+ public ExponentialPDF(double lambda)
+ {
+ this.lambda = lambda;
+ }
+
+ public double probability(Double value)
+ {
+ return lambda * Math.exp(-1.0 * value * lambda);
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/GaussianPDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/GaussianPDF.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/GaussianPDF.java
new file mode 100644
index 0000000..5cb4b9e
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/GaussianPDF.java
@@ -0,0 +1,37 @@
+/**
+ * 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.datagenerators.samplers.pdfs;
+
+public class GaussianPDF implements ProbabilityDensityFunction<Double>
+{
+ private double mean;
+ private double std;
+
+ public GaussianPDF(double mean, double std)
+ {
+ this.mean = mean;
+ this.std = std;
+ }
+
+ public double probability(Double value)
+ {
+ double diff = (mean - value) * (mean - value);
+ double var = std * std;
+ double exp = Math.exp(-1.0 * diff / (2.0 * var));
+
+ return exp / (std * Math.sqrt(2.0 * Math.PI));
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/JointPDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/JointPDF.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/JointPDF.java
new file mode 100644
index 0000000..aca60f4
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/JointPDF.java
@@ -0,0 +1,49 @@
+/**
+ * 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.datagenerators.samplers.pdfs;
+
+import java.util.List;
+
+public class JointPDF<T> implements ProbabilityDensityFunction<T>
+{
+
+ double normalizationFactor;
+ ProbabilityDensityFunction<T>[] pdfs;
+
+ public JointPDF(List<T> data, ProbabilityDensityFunction<T> ... pdfs)
+ {
+ this.pdfs = pdfs;
+
+ normalizationFactor = 0.0d;
+ for(T datum : data)
+ {
+ double prob = 1.0;
+ for(ProbabilityDensityFunction<T> pdf : pdfs)
+ prob *= pdf.probability(datum);
+ normalizationFactor += prob;
+ }
+
+ }
+
+ public double probability(T datum)
+ {
+ double weight = 1.0;
+ for(ProbabilityDensityFunction<T> pdf : pdfs)
+ weight *= pdf.probability(datum);
+
+ return weight / normalizationFactor;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/MultinomialPDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/MultinomialPDF.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/MultinomialPDF.java
new file mode 100644
index 0000000..6d39379
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/MultinomialPDF.java
@@ -0,0 +1,57 @@
+/**
+ * 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.datagenerators.samplers.pdfs;
+
+import java.util.Map;
+import java.util.Set;
+
+import com.google.common.collect.ImmutableMap;
+
+public class MultinomialPDF<T> implements ProbabilityDensityFunction<T>
+{
+ private final ImmutableMap<T, Double> probabilities;
+
+ public MultinomialPDF(Map<T, Double> probabilities)
+ {
+ this.probabilities = ImmutableMap.copyOf(probabilities);
+ }
+
+ public Set<T> getData()
+ {
+ return probabilities.keySet();
+ }
+
+ public double probability(T value)
+ {
+ if(probabilities.containsKey(value))
+ {
+ return probabilities.get(value);
+ }
+
+ return 0.0;
+ }
+
+ @Override
+ public String toString()
+ {
+ String str = "";
+ for(Map.Entry<T, Double> entry: probabilities.entrySet())
+ {
+ str += entry.getValue() + "," + entry.getKey() + "\n";
+ }
+ return str;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/ProbabilityDensityFunction.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/ProbabilityDensityFunction.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/ProbabilityDensityFunction.java
new file mode 100644
index 0000000..463e98e
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/ProbabilityDensityFunction.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.datagenerators.samplers.pdfs;
+
+public interface ProbabilityDensityFunction<T>
+{
+ public double probability(T datum);
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/UniformPDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/UniformPDF.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/UniformPDF.java
new file mode 100644
index 0000000..72d378a
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/pdfs/UniformPDF.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.datagenerators.samplers.pdfs;
+
+public class UniformPDF<T> implements ProbabilityDensityFunction<T>
+{
+ private final double probability;
+
+ public UniformPDF(long count)
+ {
+ probability = 1.0 / ((double) count);
+ }
+
+ public UniformPDF(double probability)
+ {
+ this.probability = probability;
+ }
+
+ public double probability(T datum)
+ {
+ return probability;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/BoundedMultiModalGaussianSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/BoundedMultiModalGaussianSampler.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/BoundedMultiModalGaussianSampler.java
new file mode 100644
index 0000000..da25c86
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/BoundedMultiModalGaussianSampler.java
@@ -0,0 +1,61 @@
+/**
+ * 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.datagenerators.samplers.samplers;
+
+import java.util.List;
+import java.util.Random;
+
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.commons.lang3.tuple.Pair;
+
+import com.google.common.collect.ImmutableList;
+
+public class BoundedMultiModalGaussianSampler implements Sampler<Double>
+{
+ ImmutableList<Pair<Double, Double>> distributions;
+
+ double min;
+ double max;
+ Random rng;
+
+ public BoundedMultiModalGaussianSampler(List<Pair<Double, Double>> distributions, double min, double max, SeedFactory seedFactory)
+ {
+ rng = new Random(seedFactory.getNextSeed());
+ this.distributions = ImmutableList.copyOf(distributions);
+
+ this.min = min;
+ this.max = max;
+ }
+
+ public Double sample()
+ {
+ while(true)
+ {
+ int idx = rng.nextInt(distributions.size());
+
+ double mean = distributions.get(idx).getLeft();
+ double std = distributions.get(idx).getRight();
+
+ double value = mean + rng.nextGaussian() * std;
+
+ if (value >= this.min && value <= this.max)
+ {
+ return value;
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/ConditionalSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/ConditionalSampler.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/ConditionalSampler.java
new file mode 100644
index 0000000..611aea9
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/ConditionalSampler.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.datagenerators.samplers.samplers;
+
+public interface ConditionalSampler<T, S>
+{
+ public T sample(S conditional) throws Exception;
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/DoubleSequenceSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/DoubleSequenceSampler.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/DoubleSequenceSampler.java
new file mode 100644
index 0000000..f4f1639
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/DoubleSequenceSampler.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.datagenerators.samplers.samplers;
+
+public class DoubleSequenceSampler implements Sampler<Double>
+{
+ Double start;
+ Double end;
+ Double step;
+ Double next;
+
+ public DoubleSequenceSampler()
+ {
+ start = 0.0;
+ end = null;
+ step = 1.0;
+ next = start;
+ }
+
+ public DoubleSequenceSampler(Double start)
+ {
+ this.start = start;
+ end = null;
+ step = 1.0;
+ next = start;
+ }
+
+ public DoubleSequenceSampler(Double start, Double end)
+ {
+ this.start = start;
+ this.end = end;
+ step = 1.0;
+ next = start;
+ }
+
+ public DoubleSequenceSampler(Double start, Double end, Double step)
+ {
+ this.start = start;
+ this.end = end;
+ this.step = step;
+ next = start;
+ }
+
+ public Double sample() throws Exception
+ {
+ if(end == null || next < end)
+ {
+ Double 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/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/ExponentialSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/ExponentialSampler.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/ExponentialSampler.java
new file mode 100644
index 0000000..adfbccc
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/ExponentialSampler.java
@@ -0,0 +1,37 @@
+/**
+ * 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.datagenerators.samplers.samplers;
+
+import java.util.Random;
+
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+
+public class ExponentialSampler implements Sampler<Double>
+{
+ final private Random rng;
+ final private double lambda;
+
+ public ExponentialSampler(double lambda, SeedFactory seedFactory)
+ {
+ rng = new Random(seedFactory.getNextSeed());
+ this.lambda = lambda;
+ }
+
+ public Double sample()
+ {
+ return - Math.log(1.0 - rng.nextDouble()) / lambda;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/GaussianSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/GaussianSampler.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/GaussianSampler.java
new file mode 100644
index 0000000..c6b2ea0
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/GaussianSampler.java
@@ -0,0 +1,39 @@
+/**
+ * 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.datagenerators.samplers.samplers;
+
+import java.util.Random;
+
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+
+public class GaussianSampler implements Sampler<Double>
+{
+ double mean;
+ double std;
+ Random rng;
+
+ public GaussianSampler(double mean, double std, SeedFactory seedFactory)
+ {
+ rng = new Random(seedFactory.getNextSeed());
+ this.mean = mean;
+ this.std = std;
+ }
+
+ public Double sample()
+ {
+ return rng.nextGaussian() * std + mean;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/MonteCarloSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/MonteCarloSampler.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/MonteCarloSampler.java
new file mode 100644
index 0000000..bd060e5
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/MonteCarloSampler.java
@@ -0,0 +1,55 @@
+/**
+ * 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.datagenerators.samplers.samplers;
+
+import java.util.Random;
+
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.pdfs.ProbabilityDensityFunction;
+
+
+public class MonteCarloSampler<T> implements Sampler<T>
+{
+ private final Sampler<T> stateSampler;
+ private final Random rng;
+ private final ProbabilityDensityFunction<T> acceptancePDF;
+
+ public MonteCarloSampler(Sampler<T> stateGenerator,
+ ProbabilityDensityFunction<T> acceptancePDF,
+ SeedFactory seedFactory)
+ {
+ this.acceptancePDF = acceptancePDF;
+ this.stateSampler = stateGenerator;
+
+ rng = new Random(seedFactory.getNextSeed());
+ }
+
+ public T sample() throws Exception
+ {
+ while(true)
+ {
+ T proposedState = this.stateSampler.sample();
+ double probability = acceptancePDF.probability(proposedState);
+ double r = rng.nextDouble();
+
+ if(r < probability)
+ {
+ return proposedState;
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/RouletteWheelSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/RouletteWheelSampler.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/RouletteWheelSampler.java
new file mode 100644
index 0000000..ec97ac5
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/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.datagenerators.samplers.samplers;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Random;
+
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.pdfs.MultinomialPDF;
+import org.apache.bigtop.datagenerators.samplers.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/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/Sampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/Sampler.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/Sampler.java
new file mode 100644
index 0000000..a4d5d36
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/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.datagenerators.samplers.samplers;
+
+public interface Sampler<T>
+{
+ public T sample() throws Exception;
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/SequenceSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/SequenceSampler.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/SequenceSampler.java
new file mode 100644
index 0000000..b4871ac
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/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.datagenerators.samplers.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/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/StatefulMonteCarloSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/StatefulMonteCarloSampler.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/StatefulMonteCarloSampler.java
new file mode 100644
index 0000000..4f0cf9b
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/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.datagenerators.samplers.samplers;
+
+import java.util.Random;
+
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.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/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/UniformIntSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/UniformIntSampler.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/UniformIntSampler.java
new file mode 100644
index 0000000..0cb7520
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/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.datagenerators.samplers.samplers;
+
+import java.util.Random;
+
+import org.apache.bigtop.datagenerators.samplers.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/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/UniformSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/UniformSampler.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/samplers/UniformSampler.java
new file mode 100644
index 0000000..a90ff89
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/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.datagenerators.samplers.samplers;
+
+import java.util.Random;
+
+import org.apache.bigtop.datagenerators.samplers.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/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/wfs/ConditionalWeightFunction.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/wfs/ConditionalWeightFunction.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/wfs/ConditionalWeightFunction.java
new file mode 100644
index 0000000..93a5b2c
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/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.datagenerators.samplers.wfs;
+
+public interface ConditionalWeightFunction<T, S>
+{
+ public double weight(T datum, S given);
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/wfs/WeightFunction.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/wfs/WeightFunction.java b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/wfs/WeightFunction.java
new file mode 100644
index 0000000..bceff80
--- /dev/null
+++ b/bigtop-data-generators/bigtop-samplers/src/main/java/org/apache/bigtop/datagenerators/samplers/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.datagenerators.samplers.wfs;
+
+public interface WeightFunction<T>
+{
+ public double weight(T datum);
+}
[07/11] bigtop git commit: BIGTOP-1984. Extract samplers library from
BigPetStore data generator
Posted by rn...@apache.org.
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/cli/Simulation.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/cli/Simulation.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/cli/Simulation.java
new file mode 100644
index 0000000..16aabf0
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/cli/Simulation.java
@@ -0,0 +1,188 @@
+/**
+ * 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.datagenerators.bigpetstore.cli;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Vector;
+
+import org.apache.bigtop.datagenerators.bigpetstore.Constants;
+import org.apache.bigtop.datagenerators.bigpetstore.CustomerGenerator;
+import org.apache.bigtop.datagenerators.bigpetstore.ProductGenerator;
+import org.apache.bigtop.datagenerators.bigpetstore.PurchasingModelGenerator;
+import org.apache.bigtop.datagenerators.bigpetstore.StoreGenerator;
+import org.apache.bigtop.datagenerators.bigpetstore.TransactionGenerator;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Customer;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Store;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Transaction;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.InputData;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.purchase.PurchasingModel;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.samplers.RouletteWheelSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+
+import com.google.common.collect.Lists;
+
+public class Simulation
+{
+ InputData inputData;
+ SeedFactory seedFactory;
+ int nStores;
+ int nCustomers;
+ int nPurchasingModels;
+ double simulationTime;
+
+ List<Store> stores;
+ List<Customer> customers;
+ Sampler<PurchasingModel> purchasingModelSampler;
+ List<PurchasingModel> purchasingProfiles;
+ List<Transaction> transactions;
+ List<ProductCategory> productCategories;
+
+ public Simulation(InputData inputData, int nStores, int nCustomers, int nPurchasingModels, double simulationTime, long seed)
+ {
+ this.inputData = inputData;
+ this.nStores = nStores;
+ this.nCustomers = nCustomers;
+ this.nPurchasingModels = nPurchasingModels;
+ this.simulationTime = simulationTime;
+ seedFactory = new SeedFactory(seed);
+ }
+
+ public void generateStores() throws Exception
+ {
+ System.out.println("Generating stores");
+ StoreGenerator storeGenerator = new StoreGenerator(inputData, seedFactory);
+
+ stores = new Vector<Store>();
+ for(int i = 0; i < nStores; i++)
+ {
+ Store store = storeGenerator.generate();
+ stores.add(store);
+ }
+
+ stores = Collections.unmodifiableList(stores);
+
+ System.out.println("Generated " + stores.size() + " stores");
+ }
+
+ public void generateCustomers() throws Exception
+ {
+ System.out.println("Generating customers");
+ CustomerGenerator generator = new CustomerGenerator(inputData, stores, seedFactory);
+
+ customers = new Vector<Customer>();
+ for(int i = 0; i < nCustomers; i++)
+ {
+ Customer customer = generator.generate();
+ customers.add(customer);
+ }
+
+ customers = Collections.unmodifiableList(customers);
+
+ System.out.println("Generated " + customers.size() + " customers");
+ }
+
+ public void generateProducts()
+ {
+ System.out.println("Generating products");
+ ProductGenerator generator = new ProductGenerator(Constants.PRODUCTS_COLLECTION);
+ productCategories = generator.generate();
+ }
+
+ public void generatePurchasingProfiles() throws Exception
+ {
+ System.out.println("Generating purchasing profiles");
+ PurchasingModelGenerator generator = new PurchasingModelGenerator(productCategories, seedFactory);
+
+ purchasingProfiles = new Vector<PurchasingModel>();
+ for(int i = 0; i < nPurchasingModels; i++)
+ {
+ PurchasingModel profile = generator.generate();
+ purchasingProfiles.add(profile);
+ }
+
+ System.out.println("Generated " + purchasingProfiles.size() + " purchasing profiles");
+
+ purchasingModelSampler = RouletteWheelSampler.createUniform(purchasingProfiles, seedFactory);
+ }
+
+ public void generateTransactions() throws Exception
+ {
+ System.out.println("Generating transactions");
+ transactions = Lists.newArrayList();
+
+ for(int i = 0; i < nCustomers; i++)
+ {
+ Customer customer = customers.get(i);
+ PurchasingModel profile = purchasingModelSampler.sample();
+
+ TransactionGenerator generator = new TransactionGenerator(customer,
+ profile, productCategories, seedFactory);
+
+ while(true)
+ {
+ Transaction transaction = generator.generate();
+
+ if(transaction.getDateTime() > simulationTime)
+ break;
+ transactions.add(transaction);
+ }
+ }
+
+ System.out.println("Generated " + transactions.size() + " transactions");
+ }
+
+ public void simulate() throws Exception
+ {
+ generateStores();
+ generateCustomers();
+ generateProducts();
+ generatePurchasingProfiles();
+ generateTransactions();
+ }
+
+ public List<Store> getStores()
+ {
+ return stores;
+ }
+
+ public List<Customer> getCustomers()
+ {
+ return customers;
+ }
+
+ public List<Transaction> getTransactions()
+ {
+ return transactions;
+ }
+
+ public InputData getInputData()
+ {
+ return inputData;
+ }
+
+ public List<ProductCategory> getProductCategories()
+ {
+ return this.productCategories;
+ }
+
+ public List<PurchasingModel> getPurchasingProfiles()
+ {
+ return this.purchasingProfiles;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/Customer.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/Customer.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/Customer.java
new file mode 100644
index 0000000..8847a36
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/Customer.java
@@ -0,0 +1,59 @@
+/**
+ * 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.datagenerators.bigpetstore.datamodels;
+
+import java.io.Serializable;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ZipcodeRecord;
+import org.apache.commons.lang3.tuple.Pair;
+
+public class Customer implements Serializable
+{
+ private static final long serialVersionUID = 5739806281335931258L;
+
+ int id;
+ Pair<String, String> name;
+ ZipcodeRecord location;
+ Store store;
+
+ public Customer(int id, Pair<String, String> name, Store store, ZipcodeRecord location)
+ {
+ this.id = id;
+ this.name = name;
+ this.location = location;
+ this.store = store;
+ }
+
+ public int getId()
+ {
+ return id;
+ }
+
+ public Pair<String, String> getName()
+ {
+ return name;
+ }
+
+ public ZipcodeRecord getLocation()
+ {
+ return location;
+ }
+
+ public Store getStore()
+ {
+ return store;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/PetSpecies.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/PetSpecies.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/PetSpecies.java
new file mode 100644
index 0000000..393626c
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/PetSpecies.java
@@ -0,0 +1,22 @@
+/**
+ * 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.datagenerators.bigpetstore.datamodels;
+
+public enum PetSpecies
+{
+ DOG,
+ CAT;
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/Product.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/Product.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/Product.java
new file mode 100644
index 0000000..da82647
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/Product.java
@@ -0,0 +1,96 @@
+/**
+ * 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.datagenerators.bigpetstore.datamodels;
+
+import java.io.Serializable;
+import java.util.Map;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+
+public class Product implements Serializable
+{
+ private static final long serialVersionUID = 4519472063058037956L;
+
+ ImmutableMap<String, Object> fields;
+
+ public Product(Map<String, Object> fields)
+ {
+ this.fields = ImmutableMap.copyOf(fields);
+ }
+
+ public ImmutableSet<String> getFieldNames()
+ {
+ return fields.keySet();
+ }
+
+ public Object getFieldValue(String fieldName)
+ {
+ return fields.get(fieldName);
+ }
+
+ public String getFieldValueAsString(String fieldName)
+ {
+ return fields.get(fieldName).toString();
+ }
+
+ public Double getFieldValueAsDouble(String fieldName)
+ {
+ Object value = getFieldValue(fieldName);
+ try
+ {
+ Double doubleValue = (Double) value;
+ return doubleValue;
+ }
+ catch(ClassCastException e)
+ {
+ return null;
+ }
+ }
+
+ public Long getFieldValueAsLong(String fieldName)
+ {
+ Object value = getFieldValue(fieldName);
+ try
+ {
+ Long longValue = (Long) value;
+ return longValue;
+ }
+ catch(ClassCastException e)
+ {
+ try
+ {
+ Integer intValue = (Integer) value;
+ return new Long(intValue);
+ }
+ catch(ClassCastException f)
+ {
+ return null;
+ }
+ }
+ }
+
+ public String toString()
+ {
+ String str = "";
+ for(Map.Entry<String, Object> entry : fields.entrySet())
+ {
+ str += entry.getKey() + "=" + entry.getValue() + ";";
+ }
+
+ return str;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/Store.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/Store.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/Store.java
new file mode 100644
index 0000000..61730dd
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/Store.java
@@ -0,0 +1,51 @@
+/**
+ * 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.datagenerators.bigpetstore.datamodels;
+
+import java.io.Serializable;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ZipcodeRecord;
+
+public class Store implements Serializable
+{
+ private static final long serialVersionUID = 2347066623022747969L;
+
+ int id;
+ String name;
+ ZipcodeRecord location;
+
+ public Store(int id, String name, ZipcodeRecord location)
+ {
+ this.id = id;
+ this.name = name;
+ this.location = location;
+ }
+
+ public int getId()
+ {
+ return id;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public ZipcodeRecord getLocation()
+ {
+ return location;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/Transaction.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/Transaction.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/Transaction.java
new file mode 100644
index 0000000..0ea8a66
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/Transaction.java
@@ -0,0 +1,68 @@
+/**
+ * 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.datagenerators.bigpetstore.datamodels;
+
+import java.io.Serializable;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+
+public class Transaction implements Serializable
+{
+ private static final long serialVersionUID = 103133601154354349L;
+
+ final int id;
+ final Customer customer;
+ final Store store;
+ final Double dateTime;
+ final ImmutableList<Product> products;
+
+ public Transaction(int id, Customer customer, Store store, Double dateTime, List<Product> products)
+ {
+ this.id = id;
+ this.customer = customer;
+ this.store = store;
+ this.dateTime = dateTime;
+ this.products = ImmutableList.copyOf(products);
+ }
+
+ public int getId()
+ {
+ return id;
+ }
+
+ public Customer getCustomer()
+ {
+ return customer;
+ }
+
+ public Store getStore()
+ {
+ return store;
+ }
+
+ public Double getDateTime()
+ {
+ return dateTime;
+ }
+
+ public ImmutableList<Product> getProducts()
+ {
+ return products;
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/inputs/InputData.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/inputs/InputData.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/inputs/InputData.java
new file mode 100644
index 0000000..7f5eddf
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/inputs/InputData.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.datagenerators.bigpetstore.datamodels.inputs;
+
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.List;
+
+public class InputData implements Serializable
+{
+ private static final long serialVersionUID = 9078989799806707788L;
+
+ List<ZipcodeRecord> zipcodeTable;
+ Names names;
+
+ public InputData(List<ZipcodeRecord> zipcodeTable,
+ Names names)
+ {
+ this.zipcodeTable = Collections.unmodifiableList(zipcodeTable);
+ this.names = names;
+ }
+
+ public List<ZipcodeRecord> getZipcodeTable()
+ {
+ return zipcodeTable;
+ }
+
+ public Names getNames()
+ {
+ return names;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/inputs/Names.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/inputs/Names.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/inputs/Names.java
new file mode 100644
index 0000000..2d6da89
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/inputs/Names.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.datagenerators.bigpetstore.datamodels.inputs;
+
+import java.io.Serializable;
+import java.util.Map;
+
+import com.google.common.collect.ImmutableMap;
+
+public class Names implements Serializable
+{
+ private static final long serialVersionUID = 2731634747628534453L;
+
+ final ImmutableMap<String, Double> firstNames;
+ final ImmutableMap<String, Double> lastNames;
+
+ public Names(Map<String, Double> firstNames,
+ Map<String, Double> lastNames)
+ {
+ this.firstNames = ImmutableMap.copyOf(firstNames);
+ this.lastNames = ImmutableMap.copyOf(lastNames);
+ }
+
+ public ImmutableMap<String, Double> getFirstNames()
+ {
+ return firstNames;
+ }
+
+ public ImmutableMap<String, Double> getLastNames()
+ {
+ return lastNames;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/inputs/ProductCategory.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/inputs/ProductCategory.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/inputs/ProductCategory.java
new file mode 100644
index 0000000..c14d499
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/inputs/ProductCategory.java
@@ -0,0 +1,108 @@
+/**
+ * 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.datagenerators.bigpetstore.datamodels.inputs;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.PetSpecies;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+
+public class ProductCategory implements Serializable
+{
+ private static final long serialVersionUID = -7638076590334497836L;
+
+ String categoryLabel;
+ ImmutableSet<PetSpecies> applicableSpecies;
+ ImmutableSet<String> fieldNames;
+ boolean triggerTransaction;
+ double dailyUsageRate;
+ double amountUsedPerPetAverage;
+ double amountUsedPerPetVariance;
+ double triggerTransactionRate;
+ double triggerPurchaseRate;
+ ImmutableList<Product> products;
+
+ public ProductCategory(String categoryLabel, Set<PetSpecies> species, Set<String> fieldNames,
+ boolean triggerTransaction, double dailyUsageRate, double amountUsedPerPetAverage,
+ double amountUsedPerPetVariance, double triggerTransactionRate,
+ double triggerPurchaseRate, List<Product> products)
+ {
+ this.categoryLabel = categoryLabel;
+ this.applicableSpecies = ImmutableSet.copyOf(species);
+ this.fieldNames = ImmutableSet.copyOf(fieldNames);
+ this.triggerTransaction = triggerTransaction;
+ this.dailyUsageRate = dailyUsageRate;
+ this.amountUsedPerPetAverage = amountUsedPerPetAverage;
+ this.amountUsedPerPetVariance = amountUsedPerPetVariance;
+ this.triggerTransactionRate = triggerTransactionRate;
+ this.triggerPurchaseRate = triggerPurchaseRate;
+ this.products = ImmutableList.copyOf(products);
+ }
+
+ public String getCategoryLabel()
+ {
+ return categoryLabel;
+ }
+
+ public ImmutableSet<PetSpecies> getApplicableSpecies()
+ {
+ return applicableSpecies;
+ }
+
+ public ImmutableSet<String> getFieldNames()
+ {
+ return fieldNames;
+ }
+ public Boolean getTriggerTransaction()
+ {
+ return triggerTransaction;
+ }
+
+ public Double getDailyUsageRate()
+ {
+ return dailyUsageRate;
+ }
+
+ public Double getBaseAmountUsedAverage()
+ {
+ return amountUsedPerPetAverage;
+ }
+
+ public Double getBaseAmountUsedVariance()
+ {
+ return amountUsedPerPetVariance;
+ }
+
+ public Double getTransactionTriggerRate()
+ {
+ return triggerTransactionRate;
+ }
+
+ public Double getPurchaseTriggerRate()
+ {
+ return triggerPurchaseRate;
+ }
+
+ public ImmutableList<Product> getProducts()
+ {
+ return products;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/inputs/ZipcodeRecord.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/inputs/ZipcodeRecord.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/inputs/ZipcodeRecord.java
new file mode 100644
index 0000000..e5eeb60
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datamodels/inputs/ZipcodeRecord.java
@@ -0,0 +1,90 @@
+/**
+ * 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.datagenerators.bigpetstore.datamodels.inputs;
+
+import java.io.Serializable;
+
+import org.apache.commons.lang3.tuple.Pair;
+
+public class ZipcodeRecord implements Serializable
+{
+ private static final long serialVersionUID = 1769986686070108470L;
+
+ final String zipcode;
+ final Pair<Double, Double> coordinates;
+ final String city;
+ final String state;
+ final double medianHouseholdIncome;
+ final long population;
+
+ public ZipcodeRecord(String zipcode, Pair<Double, Double> coordinates,
+ String city, String state, double medianHouseholdIncome, long population)
+ {
+ this.city = city;
+ this.state = state;
+ this.zipcode = zipcode;
+ this.coordinates = coordinates;
+ this.medianHouseholdIncome = medianHouseholdIncome;
+ this.population = population;
+ }
+
+ public String getZipcode()
+ {
+ return zipcode;
+ }
+
+ public Pair<Double, Double> getCoordinates()
+ {
+ return coordinates;
+ }
+
+ public double getMedianHouseholdIncome()
+ {
+ return medianHouseholdIncome;
+ }
+
+ public long getPopulation()
+ {
+ return population;
+ }
+
+ public double distance(ZipcodeRecord other)
+ {
+ if(other.getZipcode().equals(zipcode))
+ return 0.0;
+
+ Pair<Double, Double> otherCoords = other.getCoordinates();
+
+ double dist = Math.sin(Math.toRadians(coordinates.getLeft())) *
+ Math.sin(Math.toRadians(otherCoords.getLeft())) +
+ Math.cos(Math.toRadians(coordinates.getLeft())) *
+ Math.cos(Math.toRadians(otherCoords.getLeft())) *
+ Math.cos(Math.toRadians(coordinates.getRight() - otherCoords.getRight()));
+ dist = Math.toDegrees(Math.acos(dist)) * 69.09;
+
+ return dist;
+ }
+
+ public String getCity()
+ {
+ return city;
+ }
+
+ public String getState()
+ {
+ return state;
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datareaders/NameReader.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datareaders/NameReader.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datareaders/NameReader.java
new file mode 100644
index 0000000..ec5412a
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datareaders/NameReader.java
@@ -0,0 +1,62 @@
+/**
+ * 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.datagenerators.bigpetstore.datareaders;
+
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.Map;
+import java.util.Scanner;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.Names;
+
+import com.google.common.collect.Maps;
+
+public class NameReader
+{
+ InputStream path;
+
+ public NameReader(InputStream path)
+ {
+ this.path = path;
+ }
+
+ public Names readData() throws FileNotFoundException
+ {
+ Scanner scanner = new Scanner(path);
+
+ Map<String, Double> firstNames = Maps.newHashMap();
+ Map<String, Double> lastNames = Maps.newHashMap();
+
+ while(scanner.hasNextLine())
+ {
+ String line = scanner.nextLine();
+ String[] cols = line.trim().split(",");
+
+ String name = cols[0];
+ double weight = Double.parseDouble(cols[5]);
+
+ if(cols[4].equals("1"))
+ firstNames.put(name, weight);
+ if(cols[3].equals("1"))
+ lastNames.put(name, weight);
+ }
+
+ scanner.close();
+
+ return new Names(firstNames, lastNames);
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datareaders/ZipcodeReader.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datareaders/ZipcodeReader.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datareaders/ZipcodeReader.java
new file mode 100644
index 0000000..2478c8e
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/datareaders/ZipcodeReader.java
@@ -0,0 +1,193 @@
+/**
+ * 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.datagenerators.bigpetstore.datareaders;
+
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Scanner;
+import java.util.Set;
+import java.util.Vector;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ZipcodeRecord;
+import org.apache.commons.lang3.tuple.Pair;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+
+public class ZipcodeReader
+{
+ private static class ZipcodeLocationRecord
+ {
+ public final Pair<Double, Double> coordinates;
+ public final String state;
+ public final String city;
+
+ public ZipcodeLocationRecord(Pair<Double, Double> coordinates,
+ String city, String state)
+ {
+ this.coordinates = coordinates;
+ this.city = city;
+ this.state = state;
+ }
+ }
+
+ InputStream zipcodeIncomesFile = null;
+ InputStream zipcodePopulationFile = null;
+ InputStream zipcodeCoordinatesFile = null;
+
+ public void setIncomesFile(InputStream path)
+ {
+ this.zipcodeIncomesFile = path;
+ }
+
+ public void setPopulationFile(InputStream path)
+ {
+ this.zipcodePopulationFile = path;
+ }
+
+ public void setCoordinatesFile(InputStream path)
+ {
+ this.zipcodeCoordinatesFile = path;
+ }
+
+ private ImmutableMap<String, Double> readIncomeData(InputStream path) throws FileNotFoundException
+ {
+ Scanner scanner = new Scanner(path);
+
+ // skip headers
+ scanner.nextLine();
+ scanner.nextLine();
+
+ Map<String, Double> entries = Maps.newHashMap();
+ while(scanner.hasNextLine())
+ {
+ String line = scanner.nextLine().trim();
+ String[] cols = line.split(",");
+ // zipcodes are in the form "ZCTA5 XXXXX"
+ String zipcode = cols[2].split(" ")[1].trim();
+ try
+ {
+ double medianHouseholdIncome = Integer.parseInt(cols[5].trim());
+ entries.put(zipcode, medianHouseholdIncome);
+ }
+ catch(NumberFormatException e)
+ {
+
+ }
+ }
+
+ scanner.close();
+
+ return ImmutableMap.copyOf(entries);
+ }
+
+ private ImmutableMap<String, Long> readPopulationData(InputStream path) throws FileNotFoundException
+ {
+ Scanner scanner = new Scanner(path);
+
+ // skip header
+ scanner.nextLine();
+
+ Map<String, Long> entries = Maps.newHashMap();
+ while(scanner.hasNextLine())
+ {
+ String line = scanner.nextLine().trim();
+
+ if(line.length() == 0)
+ continue;
+
+ String[] cols = line.split(",");
+
+ String zipcode = cols[0].trim();
+ Long population = Long.parseLong(cols[1].trim());
+
+ if(entries.containsKey(zipcode))
+ {
+ entries.put(zipcode, Math.max(entries.get(zipcode), population));
+ }
+ else
+ {
+ entries.put(zipcode, population);
+ }
+ }
+
+ scanner.close();
+
+ return ImmutableMap.copyOf(entries);
+ }
+
+ private ImmutableMap<String, ZipcodeLocationRecord> readCoordinates(InputStream path) throws FileNotFoundException
+ {
+ Scanner scanner = new Scanner(path);
+
+ // skip header
+ scanner.nextLine();
+
+ Map<String, ZipcodeLocationRecord> entries = Maps.newHashMap();
+ while(scanner.hasNextLine())
+ {
+ String line = scanner.nextLine().trim();
+
+ String[] cols = line.split(", ");
+
+ // remove quote marks
+ String zipcode = cols[0].substring(1, cols[0].length() - 1);
+ String state = cols[1].substring(1, cols[1].length() - 1);
+ Double latitude = Double.parseDouble(cols[2].substring(1, cols[2].length() - 1));
+ Double longitude = Double.parseDouble(cols[3].substring(1, cols[3].length() - 1));
+ String city = cols[4].substring(1, cols[4].length() - 1);
+
+ Pair<Double, Double> coords = Pair.of(latitude, longitude);
+
+ ZipcodeLocationRecord record = new ZipcodeLocationRecord(coords, city, state);
+
+ entries.put(zipcode, record);
+ }
+
+ scanner.close();
+
+ return ImmutableMap.copyOf(entries);
+ }
+
+ public ImmutableList<ZipcodeRecord> readData() throws FileNotFoundException
+ {
+ ImmutableMap<String, Double> incomes = readIncomeData(this.zipcodeIncomesFile);
+ ImmutableMap<String, Long> populations = readPopulationData(this.zipcodePopulationFile);
+ ImmutableMap<String, ZipcodeLocationRecord> coordinates = readCoordinates(this.zipcodeCoordinatesFile);
+
+ Set<String> zipcodeSubset = new HashSet<String>(incomes.keySet());
+ zipcodeSubset.retainAll(populations.keySet());
+ zipcodeSubset.retainAll(coordinates.keySet());
+
+ List<ZipcodeRecord> table = new Vector<ZipcodeRecord>();
+ for(String zipcode : zipcodeSubset)
+ {
+ ZipcodeRecord record = new ZipcodeRecord(zipcode,
+ coordinates.get(zipcode).coordinates,
+ coordinates.get(zipcode).city,
+ coordinates.get(zipcode).state,
+ incomes.get(zipcode),
+ populations.get(zipcode));
+ table.add(record);
+ }
+
+ return ImmutableList.copyOf(table);
+ }
+}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/customer/CustomerLocationPDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/customer/CustomerLocationPDF.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/customer/CustomerLocationPDF.java
new file mode 100644
index 0000000..08cbc81
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/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.datagenerators.bigpetstore.generators.customer;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Store;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ZipcodeRecord;
+import org.apache.bigtop.datagenerators.samplers.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/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/customer/CustomerSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/customer/CustomerSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/customer/CustomerSampler.java
new file mode 100644
index 0000000..13b69a3
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/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.datagenerators.bigpetstore.generators.customer;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Customer;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Store;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ZipcodeRecord;
+import org.apache.bigtop.datagenerators.samplers.samplers.ConditionalSampler;
+import org.apache.bigtop.datagenerators.samplers.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/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/customer/CustomerSamplerBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/customer/CustomerSamplerBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/customer/CustomerSamplerBuilder.java
new file mode 100644
index 0000000..56ab761
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/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.datagenerators.bigpetstore.generators.customer;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.bigpetstore.Constants;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Customer;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Store;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.InputData;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ZipcodeRecord;
+import org.apache.bigtop.datagenerators.samplers.SeedFactory;
+import org.apache.bigtop.datagenerators.samplers.pdfs.ProbabilityDensityFunction;
+import org.apache.bigtop.datagenerators.samplers.samplers.ConditionalSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.RouletteWheelSampler;
+import org.apache.bigtop.datagenerators.samplers.samplers.Sampler;
+import org.apache.bigtop.datagenerators.samplers.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/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/customer/CustomerStorePDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/customer/CustomerStorePDF.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/customer/CustomerStorePDF.java
new file mode 100644
index 0000000..6131454
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/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.datagenerators.bigpetstore.generators.customer;
+
+import java.util.List;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Store;
+import org.apache.bigtop.datagenerators.samplers.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/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/ProductBuilderIterator.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/ProductBuilderIterator.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/ProductBuilderIterator.java
new file mode 100644
index 0000000..bf64ea7
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/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.datagenerators.bigpetstore.generators.products;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.bigpetstore.Constants;
+import org.apache.bigtop.datagenerators.bigpetstore.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/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/ProductCategoryBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/ProductCategoryBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/ProductCategoryBuilder.java
new file mode 100644
index 0000000..d105ec3
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/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.datagenerators.bigpetstore.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.datagenerators.bigpetstore.Constants;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.PetSpecies;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.inputs.ProductCategory;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.rules.AlwaysTrueRule;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.rules.NotRule;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.rules.OrRule;
+import org.apache.bigtop.datagenerators.bigpetstore.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/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/ProductFieldValue.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/ProductFieldValue.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/ProductFieldValue.java
new file mode 100644
index 0000000..1499fcd
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/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.datagenerators.bigpetstore.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/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/ProductFilterIterator.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/ProductFilterIterator.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/ProductFilterIterator.java
new file mode 100644
index 0000000..10a5f3a
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/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.datagenerators.bigpetstore.generators.products;
+
+import java.util.Iterator;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.bigpetstore.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/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/ProductIterator.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/ProductIterator.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/ProductIterator.java
new file mode 100644
index 0000000..032b0e4
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/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.datagenerators.bigpetstore.generators.products;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.bigtop.datagenerators.bigpetstore.datamodels.Product;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.cartesian.CartesianProduct;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.cartesian.CartesianProductBase;
+import org.apache.bigtop.datagenerators.bigpetstore.generators.products.cartesian.CartesianProductField;
+import org.apache.bigtop.datagenerators.bigpetstore.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/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/cartesian/CartesianProduct.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/cartesian/CartesianProduct.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/cartesian/CartesianProduct.java
new file mode 100644
index 0000000..2d1c005
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/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.datagenerators.bigpetstore.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/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/cartesian/CartesianProductBase.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/cartesian/CartesianProductBase.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/cartesian/CartesianProductBase.java
new file mode 100644
index 0000000..7765469
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/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.datagenerators.bigpetstore.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/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/cartesian/CartesianProductField.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/cartesian/CartesianProductField.java b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/generators/products/cartesian/CartesianProductField.java
new file mode 100644
index 0000000..38939f6
--- /dev/null
+++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/datagenerators/bigpetstore/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.datagenerators.bigpetstore.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()");
+ }
+
+}
[04/11] bigtop git commit: BIGTOP-1984. Extract samplers library from
BigPetStore data generator
Posted by rn...@apache.org.
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestAlwaysTrueRule.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestAlwaysTrueRule.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestAlwaysTrueRule.java
deleted file mode 100644
index c32fa1b..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestAlwaysTrueRule.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * 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.junit.Assert;
-import org.junit.Test;
-
-public class TestAlwaysTrueRule
-{
-
- @Test
- public void testRuleMatches()
- {
- Rule rule = new AlwaysTrueRule();
- Assert.assertTrue(rule.ruleMatches(null));
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestAndRule.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestAndRule.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestAndRule.java
deleted file mode 100644
index b930c38..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestAndRule.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * 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.junit.Assert;
-import org.junit.Test;
-
-public class TestAndRule
-{
-
- @Test
- public void testRuleMatches()
- {
- Rule rule = new AndRule(
- new AlwaysTrueRule(),
- new AlwaysTrueRule());
- Assert.assertTrue(rule.ruleMatches(null));
-
- rule = new AndRule(
- new AlwaysTrueRule(),
- new NotRule(
- new AlwaysTrueRule()));
- Assert.assertFalse(rule.ruleMatches(null));
-
- rule = new AndRule(
- new NotRule(
- new AlwaysTrueRule()),
- new AlwaysTrueRule());
- Assert.assertFalse(rule.ruleMatches(null));
-
- rule = new AndRule(
- new NotRule(
- new AlwaysTrueRule()),
- new NotRule(
- new AlwaysTrueRule()));
- Assert.assertFalse(rule.ruleMatches(null));
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestFieldPredicate.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestFieldPredicate.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestFieldPredicate.java
deleted file mode 100644
index 88cae45..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestFieldPredicate.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * 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.Map;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
-import org.junit.Assert;
-import org.junit.Test;
-
-import com.google.common.collect.ImmutableMap;
-
-public class TestFieldPredicate
-{
-
- @Test
- public void testRuleMatches()
- {
- Map<String, Object> fields = ImmutableMap.of("brand", (Object) "Chef Corgi",
- "flavor", (Object) "chicken");
- Product product = new Product(fields);
-
- Rule rule = new FieldPredicate("brand", "Chef Corgi");
- Assert.assertTrue(rule.ruleMatches(product));
-
- rule = new FieldPredicate("brand", "Happy Pup");
- Assert.assertFalse(rule.ruleMatches(product));
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestNotRule.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestNotRule.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestNotRule.java
deleted file mode 100644
index ee284af..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestNotRule.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * 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.junit.Assert;
-import org.junit.Test;
-
-public class TestNotRule
-{
-
- @Test
- public void testRuleMatches()
- {
- Rule rule = new NotRule(
- new AlwaysTrueRule());
- Assert.assertFalse(rule.ruleMatches(null));
-
- rule = new NotRule(
- new NotRule(
- new AlwaysTrueRule()));
- Assert.assertTrue(rule.ruleMatches(null));
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestOrRule.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestOrRule.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestOrRule.java
deleted file mode 100644
index fd6f817..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestOrRule.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * 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.junit.Assert;
-import org.junit.Test;
-
-public class TestOrRule
-{
-
- @Test
- public void testRuleMatches()
- {
- Rule rule = new OrRule(
- new AlwaysTrueRule(),
- new AlwaysTrueRule());
- Assert.assertTrue(rule.ruleMatches(null));
-
- rule = new OrRule(
- new AlwaysTrueRule(),
- new NotRule(
- new AlwaysTrueRule()));
- Assert.assertTrue(rule.ruleMatches(null));
-
- rule = new OrRule(
- new NotRule(
- new AlwaysTrueRule()),
- new AlwaysTrueRule());
- Assert.assertTrue(rule.ruleMatches(null));
-
- rule = new OrRule(
- new NotRule(
- new AlwaysTrueRule()),
- new NotRule(
- new AlwaysTrueRule()));
- Assert.assertFalse(rule.ruleMatches(null));
- }
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestProductCategoryMarkovModelSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestProductCategoryMarkovModelSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestProductCategoryMarkovModelSampler.java
deleted file mode 100644
index acb0929..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestProductCategoryMarkovModelSampler.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
- * 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.purchase;
-
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-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.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels.MarkovModel;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.UniformSampler;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.products.ProductCategoryBuilder;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.MarkovModelProductCategorySampler;
-import org.junit.Test;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-
-public class TestProductCategoryMarkovModelSampler
-{
-
- private List<ProductCategory> createProducts()
- {
- List<ProductCategory> productCategories = Lists.newArrayList();
-
- ProductCategoryBuilder foodBuilder = new ProductCategoryBuilder();
- foodBuilder.addApplicableSpecies(PetSpecies.DOG);
- foodBuilder.setAmountUsedPetPetAverage(1.0);
- foodBuilder.setAmountUsedPetPetVariance(1.0);
- foodBuilder.setDailyUsageRate(2.0);
- foodBuilder.setCategory("dogFood");
- foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood",
- Constants.PRODUCT_QUANTITY, (Object) 60.0, "Flavor", "Fish & Potato")));
- foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood",
- Constants.PRODUCT_QUANTITY, (Object) 30.0, "Flavor", "Chicken & Rice")));
- foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood",
- Constants.PRODUCT_QUANTITY, (Object) 15.0, "Flavor", "Lamb & Barley")));
- productCategories.add(foodBuilder.build());
-
- ProductCategoryBuilder bagBuilder = new ProductCategoryBuilder();
- bagBuilder.addApplicableSpecies(PetSpecies.DOG);
- bagBuilder.setAmountUsedPetPetAverage(1.0);
- bagBuilder.setAmountUsedPetPetVariance(1.0);
- bagBuilder.setDailyUsageRate(2.0);
- bagBuilder.setCategory("Poop Bags");
- bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags",
- Constants.PRODUCT_QUANTITY, (Object) 60.0, "Color", "Blue")));
- bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags",
- Constants.PRODUCT_QUANTITY, (Object) 30.0, "Color", "Red")));
- bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags",
- Constants.PRODUCT_QUANTITY, (Object) 120.0, "Flavor", "Multicolor")));
- productCategories.add(bagBuilder.build());
-
- return productCategories;
- }
-
- @Test
- public void testSample() throws Exception
- {
- SeedFactory seedFactory = new SeedFactory(1245);
-
- List<ProductCategory> productCategories = createProducts();
-
- ProductCategory productCategory = productCategories.get(0);
-
- Sampler<Double> fieldWeightSampler = new UniformSampler(seedFactory);
-
- Map<String, Double> fieldWeights = Maps.newHashMap();
- for(String fieldName : productCategory.getFieldNames())
- {
- fieldWeights.put(fieldName, fieldWeightSampler.sample());
- }
-
- MarkovModelProductCategorySampler generator = new MarkovModelProductCategorySampler(productCategory,
- fieldWeights, new UniformSampler(seedFactory), new UniformSampler(seedFactory)
- );
-
- MarkovModel<Product> model = generator.sample();
-
- assertNotNull(model);
- assertNotNull(model.getStartWeights());
- assertNotNull(model.getTransitionWeights());
- assertTrue(model.getStartWeights().size() > 0);
- assertTrue(model.getTransitionWeights().size() > 0);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingModelSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingModelSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingModelSampler.java
deleted file mode 100644
index 12efe13..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingModelSampler.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/**
- * 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.purchase;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.List;
-
-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.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.products.ProductCategoryBuilder;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.MarkovPurchasingModel;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.PurchasingModelSamplerBuilder;
-import org.junit.Test;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
-
-public class TestPurchasingModelSampler
-{
-
- private List<ProductCategory> createProducts()
- {
- List<ProductCategory> productCategories = Lists.newArrayList();
-
- ProductCategoryBuilder foodBuilder = new ProductCategoryBuilder();
- foodBuilder.addApplicableSpecies(PetSpecies.DOG);
- foodBuilder.setAmountUsedPetPetAverage(1.0);
- foodBuilder.setAmountUsedPetPetVariance(1.0);
- foodBuilder.setDailyUsageRate(2.0);
- foodBuilder.setCategory("dogFood");
- foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood",
- Constants.PRODUCT_QUANTITY, (Object) 60.0, "Flavor", "Fish & Potato")));
- foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood",
- Constants.PRODUCT_QUANTITY, (Object) 30.0, "Flavor", "Chicken & Rice")));
- foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood",
- Constants.PRODUCT_QUANTITY, (Object) 15.0, "Flavor", "Lamb & Barley")));
- productCategories.add(foodBuilder.build());
-
- ProductCategoryBuilder bagBuilder = new ProductCategoryBuilder();
- bagBuilder.addApplicableSpecies(PetSpecies.DOG);
- bagBuilder.setAmountUsedPetPetAverage(1.0);
- bagBuilder.setAmountUsedPetPetVariance(1.0);
- bagBuilder.setDailyUsageRate(2.0);
- bagBuilder.setCategory("Poop Bags");
- bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags",
- Constants.PRODUCT_QUANTITY, (Object) 60.0, "Color", "Blue")));
- bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags",
- Constants.PRODUCT_QUANTITY, (Object) 30.0, "Color", "Red")));
- bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags",
- Constants.PRODUCT_QUANTITY, (Object) 120.0, "Color", "Multicolor")));
- productCategories.add(bagBuilder.build());
-
- return productCategories;
- }
-
- @Test
- public void testSample() throws Exception
- {
- SeedFactory seedFactory = new SeedFactory(1245);
-
- List<ProductCategory> productCategories = createProducts();
-
- PurchasingModelSamplerBuilder builder = new PurchasingModelSamplerBuilder(productCategories, seedFactory);
- Sampler<MarkovPurchasingModel> sampler = builder.buildMarkovPurchasingModel();
- MarkovPurchasingModel profile = sampler.sample();
-
- assertNotNull(profile);
- assertNotNull(profile.getProductCategories());
- assertTrue(profile.getProductCategories().size() > 0);
-
- for(String label : profile.getProductCategories())
- {
- assertNotNull(profile.getProfile(label));
- assertNotNull(profile.getProfile(label).getStartWeights());
- assertTrue(profile.getProfile(label).getStartWeights().size() > 0);
- assertNotNull(profile.getProfile(label).getTransitionWeights());
- assertTrue(profile.getProfile(label).getTransitionWeights().size() > 0);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingModelSamplerBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingModelSamplerBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingModelSamplerBuilder.java
deleted file mode 100644
index 2d526ed..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingModelSamplerBuilder.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/**
- * 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.purchase;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.List;
-
-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.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.products.ProductCategoryBuilder;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.MarkovPurchasingModel;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.PurchasingModelSamplerBuilder;
-import org.junit.Test;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
-
-public class TestPurchasingModelSamplerBuilder
-{
-
- private List<ProductCategory> createProducts()
- {
- List<ProductCategory> productCategories = Lists.newArrayList();
-
- ProductCategoryBuilder foodBuilder = new ProductCategoryBuilder();
- foodBuilder.addApplicableSpecies(PetSpecies.DOG);
- foodBuilder.setAmountUsedPetPetAverage(1.0);
- foodBuilder.setAmountUsedPetPetVariance(1.0);
- foodBuilder.setDailyUsageRate(2.0);
- foodBuilder.setCategory("dogFood");
- foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood",
- Constants.PRODUCT_QUANTITY, (Object) 60.0, "Flavor", "Fish & Potato")));
- foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood",
- Constants.PRODUCT_QUANTITY, (Object) 30.0, "Flavor", "Chicken & Rice")));
- foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood",
- Constants.PRODUCT_QUANTITY, (Object) 15.0, "Flavor", "Lamb & Barley")));
- productCategories.add(foodBuilder.build());
-
- ProductCategoryBuilder bagBuilder = new ProductCategoryBuilder();
- bagBuilder.addApplicableSpecies(PetSpecies.DOG);
- bagBuilder.setAmountUsedPetPetAverage(1.0);
- bagBuilder.setAmountUsedPetPetVariance(1.0);
- bagBuilder.setDailyUsageRate(2.0);
- bagBuilder.setCategory("Poop Bags");
- bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags",
- Constants.PRODUCT_QUANTITY, (Object) 60.0, "Color", "Blue")));
- bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags",
- Constants.PRODUCT_QUANTITY, (Object) 30.0, "Color", "Red")));
- bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags",
- Constants.PRODUCT_QUANTITY, (Object) 120.0, "Color", "Multicolor")));
- productCategories.add(bagBuilder.build());
-
- return productCategories;
- }
-
- @Test
- public void testBuild() throws Exception
- {
- SeedFactory seedFactory = new SeedFactory(1245);
-
- List<ProductCategory> productCategories = createProducts();
-
- PurchasingModelSamplerBuilder builder = new PurchasingModelSamplerBuilder(productCategories, seedFactory);
- Sampler<MarkovPurchasingModel> sampler = builder.buildMarkovPurchasingModel();
- MarkovPurchasingModel profile = sampler.sample();
-
- assertNotNull(profile);
- assertNotNull(profile.getProductCategories());
- assertTrue(profile.getProductCategories().size() > 0);
-
- for(String label : profile.getProductCategories())
- {
- assertNotNull(profile.getProfile(label));
- assertNotNull(profile.getProfile(label).getStartWeights());
- assertTrue(profile.getProfile(label).getStartWeights().size() > 0);
- assertNotNull(profile.getProfile(label).getTransitionWeights());
- assertTrue(profile.getProfile(label).getTransitionWeights().size() > 0);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingProcesses.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingProcesses.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingProcesses.java
deleted file mode 100644
index c110def..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingProcesses.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * 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.purchase;
-
-import static org.junit.Assert.assertNotNull;
-
-import java.util.Map;
-
-import org.apache.bigtop.bigpetstore.datagenerator.Constants;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.RouletteWheelSampler;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.PurchasingProcesses;
-import org.junit.Test;
-
-import com.google.common.collect.Maps;
-
-public class TestPurchasingProcesses
-{
-
- @Test
- public void testSimulatePurchase() throws Exception
- {
- Map<Product, Double> productPDF = Maps.newHashMap();
-
- for(int i = 0; i < 10; i++)
- {
- Map<String, Object> fields = Maps.newHashMap();
- fields.put(Constants.PRODUCT_CATEGORY, "dog food");
- fields.put(Constants.PRODUCT_QUANTITY, (double) (i + 1));
- Product product = new Product(fields);
- productPDF.put(product, 0.1);
- }
-
- SeedFactory seedFactory = new SeedFactory(1234);
- Sampler<Product> sampler = RouletteWheelSampler.create(productPDF, seedFactory);
-
-
- Map<String, Sampler<Product>> processesMap = Maps.newHashMap();
- processesMap.put("dog food", sampler);
- PurchasingProcesses processes = new PurchasingProcesses(processesMap);
-
- Product product = processes.sample("dog food");
-
- assertNotNull(product);
- assertNotNull(product.getFieldValue(Constants.PRODUCT_CATEGORY));
- assertNotNull(product.getFieldValue(Constants.PRODUCT_QUANTITY));
-
- product = processes.sample("dog food");
-
- assertNotNull(product);
- assertNotNull(product.getFieldValue(Constants.PRODUCT_CATEGORY));
- assertNotNull(product.getFieldValue(Constants.PRODUCT_QUANTITY));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreLocationIncomePDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreLocationIncomePDF.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreLocationIncomePDF.java
deleted file mode 100644
index f9b8126..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreLocationIncomePDF.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * 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.store;
-
-import static org.junit.Assert.assertTrue;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord;
-import org.apache.commons.lang3.tuple.Pair;
-import org.junit.Test;
-
-public class TestStoreLocationIncomePDF
-{
-
- @Test
- public void testProbability() throws Exception
- {
- List<ZipcodeRecord> zipcodes = Arrays.asList(new ZipcodeRecord[] {
- new ZipcodeRecord("11111", Pair.of(1.0, 1.0), "AZ", "Tempte", 30000.0, 100),
- new ZipcodeRecord("22222", Pair.of(2.0, 2.0), "AZ", "Phoenix", 45000.0, 200),
- new ZipcodeRecord("33333", Pair.of(3.0, 3.0), "AZ", "Flagstaff", 60000.0, 300)
- });
-
- StoreLocationIncomePDF pdf = new StoreLocationIncomePDF(zipcodes, 100.0);
-
- for(ZipcodeRecord record : zipcodes)
- {
- assertTrue(pdf.probability(record) > 0.0);
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreLocationPopulationPDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreLocationPopulationPDF.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreLocationPopulationPDF.java
deleted file mode 100644
index 792f6d0..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreLocationPopulationPDF.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * 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.store;
-
-import static org.junit.Assert.assertTrue;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord;
-import org.apache.commons.lang3.tuple.Pair;
-import org.junit.Test;
-
-public class TestStoreLocationPopulationPDF
-{
-
- @Test
- public void testProbability() throws Exception
- {
- List<ZipcodeRecord> zipcodes = Arrays.asList(new ZipcodeRecord[] {
- new ZipcodeRecord("11111", Pair.of(1.0, 1.0), "AZ", "Tempte", 30000.0, 100),
- new ZipcodeRecord("22222", Pair.of(2.0, 2.0), "AZ", "Phoenix", 45000.0, 200),
- new ZipcodeRecord("33333", Pair.of(3.0, 3.0), "AZ", "Flagstaff", 60000.0, 300)
- });
-
- StoreLocationPopulationPDF pdf = new StoreLocationPopulationPDF(zipcodes);
-
- for(ZipcodeRecord record : zipcodes)
- {
- assertTrue(pdf.probability(record) > 0.0);
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreSampler.java
deleted file mode 100644
index 64589f4..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreSampler.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * 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.store;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Arrays;
-import java.util.Collection;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Store;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-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 org.apache.commons.lang3.tuple.Pair;
-import org.junit.Test;
-
-public class TestStoreSampler
-{
-
- @Test
- public void testSampler() throws Exception
- {
- Collection<ZipcodeRecord> zipcodes = Arrays.asList(new ZipcodeRecord[] {
- new ZipcodeRecord("11111", Pair.of(1.0, 1.0), "AZ", "Tempte", 30000.0, 100),
- new ZipcodeRecord("22222", Pair.of(2.0, 2.0), "AZ", "Phoenix", 45000.0, 200),
- new ZipcodeRecord("33333", Pair.of(3.0, 3.0), "AZ", "Flagstaff", 60000.0, 300)
- });
-
- SeedFactory factory = new SeedFactory(1234);
-
- Sampler<Store> sampler = new StoreSampler(new SequenceSampler(),
- RouletteWheelSampler.createUniform(zipcodes, factory));
-
- Store store = sampler.sample();
- assertNotNull(store);
- assertTrue(store.getId() >= 0);
- assertNotNull(store.getName());
- assertNotNull(store.getLocation());
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreSamplerBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreSamplerBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreSamplerBuilder.java
deleted file mode 100644
index b7b0a52..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreSamplerBuilder.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * 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.store;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Store;
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.apache.commons.lang3.tuple.Pair;
-import org.junit.Test;
-
-public class TestStoreSamplerBuilder
-{
-
- @Test
- public void testBuild() throws Exception
- {
- List<ZipcodeRecord> zipcodes = Arrays.asList(new ZipcodeRecord[] {
- new ZipcodeRecord("11111", Pair.of(1.0, 1.0), "AZ", "Tempte", 30000.0, 100),
- new ZipcodeRecord("22222", Pair.of(2.0, 2.0), "AZ", "Phoenix", 45000.0, 200),
- new ZipcodeRecord("33333", Pair.of(3.0, 3.0), "AZ", "Flagstaff", 60000.0, 300)
- });
-
- assertTrue(zipcodes.size() > 0);
-
- SeedFactory factory = new SeedFactory(1234);
-
- StoreSamplerBuilder builder = new StoreSamplerBuilder(zipcodes, factory);
- Sampler<Store> sampler = builder.build();
-
- Store store = sampler.sample();
- assertNotNull(store);
- assertTrue(store.getId() >= 0);
- assertNotNull(store.getName());
- assertNotNull(store.getLocation());
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerInventory.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerInventory.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerInventory.java
deleted file mode 100644
index 322bb5e..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerInventory.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/**
- * 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.transaction;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Map;
-
-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.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.products.ProductCategoryBuilder;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerInventory;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParameters;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParametersSamplerBuilder;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.ProductCategoryInventory;
-import org.junit.Test;
-
-import com.google.common.collect.Maps;
-
-public class TestCustomerInventory
-{
-
- @Test
- public void testPurchase() throws Exception
- {
- SeedFactory seedFactory = new SeedFactory(1234);
-
- CustomerTransactionParametersSamplerBuilder transParamsBuilder = new CustomerTransactionParametersSamplerBuilder(seedFactory);
- Sampler<CustomerTransactionParameters> sampler = transParamsBuilder.build();
-
- CustomerTransactionParameters parameters = sampler.sample();
-
- ProductCategoryBuilder builder = new ProductCategoryBuilder();
- builder.addApplicableSpecies(PetSpecies.DOG);
- builder.setAmountUsedPetPetAverage(1.0);
- builder.setAmountUsedPetPetVariance(1.0);
- builder.setDailyUsageRate(2.0);
- builder.setCategory("dog food");
-
-
- ProductCategory category = builder.build();
-
- ProductCategoryInventory productInventory = new ProductCategoryInventory(category, parameters, seedFactory);
-
- Map<String, ProductCategoryInventory> inventories = Maps.newHashMap();
- inventories.put("dog food", productInventory);
-
- CustomerInventory inventory = new CustomerInventory(inventories);
-
- for(Map.Entry<String, Double> entry : inventory.getExhaustionTimes().entrySet())
- {
- assertEquals(entry.getValue(), 0.0, 0.0001);
- }
-
- for(Map.Entry<String, Double> entry : inventory.getInventoryAmounts(0.0).entrySet())
- {
- assertEquals(entry.getValue(), 0.0, 0.0001);
- }
-
- Map<String, Object> fields = Maps.newHashMap();
- fields.put(Constants.PRODUCT_CATEGORY, "dog food");
- fields.put(Constants.PRODUCT_QUANTITY, 30.0);
- Product product = new Product(fields);
-
- inventory.simulatePurchase(1.0, product);
-
- Map<String, Double> exhaustionTimes = inventory.getExhaustionTimes();
- assertTrue(exhaustionTimes.containsKey("dog food"));
- assertTrue(exhaustionTimes.get("dog food") > 0.0);
-
- Map<String, Double> amounts = inventory.getInventoryAmounts(2.0);
- assertTrue(amounts.containsKey("dog food"));
- assertTrue(amounts.get("dog food") > 0.0);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerInventoryBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerInventoryBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerInventoryBuilder.java
deleted file mode 100644
index d8d6d70..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerInventoryBuilder.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/**
- * 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.transaction;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Map;
-
-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.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.products.ProductCategoryBuilder;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerInventory;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerInventoryBuilder;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParameters;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParametersSamplerBuilder;
-import org.junit.Test;
-
-import com.google.common.collect.Maps;
-
-public class TestCustomerInventoryBuilder
-{
-
- @Test
- public void testBuild() throws Exception
- {
- SeedFactory seedFactory = new SeedFactory(1234);
-
- CustomerTransactionParametersSamplerBuilder transParamsBuilder = new CustomerTransactionParametersSamplerBuilder(seedFactory);
- Sampler<CustomerTransactionParameters> sampler = transParamsBuilder.build();
-
- CustomerTransactionParameters parameters = sampler.sample();
-
- ProductCategoryBuilder builder = new ProductCategoryBuilder();
- builder.addApplicableSpecies(PetSpecies.DOG);
- builder.setAmountUsedPetPetAverage(1.0);
- builder.setAmountUsedPetPetVariance(1.0);
- builder.setDailyUsageRate(2.0);
- builder.setCategory("dog food");
-
- ProductCategory category = builder.build();
-
- CustomerInventoryBuilder inventoryBuilder = new CustomerInventoryBuilder(parameters, seedFactory);
- inventoryBuilder.addProductCategory(category);
-
- CustomerInventory inventory = inventoryBuilder.build();
-
- for(Map.Entry<String, Double> entry : inventory.getExhaustionTimes().entrySet())
- {
- assertEquals(entry.getValue(), 0.0, 0.0001);
- }
-
- for(Map.Entry<String, Double> entry : inventory.getInventoryAmounts(0.0).entrySet())
- {
- assertEquals(entry.getValue(), 0.0, 0.0001);
- }
-
- Map<String, Object> fields = Maps.newHashMap();
- fields.put(Constants.PRODUCT_CATEGORY, "dog food");
- fields.put(Constants.PRODUCT_QUANTITY, 30.0);
- Product product = new Product(fields);
-
- inventory.simulatePurchase(1.0, product);
-
- Map<String, Double> exhaustionTimes = inventory.getExhaustionTimes();
- assertTrue(exhaustionTimes.containsKey("dog food"));
- assertTrue(exhaustionTimes.get("dog food") > 0.0);
-
- Map<String, Double> amounts = inventory.getInventoryAmounts(2.0);
- assertTrue(amounts.containsKey("dog food"));
- assertTrue(amounts.get("dog food") > 0.0);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParameters.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParameters.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParameters.java
deleted file mode 100644
index a9fdaec..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParameters.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * 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.transaction;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.Arrays;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.PetSpecies;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParameters;
-import org.junit.Test;
-
-import com.google.common.collect.HashMultiset;
-import com.google.common.collect.Multiset;
-
-public class TestCustomerTransactionParameters
-{
-
- @Test
- public void testCountPetsBySpecies() throws Exception
- {
- Multiset<PetSpecies> petCounts = HashMultiset.create();
-
- petCounts.add(PetSpecies.CAT);
- petCounts.add(PetSpecies.CAT);
- petCounts.add(PetSpecies.CAT);
-
-
- CustomerTransactionParameters transParams = new CustomerTransactionParameters(
- petCounts, 0.0, 0.0);
-
-
- assertEquals(transParams.countPetsBySpecies(PetSpecies.CAT), 3);
- assertEquals(transParams.countPetsBySpecies(PetSpecies.DOG), 0);
- assertEquals(transParams.countPets(), 3);
- }
-
- @Test
- public void testCountPetsByMultipleSpecies() throws Exception
- {
- Multiset<PetSpecies> petCounts = HashMultiset.create();
-
- petCounts.add(PetSpecies.CAT);
- petCounts.add(PetSpecies.CAT);
- petCounts.add(PetSpecies.DOG);
-
-
- CustomerTransactionParameters transParams = new CustomerTransactionParameters(
- petCounts, 0.0, 0.0);
-
-
- assertEquals(transParams.countPetsBySpecies(Arrays.asList(PetSpecies.values())), 3);
- assertEquals(transParams.countPets(), 3);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersBuilder.java
deleted file mode 100644
index 0630c63..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersBuilder.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * 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.transaction;
-
-import static org.junit.Assert.assertTrue;
-
-import org.apache.bigtop.bigpetstore.datagenerator.datamodels.PetSpecies;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParameters;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParametersBuilder;
-import org.junit.Test;
-
-public class TestCustomerTransactionParametersBuilder
-{
-
- @Test
- public void testBuild() throws Exception
- {
- CustomerTransactionParametersBuilder builder = new CustomerTransactionParametersBuilder();
-
- builder.addPet(PetSpecies.DOG);
- builder.addPet(PetSpecies.DOG);
- builder.addPet(PetSpecies.DOG);
-
- builder.setAveragePurchaseTriggerTime(1.0);
- builder.setAverageTransactionTriggerTime(2.0);
-
- CustomerTransactionParameters transParams = builder.build();
-
- assertTrue(transParams.countPetsBySpecies(PetSpecies.DOG) == 3);
- assertTrue(transParams.countPetsBySpecies(PetSpecies.CAT) == 0);
- assertTrue(transParams.getAveragePurchaseTriggerTime() == 1.0);
- assertTrue(transParams.getAverageTransactionTriggerTime() == 2.0);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersSampler.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersSampler.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersSampler.java
deleted file mode 100644
index 49fa16d..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersSampler.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * 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.transaction;
-
-import static org.junit.Assert.assertTrue;
-
-import org.apache.bigtop.bigpetstore.datagenerator.Constants;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParameters;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParametersSamplerBuilder;
-import org.junit.Test;
-
-public class TestCustomerTransactionParametersSampler
-{
-
- @Test
- public void testSample() throws Exception
- {
- SeedFactory seedFactory = new SeedFactory(1234);
- CustomerTransactionParametersSamplerBuilder builder = new CustomerTransactionParametersSamplerBuilder(seedFactory);
- Sampler<CustomerTransactionParameters> sampler = builder.build();
-
- CustomerTransactionParameters transParams = sampler.sample();
-
- assertTrue(transParams.countPets() >= Constants.MIN_PETS);
- assertTrue(transParams.countPets() <= Constants.MAX_PETS);
- assertTrue(transParams.getAveragePurchaseTriggerTime() >= Constants.PURCHASE_TRIGGER_TIME_MIN);
- assertTrue(transParams.getAveragePurchaseTriggerTime() <= Constants.PURCHASE_TRIGGER_TIME_MAX);
- assertTrue(transParams.getAverageTransactionTriggerTime() >= Constants.TRANSACTION_TRIGGER_TIME_MIN);
- assertTrue(transParams.getAverageTransactionTriggerTime() <= Constants.TRANSACTION_TRIGGER_TIME_MAX);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersSamplerBuilder.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersSamplerBuilder.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersSamplerBuilder.java
deleted file mode 100644
index fbe4e08..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersSamplerBuilder.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * 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.transaction;
-
-import static org.junit.Assert.assertTrue;
-
-import org.apache.bigtop.bigpetstore.datagenerator.Constants;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParameters;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParametersSamplerBuilder;
-import org.junit.Test;
-
-public class TestCustomerTransactionParametersSamplerBuilder
-{
-
- @Test
- public void testBuild() throws Exception
- {
- SeedFactory seedFactory = new SeedFactory(1234);
- CustomerTransactionParametersSamplerBuilder builder = new CustomerTransactionParametersSamplerBuilder(seedFactory);
- Sampler<CustomerTransactionParameters> sampler = builder.build();
-
- CustomerTransactionParameters transParams = sampler.sample();
-
- assertTrue(transParams.countPets() >= Constants.MIN_PETS);
- assertTrue(transParams.countPets() <= Constants.MAX_PETS);
- assertTrue(transParams.getAveragePurchaseTriggerTime() >= Constants.PURCHASE_TRIGGER_TIME_MIN);
- assertTrue(transParams.getAveragePurchaseTriggerTime() <= Constants.PURCHASE_TRIGGER_TIME_MAX);
- assertTrue(transParams.getAverageTransactionTriggerTime() >= Constants.TRANSACTION_TRIGGER_TIME_MIN);
- assertTrue(transParams.getAverageTransactionTriggerTime() <= Constants.TRANSACTION_TRIGGER_TIME_MAX);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryInventory.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryInventory.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryInventory.java
deleted file mode 100644
index dc08979..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryInventory.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/**
- * 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.transaction;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Map;
-
-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.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.products.ProductCategoryBuilder;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParameters;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParametersSamplerBuilder;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.ProductCategoryInventory;
-import org.junit.Test;
-
-import com.google.common.collect.Maps;
-
-public class TestProductCategoryInventory
-{
-
- @Test
- public void testPurchase() throws Exception
- {
- SeedFactory seedFactory = new SeedFactory(1234);
-
- CustomerTransactionParametersSamplerBuilder transParamsBuilder = new CustomerTransactionParametersSamplerBuilder(seedFactory);
- Sampler<CustomerTransactionParameters> sampler = transParamsBuilder.build();
-
- CustomerTransactionParameters parameters = sampler.sample();
-
- ProductCategoryBuilder builder = new ProductCategoryBuilder();
- builder.addApplicableSpecies(PetSpecies.DOG);
- builder.setAmountUsedPetPetAverage(1.0);
- builder.setAmountUsedPetPetVariance(1.0);
- builder.setDailyUsageRate(2.0);
-
-
- ProductCategory category = builder.build();
-
- ProductCategoryInventory inventory = new ProductCategoryInventory(category, parameters, seedFactory);
-
- assertEquals(inventory.findExhaustionTime(), 0.0, 0.0001);
- assertEquals(inventory.findRemainingAmount(0.0), 0.0, 0.0001);
-
- Map<String, Object> fields = Maps.newHashMap();
- fields.put(Constants.PRODUCT_CATEGORY, "dog food");
- fields.put(Constants.PRODUCT_QUANTITY, 30.0);
- Product product = new Product(fields);
-
- inventory.simulatePurchase(1.0, product);
-
- assertTrue(inventory.findExhaustionTime() > 1.0);
- assertTrue(inventory.findRemainingAmount(1.0) > 0.0);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryUsageSimulator.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryUsageSimulator.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryUsageSimulator.java
deleted file mode 100644
index 6c093df..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryUsageSimulator.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * 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.transaction;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
-import org.apache.commons.lang3.tuple.Pair;
-import org.junit.Test;
-
-public class TestProductCategoryUsageSimulator
-{
-
- @Test
- public void testSimulate() throws Exception
- {
- SeedFactory seedFactory = new SeedFactory(1234);
-
- ProductCategoryUsageSimulator simulator = new ProductCategoryUsageSimulator(2.0, 1.0, 1.0, seedFactory);
-
- ProductCategoryUsageTrajectory trajectory = simulator.simulate(0.0, 30.0);
-
- assertEquals(0.0, trajectory.getLastAmount(), 0.0001);
-
- Pair<Double, Double> previousEntry = trajectory.getStep(0);
- for(int i = 1; i < trajectory.size(); i++)
- {
- Pair<Double, Double> entry = trajectory.getStep(i);
- // time should move forward
- assertTrue(previousEntry.getLeft() <= entry.getLeft());
- // remaining amounts should go down
- assertTrue(previousEntry.getRight() >= entry.getRight());
- previousEntry = entry;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryUsageTrajectory.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryUsageTrajectory.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryUsageTrajectory.java
deleted file mode 100644
index 5462de2..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryUsageTrajectory.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * 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.transaction;
-
-import static org.junit.Assert.assertEquals;
-
-import org.apache.commons.lang3.tuple.Pair;
-import org.junit.Test;
-
-public class TestProductCategoryUsageTrajectory
-{
-
- @Test
- public void testTrajectory()
- {
- double initialAmount = 30.0;
- double initialTime = 0.0;
-
- ProductCategoryUsageTrajectory trajectory = new ProductCategoryUsageTrajectory(initialTime, initialAmount);
-
- assertEquals(trajectory.size(), 1);
-
- Pair<Double, Double> entry = trajectory.getStep(0);
- assertEquals(initialTime, entry.getLeft(), 0.0001);
- assertEquals(initialAmount, entry.getRight(), 0.0001);
-
- trajectory.append(1.0, 25.0);
-
- assertEquals(2, trajectory.size());
-
- entry = trajectory.getStep(1);
- assertEquals(1.0, entry.getLeft(), 0.0001);
- assertEquals(25.0, entry.getRight(), 0.0001);
-
- assertEquals(1.0, trajectory.getLastTime(), 0.0001);
- assertEquals(25.0, trajectory.getLastAmount(), 0.0001);
- }
-
- @Test
- public void testAmountAtTime()
- {
- ProductCategoryUsageTrajectory trajectory = new ProductCategoryUsageTrajectory(0.0, 30.0);
- trajectory.append(1.0, 25.0);
- trajectory.append(2.0, 20.0);
- trajectory.append(3.0, 50.0);
- trajectory.append(4.0, 40.0);
- trajectory.append(4.0, 50.0);
- trajectory.append(5.0, 30.0);
-
- assertEquals(30.0, trajectory.amountAtTime(0.5), 0.0001);
- assertEquals(50.0, trajectory.amountAtTime(4.0), 0.0001);
- assertEquals(30.0, trajectory.amountAtTime(10.0), 0.0001);
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionPurchasesHiddenMarkovModel.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionPurchasesHiddenMarkovModel.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionPurchasesHiddenMarkovModel.java
deleted file mode 100644
index 6383c2e..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionPurchasesHiddenMarkovModel.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/**
- * 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.transaction;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.List;
-import java.util.Map;
-
-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.framework.SeedFactory;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels.MarkovModel;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels.MarkovModelBuilder;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
-import org.apache.bigtop.bigpetstore.datagenerator.framework.wfs.ConditionalWeightFunction;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.products.ProductCategoryBuilder;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.MarkovPurchasingModel;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.PurchasingProcesses;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CategoryWeightFunction;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerInventory;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerInventoryBuilder;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParameters;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParametersSamplerBuilder;
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.TransactionPurchasesHiddenMarkovModel;
-import org.junit.Test;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-
-public class TestTransactionPurchasesHiddenMarkovModel
-{
-
- private List<Product> createProducts(String category)
- {
- List<Product> products = Lists.newArrayList();
-
- for(int i = 0; i < 10; i++)
- {
- Map<String, Object> fields = Maps.newHashMap();
- fields.put(Constants.PRODUCT_CATEGORY, category);
- fields.put(Constants.PRODUCT_QUANTITY, (double) (i + 1));
- Product product = new Product(fields);
- products.add(product);
- }
-
- return products;
- }
-
- private MarkovModel<Product> createMarkovModel(ProductCategory category)
- {
- MarkovModelBuilder<Product> markovBuilder = new MarkovModelBuilder<Product>();
-
- for(Product product1 : category.getProducts())
- {
- markovBuilder.addStartState(product1, 1.0);
- for(Product product2 : category.getProducts())
- {
- markovBuilder.addTransition(product1, product2, 1.0);
- }
- }
-
- return markovBuilder.build();
- }
-
- protected PurchasingProcesses createProcesses(ProductCategory dogFoodCategory,
- ProductCategory catFoodCategory, SeedFactory seedFactory)
- {
- MarkovModel<Product> dogFoodModel = createMarkovModel(dogFoodCategory);
- MarkovModel<Product> catFoodModel = createMarkovModel(catFoodCategory);
-
- Map<String, MarkovModel<Product>> models = Maps.newHashMap();
- models.put("dog food", dogFoodModel);
- models.put("cat food", catFoodModel);
-
- MarkovPurchasingModel profile = new MarkovPurchasingModel(models);
-
- return profile.buildProcesses(seedFactory);
- }
-
- protected ProductCategory createCategory(String category)
- {
- List<Product> products = createProducts(category);
-
- ProductCategoryBuilder builder = new ProductCategoryBuilder();
-
- if(category.equals("dog food"))
- {
- builder.addApplicableSpecies(PetSpecies.DOG);
- }
- else
- {
- builder.addApplicableSpecies(PetSpecies.CAT);
- }
-
- builder.setAmountUsedPetPetAverage(1.0);
- builder.setAmountUsedPetPetVariance(1.0);
- builder.setDailyUsageRate(2.0);
- builder.setCategory(category);
- builder.setTriggerPurchaseRate(1.0 / 10.0);
- builder.setTriggerPurchaseRate(1.0 / 10.0);
-
- for(Product product : products)
- {
- builder.addProduct(product);
- }
-
- return builder.build();
- }
-
- protected TransactionPurchasesHiddenMarkovModel createHMM() throws Exception
- {
- SeedFactory seedFactory = new SeedFactory(1234);
-
- ProductCategory dogFoodCategory = createCategory("dog food");
- ProductCategory catFoodCategory = createCategory("cat food");
-
- PurchasingProcesses processes = createProcesses(dogFoodCategory, catFoodCategory, seedFactory);
-
- CustomerTransactionParametersSamplerBuilder transParamsBuilder = new CustomerTransactionParametersSamplerBuilder(seedFactory);
- Sampler<CustomerTransactionParameters> sampler = transParamsBuilder.build();
-
- CustomerTransactionParameters parameters = sampler.sample();
-
- CustomerInventoryBuilder inventoryBuilder = new CustomerInventoryBuilder(parameters, seedFactory);
- inventoryBuilder.addProductCategory(dogFoodCategory);
- inventoryBuilder.addProductCategory(catFoodCategory);
- CustomerInventory inventory = inventoryBuilder.build();
-
- ConditionalWeightFunction<Double, Double> categoryWF =
- new CategoryWeightFunction(parameters.getAveragePurchaseTriggerTime());
-
- TransactionPurchasesHiddenMarkovModel hmm = new TransactionPurchasesHiddenMarkovModel(processes,
- categoryWF, inventory, seedFactory);
-
- return hmm;
- }
-
- @Test
- public void testChooseCategory() throws Exception
- {
- TransactionPurchasesHiddenMarkovModel hmm = createHMM();
-
- String category = hmm.chooseCategory(1.0, 0);
-
- assertNotNull(category);
- assertTrue(category.equals(TransactionPurchasesHiddenMarkovModel.STOP_STATE) ||
- category.equals("dog food") ||
- category.equals("cat food"));
- }
-
- @Test
- public void testChooseProduct() throws Exception
- {
- TransactionPurchasesHiddenMarkovModel hmm = createHMM();
-
- Product product = hmm.chooseProduct("dog food");
-
- assertNotNull(product);
- assertTrue(product.getFieldValue(Constants.PRODUCT_CATEGORY).equals("dog food"));
-
- product = hmm.chooseProduct("cat food");
-
- assertNotNull(product);
- assertTrue(product.getFieldValue(Constants.PRODUCT_CATEGORY).equals("cat food"));
- }
-
- @Test
- public void testSample() throws Exception
- {
- TransactionPurchasesHiddenMarkovModel hmm = createHMM();
-
- List<Product> purchase = hmm.sample(1.0);
-
- assertTrue(purchase.size() > 0);
-
- for(int i = 0; i < purchase.size(); i++)
- {
- Product product = purchase.get(i);
-
- // first product should never be null
- assertNotNull(product);
- assertTrue(product.getFieldValue(Constants.PRODUCT_CATEGORY).equals("dog food") ||
- product.getFieldValue(Constants.PRODUCT_CATEGORY).equals("cat food"));
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/15af83eb/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionTimePDF.java
----------------------------------------------------------------------
diff --git a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionTimePDF.java b/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionTimePDF.java
deleted file mode 100644
index 6c2bf31..0000000
--- a/bigtop-data-generators/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionTimePDF.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * 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.transaction;
-
-import static org.junit.Assert.assertEquals;
-
-import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.TransactionTimePDF;
-import org.junit.Test;
-
-public class TestTransactionTimePDF
-{
-
- @Test
- public void testProbability() throws Exception
- {
- TransactionTimePDF pdf = new TransactionTimePDF();
-
- assertEquals(pdf.probability(0.5, 0.75), 0.0, 0.000001);
- assertEquals(pdf.probability(0.5, 0.5), 1.0, 0.000001);
- assertEquals(pdf.probability(0.75, 0.5), 1.0, 0.000001);
- }
-}