Tournament is a group of fucntions that help you keep scores in a swiss style tournament.
In order to access the functions built in the tournament.py file, clone the repository and use the Postgres console to import the tournament.sql file in order to create the database. The command to do so is: psql -f tournament.sql
Import the module to your file and that´s it. The functions in the file are the following:
Connect to the PostgreSQL database.
Returns a database connection.
Desonnect from the PostgreSQL database.
Commit to the PostgreSQL database."""
connection.commit()
###Example of a connection:
``` db = connect() cur = db.cursor() query = "DELETE FROM table_name" cur.execute(query) commit_connection(db) close_connection(db) ```
Adds registers to the database, the specified column = data to the table
Args:
**column_data: Dictionary with the column = value to be inserted
table: Table where the register goes
Returns:
"OK" if correctly inserted
"ERROR" Database error description
Remove all the records from the database of a given table.
Args:
table: Table to erase the registers from
Returns:
"OK"
"ERROR" Database error description
Remove all the match records from the database.
Returns:
"OK"
"ERROR" Database error description
Remove all the player records from the database.
Returns:
"OK"
"ERROR" Database error description
Remove all the torunaments records from the database.
Returns:
"OK"
"ERROR" Database error description
Returns the number of players currently registered.
Returns:
A one value tuple with number of players in the database
ERROR - Problems with the database
Adds a player to the tournament database.
Args:
name: the player's full name (need not be unique).
Returns:
"OK" if correctly inserted
"ERROR" Database error description
Adds a torunament to the tournament database.
Args:
name: the tourament name (need not be unique).
Returns:
"ERROR" Database error description
Records the outcome of a single match between two players.
Args:
winner: the id number of the player who won
loser: the id number of the player who lost
tournament: Id of the tournament the match belongs to
Returns:
"OK" if correctly inserted
"ERROR" Database error description
"ERROR - Game duplicated" If the game is already in the database
"ERROR Players not in the same tournament"
"""
Checks if a particular game from a particular tournament is already in
the database
Args:
Winner and loser: The ID of the participants of the match
Returns:
False if the game is not present
True if the game is already present
Checks if a couple of players are in the same tournament and can play a
match
Args:
Winner and loser: Ids of the players
Returns:
False if the game is not present
True if the game is already present
Returns a list of the players and their win records, sorted by wins.
The tournament ID = 0 is reserved for all tournaments
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.
Args:
tournament: tournament_ID
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
Returns a list of pairs of players for the next round of a match.
Assuming that there are an even number of players registered, each player
appears exactly once in the pairings. Each player is paired with another
player with an equal or nearly-equal win record, that is, a player adjacent
to him or her in the standings.
Args:
tournament: tournament_ID
Returns:
A list of tuples, each of which contains (id1, name1, id2, name2)
id1: the first player's unique id
name1: the first player's name
id2: the second player's unique id
name2: the second player's name