tournament
by Douglas A. Seifert (doug at dseifert dot net) http://www.dseifert.net/code/tournament http://github.org/seifertd/tournament http://rubygems.org/gems/tournament
Small library, command line program and Rails web GUI for managing a NCAA basketball tournament pool.
The tournament command line program is installed as ‘pool’. The library has the 2010 NCAA tournament pre-configured. If you were to use this library for the 2011 NCAA tournament, code changes would be necessary. FIXME: (add ability to read teams from a simple configuration file). For usage, just execute
pool --help
For command specific usage, execute
pool [command] --help
where [command] is one of the available commands described below. The pool command saves state in a file called pool.yml by default. This can be overridden in all cases by using the —save-file option.
The pool manager would use this program as follows:
If your scoring strategy is not one of the above, you will have to add a class to the ScoringStrategy module, in file lib/tournament/scoring_strategy.rb.
pool setup [--scoring=upset]
Use the —scoring argument to change from the default basic scoring strategy. If the basic strategy is ok, the —scoring argument is not required.
As mentioned above, unless overridden by using the —save-file option, the pool will save itself to the file ‘pool.yml‘
pool fee 10 pool payout 1 80 pool payout 2 20 pool payout last 10 -C
The above commands say that each entry fee is 10 units (this is all for fun, not profit, right?) and that the 1st place finisher would receive 80% of the total payout, the 2nd place finisher would receive 20% of the total payout and the last place finisher would receive 10 units back (would get her entry fee back). No error checking is done with this. FIXME: Add error checking.
pool dump
This will save the tournament entry file as tournament.yml unless the —entry option is used to override it.
pool entry --add=path/to/entry.yml
pool update
pool report [final_four|entry|region|leader|score]
The final four report can only be run once the final four teams have been determined.
pool report possibility
A Rails web application is available if you don’t want to use the command line to manage your pool.
The web application can be installed by running the pool command as follows
pool install_webgui --web-dir=/path/to/directory [options]
The above command will copy the Rails app to the specified directory.
There are several options you can provide in addition to —web-dir to control how the application is installed:
--site-name="Site Name" (Default: 'Tournament')
--relative-root=/my_pool (Default: empty, no root is set)
--admin-email=admin
--email-server=smtp.myisp.com --email-port=25 --email-domain=mydomain.com --email-user=myuser --email-password=mypass --email-auth=login|plain|cram_md5
See guides.rubyonrails.org/action_mailer_basics.html#_action_mailer_configuration for more info on how to configure a Rails app for sending email.
--use-princexml=/full/path/to/prince
If prince is not available on the path you specify, the princexml distribution will be downloaded and installed using the distribution’s install.sh script. In order to do this, the tar program must be available on your installation system.
--tmp-dir=/path/to/tmp/dir
Before being able to run the web gui for the first time, you have to generate the web site authorization keys, prepare the sqlite database and create an admin account. Change to the website installation directory and perform the following steps.
RAILS_ENV=production rake auth:gen:site_key
RAILS_ENV=production rake db:migrate
RAILS_ENV=production rake "admin:create[login,email,name,password]"
In the above command, substitute “login” for the desired admin user’s login name, “email” for the administrators email address, “name” for the admin user’s name (eg, “Joe Admin”), and “password” for the desired admin account password
If the tournament gem is updated, you can pull in the changes as follows:
sudo gem update tournament
cd $install_dir; RAILS_ENV=production rake db:migrate
Load the entry page in your brower. Log in as the admin user you configured during installation. Click on on the ‘All Pools’ link on the right sidebar. Create a new pool and fill in the information. Each time you save this form, a new blank payouts line will be added so that you can configure as many payouts as you desire.
After the basic pool configuration is set up, click on the ‘Teams’ link in the right sidebar. You are presented with four region brackets to fill in. Keep in mind that the pink region champs will play each other in the final four and the light blue region champs will play each other in the final four so you can get the bracket right. The web application is preconfigured with over 300 NCAA schools. The team name fields are auto-complete fields — type in a few letters and pause and you will be presented with a list of matching teams. The Short Name field should be a three letter abbreviation for the team. The abbreviations have to be unique across the entire tournament field.
Once the teams are configured, go back to the pool basic information form, click the Active check box and save the form. The pool is now ready for entries to be added to it. Invite your friends to join the pool by giving them the url for the entry page. They will be asked to register. After registering and logging in, they will be able to submit entries to your pool.
As the tournament progresses, use the ‘Tournament Bracket’ link on the right sidebar to record the winning teams.
Use the report links to run reports, etc.
After about 21 teams are left in the tournament, you can run the possibility report. This report runs through every possible way the tournament can come out and ranks each entry against the possiblity. The report lists the “chance to win” for each entry. The chance to win is the percentage of possible outcomes that would result in that entry coming in first.
The possibility report requires that a rake task be run on the web server. It is very processor intensive and can take a long time to complete. To generate the possibility report data file, run the following command from the web gui install directory on the server:
RAILS_ENV=production rake report:possibilities
A GUI for filling out tournment bracket entries is included and is run by executing the program “picker”. If no argument is included, a blank entry is started. It can be filled in and saved using one of the buttons at the top of the screen. The entry is saved as a YAML file for a Tournament::Entry object. The picker program optionally takes one argument, the path to a Tournament::Entry YAML file. It will open with the provided entry’s picks pre filled in.
The GUI also may be used for keeping the NCAA tournament entry YAML file up to date:
picker tournament.yml
The GUI works as long as you don’t try to go back and change games from played to unknown outcome.
Verified working on
(The MIT License)
Copyright © 2008
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Generated with the Darkfish Rdoc Generator 1.1.6.