Esempio n. 1
0
def createUserColls(db: pymongo.MongoClient, followFactor: float) -> None:

    users: list[User] = []
    rankings: list[perf.Ranking] = []
    perfs: list[perf.Perf] = []
    relations: list[Relation] = []
    history: list[History] = []
    fideMap = {}

    for uid in gen.uids:
        users.append(User(uid))
        for stat in users[-1].detachPerfs():
            perfs.append(stat)
            rankings.append(stat.getRanking())
        gen.fideMap[uid] = users[-1].profile["fideRating"]
        history.append(History(users[-1]))

    users.extend(User.createSpecialUsers())
    for u in users:
        for f in random.sample(gen.uids, int(followFactor * len(gen.uids))):
            evt.follow(u._id, util.timeSince(u.createdAt), f)

    util.bulkwrite(db.pref, [pref.Pref(u._id) for u in users])
    util.bulkwrite(db.user4, users)
    util.bulkwrite(db.ranking, rankings)
    util.bulkwrite(db.perf_stat, perfs)
    util.bulkwrite(db.history4, history)
Esempio n. 2
0
def createBlogColls(db: pymongo.MongoClient, numBlogs: int) -> None:
    ublogs: list = []
    uposts: list = []

    for (numPosts,
         uid) in zip(util.randomPartition(numBlogs, len(gen.uids), 0),
                     gen.uids):
        if numPosts == 0:
            continue
        ublogs.append(UBlog(uid))
        for _ in range(numPosts):
            uposts.append(UBlogPost(uid))

    util.bulkwrite(db.ublog_blog, ublogs)
    util.bulkwrite(db.ublog_post, uposts)
Esempio n. 3
0
def createTeamColls(db: pymongo.MongoClient, totalNumPosts: int) -> None:

    if len(gen.teams) == 0:
        return

    categs: list[forum.Categ] = []
    topics: list[forum.Topic] = []
    posts: list[forum.Post] = []
    teams: list[Team] = []
    allMembers: list[TeamMember] = []
    numTeamPostsList = util.randomPartition(totalNumPosts, len(gen.teams))

    for (teamName, numTeamPosts) in zip(gen.teams, numTeamPostsList):

        t = Team(teamName)
        teams.append(t)
        evt.addTeam(t.createdBy, t.createdAt, t._id, t.name)
        categs.append(forum.Categ(teamName, True))

        teamMembers = t.createMembers()
        for m in teamMembers:
            if m.user != t.createdBy:
                evt.joinTeam(m.user, util.timeSince(t.createdAt), t._id,
                             t.name)

        allMembers.extend(teamMembers)

        for numPosts in util.randomPartition(numTeamPosts,
                                             int(numTeamPosts / 10) + 1):
            if numPosts == 0:
                continue
            t = forum.Topic(random.choice(gen.topics), categs[-1]._id)
            topics.append(t)
            for _ in range(numPosts):
                p = forum.Post(random.choice(teamMembers).user)
                posts.append(p)
                t.correlatePost(p)
                evt.addPost(p.userId, p.createdAt, p._id, t._id, t.name)
            categs[-1].addTopic(t)

    util.bulkwrite(db.f_categ, categs, True)
    util.bulkwrite(db.f_topic, topics, True)
    util.bulkwrite(db.f_post, posts, True)
    util.bulkwrite(db.team, teams)
    util.bulkwrite(db.team_member, allMembers)
Esempio n. 4
0
def createForumColls(db: pymongo.MongoClient, numPosts: int) -> None:

    if numPosts < 1:
        return

    categs: dict[str, Categ] = {}
    topics: list[Topic] = []
    posts: list[Post] = []

    for catName in gen.categs:
        categ = Categ(catName)
        categs[categ._id] = categ
    for topicName in gen.topics:
        topics.append(Topic(topicName, random.choice(list(categs.keys()))))
    for _ in range(numPosts):
        p = Post(gen.randomUid())
        posts.append(p)
        t = random.choice(topics)
        t.correlatePost(p)
        evt.addPost(p.userId, p.createdAt, p._id, t._id, t.name)

    # don't keep topics that didn't get randomly assigned any posts
    [categs[t.categId].addTopic(t) for t in topics if hasattr(t, "lastPostId")]

    # now we can write everything
    util.bulkwrite(db.f_categ, categs.values())
    util.bulkwrite(db.f_topic, topics)
    util.bulkwrite(db.f_post, posts)
Esempio n. 5
0
def createGameColls(db: pymongo.MongoClient) -> None:

    games: list[game.Game] = []
    crosstable: dict[str, Result] = {}

    # TODO: integrate fideMap wherever
    for bsonGame in gen.games:
        us = random.sample(gen.uids, 2)
        g = Game(bsonGame, us[0], us[1])
        games.append(g)
        evt.addGame(us[0], g.ca, us[1], g.outcome(us[0]),
                    g._id + g.__dict__["is"][0:4])
        evt.addGame(us[1], g.ca, us[0], g.outcome(us[1]),
                    g._id + g.__dict__["is"][4:])

        id: str = f"{us[0]}/{us[1]}" if us[0] < us[1] else f"{us[1]}/{us[0]}"
        crosstable.setdefault(id, Result(id)).addGame(g)

    util.bulkwrite(db.game5, games)
    util.bulkwrite(db.puzzle2_path, [ObjWrapper(pp) for pp in gen.puzzlePaths])
    util.bulkwrite(db.puzzle2_puzzle, [ObjWrapper(p) for p in gen.puzzles])
    # TODO find out why crosstable and matchup are separate slices of what could be same collection
    util.bulkwrite(db.crosstable2, crosstable.values())
    util.bulkwrite(db.matchup, crosstable.values())
Esempio n. 6
0
def createEventColls(db: pymongo.MongoClient) -> None:
    activities: list[dict] = []
    relations: list[Relation] = []

    for (days, udicts) in sorted(evt.activityMap.items()):
        activities.extend(udicts.values())
    for uid in evt.relationMap.keys():
        relations.extend([Relation(uid, f) for f in evt.relationMap[uid]])

    util.bulkwrite(db.relation, relations)
    util.bulkwrite(db.activity2, activities)
    util.bulkwrite(db.timeline_entry, evt.timeline)