Beispiel #1
0
 def remove_player(name):
     name = name.upper()
     find_player = Player.find_by_name(name)
     if find_player is not None:
         find_player.remove_from_mongo()
         pAll = Player_All.find_by_name(name)
         pAll.remove_from_mongo()
     else:
         return None
Beispiel #2
0
 def remove_player(name):
     name = name.upper()
     find_player = Player.find_by_name(name)
     if find_player is not None:
         find_player.remove_from_mongo()
         pAll = Player_All.find_by_name(name)
         pAll.remove_from_mongo()
     else:
         return None
Beispiel #3
0
def remove_player():
    if request.method == 'GET':
        return redirect('/dashboard')
    else:
        name = request.form['player_name']
        password = request.form['password']
        _id = session['_id']
        room = Room.find_by_id(_id)
        if room.password == password and name is not None:
            player = Player.find_by_name(name)
            player.remove_from_mongo()
            return redirect('/dashboard')
        else:
            return redirect('/dashboard-error')
Beispiel #4
0
def stat():
    if request.method == 'GET':
        return redirect('/dashboard')
    else:
        name = request.form['player_name']
        _id = session['_id']
        room = Room.find_by_id(_id)
        player = Player.find_by_name(name)
        playerAll = Player_All.find_by_name(name)
        current_rate = ((player.wins / player.games_played) * 100)
        ovr_rate = ((playerAll.wins / playerAll.games_played) * 100)
        matches = room.get_matches()
        player_match = []
        for match in matches:
            if match.p1 == player.name or match.p2 == player.name and name is not None:
                player_match.append(match)
        return render_template('stat.html', player=player, matches=player_match, playerAll=playerAll, current_rate=current_rate, ovr_rate=ovr_rate)
Beispiel #5
0
    def update_table(p1, p2, p1score, p2score):
        p1 = p1.upper()
        p2 = p2.upper()
        room_id = session['_id']
        points = Points.get_points(room_id)
        player1_data = Database.find_one("players", {"name": p1})
        player2_data = Database.find_one("players", {"name": p2})

        if player1_data and player2_data is not None:
            if p1score > p2score:
                winner = Player.find_by_name(p1)
                winner.wins = winner.wins + 1
                winner.games_played = winner.games_played + 1
                winner.points = winner.points + int(points.ppw)
                loser = Player.find_by_name(p2)
                loser.loss = loser.loss + 1
                loser.games_played = loser.games_played + 1

                winnertot = Player_All.find_by_name(p1)
                winnertot.wins = winnertot.wins + 1
                winnertot.games_played = winnertot.games_played + 1
                winnertot.points = winnertot.points + int(points.ppw)
                losertot = Player_All.find_by_name(p2)
                losertot.loss = losertot.loss + 1
                losertot.games_played = losertot.games_played + 1

                winner.update_mongo()
                loser.update_mongo()
                winnertot.update_mongo()
                losertot.update_mongo()

            elif p2score > p1score:
                winner = Player.find_by_name(p2)
                winner.wins = winner.wins + 1
                winner.games_played = winner.games_played + 1
                winner.points = winner.points + int(points.ppw)
                loser = Player.find_by_name(p1)
                loser.loss = loser.loss + 1
                loser.games_played = loser.games_played + 1

                winnertot = Player_All.find_by_name(p2)
                winnertot.wins = winnertot.wins + 1
                winnertot.games_played = winnertot.games_played + 1
                winnertot.points = winnertot.points + int(points.ppw)
                losertot = Player_All.find_by_name(p1)
                losertot.loss = losertot.loss + 1
                losertot.games_played = losertot.games_played + 1

                winner.update_mongo()
                loser.update_mongo()
                winnertot.update_mongo()
                losertot.update_mongo()

            else:
                p1 = Player.find_by_name(p1)
                p2 = Player.find_by_name(p2)
                p1.draw = p1.draw + int(points.ppd)
                p2.draw = p2.draw + int(points.ppd)
                p1.points = p1.points + 1
                p2.points = p2.points + 1

                p1tot = Player_All.find_by_name(p1)
                p2tot = Player_All.find_by_name(p2)
                p1tot.draw = p1tot.draw + int(points.ppd)
                p2tot.draw = p2tot.draw + int(points.ppd)
                p1tot.points = p1tot.points + 1
                p2tot.points = p2tot.points + 1

                p1.update_mongo()
                p2.update_mongo()
                p1tot.update_mongo()
                p2tot.update_mongo()
        else:
            return None
Beispiel #6
0
    def update_table(p1, p2, p1score, p2score):
        p1 = p1.upper()
        p2 = p2.upper()
        room_id = session['_id']
        points = Points.get_points(room_id)
        player1_data = Database.find_one("players", {"name": p1})
        player2_data = Database.find_one("players", {"name": p2})

        if player1_data and player2_data is not None:
            if p1score > p2score:
                winner = Player.find_by_name(p1)
                winner.wins = winner.wins + 1
                winner.games_played = winner.games_played + 1
                winner.points = winner.points + int(points.ppw)
                loser = Player.find_by_name(p2)
                loser.loss = loser.loss + 1
                loser.games_played = loser.games_played + 1

                winnertot = Player_All.find_by_name(p1)
                winnertot.wins = winnertot.wins + 1
                winnertot.games_played = winnertot.games_played + 1
                winnertot.points = winnertot.points + int(points.ppw)
                losertot = Player_All.find_by_name(p2)
                losertot.loss = losertot.loss + 1
                losertot.games_played = losertot.games_played + 1

                winner.update_mongo()
                loser.update_mongo()
                winnertot.update_mongo()
                losertot.update_mongo()

            elif p2score > p1score:
                winner = Player.find_by_name(p2)
                winner.wins = winner.wins + 1
                winner.games_played = winner.games_played + 1
                winner.points = winner.points + int(points.ppw)
                loser = Player.find_by_name(p1)
                loser.loss = loser.loss + 1
                loser.games_played = loser.games_played + 1

                winnertot = Player_All.find_by_name(p2)
                winnertot.wins = winnertot.wins + 1
                winnertot.games_played = winnertot.games_played + 1
                winnertot.points = winnertot.points + int(points.ppw)
                losertot = Player_All.find_by_name(p1)
                losertot.loss = losertot.loss + 1
                losertot.games_played = losertot.games_played + 1

                winner.update_mongo()
                loser.update_mongo()
                winnertot.update_mongo()
                losertot.update_mongo()

            else:
                p1 = Player.find_by_name(p1)
                p2 = Player.find_by_name(p2)
                p1.draw = p1.draw + int(points.ppd)
                p2.draw = p2.draw + int(points.ppd)
                p1.points = p1.points + 1
                p2.points = p2.points + 1

                p1tot = Player_All.find_by_name(p1)
                p2tot = Player_All.find_by_name(p2)
                p1tot.draw = p1tot.draw + int(points.ppd)
                p2tot.draw = p2tot.draw + int(points.ppd)
                p1tot.points = p1tot.points + 1
                p2tot.points = p2tot.points + 1

                p1.update_mongo()
                p2.update_mongo()
                p1tot.update_mongo()
                p2tot.update_mongo()
        else:
            return None