-
Notifications
You must be signed in to change notification settings - Fork 6
/
DataSetGenerator.java
239 lines (224 loc) · 7.36 KB
/
DataSetGenerator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
package com.geet.mining.dataset;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import com.geet.mining.model.Event;
import com.geet.mining.model.Issue;
import com.geet.mining.model.Status;
import com.geet.mining.model.Transaction;
import com.geet.mining.model.Transaction.TransactionBuilder;
import com.geet.mining.model.TransactionModule;
public class DataSetGenerator {
static Set<TransactionModule> modules;
static Set<Event> allEvents = new HashSet<Event>();
static List<String> moduleString = new ArrayList<String>();
public DataSetGenerator() {
initializeModules();
}
private static void initializeEvents() {
allEvents.add(new Event("a"));
allEvents.add(new Event("b"));
allEvents.add(new Event("c"));
allEvents.add(new Event("d"));
allEvents.add(new Event("e"));
allEvents.add(new Event("x1"));
allEvents.add(new Event("x2"));
allEvents.add(new Event("x3"));
allEvents.add(new Event("x4"));
allEvents.add(new Event("x5"));
allEvents.add(new Event("x6"));
allEvents.add(new Event("x7"));
allEvents.add(new Event("x8"));
allEvents.add(new Event("y1"));
allEvents.add(new Event("y2"));
allEvents.add(new Event("p"));
allEvents.add(new Event("q"));
allEvents.add(new Event("k"));
allEvents.add(new Event("z"));
}
private static Event getEvent(String evStr) {
for (Event event : allEvents) {
if (event.getEventString().equals(evStr)) {
return event.clone();
}
}
return null;
}
public Issue getRandomIssue(){
Issue randomIssue=new Issue(executeRandomTransactions());
return randomIssue;
}
private static void initializeModules() {
initializeEvents();
TransactionModule module = new TransactionModule();
Set<Event> events = new HashSet<Event>();
modules = new HashSet<TransactionModule>();
// New Instance Starts //
module = new TransactionModule();
events = new HashSet<Event>();
events.add(getEvent("a"));
events.add(getEvent("b"));
events.add(getEvent("x1"));
events.add(getEvent("x2"));
events.add(getEvent("x3"));
events.add(getEvent("x4"));
events.add(getEvent("x5"));
events.add(getEvent("x6"));
events.add(getEvent("x7"));
events.add(getEvent("x8"));
events.add(getEvent("z"));
module.eventSet = Event.getClonedEvents(events);
module.transactionID = "T1";
moduleString.add(module.transactionID);
modules.add(module);
// New Instance Ends //
// New Instance Starts //
module = new TransactionModule();
events = new HashSet<Event>();
events.add(getEvent("a"));
events.add(getEvent("b"));
events.add(getEvent("p"));
events.add(getEvent("z"));
module.eventSet = Event.getClonedEvents(events);
module.transactionID = "T2";
moduleString.add(module.transactionID);
modules.add(module);
// New Instance Ends //
// New Instance Starts //
module = new TransactionModule();
events = new HashSet<Event>();
events.add(getEvent("a"));
events.add(getEvent("b"));
events.add(getEvent("q"));
events.add(getEvent("z"));
module.eventSet = Event.getClonedEvents(events);
module.transactionID = "T3";
moduleString.add(module.transactionID);
modules.add(module);
// New Instance Ends //
// New Instance Starts //
module = new TransactionModule();
events = new HashSet<Event>();
events.add(getEvent("a"));
events.add(getEvent("b"));
events.add(getEvent("k"));
events.add(getEvent("z"));
module.eventSet = Event.getClonedEvents(events);
module.transactionID = "T4";
moduleString.add(module.transactionID);
modules.add(module);
// New Instance Ends //
// New Instance Starts //
module = new TransactionModule();
events = new HashSet<Event>();
events.add(getEvent("a"));
events.add(getEvent("b"));
events.add(getEvent("c"));
events.add(getEvent("d"));
events.add(getEvent("e"));
events.add(getEvent("y1"));
events.add(getEvent("z"));
module.eventSet = Event.getClonedEvents(events);
module.transactionID = "T5";
moduleString.add(module.transactionID);
modules.add(module);
// New Instance Ends //
// New Instance Starts //
module = new TransactionModule();
events = new HashSet<Event>();
events.add(getEvent("a"));
events.add(getEvent("b"));
events.add(getEvent("c"));
events.add(getEvent("d"));
events.add(getEvent("e"));
events.add(getEvent("y2"));
events.add(getEvent("z"));
module.eventSet = Event.getClonedEvents(events);
module.transactionID = "T6";
moduleString.add(module.transactionID);
modules.add(module);
// New Instance Ends //
// New Instance Starts //
module = new TransactionModule();
events = new HashSet<Event>();
events.add(getEvent("a"));
events.add(getEvent("b"));
events.add(getEvent("c"));
events.add(getEvent("d"));
events.add(getEvent("e"));
events.add(getEvent("z"));
module.eventSet = Event.getClonedEvents(events);
module.transactionID = "T7";
moduleString.add(module.transactionID);
modules.add(module);
// New Instance Ends //
}
private static TransactionModule setTransactionModuleData(String transactionID,int fail, int succ){
TransactionModule transactionModule = new TransactionModule();
for (TransactionModule module : modules) {
if (module.transactionID.equals(transactionID)) {
transactionModule = module.toClone();
transactionModule.fail = fail;
transactionModule.succeed = succ;
return transactionModule;
}
}
return null;
}
// randomly execute transactions and results
private List<Transaction> executeRandomTransactions(){
// transactionID to be random but belongs to transaction modules type
// transaction event to random but belongs to that transaction module type
// transaction status to be random either 0 or 1 referring success or failure
List<Transaction> transactions = new ArrayList<Transaction>();
Random random = new Random();
int moduleSize = modules.size();
int counter = 0;
while (counter < 100 || random.nextBoolean()) {
// first transaction ID
int moduleToPick = random.nextInt(moduleSize);
TransactionModule transactionModule= setTransactionModuleData(moduleString.get(moduleToPick),0,0);
for (Event event:transactionModule.eventSet) {
String transactionID = transactionModule.transactionID;
Status transactionStatus = Status.SUCCESS;
if (random.nextBoolean()) {
transactionStatus = Status.FAILURE;
}
Transaction transaction = new TransactionBuilder().event(event).transactionID(transactionID)
.time(System.currentTimeMillis()+"").log("log").transactionStatus(transactionStatus).build();
System.out.println(transaction);
transactions.add(transaction);
}
counter++;
}
return transactions;
}
public static void generateDataSet(){
for (int i = 0; i < 50; i++) {
try {
File dir = new File("src/com/geet/mining/input/issue_"+i);
if (!dir.exists()) {
System.out.println(dir.mkdir());;
}
FileWriter fileWriter = new FileWriter(new File(dir.getAbsolutePath()+"/logs.txt"));
List<Transaction> transactions = new DataSetGenerator().executeRandomTransactions();
for (Transaction transaction : transactions) {
System.out.println(transaction);
fileWriter.write(transaction+"\n");
}
fileWriter.close();
System.out.println(transactions.size());
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
generateDataSet();
}
}