use of ldbc.snb.datagen.entities.dynamic.Forum in project ldbc_snb_datagen_spark by ldbc.
the class PersonActivityGenerator method generateWall.
/**
* Generates the personal wall for a Person. Note, only this Person creates Posts in the wall.
*
* @param person Person
*/
private GenWall<Triplet<Post, Stream<Like>, Stream<Pair<Comment, Stream<Like>>>>> generateWall(Person person, long blockId) {
// Generate wall
Forum wall = forumGenerator.createWall(randomFarm, startForumId++, person, blockId);
// Could be null as moderator can't be added
if (wall == null)
return new GenWall<>(Stream.empty());
// creates a forum membership for the moderator
// only the moderator can post on their wall
ForumMembership moderator = new ForumMembership(wall.getId(), wall.getCreationDate() + DatagenParams.delta, wall.getDeletionDate(), new PersonSummary(person), Forum.ForumType.WALL, false);
// list of members who can post on the wall - only moderator of wall can post on it
List<ForumMembership> memberships = new ArrayList<>();
memberships.add(moderator);
Stream<Triplet<Post, Stream<Like>, Stream<Pair<Comment, Stream<Like>>>>> uniform = uniformPostGenerator.createPosts(randomFarm, wall, memberships, numPostsPerGroup(randomFarm, wall, DatagenParams.maxNumPostPerMonth, DatagenParams.maxNumFriends), messageIdIterator, blockId);
Stream<Triplet<Post, Stream<Like>, Stream<Pair<Comment, Stream<Like>>>>> flashMob = flashmobPostGenerator.createPosts(randomFarm, wall, memberships, numPostsPerGroup(randomFarm, wall, DatagenParams.maxNumFlashmobPostPerMonth, DatagenParams.maxNumFriends), messageIdIterator, blockId);
return new GenWall<>(Stream.of(new Triplet<>(wall, wall.getMemberships().stream(), Stream.concat(uniform, flashMob))));
}
use of ldbc.snb.datagen.entities.dynamic.Forum in project ldbc_snb_datagen_spark by ldbc.
the class PostGenerator method createPosts.
public Stream<Triplet<Post, Stream<Like>, Stream<Pair<Comment, Stream<Like>>>>> createPosts(RandomGeneratorFarm randomFarm, final Forum forum, final List<ForumMembership> memberships, long numPostsInForum, Iterator<Long> idIterator, long blockId) {
Properties properties = new Properties();
properties.setProperty("type", "post");
return memberships.stream().flatMap(member -> {
// generate number of posts by this member
double numPostsPerMember = numPostsInForum / (double) memberships.size();
if (numPostsPerMember < 1.0) {
double prob = randomFarm.get(RandomGeneratorFarm.Aspect.NUM_POST).nextDouble();
if (prob < numPostsPerMember)
numPostsPerMember = 1.0;
} else {
numPostsPerMember = Math.ceil(numPostsPerMember);
}
final int numPostsPerMemberInt = (int) numPostsPerMember;
// 0 to 20
int numComments = randomFarm.get(RandomGeneratorFarm.Aspect.NUM_COMMENT).nextInt(DatagenParams.maxNumComments + 1);
return Streams.stream(Iterators.forIterator(0, i -> i < numPostsPerMemberInt, i -> ++i, i -> {
// create post core
PostCore postCore = generatePostInfo(randomFarm.get(RandomGeneratorFarm.Aspect.DELETION_POST), randomFarm.get(RandomGeneratorFarm.Aspect.TAG), randomFarm.get(RandomGeneratorFarm.Aspect.DATE), forum, member, numComments);
if (postCore == null)
return Iterators.ForIterator.CONTINUE();
// create content, county, ip - sometimes randomise
String content = this.generator.generateText(member.getPerson(), postCore.getTags(), properties);
int country = member.getPerson().getCountry();
IP ip = member.getPerson().getIpAddress();
Random random = randomFarm.get(RandomGeneratorFarm.Aspect.DIFF_IP_FOR_TRAVELER);
if (PersonBehavior.changeUsualCountry(random, postCore.getCreationDate())) {
random = randomFarm.get(RandomGeneratorFarm.Aspect.COUNTRY);
country = Dictionaries.places.getRandomCountryUniform(random);
random = randomFarm.get(RandomGeneratorFarm.Aspect.IP);
ip = Dictionaries.ips.getIP(random, country);
}
Post post = new Post();
// create post with above information and from post info
post.initialize(SN.formId(SN.composeId(idIterator.next(), postCore.getCreationDate()), blockId), postCore.getCreationDate(), postCore.getDeletionDate(), member.getPerson(), forum.getId(), content, new ArrayList<>(postCore.getTags()), country, ip, Dictionaries.browsers.getPostBrowserId(randomFarm.get(RandomGeneratorFarm.Aspect.DIFF_BROWSER), randomFarm.get(RandomGeneratorFarm.Aspect.BROWSER), member.getPerson().getBrowserId()), forum.getLanguage(), postCore.isExplicitlyDeleted());
Stream<Like> likeStream = randomFarm.get(RandomGeneratorFarm.Aspect.NUM_LIKE).nextDouble() <= 0.1 ? likeGenerator.generateLikes(randomFarm.get(RandomGeneratorFarm.Aspect.DELETION_LIKES), randomFarm.get(RandomGeneratorFarm.Aspect.NUM_LIKE), forum, post, Like.LikeType.POST) : Stream.empty();
Stream<Pair<Comment, Stream<Like>>> commentStream = commentGenerator.createComments(randomFarm, forum, post, numComments, idIterator, blockId);
return Iterators.ForIterator.RETURN(new Triplet<>(post, likeStream, commentStream));
}));
});
}
Aggregations