http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreSamplerBuilder.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreSamplerBuilder.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreSamplerBuilder.java deleted file mode 100644 index b7b0a52..0000000 --- a/bigtop-bigpetstore/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/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerInventory.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerInventory.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerInventory.java deleted file mode 100644 index 322bb5e..0000000 --- a/bigtop-bigpetstore/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/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerInventoryBuilder.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerInventoryBuilder.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerInventoryBuilder.java deleted file mode 100644 index d8d6d70..0000000 --- a/bigtop-bigpetstore/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/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParameters.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParameters.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParameters.java deleted file mode 100644 index a9fdaec..0000000 --- a/bigtop-bigpetstore/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/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersBuilder.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersBuilder.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersBuilder.java deleted file mode 100644 index 0630c63..0000000 --- a/bigtop-bigpetstore/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/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersSampler.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersSampler.java deleted file mode 100644 index 49fa16d..0000000 --- a/bigtop-bigpetstore/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/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersSamplerBuilder.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersSamplerBuilder.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersSamplerBuilder.java deleted file mode 100644 index fbe4e08..0000000 --- a/bigtop-bigpetstore/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/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryInventory.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryInventory.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryInventory.java deleted file mode 100644 index dc08979..0000000 --- a/bigtop-bigpetstore/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/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryUsageSimulator.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryUsageSimulator.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryUsageSimulator.java deleted file mode 100644 index 6c093df..0000000 --- a/bigtop-bigpetstore/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/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryUsageTrajectory.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryUsageTrajectory.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryUsageTrajectory.java deleted file mode 100644 index 5462de2..0000000 --- a/bigtop-bigpetstore/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/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionPurchasesHiddenMarkovModel.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionPurchasesHiddenMarkovModel.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionPurchasesHiddenMarkovModel.java deleted file mode 100644 index 6383c2e..0000000 --- a/bigtop-bigpetstore/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/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionTimePDF.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionTimePDF.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionTimePDF.java deleted file mode 100644 index 6c2bf31..0000000 --- a/bigtop-bigpetstore/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); - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/README.md ---------------------------------------------------------------------- diff --git a/bigtop-data-generators/bigpetstore-data-generator/README.md b/bigtop-data-generators/bigpetstore-data-generator/README.md new file mode 100644 index 0000000..1acfe90 --- /dev/null +++ b/bigtop-data-generators/bigpetstore-data-generator/README.md @@ -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. +--> +BigPetStore Data Generator +========================== + +BigPetStore ... + +Data Generator ... + +======= +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/bigpetstore-data-generator-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 + + +Running the Data Generator +-------------------------- +The data generator can be used as a library (for incorporating in +Hadoop or Spark applications) or using a command-line interface. +The data generator CLI requires several parameters. To get +descriptions: + + $ java -jar build/libs/bigpetstore-data-generator-0.9.0-SNAPSHOT.jar + +Here is an example for generating 10 stores, 1000 customers, 100 purchasing models, +and a year of transactions: + + $ java -jar build/libs/bigpetstore-data-generator-0.9.0-SNAPSHOT.jar generatedData/ 10 1000 100 365.0 + + +Groovy Drivers for Scripting +---------------------------- +Several Groovy example script drivers are included in the `groovy_example_drivers` directory. +Groovy scripts can be used to easily call and interact with classes in the data generator +jar without having to create separate Java projects or worry about compilation. I've found +them to be very useful for interactive exploration and validating my implementations +when unit tests alone aren't sufficient. + +To use Groovy scripts, you will need to have Groovy installed on your system. Build the +data generator as instructed above. Then run the scripts in the `groovy_example_drivers` +directory as so: + + $ groovy -classpath ../build/libs/bigpetstore-data-generator-0.9.0-SNAPSHOT.jar MonteCarloExponentialSamplingExample.groovy + http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/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 new file mode 100644 index 0000000..8c2ea57 --- /dev/null +++ b/bigtop-data-generators/bigpetstore-data-generator/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 = '0.9.0-SNAPSHOT' + +jar { + + from { + configurations.runtime.collect { + it.isDirectory() ? it : zipTree(it) + } + } + + manifest { + attributes 'Title': 'BigPetStore Data Generator', 'Version': version + attributes 'Main-Class': 'org.apache.bigtop.bigpetstore.datagenerator.cli.Driver' + } +} + +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 'com.google.code.gson:gson:2.3' + compile 'org.apache.commons:commons-lang3:3.4' + + testCompile 'junit:junit:4.+' +} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/groovy_example_drivers/MonteCarloExponentialSamplingExample.groovy ---------------------------------------------------------------------- diff --git a/bigtop-data-generators/bigpetstore-data-generator/groovy_example_drivers/MonteCarloExponentialSamplingExample.groovy b/bigtop-data-generators/bigpetstore-data-generator/groovy_example_drivers/MonteCarloExponentialSamplingExample.groovy new file mode 100644 index 0000000..7f11fed --- /dev/null +++ b/bigtop-data-generators/bigpetstore-data-generator/groovy_example_drivers/MonteCarloExponentialSamplingExample.groovy @@ -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. + */ +import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.MonteCarloSampler +import org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs.ExponentialPDF +import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.UniformSampler +import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory + +averageValue = 2.0 + +seedFactory = new SeedFactory() +uniformSampler = new UniformSampler(0.0, 100.0, seedFactory) +pdf = new ExponentialPDF(1.0 / averageValue) + + +mcSampler = new MonteCarloSampler(uniformSampler, pdf, seedFactory) + +sample = mcSampler.sample() + +println("Sampled the value: " + sample) + +sampleSum = 0.0 +for(int i = 0; i < 10000; i++) +{ + sampleSum += mcSampler.sample() +} + +sampleAverage = sampleSum / 10000.0 + +println("Expected Average: " + averageValue) +println("Observed Average: " + sampleAverage) + http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/groovy_example_drivers/MonteCarloGaussianSamplingExample.groovy ---------------------------------------------------------------------- diff --git a/bigtop-data-generators/bigpetstore-data-generator/groovy_example_drivers/MonteCarloGaussianSamplingExample.groovy b/bigtop-data-generators/bigpetstore-data-generator/groovy_example_drivers/MonteCarloGaussianSamplingExample.groovy new file mode 100644 index 0000000..ebffc91 --- /dev/null +++ b/bigtop-data-generators/bigpetstore-data-generator/groovy_example_drivers/MonteCarloGaussianSamplingExample.groovy @@ -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. + */ +import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.MonteCarloSampler +import org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs.GaussianPDF +import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.UniformSampler +import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory + +averageValue = 10.0 +stdValue = 2.0 + +seedFactory = new SeedFactory() +uniformSampler = new UniformSampler(-100.0, 100.0, seedFactory) +pdf = new GaussianPDF(averageValue, stdValue) + + +mcSampler = new MonteCarloSampler(uniformSampler, pdf, seedFactory) + +sample = mcSampler.sample() + +println("Sampled the value: " + sample) + +sampleSum = 0.0 +for(int i = 0; i < 100000; i++) +{ + sampleSum += mcSampler.sample() +} + +sampleAverage = sampleSum / 100000.0 + +println("Expected Average: " + averageValue) +println("Observed Average: " + sampleAverage) + http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/settings.gradle ---------------------------------------------------------------------- diff --git a/bigtop-data-generators/bigpetstore-data-generator/settings.gradle b/bigtop-data-generators/bigpetstore-data-generator/settings.gradle new file mode 100644 index 0000000..cf398e8 --- /dev/null +++ b/bigtop-data-generators/bigpetstore-data-generator/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 = "bigpetstore-data-generator" \ No newline at end of file http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/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 new file mode 100644 index 0000000..ff87c2e --- /dev/null +++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/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.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/3bbbb557/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 new file mode 100644 index 0000000..799b2e3 --- /dev/null +++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/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.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/3bbbb557/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 new file mode 100644 index 0000000..a67acd7 --- /dev/null +++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/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.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/3bbbb557/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 new file mode 100644 index 0000000..cd008ac --- /dev/null +++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/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.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/3bbbb557/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 new file mode 100644 index 0000000..6994d9e --- /dev/null +++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/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.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/3bbbb557/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 new file mode 100644 index 0000000..df6d759 --- /dev/null +++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/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.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/3bbbb557/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 new file mode 100644 index 0000000..8f78bb7 --- /dev/null +++ b/bigtop-data-generators/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/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.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(); + } +}
