Ejemplo n.º 1
0
    def best_worst_glicko():
        ranks = Rank_Glicko.query().all()
        ranks = sorted(ranks, key=lambda x: x.rating.value - (x.rd.value), reverse=best)

        table = [['Rank', 'Rating', 'RD', 'Nick', 'Firstname', 'Lastname', 'ID']]
        #print "Rank\tRating\tRD\tNick\tForename\tSurname\tid"

        for i in range(min(args.amount, len(ranks))):
            player = Player().query().get(player_id=ranks[i].player_id.value)
            #print "%d\t%d\t%d\t%s\t%s,\t%s\t%s" % (i + 1, ranks[i].rating.value,
            #    ranks[i].rd.value, player.nickname.value, player.firstname.value,
            #    player.lastname.value, player.player_id.value)
            table.append([i + 1, int(ranks[i].rating.value),
                int(ranks[i].rd.value), player.nickname.value, player.firstname.value,
                player.lastname.value, player.player_id.value])
        utils.print_table(table)
Ejemplo n.º 2
0
    def best_worst_elo():
        ranks = Rank_Elo.query().all()
        ranks = sorted(ranks, key=lambda x: x.value.value, reverse=best)

        # the table to print out
        table = [['Rank', 'Rating', 'Nick', 'Firstname', 'Lastname', 'ID']]
        #print "Rank\tRating\tNick\tForename\tSurname\tid"

        for i in range(min(args.amount, len(ranks))):
            player = Player().query().get(player_id=ranks[i].player_id.value)
            #print "%d\t%d\t%s\t%s,\t%s\t%s" % (i + 1, ranks[i].value.value,
            #    player.nickname.value, player.firstname.value,
            #    player.lastname.value, player.player_id.value)
            table.append([
                i + 1, ranks[i].value.value, player.nickname.value,
                player.firstname.value, player.lastname.value,
                player.player_id.value
            ])
        utils.print_table(table)
Ejemplo n.º 3
0
def history(args):

    if args.player1 == args.player2:
        print "Player1 and Player2 are equal. Use 'history <player>'."
        return

    # store all players in a dict (player_id --> player) and get player1/2
    players = Player.query().all()
    pdict = {}
    for player in players:
        pdict[player.player_id.value] = player
        if player.nickname.value == args.player1:
            player1 = player
        if player.nickname.value == args.player2:
            player2 = player

    if args.player2 is None:
        print "Searching for the history of %s\n" % args.player1

        # the table to print out
        table = [['Opponent', 'Outcome', 'Date']]

        # get all matches with player 1
        matches = Match1on1.query().filter(
            player1=player1.player_id.value).filter(
                player2=player1.player_id.value).join_or().all()

        won = 0
        lost = 0
        draw = 0

        # iterate over all matches
        for match in matches:
            # check who the opponent is and who actually won
            opponent = match.player1.value
            if match.outcome.value == 0.5:
                outcome = "Draw"
                draw += 1
            if opponent == player1.player_id.value:
                opponent = match.player2.value
                if match.outcome.value == 1:
                    outcome = "Won"
                    won += 1
                elif match.outcome.value == 0:
                    lost += 1
                    outcome = "Lost"
            else:
                if match.outcome.value == 1:
                    outcome = "Lost"
                    lost += 1
                elif match.outcome.value == 0:
                    outcome = "Won"
                    won += 1

            table.append(
                [pdict[opponent].nickname.value, outcome, match.date.value])

        # finally print the table
        utils.print_table(table)
        print "\nStatistics:"
        print "Won:  %d\nLost: %d\nDraw: %d" % (won, lost, draw)

    else:
        #TODO modify this when IN (...) works
        print "Searching for the history of %s and %s\n" % (args.player1,
                                                            args.player2)

        # the table to print out
        table = [['Winner', 'Date']]

        # get all matches with player 1
        matches1 = Match1on1.query().filter(
            player1=player1.player_id.value).filter(
                player2=player1.player_id.value).join_or().all()

        # get all matches with player 2
        matches2 = Match1on1.query().filter(
            player1=player2.player_id.value).filter(
                player2=player2.player_id.value).join_or().all()

        statistics = {args.player1: 0, args.player2: 0, 'Draw': 0}

        # Find the intersection of the two list. Other methods do not work
        # because the 'in' operator does not seem to work with instances
        matches = [
            x for x in matches1
            if [y for y in matches2 if y.match_id.value == x.match_id.value]
        ]

        for match in matches:
            if match.outcome.value == 0:
                nickname = pdict[match.player2.value].nickname.value
                table.append([nickname, match.date.value])
                statistics[nickname] += 1
            elif match.outcome.value == 1:
                nickname = pdict[match.player2.value].nickname.value
                table.append([nickname, match.date.value])
                statistics[nickname] += 1
            else:
                table.append(['Draw', match.date.value])
                statistics['Draw'] += 1

        # finally print the table
        utils.print_table(table)

        print "\nStatistics for %s:" % args.player1
        print "Won:  %d\nLost: %d\nDraw: %d" % (
            statistics[args.player1], len(matches) - statistics[args.player1] -
            statistics["Draw"], statistics["Draw"])

        print "\nStatistics for %s:" % args.player2
        print "Won:  %d\nLost: %d\nDraw: %d" % (
            statistics[args.player2], len(matches) - statistics[args.player2] -
            statistics["Draw"], statistics["Draw"])
Ejemplo n.º 4
0
def history(args):

    if args.player1 == args.player2:
        print "Player1 and Player2 are equal. Use 'history <player>'."
        return

    # store all players in a dict (player_id --> player) and get player1/2
    players = Player.query().all()
    pdict = {}
    for player in players:
        pdict[player.player_id.value] = player
        if player.nickname.value == args.player1:
            player1 = player
        if player.nickname.value == args.player2:
            player2 = player

    if args.player2 is None:
        print "Searching for the history of %s\n" % args.player1

        # the table to print out
        table = [['Opponent', 'Outcome', 'Date']]

        # get all matches with player 1
        matches = Match1on1.query().filter(
            player1=player1.player_id.value).filter(
            player2=player1.player_id.value).join_or().all()

        won = 0
        lost = 0
        draw = 0

        # iterate over all matches
        for match in matches:
            # check who the opponent is and who actually won
            opponent = match.player1.value
            if match.outcome.value == 0.5:
                outcome = "Draw"
                draw += 1
            if opponent == player1.player_id.value:
                opponent = match.player2.value
                if match.outcome.value == 1:
                    outcome = "Won"
                    won += 1
                elif match.outcome.value == 0:
                    lost += 1
                    outcome = "Lost"
            else:
                if match.outcome.value == 1:
                    outcome = "Lost"
                    lost += 1
                elif match.outcome.value == 0:
                    outcome = "Won"
                    won += 1

            table.append([pdict[opponent].nickname.value, outcome,
                match.date.value])

        # finally print the table
        utils.print_table(table)
        print "\nStatistics:"
        print "Won:  %d\nLost: %d\nDraw: %d" % (won, lost, draw)

    else:
        #TODO modify this when IN (...) works
        print "Searching for the history of %s and %s\n" % (args.player1,
            args.player2)

        # the table to print out
        table = [['Winner', 'Date']]

        # get all matches with player 1
        matches1 = Match1on1.query().filter(
            player1=player1.player_id.value).filter(
            player2=player1.player_id.value).join_or().all()

        # get all matches with player 2
        matches2 = Match1on1.query().filter(
            player1=player2.player_id.value).filter(
            player2=player2.player_id.value).join_or().all()

        statistics = {args.player1: 0, args.player2: 0, 'Draw': 0}

        # Find the intersection of the two list. Other methods do not work
        # because the 'in' operator does not seem to work with instances
        matches = [x for x in matches1 if
            [y for y in matches2 if y.match_id.value == x.match_id.value]]

        for match in matches:
            if match.outcome.value == 0:
                nickname = pdict[match.player2.value].nickname.value
                table.append([nickname, match.date.value])
                statistics[nickname] += 1
            elif match.outcome.value == 1:
                nickname = pdict[match.player2.value].nickname.value
                table.append([nickname, match.date.value])
                statistics[nickname] += 1
            else:
                table.append(['Draw', match.date.value])
                statistics['Draw'] += 1

        # finally print the table
        utils.print_table(table)

        print "\nStatistics for %s:" % args.player1
        print "Won:  %d\nLost: %d\nDraw: %d" % (statistics[args.player1],
            len(matches) - statistics[args.player1] - statistics["Draw"],
            statistics["Draw"])

        print "\nStatistics for %s:" % args.player2
        print "Won:  %d\nLost: %d\nDraw: %d" % (statistics[args.player2],
            len(matches) - statistics[args.player2] - statistics["Draw"],
            statistics["Draw"])