Tournament planner is a tool for planning and keeping scores of game or sports tournaments. It uses a Swiss pairing system where players compete against others on their same level, based on results in the tournament.
The program uses PostgreSQL, Virtual Box, Vagrant, Psychopg2 and Python 2.7 to create a back-end solution for managing a tournament after the Swiss model. In a Swiss model tournament players do not get knocked out, but in each round they play agains players who have the same amount of wins as they have.
To use the module, you first need to install the following:
- Python2.7
- Virtual Box
- Vagrant
- GIT (Recommended)
- Install all software listed above.
- In GIT, cd to your project folder and type
git clone https://github.com/udacity/fullstack-nanodegree-vm
- Inside the vagrant folder, clone this repository
git clone https://github.com/stonescar/tournament-planner
- Type
vagrant up
to boot your virtual machine (This might take a while...) - When the VM is booted, log in with
vagrant ssh
- cd to the tournament planner folder with
cd /vagrant/tournament-planner
- To build the database, type
psql
, then\i tournament.sql
- Press
CTRL+D
to exit psql - You can now run the example program with
python play.py
or build your project and import tournament.py
Filename | Description |
---|---|
tournament.py | Contains the functions to create new tournaments, add players, report matches, views standings etc. This is the file you must import to your project. |
tournament.sql | Contains all the database, table and view schemas |
tournament-test.py | A file to test the functionality in tournament.py |
play.py | An example of how the tournament.py file can be used. |
LICENSE | License file for this project |
README.md | This readme file |
A short description of the functions in tournament.py
. Se the docstrings for more detailed information.
- connect(): Sets up and returns a database connection. Edit this to fit your database
- deleteTournaments(): Deletes ALL tournaments
- deleteTournament(id): Deletes a tournament
- deleteMatches(tournament): Deletes all matches, or just all matches for a given tournament
- deletePlayers(): Deletes ALL players
- newTournament(name): Creates a new tournament
- countPlayers(tournament): Counts ALL players in the database, or just those assigned to a given tournament
- registerPlayer(name): Adds a new player to the database
- assignPlayers(tournament, *players): Assigns a list of players to a tournament
- quicktournament(t_name, *players): Creates a new tournament and adds assigns players to it
- playerStandings(tournament): Returns a list of all players in a tournament, sorted by wins
- reportMatch(tournament, winner, loser): Report the outcome of a match
- swissPairings(tournament): Returns a list of pairs of players based on the Swiss model
- randomPairings(tournament): Returns a lis of random pairs of players
Listed below are the tables the data is stored in and the views that have been created to retreieve the data easily. For each table or view is an example table showing how the tables and views could look like. Values in tables in parentheses shows the value that the foreign key points to.
Holds the unique id
of the player as a primary key, and the player's name
as a text value.
id | name |
---|---|
1 | Steinar |
2 | Mike |
3 | Rachel |
4 | Steve |
5 | Molly |
6 | Janet |
7 | Peter |
Holds the unique id
of the tournament as a primary key, and the tournament name
as a text value:
id | name |
---|---|
1 | myTournament |
2 | Tournament 2 |
Assigns players to tournaments. player
references to the id
field in the players table, and tournament
references to the id
in the tournaments table. This way a user can be in many different tournaments.
tournament | player |
---|---|
1 (myTournament) | 1 (Steinar) |
1 (myTournament) | 2 (Mike) |
1 (myTournament) | 3 (Rachel) |
1 (myTournament) | 4 (Steve) |
2 (Tournament 2) | 3 (Rachel) |
2_(Tournament 2)_ | 5 (Molly) |
2_(Tournament 2)_ | 6 (Janet) |
2_(Tournament 2)_ | 7 (Peter) |
Stores results of matches in all tournaments. Hold the unique id
of the match as a primary key, tournament
references to the id
field in the tournament table and tells which tournement the match was part of, while winner
and loser
references to the id
field in the players table representing the two players in the match, where the winner of the match is set as winner
.
id | tournament | winner | loser |
---|---|---|---|
1 | 1 (myTournament) | 1 (Steinar) | 4 (Steve) |
2 | 1 (myTournament) | 3 (Rachel) | 2 (Mike) |
3 | 1 (myTournament) | 1 (Steinar) | 3 (Rachel) |
4 | 1 (myTournament) | 2 (Mike) | 4 (Steve) |
5 | 2 (Tournament 2) | 3 (Rachel) | 7 (Peter) |
6 | 2 (Tournament 2) | 6 (Janet) | 5 (Molly) |
Temporary view that lists all matches for all players. So all the matches a player has played will be listed in this view and connected to his id and name. tournament
references to the id
field of the tournaments table for later sorting and selecting. id
and name
references to the player's id and name in the players table. winner
and loser
holds the ids of the player in the match, with winner
showing who won.
This view is only used for further selecting, sorting and grouping, i.e. in the standings view.
tournament | id | name | winner | loser |
---|---|---|---|---|
1 (myTournament) | 1 | Steinar | 1 | 4 (Steve) |
1 (myTournament) | 1 | Steinar | 1 | 3 (Rachel) |
1 (myTournament) | 2 | Mike | 2 | 4 (Steve) |
1 (myTournament) | 2 | Mike | 3 (Rachel) | 2 |
1 (myTournament) | 3 | Rachel | 1 (Steinar) | 3 |
1 (myTournament) | 3 | Rachel | 3 | 2 (Mike) |
... | ... | ... | ... | ... |
2 (Tournament 2) | 3 | Rachel | 3 | 7 (Peter) |
... | ... | ... | ... | ... |
Shows the current standings of all tournaments. Lists all players, sorted by number of wins. Includes tournament
(id
of tournament), id
(player's id
), name
(player's name
), matches
(the total number of matches the player has played) and wins
(the total number of matches the player has won. Use ...WHERE tournament = [tournament-id]
to only show standings for one tournament.
tournament | id | name | matches | wins |
---|---|---|---|---|
1 (myTournament) | 1 | Steinar | 2 | 2 |
1 (myTournament) | 3 | Rachel | 2 | 1 |
1 (myTournament) | 2 | Mike | 2 | 1 |
1 (myTournament) | 1 | Steve | 2 | 0 |
2 (Tournament 2) | 3 | Rachel | 1 | 1 |
2 (Tournament 2) | 6 | Janet | 1 | 1 |
2 (Tournament 2) | 7 | Peter | 1 | 0 |
2 (Tournament 2) | 5 | Molly | 1 | 0 |
This project is licensed under the MIT License.