Created
July 23, 2013 12:56
-
-
Save mwacc/6062165 to your computer and use it in GitHub Desktop.
Product list generator for BasketAnalys example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Constants { | |
static final goods = [ | |
'Apple', 'Orange', 'Pineaple', 'Cherry', 'Beef', 'Sugar', 'Milk', | |
'Pear', 'Limon', 'Blubbery', 'IceCream', 'Cake', 'Orange', 'Milk', | |
'Cola', 'Bread', 'Coffe', 'Cookies', 'Beer', 'Tea', 'Salmon', 'Steal Water', 'Nuts'] | |
} | |
rand = new Random() | |
def createProduct() { | |
return Constants.goods[ rand.nextInt( Constants.goods.size() ) ] | |
} | |
def createTransaction(int itemsNum) { | |
List<String> list = new ArrayList<String>(); | |
for(int i = 0; i < itemsNum; i++) { | |
String newProduct = createProduct(); | |
if(list.contains(newProduct)) { | |
i--; | |
}else{ | |
list.add(newProduct); | |
} | |
} | |
// create relation betweens Steal Water and Nuts | |
if(list.contains('Nuts') && !list.contains('Steal Water') && (rand.nextInt(10)+1) % 7 != 0) { | |
list.add('Steal Water') | |
} | |
return list.join(',') | |
} | |
def createDataSet(int recordsNum) { | |
for(int i = 0; i < recordsNum; i++){ | |
System.out.println( createTransaction(rand.nextInt(5)+4) ) | |
} | |
} | |
createDataSet(250) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment