Giter VIP home page Giter VIP logo

swisstournament's Introduction

#Swiss Tournament This project was conceptualized by the Udacity staff as a practice project for the students of its Relational Databases course. ##Overview This project simulates a swiss tournament and in that context demonstrates the principles of database design and one complex query against a database. A swiss system tournament is a tournament without eliminations. Competitor face each other in lg(N) rounds. In each round the players are paired such that each players competes with another player that is closest to him/her in ranking. In this project, the ranking is determined using the match history in the tournament. For more information about Swiss system tournament, please refer to Wikipedia.

##Files ###tournament.sql This is the main document in this project. It sets up the tournament database and its tables. The database has two tables and a view:

  • Players table: with an id and a name field.
  • Matches table: contains id, winner, loser, and draw fields (draw field is never used in the program and is reserved for future)
  • Standings view: this view is created using a complex SQL statement explained below. It contains the number of wins and total matches for each player.

Standings SQL statement:

Here's the SQL statement used to create the Standings view:

create view standings as (
	select Players.id, name, wins, nummatches from 
		Players join (
		select t1.id, t1.nummatches, t2.wins from (
				select Players.id, count(Matches.winner) as nummatches from 
				Players left join Matches on (Players.id = Matches.loser or Players.id = Matches.winner) group by Players.id
			) as t1 join (
				select Players.id, count(Matches.winner) as wins 
				from Players left join Matches on Players.id = Matches.winner group by Players.id
			)as t2 on t1.id = t2.id
		) t3 on Players.id = t3.id 
	order by t3.wins desc);

This statement first creates t1 and t2 tables using sub-statements. Table t1 contains the total number of matches for each player and table t2 contains the number of matches the player has won. Table t3 is then created by joining t1 and t2 and the view is created by joing Players with t3. There are a total of four join operations in this statement and that is why it is complex.

###tournament.py This file provides methods to interact with our PostgreSQL database using Python's psycopg2 library.

###tournament_test.py This file tests the methods in tournament.py. Most of the code in this file was provided by the Udacity.com staff.

##Deployment In order to test the code in this project you must first install the PostgreSQL server on your computer followed by Python2. After that you can run the code by typing psql -f tournament.sql && python tournament_test.py into your terminal. Alternatively, you can substitute PostgreSQL with your database system to deploy the project.

swisstournament's People

Contributors

tahahojati avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.