tournament 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (264) hide show
  1. data/History.txt +15 -0
  2. data/Manifest.txt +241 -2
  3. data/README.txt +152 -12
  4. data/Rakefile +9 -6
  5. data/bin/benchmark_pool +0 -0
  6. data/bin/gui.rb +3 -1
  7. data/bin/picker +0 -0
  8. data/bin/pool +139 -15
  9. data/lib/tournament/bracket.rb +33 -50
  10. data/lib/tournament/entry.rb +3 -0
  11. data/lib/tournament/pool.rb +144 -93
  12. data/lib/tournament/scoring_strategy.rb +69 -0
  13. data/lib/tournament/webgui_installer.rb +109 -0
  14. data/tasks/ann.rake +19 -14
  15. data/tasks/bones.rake +6 -25
  16. data/tasks/gem.rake +46 -36
  17. data/tasks/git.rake +41 -0
  18. data/tasks/jamis.rb +589 -0
  19. data/tasks/notes.rake +28 -0
  20. data/tasks/post_load.rake +18 -11
  21. data/tasks/{doc.rake → rdoc.rake} +12 -9
  22. data/tasks/rubyforge.rake +12 -12
  23. data/tasks/setup.rb +121 -80
  24. data/tasks/spec.rake +12 -13
  25. data/tasks/svn.rake +15 -11
  26. data/tasks/test.rake +6 -6
  27. data/test/test_tournament.rb +8 -0
  28. data/test/test_webgui_installer.rb +64 -0
  29. data/webgui/README +256 -0
  30. data/webgui/Rakefile +10 -0
  31. data/webgui/app/controllers/admin_controller.rb +61 -0
  32. data/webgui/app/controllers/application.rb +25 -0
  33. data/webgui/app/controllers/entry_controller.rb +97 -0
  34. data/webgui/app/controllers/pool_controller.rb +4 -0
  35. data/webgui/app/controllers/reports_controller.rb +7 -0
  36. data/webgui/app/controllers/sessions_controller.rb +43 -0
  37. data/webgui/app/controllers/teams_controller.rb +75 -0
  38. data/webgui/app/controllers/users_controller.rb +57 -0
  39. data/webgui/app/helpers/admin_helper.rb +2 -0
  40. data/webgui/app/helpers/application_helper.rb +3 -0
  41. data/webgui/app/helpers/entry_helper.rb +2 -0
  42. data/webgui/app/helpers/pool_helper.rb +2 -0
  43. data/webgui/app/helpers/reports_helper.rb +2 -0
  44. data/webgui/app/helpers/sessions_helper.rb +2 -0
  45. data/webgui/app/helpers/teams_helper.rb +2 -0
  46. data/webgui/app/helpers/users_helper.rb +93 -0
  47. data/webgui/app/models/entry.rb +42 -0
  48. data/webgui/app/models/pool.rb +141 -0
  49. data/webgui/app/models/region.rb +3 -0
  50. data/webgui/app/models/role.rb +4 -0
  51. data/webgui/app/models/seeding.rb +4 -0
  52. data/webgui/app/models/team.rb +6 -0
  53. data/webgui/app/models/user.rb +98 -0
  54. data/webgui/app/models/user_mailer.rb +25 -0
  55. data/webgui/app/views/admin/bracket.html.erb +3 -0
  56. data/webgui/app/views/admin/entries.html.erb +25 -0
  57. data/webgui/app/views/admin/index.html.erb +17 -0
  58. data/webgui/app/views/admin/pool.html.erb +53 -0
  59. data/webgui/app/views/entry/index.html.erb +16 -0
  60. data/webgui/app/views/entry/print.erb +1 -0
  61. data/webgui/app/views/entry/print.html.erb +1 -0
  62. data/webgui/app/views/entry/show.html.erb +1 -0
  63. data/webgui/app/views/layouts/bracket.html.erb +37 -0
  64. data/webgui/app/views/layouts/default.html.erb +62 -0
  65. data/webgui/app/views/layouts/print.html.erb +12 -0
  66. data/webgui/app/views/layouts/report.html.erb +38 -0
  67. data/webgui/app/views/pool/index.html.erb +36 -0
  68. data/webgui/app/views/reports/_report.html.erb +11 -0
  69. data/webgui/app/views/reports/show.html.erb +12 -0
  70. data/webgui/app/views/sessions/new.html.erb +21 -0
  71. data/webgui/app/views/shared/_admins.html.erb +8 -0
  72. data/webgui/app/views/shared/_bracket.html.erb +1296 -0
  73. data/webgui/app/views/teams/choose.html.erb +57 -0
  74. data/webgui/app/views/user_mailer/activation.erb +3 -0
  75. data/webgui/app/views/user_mailer/signup_notification.erb +8 -0
  76. data/webgui/app/views/users/_user_bar.html.erb +8 -0
  77. data/webgui/app/views/users/new.html.erb +19 -0
  78. data/webgui/config/boot.rb +109 -0
  79. data/webgui/config/database.yml +22 -0
  80. data/webgui/config/environment.rb +78 -0
  81. data/webgui/config/environments/development.rb +29 -0
  82. data/webgui/config/environments/production.rb +24 -0
  83. data/webgui/config/environments/test.rb +22 -0
  84. data/webgui/config/initializers/inflections.rb +10 -0
  85. data/webgui/config/initializers/mime_types.rb +5 -0
  86. data/webgui/config/initializers/new_rails_defaults.rb +17 -0
  87. data/webgui/config/initializers/pool.rb +33 -0
  88. data/webgui/config/initializers/site_keys.rb +38 -0
  89. data/webgui/config/locales/en.yml +5 -0
  90. data/webgui/config/routes.rb +56 -0
  91. data/webgui/db/development.sqlite3 +0 -0
  92. data/webgui/db/migrate/20090216015836_create_entries.rb +13 -0
  93. data/webgui/db/migrate/20090217001611_add_tie_break_to_entry.rb +9 -0
  94. data/webgui/db/migrate/20090217004039_create_users.rb +23 -0
  95. data/webgui/db/migrate/20090217014940_relate_entry_and_user.rb +10 -0
  96. data/webgui/db/migrate/20090218024350_create_roles.rb +17 -0
  97. data/webgui/db/migrate/20090218024657_add_postition_to_roles.rb +9 -0
  98. data/webgui/db/migrate/20090218025240_add_admin_role.rb +10 -0
  99. data/webgui/db/migrate/20090225022928_create_pools.rb +16 -0
  100. data/webgui/db/migrate/20090225030346_associate_pool_and_entry.rb +9 -0
  101. data/webgui/db/migrate/20090225072358_change_pool_data_column.rb +9 -0
  102. data/webgui/db/migrate/20090225072849_add_completed_to_entries.rb +9 -0
  103. data/webgui/db/migrate/20090225074149_add_pool_id_index_to_entries.rb +9 -0
  104. data/webgui/db/migrate/20090225084414_add_user_id_to_pool.rb +9 -0
  105. data/webgui/db/migrate/20090226021913_add_active_to_pools.rb +9 -0
  106. data/webgui/db/migrate/20090226142240_rename_bracket_column_to_data.rb +9 -0
  107. data/webgui/db/migrate/20090301014710_create_teams.rb +84 -0
  108. data/webgui/db/migrate/20090301025902_add_more_teams.rb +16 -0
  109. data/webgui/db/migrate/20090301041526_create_seedings.rb +16 -0
  110. data/webgui/db/migrate/20090301090511_create_regions.rb +14 -0
  111. data/webgui/db/migrate/teams.txt +347 -0
  112. data/webgui/db/pool.yml +408 -0
  113. data/webgui/db/schema.rb +91 -0
  114. data/webgui/db/test.sqlite3 +0 -0
  115. data/webgui/doc/README_FOR_APP +5 -0
  116. data/webgui/lib/authenticated_system.rb +189 -0
  117. data/webgui/lib/authenticated_test_helper.rb +11 -0
  118. data/webgui/lib/form_object.rb +70 -0
  119. data/webgui/lib/pdf_helper.rb +47 -0
  120. data/webgui/lib/prince.rb +74 -0
  121. data/webgui/lib/saves_picks.rb +23 -0
  122. data/webgui/lib/tasks/admin.rake +10 -0
  123. data/webgui/public/404.html +30 -0
  124. data/webgui/public/422.html +30 -0
  125. data/webgui/public/500.html +33 -0
  126. data/webgui/public/dispatch.cgi +10 -0
  127. data/webgui/public/dispatch.fcgi +24 -0
  128. data/webgui/public/dispatch.rb +10 -0
  129. data/webgui/public/favicon.ico +0 -0
  130. data/webgui/public/images/2009FinalFour.png +0 -0
  131. data/webgui/public/images/rails.png +0 -0
  132. data/webgui/public/javascripts/application.js +2 -0
  133. data/webgui/public/javascripts/bracket.js +73 -0
  134. data/webgui/public/javascripts/controls.js +963 -0
  135. data/webgui/public/javascripts/dragdrop.js +973 -0
  136. data/webgui/public/javascripts/effects.js +1128 -0
  137. data/webgui/public/javascripts/prototype.js +4320 -0
  138. data/webgui/public/robots.txt +5 -0
  139. data/webgui/public/stylesheets/bracket-print.css +39 -0
  140. data/webgui/public/stylesheets/bracket.css +125 -0
  141. data/webgui/public/stylesheets/main.css +144 -0
  142. data/webgui/public/stylesheets/prince.css +6 -0
  143. data/webgui/public/stylesheets/prince_landscape.css +1 -0
  144. data/webgui/script/about +4 -0
  145. data/webgui/script/console +3 -0
  146. data/webgui/script/dbconsole +3 -0
  147. data/webgui/script/destroy +3 -0
  148. data/webgui/script/generate +3 -0
  149. data/webgui/script/performance/benchmarker +3 -0
  150. data/webgui/script/performance/profiler +3 -0
  151. data/webgui/script/performance/request +3 -0
  152. data/webgui/script/plugin +3 -0
  153. data/webgui/script/process/inspector +3 -0
  154. data/webgui/script/process/reaper +3 -0
  155. data/webgui/script/process/spawner +3 -0
  156. data/webgui/script/runner +3 -0
  157. data/webgui/script/server +3 -0
  158. data/webgui/test/fixtures/entries.yml +10 -0
  159. data/webgui/test/fixtures/pools.yml +14 -0
  160. data/webgui/test/fixtures/regions.yml +11 -0
  161. data/webgui/test/fixtures/roles.yml +11 -0
  162. data/webgui/test/fixtures/roles_users.yml +3 -0
  163. data/webgui/test/fixtures/seedings.yml +12 -0
  164. data/webgui/test/fixtures/teams.yml +3051 -0
  165. data/webgui/test/fixtures/users.yml +44 -0
  166. data/webgui/test/functional/admin_controller_test.rb +8 -0
  167. data/webgui/test/functional/entry_controller_test.rb +27 -0
  168. data/webgui/test/functional/pool_controller_test.rb +8 -0
  169. data/webgui/test/functional/reports_controller_test.rb +8 -0
  170. data/webgui/test/functional/sessions_controller_test.rb +82 -0
  171. data/webgui/test/functional/teams_controller_test.rb +216 -0
  172. data/webgui/test/functional/users_controller_test.rb +88 -0
  173. data/webgui/test/performance/browsing_test.rb +9 -0
  174. data/webgui/test/test_helper.rb +38 -0
  175. data/webgui/test/unit/entry_test.rb +8 -0
  176. data/webgui/test/unit/pool_test.rb +8 -0
  177. data/webgui/test/unit/region_test.rb +8 -0
  178. data/webgui/test/unit/role_test.rb +8 -0
  179. data/webgui/test/unit/seeding_test.rb +8 -0
  180. data/webgui/test/unit/team_test.rb +10 -0
  181. data/webgui/test/unit/user_mailer_test.rb +31 -0
  182. data/webgui/test/unit/user_test.rb +109 -0
  183. data/webgui/vendor/plugins/auto_complete/README +23 -0
  184. data/webgui/vendor/plugins/auto_complete/Rakefile +22 -0
  185. data/webgui/vendor/plugins/auto_complete/init.rb +2 -0
  186. data/webgui/vendor/plugins/auto_complete/lib/auto_complete.rb +47 -0
  187. data/webgui/vendor/plugins/auto_complete/lib/auto_complete_macros_helper.rb +143 -0
  188. data/webgui/vendor/plugins/auto_complete/test/auto_complete_test.rb +67 -0
  189. data/webgui/vendor/plugins/enumerations_mixin/ATTENTION +15 -0
  190. data/webgui/vendor/plugins/enumerations_mixin/LICENSE +20 -0
  191. data/webgui/vendor/plugins/enumerations_mixin/README_ENUMERATIONS +163 -0
  192. data/webgui/vendor/plugins/enumerations_mixin/init.rb +21 -0
  193. data/webgui/vendor/plugins/enumerations_mixin/lib/active_record/acts/enumerated.rb +177 -0
  194. data/webgui/vendor/plugins/enumerations_mixin/lib/active_record/aggregations/has_enumerated.rb +60 -0
  195. data/webgui/vendor/plugins/enumerations_mixin/lib/active_record/virtual_enumerations.rb +68 -0
  196. data/webgui/vendor/plugins/enumerations_mixin/virtual_enumerations_sample.rb +76 -0
  197. data/webgui/vendor/plugins/restful_authentication/.gitignore +21 -0
  198. data/webgui/vendor/plugins/restful_authentication/CHANGELOG +68 -0
  199. data/webgui/vendor/plugins/restful_authentication/README.textile +224 -0
  200. data/webgui/vendor/plugins/restful_authentication/Rakefile +32 -0
  201. data/webgui/vendor/plugins/restful_authentication/TODO +15 -0
  202. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/USAGE +1 -0
  203. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/authenticated_generator.rb +478 -0
  204. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/lib/insert_routes.rb +54 -0
  205. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/_model_partial.html.erb +8 -0
  206. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/activation.erb +3 -0
  207. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/authenticated_system.rb +189 -0
  208. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/authenticated_test_helper.rb +22 -0
  209. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/controller.rb +43 -0
  210. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/helper.rb +2 -0
  211. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/login.html.erb +16 -0
  212. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/mailer.rb +25 -0
  213. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/migration.rb +26 -0
  214. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/model.rb +83 -0
  215. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/model_controller.rb +85 -0
  216. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/model_helper.rb +93 -0
  217. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/model_helper_spec.rb +158 -0
  218. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/observer.rb +11 -0
  219. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/signup.html.erb +19 -0
  220. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/signup_notification.erb +8 -0
  221. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/site_keys.rb +38 -0
  222. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/controllers/access_control_spec.rb +90 -0
  223. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/controllers/authenticated_system_spec.rb +102 -0
  224. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/controllers/sessions_controller_spec.rb +139 -0
  225. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/controllers/users_controller_spec.rb +198 -0
  226. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/fixtures/users.yml +60 -0
  227. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/helpers/users_helper_spec.rb +141 -0
  228. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/models/user_spec.rb +290 -0
  229. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/rest_auth_stories.rb +22 -0
  230. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/rest_auth_stories_helper.rb +81 -0
  231. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/steps/ra_navigation_steps.rb +49 -0
  232. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/steps/ra_resource_steps.rb +179 -0
  233. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/steps/ra_response_steps.rb +171 -0
  234. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/steps/user_steps.rb +153 -0
  235. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/users/accounts.story +186 -0
  236. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/users/sessions.story +134 -0
  237. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/test/functional_test.rb +82 -0
  238. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/test/mailer_test.rb +31 -0
  239. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/test/model_functional_test.rb +93 -0
  240. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/test/unit_test.rb +164 -0
  241. data/webgui/vendor/plugins/restful_authentication/init.rb +1 -0
  242. data/webgui/vendor/plugins/restful_authentication/install.rb +1 -0
  243. data/webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb +82 -0
  244. data/webgui/vendor/plugins/restful_authentication/lib/authentication/by_password.rb +64 -0
  245. data/webgui/vendor/plugins/restful_authentication/lib/authentication.rb +40 -0
  246. data/webgui/vendor/plugins/restful_authentication/lib/authorization/aasm_roles.rb +63 -0
  247. data/webgui/vendor/plugins/restful_authentication/lib/authorization/stateful_roles.rb +62 -0
  248. data/webgui/vendor/plugins/restful_authentication/lib/authorization.rb +14 -0
  249. data/webgui/vendor/plugins/restful_authentication/lib/trustification/email_validation.rb +20 -0
  250. data/webgui/vendor/plugins/restful_authentication/lib/trustification.rb +14 -0
  251. data/webgui/vendor/plugins/restful_authentication/notes/AccessControl.txt +2 -0
  252. data/webgui/vendor/plugins/restful_authentication/notes/Authentication.txt +5 -0
  253. data/webgui/vendor/plugins/restful_authentication/notes/Authorization.txt +154 -0
  254. data/webgui/vendor/plugins/restful_authentication/notes/RailsPlugins.txt +78 -0
  255. data/webgui/vendor/plugins/restful_authentication/notes/SecurityFramework.graffle +0 -0
  256. data/webgui/vendor/plugins/restful_authentication/notes/SecurityFramework.png +0 -0
  257. data/webgui/vendor/plugins/restful_authentication/notes/SecurityPatterns.txt +163 -0
  258. data/webgui/vendor/plugins/restful_authentication/notes/Tradeoffs.txt +126 -0
  259. data/webgui/vendor/plugins/restful_authentication/notes/Trustification.txt +49 -0
  260. data/webgui/vendor/plugins/restful_authentication/rails/init.rb +3 -0
  261. data/webgui/vendor/plugins/restful_authentication/restful-authentication.gemspec +33 -0
  262. data/webgui/vendor/plugins/restful_authentication/tasks/auth.rake +33 -0
  263. metadata +288 -8
  264. data/tasks/annotations.rake +0 -22
data/bin/pool CHANGED
@@ -1,10 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
- require File.expand_path(
3
- File.join(File.dirname(__FILE__), '..', 'lib', 'tournament'))
2
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'tournament'))
4
3
 
5
4
  require 'rubygems'
6
5
  require 'main'
7
6
  require 'yaml'
7
+ require 'fileutils'
8
+ require 'net/http'
9
+ require 'uri'
8
10
 
9
11
  Main do
10
12
 
@@ -20,7 +22,7 @@ Main do
20
22
 
21
23
  def init_pool
22
24
  @pool = Tournament::Pool.ncaa_2008
23
- @pool.bracket.scoring_strategy = Tournament::Bracket.strategy_for_name(params['scoring'].value)
25
+ @pool.scoring_strategy = Tournament::ScoringStrategy.strategy_for_name(params['scoring'].value)
24
26
  end
25
27
 
26
28
  def save_pool
@@ -31,34 +33,152 @@ Main do
31
33
  end
32
34
  end
33
35
 
34
- option('save-file', 's') do
35
- optional
36
- argument :required
37
- default 'pool.yml'
38
- arity 1
39
- description "Save file for the pool."
36
+ mode('install_webgui') do
37
+ description 'Installs the Rails webgui.'
38
+ option('web-dir', 'W') do
39
+ required
40
+ argument :required
41
+ arity 1
42
+ description "Installation directory for the Rails application."
43
+ error(:after) { puts usage.to_s }
44
+ end
45
+ option('site-name', 'S') do
46
+ optional
47
+ argument :required
48
+ default 'Tournament'
49
+ arity 1
50
+ description "Web site name used in <title> tags an email subject lines."
51
+ end
52
+ option('relative-root', 'R') do
53
+ optional
54
+ argument :required
55
+ arity 1
56
+ description "Relative URL root if you are installing the web application as a subdirectory in an existing website."
57
+ end
58
+ option('admin-email') do
59
+ required
60
+ argument :required
61
+ arity 1
62
+ description "Email address of the admin account."
63
+ error(:after) { puts usage.to_s }
64
+ end
65
+ option('email-server') do
66
+ optional
67
+ argument :required
68
+ arity 1
69
+ description "SMTP email server name."
70
+ end
71
+ option('email-port') do
72
+ cast :int
73
+ optional
74
+ argument :required
75
+ default 25
76
+ arity 1
77
+ description "SMTP email server port."
78
+ end
79
+ option('email-domain') do
80
+ optional
81
+ argument :required
82
+ arity 1
83
+ description "SMTP email server HELO domain."
84
+ end
85
+ option('email-user') do
86
+ optional
87
+ argument :required
88
+ arity 1
89
+ description "SMTP email server user name."
90
+ end
91
+ option('email-password') do
92
+ optional
93
+ argument :required
94
+ arity 1
95
+ description "SMTP email server user name."
96
+ end
97
+ option('email-auth') do
98
+ optional
99
+ argument :required
100
+ default 'login'
101
+ arity 1
102
+ validate {|ea| ['login', 'plain', 'cram_md5'].include?(ea)}
103
+ description "SMTP email server authentication type."
104
+ end
105
+ option('use-princexml', 'X') do
106
+ optional
107
+ argument :required
108
+ arity 1
109
+ description "Location of prince xml command line program, or directory into which the program will be installed after being downloaded from the Prince XML website."
110
+ end
111
+ option('tmp-dir', 't') do
112
+ optional
113
+ argument :required
114
+ default '/tmp'
115
+ arity 1
116
+ description "Temp directory location."
117
+ end
118
+ def run
119
+ installer = Tournament::WebguiInstaller.new(params['web-dir'].value)
120
+ installer.tmp_dir = params['tmp-dir'].value
121
+ options = params.to_options
122
+ if params['use-princexml'].given?
123
+ prince_xml = params['use-princexml'].value
124
+ if File.exist?(prince_xml) && File.executable?(prince_xml) && !File.directory?(prince_xml)
125
+ puts "=> USING PRINCE XML EXECUTABLE #{prince_xml}"
126
+ elsif File.exist?(prince_xml) && File.executable?(prince_xml) && File.directory?(prince_xml)
127
+ puts "=> INSTALLING PRINCE XML INTO #{prince_xml}"
128
+ installer.install_prince(prince_xml)
129
+ prince_xml = File.join(prince_xml, 'bin', 'prince')
130
+ else
131
+ print usage.to_s
132
+ exit_warn!
133
+ end
134
+ options['prince-path'] = prince_xml
135
+ end
136
+ puts "=> INSTALLING TOURNAMENT WEB GUI INTO #{installer.install_dir}"
137
+ installer.install_webgui
138
+ puts "=> ADJUSTING TOURNAMENT WEB GUI CONFIGURATION"
139
+ installer.adjust_configuration(options)
140
+
141
+ puts "=> INSTALLATION COMPLETE."
142
+ puts "You should now change to #{installer.install_dir} and"
143
+ puts "perform the following steps:"
144
+ puts " 1. RAILS_ENV=production rake db:migrate"
145
+ puts " 2. RAILS_ENV=production rake \"admin:create[admin,#{params['admin-email'].value},Joe Admin,password]\""
146
+ puts " You should substitute your desired admin user login, name and password."
147
+ end
148
+ end
149
+
150
+ mixin :savefile do
151
+ option('save-file', 's') do
152
+ optional
153
+ argument :required
154
+ default 'pool.yml'
155
+ arity 1
156
+ description "Save file for the pool."
157
+ end
40
158
  end
41
159
 
42
160
  mode('setup') do
43
161
  description "Sets up the pool the first time"
162
+ mixin :savefile
44
163
  option('scoring', 'S') do
45
164
  optional
46
165
  argument :required
47
166
  arity 1
48
167
  default 'basic_scoring_strategy'
49
- validate {|s| Tournament::Bracket.available_strategies.include?(s)}
50
- description "Sets the scoring strategy, should be one of #{Tournament::Bracket.available_strategies.join(', ')}"
168
+ validate {|s| Tournament::ScoringStrategy.available_strategies.include?(s)}
169
+ description "Sets the scoring strategy, should be one of #{Tournament::ScoringStrategy.available_strategies.join(', ')}"
51
170
  end
52
171
  def run
53
172
  init_pool
54
173
  puts "Initialized new pool"
55
174
  puts "Scoring:"
56
- puts @pool.bracket.scoring_strategy.description
175
+ puts @pool.scoring_strategy.description
57
176
  save_pool
58
177
  end
59
178
  end
60
179
 
61
180
  mode('update') do
181
+ mixin :savefile
62
182
  option('entry', 'e') do
63
183
  optional
64
184
  argument :required
@@ -69,12 +189,13 @@ Main do
69
189
  def run
70
190
  load_pool
71
191
  tournament = YAML::load_file(params['entry'].value)
72
- @pool.bracket = tournament.picks
192
+ @pool.tournament_entry = tournament
73
193
  save_pool
74
194
  end
75
195
  end
76
196
 
77
197
  mode('fee') do
198
+ mixin :savefile
78
199
  argument('amount') do
79
200
  required
80
201
  cast :integer
@@ -89,6 +210,7 @@ Main do
89
210
  end
90
211
 
91
212
  mode('payout') do
213
+ mixin :savefile
92
214
  option('constant-amount', 'C') do
93
215
  optional
94
216
  arity 1
@@ -122,6 +244,7 @@ Main do
122
244
  end
123
245
 
124
246
  mode('entry') do
247
+ mixin :savefile
125
248
  option('add', 'a') do
126
249
  optional
127
250
  argument :required
@@ -151,6 +274,7 @@ Main do
151
274
  end
152
275
 
153
276
  mode('dump') do
277
+ mixin :savefile
154
278
  option('entry', 'e') do
155
279
  optional
156
280
  argument :required
@@ -159,14 +283,14 @@ Main do
159
283
  end
160
284
  def run
161
285
  load_pool
162
- tournament = Tournament::Entry.new('Tournament', @pool.bracket, 0)
163
286
  File.open(params['entry'].value, "w") do |f|
164
- YAML::dump(tournament, f)
287
+ YAML::dump(@pool.tournament_entry, f)
165
288
  end
166
289
  end
167
290
  end
168
291
 
169
292
  mode('report') do
293
+ mixin :savefile
170
294
  available_reports = Tournament::Pool.instance_methods(false).map do |name|
171
295
  if idx = name.index("_report")
172
296
  name[0,idx]
@@ -4,46 +4,7 @@ class Tournament::Bracket
4
4
  attr_reader :teams # The teams in the bracket
5
5
  attr_reader :rounds # The number of rounds in the bracket
6
6
  attr_reader :winners # The winners of each game in the bracket
7
- attr_accessor :scoring_strategy # The strategy used to assign points to correct picks
8
7
 
9
- # Class representing a scoring strategy where correct picks
10
- # are worth 2 X the round number
11
- class BasicScoringStrategy
12
- def score(pick, winner, loser, round)
13
- winner != UNKNOWN_TEAM && pick == winner ? round * 2 : 0
14
- end
15
- def description
16
- "Each game is worth 2 times the round number."
17
- end
18
- end
19
-
20
- # Class representing a scoring strategy where correct picks
21
- # are worth a base amount per round (3, 5, 11, 19, 30 and 40)
22
- # plus the seed number of the winner.
23
- class UpsetScoringStrategy
24
- PER_ROUND = [3, 5, 11, 19, 30, 40]
25
- def score(pick, winner, loser, round)
26
- if winner != UNKNOWN_TEAM && pick == winner
27
- return PER_ROUND[round-1] + winner.seed
28
- end
29
- return 0
30
- end
31
- def description
32
- "Games are worth #{PER_ROUND.join(', ')} per round plus the seed number of the winning team."
33
- end
34
- end
35
-
36
- # Returns names of available strategies. The names returned are suitable
37
- # for use in the strategy_for_name method
38
- def self.available_strategies
39
- return ['basic_scoring_strategy', 'upset_scoring_strategy']
40
- end
41
-
42
- # Returns an instantiated strategy class for the named strategy.
43
- def self.strategy_for_name(name)
44
- clazz = Tournament::Bracket.const_get(name.capitalize.gsub(/_([a-zA-Z])/) {|m| $1.upcase})
45
- return clazz.new
46
- end
47
8
 
48
9
  UNKNOWN_TEAM = :unk unless defined?(UNKNOWN_TEAM)
49
10
 
@@ -54,11 +15,11 @@ class Tournament::Bracket
54
15
  @winners = [@teams] + (1..@rounds).map do |r|
55
16
  [UNKNOWN_TEAM] * games_in_round(r)
56
17
  end
57
- @scoring_strategy = BasicScoringStrategy.new
58
18
  end
59
19
 
60
20
  # Returns true if the provided team has not lost
61
21
  def still_alive?(team)
22
+ return false if team == UNKNOWN_TEAM
62
23
  team_index = @winners[0].index(team)
63
24
  game = team_index/2
64
25
  round = 1
@@ -96,6 +57,16 @@ class Tournament::Bracket
96
57
  return round
97
58
  end
98
59
 
60
+ # Returns true if all games have been decided
61
+ def complete?
62
+ round = 0
63
+ while round < self.rounds
64
+ return false if @winners[round+1].any? {|t| t == UNKNOWN_TEAM}
65
+ round += 1
66
+ end
67
+ return true
68
+ end
69
+
99
70
  # Returns the number of teams left in the bracket.
100
71
  def teams_left
101
72
  return 1 + @winners.inject(0) { |memo, arr| arr.inject(memo) {|memo, team| memo += (team == UNKNOWN_TEAM ? 1 : 0)} }
@@ -196,7 +167,6 @@ class Tournament::Bracket
196
167
  # that would result.
197
168
  def bracket_for(possibility)
198
169
  pick_bracket = Tournament::Bracket.new(self.teams)
199
- pick_bracket.scoring_strategy = self.scoring_strategy
200
170
  round = 1
201
171
  while round <= pick_bracket.rounds
202
172
  gir = pick_bracket.games_in_round(round)
@@ -216,7 +186,7 @@ class Tournament::Bracket
216
186
  return pick_bracket
217
187
  end
218
188
 
219
- # Returns a two element array containing the Team's in the
189
+ # Returns a two element array containing the Teams in the
220
190
  # matchup for the given round and game
221
191
  def matchup(round, game)
222
192
  return @winners[round-1][(game-1)*2..(game-1)*2+1]
@@ -253,6 +223,17 @@ class Tournament::Bracket
253
223
  end
254
224
  end
255
225
 
226
+ # Given a overall game number, return the round and round game number
227
+ def round_and_game(overall_game)
228
+ 1.upto(rounds) do |r|
229
+ if overall_game <= games_in_round(r)
230
+ return [r, overall_game]
231
+ else
232
+ overall_game -= games_in_round(r)
233
+ end
234
+ end
235
+ end
236
+
256
237
  # Sets the winner of the given round and game to the provided team
257
238
  def set_winner(round, game, team)
258
239
  if UNKNOWN_TEAM == team || matchup(round, game).include?(team)
@@ -277,8 +258,8 @@ class Tournament::Bracket
277
258
  end
278
259
 
279
260
  # Compute the maximum possible score if all remaining picks in this
280
- # bracket turn out to be correct.
281
- def maximum_score(other_bracket)
261
+ # bracket turn out to be correct using the given scoring strategy.
262
+ def maximum_score(other_bracket, scoring_strategy)
282
263
  score = 0
283
264
  round = 1
284
265
  while round <= self.rounds
@@ -288,7 +269,7 @@ class Tournament::Bracket
288
269
  winner, loser = other_bracket.winner_and_loser(round, game)
289
270
  pick = self.winner(round, game)
290
271
  winner = pick if winner == UNKNOWN_TEAM && other_bracket.still_alive?(pick)
291
- score += other_bracket.scoring_strategy.score(pick, winner, loser, round)
272
+ score += scoring_strategy.score(pick, winner, loser, round)
292
273
  game += 1
293
274
  end
294
275
  round += 1
@@ -297,8 +278,9 @@ class Tournament::Bracket
297
278
  end
298
279
 
299
280
  # Computes the total score of this bracket using other_bracket
300
- # as the guide
301
- def score_against(other_bracket)
281
+ # to determine correct picks. Use the provided scoring strategy
282
+ # to compute the score.
283
+ def score_against(other_bracket, scoring_strategy)
302
284
  score = 0
303
285
  round = 1
304
286
  while round <= self.rounds
@@ -306,7 +288,7 @@ class Tournament::Bracket
306
288
  game = 1
307
289
  while game <= games_in_round
308
290
  winner, loser = other_bracket.winner_and_loser(round, game)
309
- score += other_bracket.scoring_strategy.score(self.winner(round, game), winner, loser, round)
291
+ score += scoring_strategy.score(self.winner(round, game), winner, loser, round)
310
292
  #puts "round #{round} game #{game} winner #{winner} loser #{loser} pick #{self.winner(round,game)}"
311
293
  game += 1
312
294
  end
@@ -316,19 +298,20 @@ class Tournament::Bracket
316
298
  end
317
299
 
318
300
  # Compute the score for a particular round against the other_bracket
301
+ # using the provided scoring strategy.
319
302
  # Returns an array of two element arrays, one for each game in the
320
303
  # round. The first element of the subarray is the score and the
321
304
  # second element is the team that was picked. If the winner of the
322
305
  # game is unknown (because it has not been played), the score element
323
306
  # will be nil.
324
- def scores_for_round(round, other_bracket)
307
+ def scores_for_round(round, other_bracket, scoring_strategy)
325
308
  games_in_round = self.games_in_round(round)
326
309
  return (1..games_in_round).to_a.map do |g|
327
310
  winner, loser = other_bracket.winner_and_loser(round, g)
328
311
  pick = self.winner(round, g)
329
312
  score = nil
330
313
  if winner != UNKNOWN_TEAM || !other_bracket.still_alive?(pick)
331
- score = other_bracket.scoring_strategy.score(pick, winner, loser, round)
314
+ score = scoring_strategy.score(pick, winner, loser, round)
332
315
  end
333
316
  [score, pick]
334
317
  end
@@ -10,4 +10,7 @@ class Tournament::Entry
10
10
  @picks = picks
11
11
  @tie_breaker = tie_breaker
12
12
  end
13
+
14
+ # Alias picks as bracket
15
+ alias_method :bracket, :picks
13
16
  end