示例#1
0
def import_results(args):
    """
    Imports the match data of a csv file into the result table.

    :param args: A list with arguments from the argument parser
    :type args: namespace
    """

    print "Importing results from", args.file

    try:
        csvfile, reader, hasHeader = utils.get_csv(args.file)
        line = 0

        if hasHeader:
            print "\tFirst line of csv file is ignored. It seems to be a " \
                  "header row.\n"

        # nickname --> player
        players = {}

        for row in reader:
            if line != 0 or (line == 0 and not hasHeader):
                if row[1] is row[2]:
                    continue

                player1 = players.get(row[1], None)
                player2 = players.get(row[2], None)
                if player1 is None:
                    player1, created = utils.add_player(row[1], commit=False)
                    players[player1.nickname.value] = player1
                if player2 is None:
                    player2, created = utils.add_player(row[2], commit=False)
                    players[player2.nickname.value] = player2

                dbRow = Match1on1(player1=player1.player_id.value,
                                  player2=player2.player_id.value,
                                  outcome=row[3],
                                  date=row[0])
                dbRow.save(commit=False)

            if line % 100 == 0:
                sys.stdout.write("\r" + "Imported %d entries..." % line)
                sys.stdout.flush()
            line = line + 1

        Rank_Elo.commit()
        Rank_Glicko.commit()
        Match1on1.commit()
        csvfile.close()
        print "\rImported %d entries." % (line - (1 if hasHeader else 0))
    except csv.Error:
        print "Error importing %s in line %d" % (args.file, line)
    except IOError:
        print "No such file: %s" % args.file
示例#2
0
def import_results(args):
    """
    Imports the match data of a csv file into the result table.

    :param args: A list with arguments from the argument parser
    :type args: namespace
    """

    print "Importing results from", args.file

    try:
        csvfile, reader, hasHeader = utils.get_csv(args.file)
        line = 0

        if hasHeader:
            print "\tFirst line of csv file is ignored. It seems to be a " \
                  "header row.\n"

        # nickname --> player
        players = {}

        for row in reader:
            if line != 0 or (line == 0 and not hasHeader):
                if row[1] is row[2]:
                    continue

                player1 = players.get(row[1], None)
                player2 = players.get(row[2], None)
                if player1 is None:
                    player1, created = utils.add_player(row[1], commit=False)
                    players[player1.nickname.value] = player1
                if player2 is None:
                    player2, created = utils.add_player(row[2], commit=False)
                    players[player2.nickname.value] = player2

                dbRow = Match1on1(player1=player1.player_id.value,
                    player2=player2.player_id.value, outcome=row[3],
                    date=row[0])
                dbRow.save(commit=False)

            if line % 100 == 0:
                sys.stdout.write("\r" + "Imported %d entries..." % line)
                sys.stdout.flush()
            line = line + 1

        Rank_Elo.commit()
        Rank_Glicko.commit()
        Match1on1.commit()
        csvfile.close()
        print "\rImported %d entries." % (line - (1 if hasHeader else 0))
    except csv.Error:
        print "Error importing %s in line %d" % (args.file, line)
    except IOError:
        print "No such file: %s" % args.file
示例#3
0
    def update_elo():
        sys.stdout.write("Query matches...")
        matches = Match1on1.query().all()
        sys.stdout.write("\rBeginning to update %d matches" % len(matches))
        print ""

        # constants
        conf = utils.get_config(args)
        k = conf["elo.chess.k"]
        func = conf["elo.chess.function"]

        # Query all ratings and store it in a dictionary. This is done to store
        # the newest rating data in memory. We do not have to commit.
        ratings = Rank_Elo.query().all()
        rdict = {}
        for r in ratings:
            rdict[r.player_id.value] = r

        updates = 0
        for match in matches:
            rating1 = rdict[match.player1.value]
            rating2 = rdict[match.player2.value]

            result = elo.elo1on1(rating1.value.value, rating2.value.value,
                                 match.outcome.value, k, func)
            rating1.value = result[0]
            rating2.value = result[1]

            updates = updates + 1
            if updates % 50 == 0:
                sys.stdout.write("\r" + "Updated %d matches..." % updates)
                sys.stdout.flush()

        # update table
        for r in ratings:
            r.save(commit=False)
        Rank_Elo.commit()
        print "\rUpdated", updates, "matches."
示例#4
0
    def update_elo():
        sys.stdout.write("Query matches...")
        matches = Match1on1.query().all()
        sys.stdout.write("\rBeginning to update %d matches" % len(matches))
        print ""

        # constants
        conf = utils.get_config(args)
        k = conf["elo.chess.k"]
        func = conf["elo.chess.function"]

        # Query all ratings and store it in a dictionary. This is done to store
        # the newest rating data in memory. We do not have to commit.
        ratings = Rank_Elo.query().all()
        rdict = {}
        for r in ratings:
            rdict[r.player_id.value] = r

        updates = 0
        for match in matches:
            rating1 = rdict[match.player1.value]
            rating2 = rdict[match.player2.value]

            result = elo.elo1on1(rating1.value.value, rating2.value.value,
                match.outcome.value, k, func)
            rating1.value = result[0]
            rating2.value = result[1]

            updates = updates + 1
            if updates % 50 == 0:
                sys.stdout.write("\r" + "Updated %d matches..." % updates)
                sys.stdout.flush()

        # update table
        for r in ratings:
            r.save(commit=False)
        Rank_Elo.commit()
        print "\rUpdated", updates, "matches."
示例#5
0
 def clear_elo():
     ranks = Rank_Elo.query().all()
     for rank in ranks:
         rank.value = 1500
         rank.save(commit=False)
     Rank_Elo.commit()
示例#6
0
 def clear_elo():
     ranks = Rank_Elo.query().all()
     for rank in ranks:
         rank.value = 1500
         rank.save(commit=False)
     Rank_Elo.commit()