def playerStandings():
    """
    Returns a list of the players and their win records, sorted by wins.
    Included as legacy support for old tournament tests.

    The first entry in the list should be the player in first place, or a
    player tied for first place if there is currently a tie.

    Returns:
      A list of tuples, each of which contains (id, name, wins, matches):
        id: the player's unique id (assigned by the database)
        name: the player's full name (as registered)
        wins: the number of matches the player has won
        matches: the number of matches the player has played
    """

    tournID = main.getTournamentIDFromName("Tournament for legacy tests")

    # Simply calls the new playerStandings function, passing in the
    # legacy tournament as the specified tournament.
    newResult = main.playerStandingsForTournament(tournID)
    legacyResult = [(result[0], result[1],
                     result[7], result[10]) for result in newResult]

    return legacyResult
def registerPlayer(playerName):
    """
    Adds a player to the tournament database. Included as legacy support for
    older tournament tests.

    Args:
      name: the player's full name (need not be unique).
    """

    tournName = "Tournament for legacy tests"

    # Connect to database
    conn, c = main.connect()

    # Insert a new player with this name
    SQL = "INSERT INTO player (playerName) values (%s);"
    data = (playerName, )
    c.execute(SQL, data)

    # If the legacy tournament doesn't exist,
    if main.getTournamentIDFromName(tournName) == None:
        SQL = "INSERT INTO tournament (tournamentName) values (%s);"
        data = (tournName, )
        c.execute(SQL, data)

    # Commit current changes.
    conn.commit()

    # Retrieve the newly created player, and legacy tournament.
    playerID = getPlayerIDFromName(playerName)
    tournID = main.getTournamentIDFromName(tournName)

    # Insert the player into the tournament.
    SQL = ("INSERT INTO tournamentPlayer (tournamentID, playerID)"
           " values (%s, %s);")
    data = (tournID, playerID)
    c.execute(SQL, data)

    # Close database connection
    conn.commit()
    conn.close()
def reportMatch(winner, loser):
    """
    Records the outcome of a single match between two players. Included as
    legacy support for old tournament tests.

    Args:
      winner:  the id number of the player who won
      loser:  the id number of the player who lost
    """

    tournID = main.getTournamentIDFromName("Tournament for legacy tests")

    main.playMatch(tournID, winner, loser, "p1 wins")