3
3
4
4
import ldbc .snb .datagen .dictionary .Dictionaries ;
5
5
import ldbc .snb .datagen .objects .*;
6
+ import ldbc .snb .datagen .serializer .PersonActivityExporter ;
6
7
import ldbc .snb .datagen .serializer .PersonActivitySerializer ;
7
8
import ldbc .snb .datagen .serializer .UpdateEventSerializer ;
8
9
import ldbc .snb .datagen .util .FactorTable ;
@@ -29,23 +30,22 @@ public class PersonActivityGenerator {
29
30
private long forumId = 0 ;
30
31
private long messageId = 0 ;
31
32
private FactorTable factorTable_ ;
33
+ private PersonActivityExporter exporter_ ;
32
34
33
35
public PersonActivityGenerator ( PersonActivitySerializer serializer , UpdateEventSerializer updateSerializer ) {
34
36
personActivitySerializer_ = serializer ;
35
37
updateSerializer_ = updateSerializer ;
36
38
randomFarm_ = new RandomGeneratorFarm ();
37
- // load generators
38
39
forumGenerator_ = new ForumGenerator ();
39
- //david
40
40
Random random = new Random ();
41
41
TextGenerator generator = new LdbcSnbTextGenerator (random , Dictionaries .tags );
42
- //d: end
43
- uniformPostGenerator_ = new UniformPostGenerator (generator );
44
- flashmobPostGenerator_ = new FlashmobPostGenerator (generator );
45
- photoGenerator_ = new PhotoGenerator ();
46
- commentGenerator_ = new CommentGenerator (generator );
47
- likeGenerator_ = new LikeGenerator ();
42
+ likeGenerator_ = new LikeGenerator ();
43
+ commentGenerator_ = new CommentGenerator (generator , likeGenerator_ );
44
+ uniformPostGenerator_ = new UniformPostGenerator (generator , commentGenerator_ , likeGenerator_ );
45
+ flashmobPostGenerator_ = new FlashmobPostGenerator (generator , commentGenerator_ , likeGenerator_ );
46
+ photoGenerator_ = new PhotoGenerator (likeGenerator_ );
48
47
factorTable_ = new FactorTable ();
48
+ exporter_ = new PersonActivityExporter (personActivitySerializer_ , updateSerializer_ , factorTable_ );
49
49
}
50
50
51
51
private void generateActivity ( Person person , ArrayList <Person > block ) {
@@ -70,9 +70,9 @@ public void reset() {
70
70
private void generateWall ( Person person , ArrayList <Person > block ) {
71
71
// generate wall
72
72
Forum wall = forumGenerator_ .createWall (randomFarm_ , forumId ++, person );
73
- export (wall );
73
+ exporter_ . export (wall );
74
74
for ( ForumMembership fm : wall .memberships ()) {
75
- export (fm );
75
+ exporter_ . export (fm );
76
76
}
77
77
78
78
// generate wall posts
@@ -81,36 +81,8 @@ private void generateWall( Person person, ArrayList<Person> block ) {
81
81
);
82
82
ArrayList <ForumMembership > fakeMembers = new ArrayList <ForumMembership >();
83
83
fakeMembers .add (personMembership );
84
- ArrayList <Post > wallPosts = uniformPostGenerator_ .createPosts (randomFarm_ , wall , fakeMembers , numPostsPerGroup (randomFarm_ , wall , DatagenParams .maxNumPostPerMonth , DatagenParams .maxNumFriends ), messageId );
85
- long aux = messageId + wallPosts .size ();
86
- wallPosts .addAll (flashmobPostGenerator_ .createPosts (randomFarm_ , wall , fakeMembers , numPostsPerGroup (randomFarm_ , wall , DatagenParams .maxNumFlashmobPostPerMonth , DatagenParams .maxNumFriends ), aux ));
87
- messageId +=wallPosts .size ();
88
-
89
- for ( Post p : wallPosts ) {
90
- export (p );
91
- // generate likes to post
92
- if ( randomFarm_ .get (RandomGeneratorFarm .Aspect .NUM_LIKE ).nextDouble () <= 0.1 ) {
93
- ArrayList <Like > postLikes = likeGenerator_ .generateLikes (randomFarm_ .get (RandomGeneratorFarm .Aspect .NUM_LIKE ), wall , p , Like .LikeType .POST );
94
- for ( Like l : postLikes ) {
95
- export (l );
96
- }
97
- }
98
- //// generate comments
99
- int numComments = randomFarm_ .get (RandomGeneratorFarm .Aspect .NUM_COMMENT ).nextInt (DatagenParams .maxNumComments +1 );
100
- ArrayList <Comment > comments = commentGenerator_ .createComments (randomFarm_ , wall , p , numComments , messageId );
101
- messageId +=comments .size ();
102
- for ( Comment c : comments ) {
103
- export (c );
104
- // generate likes to comments
105
- if ( c .content ().length () > 10 && randomFarm_ .get (RandomGeneratorFarm .Aspect .NUM_LIKE ).nextDouble () <= 0.1 ) {
106
- ArrayList <Like > commentLikes = likeGenerator_ .generateLikes (randomFarm_ .get (RandomGeneratorFarm .Aspect .NUM_LIKE ), wall , c , Like .LikeType .COMMENT );
107
- for ( Like l : commentLikes ) {
108
- export (l );
109
- }
110
- }
111
- }
112
- }
113
-
84
+ messageId = uniformPostGenerator_ .createPosts (randomFarm_ , wall , fakeMembers , numPostsPerGroup (randomFarm_ , wall , DatagenParams .maxNumPostPerMonth , DatagenParams .maxNumFriends ), messageId , exporter_ );
85
+ messageId = flashmobPostGenerator_ .createPosts (randomFarm_ , wall , fakeMembers , numPostsPerGroup (randomFarm_ , wall , DatagenParams .maxNumFlashmobPostPerMonth , DatagenParams .maxNumFriends ), messageId , exporter_ );
114
86
}
115
87
116
88
private void generateGroups ( Person person , ArrayList <Person > block ) {
@@ -120,41 +92,15 @@ private void generateGroups( Person person, ArrayList<Person> block ) {
120
92
int numGroup = randomFarm_ .get (RandomGeneratorFarm .Aspect .NUM_FORUM ).nextInt (DatagenParams .maxNumGroupCreatedPerUser )+1 ;
121
93
for (int j = 0 ; j < numGroup ; j ++) {
122
94
Forum group = forumGenerator_ .createGroup (randomFarm_ , forumId ++, person , block );
123
- export (group );
95
+ exporter_ . export (group );
124
96
125
97
for ( ForumMembership fm : group .memberships ()) {
126
- export (fm );
98
+ exporter_ . export (fm );
127
99
}
128
100
129
101
// generate uniform posts/comments
130
- ArrayList <Post > groupPosts = uniformPostGenerator_ .createPosts (randomFarm_ , group , group .memberships (), numPostsPerGroup (randomFarm_ , group , DatagenParams .maxNumGroupPostPerMonth , DatagenParams .maxNumMemberGroup ), messageId );
131
- long aux = messageId +groupPosts .size ();
132
- groupPosts .addAll (flashmobPostGenerator_ .createPosts (randomFarm_ , group , group .memberships (), numPostsPerGroup (randomFarm_ , group , DatagenParams .maxNumGroupFlashmobPostPerMonth , DatagenParams .maxNumMemberGroup ),aux ));
133
- messageId += groupPosts .size ();
134
- for ( Post p : groupPosts ) {
135
- export (p );
136
- // generate likes to post
137
- if ( randomFarm_ .get (RandomGeneratorFarm .Aspect .NUM_LIKE ).nextDouble () <= 0.1 ) {
138
- ArrayList <Like > postLikes = likeGenerator_ .generateLikes (randomFarm_ .get (RandomGeneratorFarm .Aspect .NUM_LIKE ), group , p , Like .LikeType .POST );
139
- for ( Like l : postLikes ) {
140
- export (l );
141
- }
142
- }
143
- // generate comments
144
- int numComments = randomFarm_ .get (RandomGeneratorFarm .Aspect .NUM_COMMENT ).nextInt (DatagenParams .maxNumComments +1 );
145
- ArrayList <Comment > comments = commentGenerator_ .createComments (randomFarm_ , group , p , numComments , messageId );
146
- messageId +=comments .size ();
147
- for ( Comment c : comments ) {
148
- export (c );
149
- // generate likes to comments
150
- if ( c .content ().length () > 10 && randomFarm_ .get (RandomGeneratorFarm .Aspect .NUM_LIKE ).nextDouble () <= 0.1 ) {
151
- ArrayList <Like > commentLikes = likeGenerator_ .generateLikes (randomFarm_ .get (RandomGeneratorFarm .Aspect .NUM_LIKE ), group , c , Like .LikeType .COMMENT );
152
- for ( Like l : commentLikes ) {
153
- export (l );
154
- }
155
- }
156
- }
157
- }
102
+ messageId = uniformPostGenerator_ .createPosts (randomFarm_ , group , group .memberships (), numPostsPerGroup (randomFarm_ , group , DatagenParams .maxNumGroupPostPerMonth , DatagenParams .maxNumMemberGroup ), messageId , exporter_ );
103
+ messageId = flashmobPostGenerator_ .createPosts (randomFarm_ , group , group .memberships (), numPostsPerGroup (randomFarm_ , group , DatagenParams .maxNumGroupFlashmobPostPerMonth , DatagenParams .maxNumMemberGroup ),messageId , exporter_ );
158
104
}
159
105
}
160
106
@@ -169,10 +115,10 @@ private void generateAlbums(Person person, ArrayList<Person> block ) {
169
115
}
170
116
for (int i = 0 ; i < numPhotoAlbums ; i ++) {
171
117
Forum album = forumGenerator_ .createAlbum (randomFarm_ , forumId ++, person , i );
172
- export (album );
118
+ exporter_ . export (album );
173
119
174
120
for ( ForumMembership fm : album .memberships ()) {
175
- export (fm );
121
+ exporter_ . export (fm );
176
122
}
177
123
178
124
ForumMembership personMembership = new ForumMembership (album .id (),
@@ -181,18 +127,7 @@ private void generateAlbums(Person person, ArrayList<Person> block ) {
181
127
ArrayList <ForumMembership > fakeMembers = new ArrayList <ForumMembership >();
182
128
fakeMembers .add (personMembership );
183
129
int numPhotos = randomFarm_ .get (RandomGeneratorFarm .Aspect .NUM_PHOTO ).nextInt (DatagenParams .maxNumPhotoPerAlbums +1 );
184
- ArrayList <Photo > photos = photoGenerator_ .createPhotos (randomFarm_ , album , fakeMembers , numPhotos , messageId );
185
- messageId +=photos .size ();
186
- for ( Photo p : photos ) {
187
- export (p );
188
- // generate likes
189
- if ( randomFarm_ .get (RandomGeneratorFarm .Aspect .NUM_LIKE ).nextDouble () <= 0.1 ) {
190
- ArrayList <Like > photoLikes = likeGenerator_ .generateLikes (randomFarm_ .get (RandomGeneratorFarm .Aspect .NUM_LIKE ), album , p , Like .LikeType .PHOTO );
191
- for ( Like l : photoLikes ) {
192
- export (l );
193
- }
194
- }
195
- }
130
+ messageId = photoGenerator_ .createPhotos (randomFarm_ , album , fakeMembers , numPhotos , messageId , exporter_ );
196
131
}
197
132
}
198
133
@@ -237,58 +172,6 @@ public void generateActivityForBlock( int seed, ArrayList<Person> block, Context
237
172
System .out .println ("Average person activity generation time " +personGenerationTime / (float )block .size ());
238
173
}
239
174
240
- private void export (Forum forum ) {
241
- if (forum .creationDate () < Dictionaries .dates .getUpdateThreshold () || !DatagenParams .updateStreams ) {
242
- personActivitySerializer_ .export (forum );
243
- } else {
244
- updateSerializer_ .export (forum );
245
- }
246
- }
247
-
248
- private void export (Post post ) {
249
- if (post .creationDate () < Dictionaries .dates .getUpdateThreshold () || !DatagenParams .updateStreams ) {
250
- personActivitySerializer_ .export (post );
251
- factorTable_ .extractFactors (post );
252
- } else {
253
- updateSerializer_ .export (post );
254
- }
255
- }
256
-
257
- private void export (Comment comment ) {
258
- if (comment .creationDate () < Dictionaries .dates .getUpdateThreshold () || !DatagenParams .updateStreams ) {
259
- personActivitySerializer_ .export (comment );
260
- factorTable_ .extractFactors (comment );
261
- } else {
262
- updateSerializer_ .export (comment );
263
- }
264
- }
265
-
266
- private void export (Photo photo ) {
267
- if (photo .creationDate () < Dictionaries .dates .getUpdateThreshold () || !DatagenParams .updateStreams ) {
268
- personActivitySerializer_ .export (photo );
269
- factorTable_ .extractFactors (photo );
270
- } else {
271
- updateSerializer_ .export (photo );
272
- }
273
- }
274
-
275
- private void export (ForumMembership member ) {
276
- if (member .creationDate () < Dictionaries .dates .getUpdateThreshold () || !DatagenParams .updateStreams ) {
277
- personActivitySerializer_ .export (member );
278
- factorTable_ .extractFactors (member );
279
- } else {
280
- updateSerializer_ .export (member );
281
- }
282
- }
283
-
284
- private void export (Like like ) {
285
- if (like .date < Dictionaries .dates .getUpdateThreshold () || !DatagenParams .updateStreams ) {
286
- personActivitySerializer_ .export (like );
287
- factorTable_ .extractFactors (like );
288
- } else {
289
- updateSerializer_ .export (like );
290
- }
291
- }
292
175
293
176
public void writeFactors ( OutputStream writer ) {
294
177
factorTable_ .write (writer );
0 commit comments