Ejemplo n.º 1
0
def add_leader_to_bd(leaders):
    result = []
    member = {}
    member["duration"] = leaders["map_challenge_mode_id"]
    for x in leaders["leading_groups"]:
        member["duration"] = x["duration"]
        member["completed_timestamp"] = x["completed_timestamp"]
        member["keystone_level"] = x["keystone_level"]
        member["keystone_id"] = leaders["map_challenge_mode_id"]
        for profile in x["members"]:
            member["player_id"] = profile["profile"]["id"]
            member["player_name"] = profile["profile"]["name"]
            member["player_server"] = profile["profile"]["realm"]["id"]
            member["player_faction"] = profile["faction"]["type"]
            member["player_specialization"] = profile["specialization"]["id"]
            result.append(MyC.Leaderboard(**member))
    for lead in result:
        server = db.Leaderboard(
            duration=lead.duration,
            completed_timestamp=lead.completed_timestamp,
            keystone_level=lead.keystone_level,
            keystone_id=lead.keystone_id,
            player_id=lead.player_id,
            player_name=lead.player_name,
            player_server=lead.player_server,
            player_faction=lead.player_faction,
            player_specialization=lead.player_specialization,
        )
    session_db.merge(server)
    session_db.commit()
Ejemplo n.º 2
0
    def setUp(self):
        key_input = "username"
        self.success_test_params = [
            {
                key_input:
                'player13423',
                KEY_EXPECTED:
                ["<Leaderboard 'user1'>", "<Leaderboard 'player13423'>"],
            },
            {
                key_input:
                'player2111',
                KEY_EXPECTED: [
                    "<Leaderboard 'user1'>", "<Leaderboard 'player13423'>",
                    "<Leaderboard 'player2111'>"
                ],
            },
            {
                key_input:
                'player3123',
                KEY_EXPECTED: [
                    "<Leaderboard 'user1'>", "<Leaderboard 'player13423'>",
                    "<Leaderboard 'player2111'>", "<Leaderboard 'player3123'>"
                ],
            },
        ]

        initial_person = models.Leaderboard(username=INITIAL_USERNAME,
                                            score=100)
        self.initial_db_mock = [initial_person]
Ejemplo n.º 3
0
def get_users():
    conn = get_db()
    cs = []
    for row in conn.execute("SELECT * FROM Users"):
        c = models.Leaderboard()
        c.User_Id = row[0]
        c.Username = row[1]
        c.Description = row[2]
        c.Password = row[3]
        cs.append(c)
    return cs
Ejemplo n.º 4
0
def get_leaderboards():
    conn = get_db()
    cs = []
    for row in conn.execute("SELECT * FROM Leaderboards"):
        c = models.Leaderboard()
        c.Lb_Id = row[0]
        c.User_Id = row[1]
        c.Name = row[2]
        c.Description = row[3]
        c.Genre = row[4]
        cs.append(c)
    return cs
Ejemplo n.º 5
0
def add_user(user):
    """
    Adds user to database
    """
    new_user = models.Leaderboard(username=user, score=100)
    db.session.add(new_user)
    db.session.commit()
    all_people = models.Leaderboard.query.all()
    users = []
    for person in all_people:
        users.append(person.username)
    return users
Ejemplo n.º 6
0
    def setUp(self):
        key_input = "players"
        second_key_input = "winner"
        self.success_test_params = [
            {
                key_input: ['player3', 'player4'],
                second_key_input:
                "O",
                KEY_EXPECTED: [
                    "<Leaderboard 'player1'>", 99, "<Leaderboard 'player2'>",
                    101
                ],
            },
            {
                key_input: ['player3', 'player4'],
                second_key_input:
                "O",
                KEY_EXPECTED: [
                    "<Leaderboard 'player1'>", 98, "<Leaderboard 'player2'>",
                    102
                ],
            },
            {
                key_input: ['player3', 'player4'],
                second_key_input:
                "Draw",
                KEY_EXPECTED: [
                    "<Leaderboard 'player1'>", 98, "<Leaderboard 'player2'>",
                    102
                ],
            },
        ]

        initial_person1 = models.Leaderboard(username='******', score=100)
        initial_person2 = models.Leaderboard(username='******', score=100)
        self.initial_db_mock = [initial_person1, initial_person2]
Ejemplo n.º 7
0
def new_user_helper(userdata):
    '''Helper for on_new_user function'''
    user_check = DB.session.query(
        models.Leaderboard).filter_by(username=userdata['username']).first()
    if user_check is None:
        new_user = models.Leaderboard(username=userdata['username'], score=100)
        DB.session.add(new_user)
        DB.session.commit()
    active_user_check = DB.session.query(
        models.Active).filter_by(name=userdata['username']).first()
    if active_user_check is None:
        new_active_user = models.Active(name=userdata['username'])
        DB.session.add(new_active_user)
        DB.session.commit()
    all_people = DB.session.query(models.Leaderboard).order_by(
        models.Leaderboard.score.desc()).all()
    for person in all_people:
        if person.username not in ALLUSERS:
            ALLUSERS.append(person.username)
            USERSCORES.append(person.score)
    for person in models.Active.query.all():
        if person.name not in ACTIVEUSERS:
            ACTIVEUSERS.append(person.name)
    return ALLUSERS