tournament 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +15 -0
- data/Manifest.txt +241 -2
- data/README.txt +152 -12
- data/Rakefile +9 -6
- data/bin/benchmark_pool +0 -0
- data/bin/gui.rb +3 -1
- data/bin/picker +0 -0
- data/bin/pool +139 -15
- data/lib/tournament/bracket.rb +33 -50
- data/lib/tournament/entry.rb +3 -0
- data/lib/tournament/pool.rb +144 -93
- data/lib/tournament/scoring_strategy.rb +69 -0
- data/lib/tournament/webgui_installer.rb +109 -0
- data/tasks/ann.rake +19 -14
- data/tasks/bones.rake +6 -25
- data/tasks/gem.rake +46 -36
- data/tasks/git.rake +41 -0
- data/tasks/jamis.rb +589 -0
- data/tasks/notes.rake +28 -0
- data/tasks/post_load.rake +18 -11
- data/tasks/{doc.rake → rdoc.rake} +12 -9
- data/tasks/rubyforge.rake +12 -12
- data/tasks/setup.rb +121 -80
- data/tasks/spec.rake +12 -13
- data/tasks/svn.rake +15 -11
- data/tasks/test.rake +6 -6
- data/test/test_tournament.rb +8 -0
- data/test/test_webgui_installer.rb +64 -0
- data/webgui/README +256 -0
- data/webgui/Rakefile +10 -0
- data/webgui/app/controllers/admin_controller.rb +61 -0
- data/webgui/app/controllers/application.rb +25 -0
- data/webgui/app/controllers/entry_controller.rb +97 -0
- data/webgui/app/controllers/pool_controller.rb +4 -0
- data/webgui/app/controllers/reports_controller.rb +7 -0
- data/webgui/app/controllers/sessions_controller.rb +43 -0
- data/webgui/app/controllers/teams_controller.rb +75 -0
- data/webgui/app/controllers/users_controller.rb +57 -0
- data/webgui/app/helpers/admin_helper.rb +2 -0
- data/webgui/app/helpers/application_helper.rb +3 -0
- data/webgui/app/helpers/entry_helper.rb +2 -0
- data/webgui/app/helpers/pool_helper.rb +2 -0
- data/webgui/app/helpers/reports_helper.rb +2 -0
- data/webgui/app/helpers/sessions_helper.rb +2 -0
- data/webgui/app/helpers/teams_helper.rb +2 -0
- data/webgui/app/helpers/users_helper.rb +93 -0
- data/webgui/app/models/entry.rb +42 -0
- data/webgui/app/models/pool.rb +141 -0
- data/webgui/app/models/region.rb +3 -0
- data/webgui/app/models/role.rb +4 -0
- data/webgui/app/models/seeding.rb +4 -0
- data/webgui/app/models/team.rb +6 -0
- data/webgui/app/models/user.rb +98 -0
- data/webgui/app/models/user_mailer.rb +25 -0
- data/webgui/app/views/admin/bracket.html.erb +3 -0
- data/webgui/app/views/admin/entries.html.erb +25 -0
- data/webgui/app/views/admin/index.html.erb +17 -0
- data/webgui/app/views/admin/pool.html.erb +53 -0
- data/webgui/app/views/entry/index.html.erb +16 -0
- data/webgui/app/views/entry/print.erb +1 -0
- data/webgui/app/views/entry/print.html.erb +1 -0
- data/webgui/app/views/entry/show.html.erb +1 -0
- data/webgui/app/views/layouts/bracket.html.erb +37 -0
- data/webgui/app/views/layouts/default.html.erb +62 -0
- data/webgui/app/views/layouts/print.html.erb +12 -0
- data/webgui/app/views/layouts/report.html.erb +38 -0
- data/webgui/app/views/pool/index.html.erb +36 -0
- data/webgui/app/views/reports/_report.html.erb +11 -0
- data/webgui/app/views/reports/show.html.erb +12 -0
- data/webgui/app/views/sessions/new.html.erb +21 -0
- data/webgui/app/views/shared/_admins.html.erb +8 -0
- data/webgui/app/views/shared/_bracket.html.erb +1296 -0
- data/webgui/app/views/teams/choose.html.erb +57 -0
- data/webgui/app/views/user_mailer/activation.erb +3 -0
- data/webgui/app/views/user_mailer/signup_notification.erb +8 -0
- data/webgui/app/views/users/_user_bar.html.erb +8 -0
- data/webgui/app/views/users/new.html.erb +19 -0
- data/webgui/config/boot.rb +109 -0
- data/webgui/config/database.yml +22 -0
- data/webgui/config/environment.rb +78 -0
- data/webgui/config/environments/development.rb +29 -0
- data/webgui/config/environments/production.rb +24 -0
- data/webgui/config/environments/test.rb +22 -0
- data/webgui/config/initializers/inflections.rb +10 -0
- data/webgui/config/initializers/mime_types.rb +5 -0
- data/webgui/config/initializers/new_rails_defaults.rb +17 -0
- data/webgui/config/initializers/pool.rb +33 -0
- data/webgui/config/initializers/site_keys.rb +38 -0
- data/webgui/config/locales/en.yml +5 -0
- data/webgui/config/routes.rb +56 -0
- data/webgui/db/development.sqlite3 +0 -0
- data/webgui/db/migrate/20090216015836_create_entries.rb +13 -0
- data/webgui/db/migrate/20090217001611_add_tie_break_to_entry.rb +9 -0
- data/webgui/db/migrate/20090217004039_create_users.rb +23 -0
- data/webgui/db/migrate/20090217014940_relate_entry_and_user.rb +10 -0
- data/webgui/db/migrate/20090218024350_create_roles.rb +17 -0
- data/webgui/db/migrate/20090218024657_add_postition_to_roles.rb +9 -0
- data/webgui/db/migrate/20090218025240_add_admin_role.rb +10 -0
- data/webgui/db/migrate/20090225022928_create_pools.rb +16 -0
- data/webgui/db/migrate/20090225030346_associate_pool_and_entry.rb +9 -0
- data/webgui/db/migrate/20090225072358_change_pool_data_column.rb +9 -0
- data/webgui/db/migrate/20090225072849_add_completed_to_entries.rb +9 -0
- data/webgui/db/migrate/20090225074149_add_pool_id_index_to_entries.rb +9 -0
- data/webgui/db/migrate/20090225084414_add_user_id_to_pool.rb +9 -0
- data/webgui/db/migrate/20090226021913_add_active_to_pools.rb +9 -0
- data/webgui/db/migrate/20090226142240_rename_bracket_column_to_data.rb +9 -0
- data/webgui/db/migrate/20090301014710_create_teams.rb +84 -0
- data/webgui/db/migrate/20090301025902_add_more_teams.rb +16 -0
- data/webgui/db/migrate/20090301041526_create_seedings.rb +16 -0
- data/webgui/db/migrate/20090301090511_create_regions.rb +14 -0
- data/webgui/db/migrate/teams.txt +347 -0
- data/webgui/db/pool.yml +408 -0
- data/webgui/db/schema.rb +91 -0
- data/webgui/db/test.sqlite3 +0 -0
- data/webgui/doc/README_FOR_APP +5 -0
- data/webgui/lib/authenticated_system.rb +189 -0
- data/webgui/lib/authenticated_test_helper.rb +11 -0
- data/webgui/lib/form_object.rb +70 -0
- data/webgui/lib/pdf_helper.rb +47 -0
- data/webgui/lib/prince.rb +74 -0
- data/webgui/lib/saves_picks.rb +23 -0
- data/webgui/lib/tasks/admin.rake +10 -0
- data/webgui/public/404.html +30 -0
- data/webgui/public/422.html +30 -0
- data/webgui/public/500.html +33 -0
- data/webgui/public/dispatch.cgi +10 -0
- data/webgui/public/dispatch.fcgi +24 -0
- data/webgui/public/dispatch.rb +10 -0
- data/webgui/public/favicon.ico +0 -0
- data/webgui/public/images/2009FinalFour.png +0 -0
- data/webgui/public/images/rails.png +0 -0
- data/webgui/public/javascripts/application.js +2 -0
- data/webgui/public/javascripts/bracket.js +73 -0
- data/webgui/public/javascripts/controls.js +963 -0
- data/webgui/public/javascripts/dragdrop.js +973 -0
- data/webgui/public/javascripts/effects.js +1128 -0
- data/webgui/public/javascripts/prototype.js +4320 -0
- data/webgui/public/robots.txt +5 -0
- data/webgui/public/stylesheets/bracket-print.css +39 -0
- data/webgui/public/stylesheets/bracket.css +125 -0
- data/webgui/public/stylesheets/main.css +144 -0
- data/webgui/public/stylesheets/prince.css +6 -0
- data/webgui/public/stylesheets/prince_landscape.css +1 -0
- data/webgui/script/about +4 -0
- data/webgui/script/console +3 -0
- data/webgui/script/dbconsole +3 -0
- data/webgui/script/destroy +3 -0
- data/webgui/script/generate +3 -0
- data/webgui/script/performance/benchmarker +3 -0
- data/webgui/script/performance/profiler +3 -0
- data/webgui/script/performance/request +3 -0
- data/webgui/script/plugin +3 -0
- data/webgui/script/process/inspector +3 -0
- data/webgui/script/process/reaper +3 -0
- data/webgui/script/process/spawner +3 -0
- data/webgui/script/runner +3 -0
- data/webgui/script/server +3 -0
- data/webgui/test/fixtures/entries.yml +10 -0
- data/webgui/test/fixtures/pools.yml +14 -0
- data/webgui/test/fixtures/regions.yml +11 -0
- data/webgui/test/fixtures/roles.yml +11 -0
- data/webgui/test/fixtures/roles_users.yml +3 -0
- data/webgui/test/fixtures/seedings.yml +12 -0
- data/webgui/test/fixtures/teams.yml +3051 -0
- data/webgui/test/fixtures/users.yml +44 -0
- data/webgui/test/functional/admin_controller_test.rb +8 -0
- data/webgui/test/functional/entry_controller_test.rb +27 -0
- data/webgui/test/functional/pool_controller_test.rb +8 -0
- data/webgui/test/functional/reports_controller_test.rb +8 -0
- data/webgui/test/functional/sessions_controller_test.rb +82 -0
- data/webgui/test/functional/teams_controller_test.rb +216 -0
- data/webgui/test/functional/users_controller_test.rb +88 -0
- data/webgui/test/performance/browsing_test.rb +9 -0
- data/webgui/test/test_helper.rb +38 -0
- data/webgui/test/unit/entry_test.rb +8 -0
- data/webgui/test/unit/pool_test.rb +8 -0
- data/webgui/test/unit/region_test.rb +8 -0
- data/webgui/test/unit/role_test.rb +8 -0
- data/webgui/test/unit/seeding_test.rb +8 -0
- data/webgui/test/unit/team_test.rb +10 -0
- data/webgui/test/unit/user_mailer_test.rb +31 -0
- data/webgui/test/unit/user_test.rb +109 -0
- data/webgui/vendor/plugins/auto_complete/README +23 -0
- data/webgui/vendor/plugins/auto_complete/Rakefile +22 -0
- data/webgui/vendor/plugins/auto_complete/init.rb +2 -0
- data/webgui/vendor/plugins/auto_complete/lib/auto_complete.rb +47 -0
- data/webgui/vendor/plugins/auto_complete/lib/auto_complete_macros_helper.rb +143 -0
- data/webgui/vendor/plugins/auto_complete/test/auto_complete_test.rb +67 -0
- data/webgui/vendor/plugins/enumerations_mixin/ATTENTION +15 -0
- data/webgui/vendor/plugins/enumerations_mixin/LICENSE +20 -0
- data/webgui/vendor/plugins/enumerations_mixin/README_ENUMERATIONS +163 -0
- data/webgui/vendor/plugins/enumerations_mixin/init.rb +21 -0
- data/webgui/vendor/plugins/enumerations_mixin/lib/active_record/acts/enumerated.rb +177 -0
- data/webgui/vendor/plugins/enumerations_mixin/lib/active_record/aggregations/has_enumerated.rb +60 -0
- data/webgui/vendor/plugins/enumerations_mixin/lib/active_record/virtual_enumerations.rb +68 -0
- data/webgui/vendor/plugins/enumerations_mixin/virtual_enumerations_sample.rb +76 -0
- data/webgui/vendor/plugins/restful_authentication/.gitignore +21 -0
- data/webgui/vendor/plugins/restful_authentication/CHANGELOG +68 -0
- data/webgui/vendor/plugins/restful_authentication/README.textile +224 -0
- data/webgui/vendor/plugins/restful_authentication/Rakefile +32 -0
- data/webgui/vendor/plugins/restful_authentication/TODO +15 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/USAGE +1 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/authenticated_generator.rb +478 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/lib/insert_routes.rb +54 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/_model_partial.html.erb +8 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/activation.erb +3 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/authenticated_system.rb +189 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/authenticated_test_helper.rb +22 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/controller.rb +43 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/helper.rb +2 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/login.html.erb +16 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/mailer.rb +25 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/migration.rb +26 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/model.rb +83 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/model_controller.rb +85 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/model_helper.rb +93 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/model_helper_spec.rb +158 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/observer.rb +11 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/signup.html.erb +19 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/signup_notification.erb +8 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/site_keys.rb +38 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/controllers/access_control_spec.rb +90 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/controllers/authenticated_system_spec.rb +102 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/controllers/sessions_controller_spec.rb +139 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/controllers/users_controller_spec.rb +198 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/fixtures/users.yml +60 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/helpers/users_helper_spec.rb +141 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/models/user_spec.rb +290 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/rest_auth_stories.rb +22 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/rest_auth_stories_helper.rb +81 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/steps/ra_navigation_steps.rb +49 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/steps/ra_resource_steps.rb +179 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/steps/ra_response_steps.rb +171 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/steps/user_steps.rb +153 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/users/accounts.story +186 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/users/sessions.story +134 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/test/functional_test.rb +82 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/test/mailer_test.rb +31 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/test/model_functional_test.rb +93 -0
- data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/test/unit_test.rb +164 -0
- data/webgui/vendor/plugins/restful_authentication/init.rb +1 -0
- data/webgui/vendor/plugins/restful_authentication/install.rb +1 -0
- data/webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb +82 -0
- data/webgui/vendor/plugins/restful_authentication/lib/authentication/by_password.rb +64 -0
- data/webgui/vendor/plugins/restful_authentication/lib/authentication.rb +40 -0
- data/webgui/vendor/plugins/restful_authentication/lib/authorization/aasm_roles.rb +63 -0
- data/webgui/vendor/plugins/restful_authentication/lib/authorization/stateful_roles.rb +62 -0
- data/webgui/vendor/plugins/restful_authentication/lib/authorization.rb +14 -0
- data/webgui/vendor/plugins/restful_authentication/lib/trustification/email_validation.rb +20 -0
- data/webgui/vendor/plugins/restful_authentication/lib/trustification.rb +14 -0
- data/webgui/vendor/plugins/restful_authentication/notes/AccessControl.txt +2 -0
- data/webgui/vendor/plugins/restful_authentication/notes/Authentication.txt +5 -0
- data/webgui/vendor/plugins/restful_authentication/notes/Authorization.txt +154 -0
- data/webgui/vendor/plugins/restful_authentication/notes/RailsPlugins.txt +78 -0
- data/webgui/vendor/plugins/restful_authentication/notes/SecurityFramework.graffle +0 -0
- data/webgui/vendor/plugins/restful_authentication/notes/SecurityFramework.png +0 -0
- data/webgui/vendor/plugins/restful_authentication/notes/SecurityPatterns.txt +163 -0
- data/webgui/vendor/plugins/restful_authentication/notes/Tradeoffs.txt +126 -0
- data/webgui/vendor/plugins/restful_authentication/notes/Trustification.txt +49 -0
- data/webgui/vendor/plugins/restful_authentication/rails/init.rb +3 -0
- data/webgui/vendor/plugins/restful_authentication/restful-authentication.gemspec +33 -0
- data/webgui/vendor/plugins/restful_authentication/tasks/auth.rake +33 -0
- metadata +288 -8
- data/tasks/annotations.rake +0 -22
data/lib/tournament/pool.rb
CHANGED
@@ -7,12 +7,14 @@ class Tournament::Pool
|
|
7
7
|
attr_reader :entries # Tournament::Entry objects for participants
|
8
8
|
attr_reader :payouts # Hash of payouts by rank
|
9
9
|
attr_accessor :entry_fee # The amount each entry paid to participate
|
10
|
+
attr_reader :scoring_strategy # The scoring strategy for the pool
|
10
11
|
|
11
12
|
# Create a new empty pool with no Regions or Entries
|
12
13
|
def initialize
|
13
14
|
@regions = Array.new(4)
|
14
15
|
@entries = []
|
15
16
|
@payouts = {}
|
17
|
+
@scoring_strategy = Tournament::ScoringStrategy::Basic.new
|
16
18
|
end
|
17
19
|
|
18
20
|
# add regions to the pool. Champ of region with index = 0 plays
|
@@ -29,6 +31,11 @@ class Tournament::Pool
|
|
29
31
|
@entries << entry
|
30
32
|
end
|
31
33
|
|
34
|
+
# Set new scoring strategy. This should not be allowed.
|
35
|
+
def scoring_strategy=(new_strat)
|
36
|
+
@scoring_strategy = new_strat
|
37
|
+
end
|
38
|
+
|
32
39
|
# Add an Tournament::Entry object to the pool after reading the Tournament::Entry
|
33
40
|
# from the provided YAML file.
|
34
41
|
def add_entry_yaml(yaml)
|
@@ -43,6 +50,12 @@ class Tournament::Pool
|
|
43
50
|
end
|
44
51
|
end
|
45
52
|
|
53
|
+
# Replace existing matching entry with the provided entry
|
54
|
+
def update_entry(entry)
|
55
|
+
remove_by_name(entry.name)
|
56
|
+
@entries << entry
|
57
|
+
end
|
58
|
+
|
46
59
|
# Set a payout. Takes a rank (or the symbol :last for
|
47
60
|
# last place), along with the payout. The payout may be
|
48
61
|
# a positive integer, in which case, it represents a
|
@@ -56,11 +69,11 @@ class Tournament::Pool
|
|
56
69
|
@payouts[rank] = payout
|
57
70
|
end
|
58
71
|
|
59
|
-
# Creates a
|
72
|
+
# Creates a entry for the pool by combining all the
|
60
73
|
# regions into one bracket of 64 teams. By default the
|
61
|
-
# bracket uses the basic scoring strategy.
|
62
|
-
def
|
63
|
-
unless @
|
74
|
+
# entry bracket uses the basic scoring strategy.
|
75
|
+
def tournament_entry
|
76
|
+
unless @tournament_entry
|
64
77
|
if @regions.compact.size != 4
|
65
78
|
raise "Not all regions have been set."
|
66
79
|
end
|
@@ -68,15 +81,16 @@ class Tournament::Pool
|
|
68
81
|
region[:teams]
|
69
82
|
end
|
70
83
|
all_teams = all_teams.flatten
|
71
|
-
|
84
|
+
bracket = Tournament::Bracket.new(all_teams)
|
85
|
+
@tournament_entry = Tournament::Entry.new('Tournament Entry', bracket, nil)
|
72
86
|
end
|
73
|
-
return @
|
87
|
+
return @tournament_entry
|
74
88
|
end
|
75
89
|
|
76
90
|
# Replaces the pool's bracket (as in after updating the bracket
|
77
91
|
# for game results)
|
78
|
-
def
|
79
|
-
@
|
92
|
+
def tournament_entry=(new_entry)
|
93
|
+
@tournament_entry = new_entry
|
80
94
|
end
|
81
95
|
|
82
96
|
# Creates a Pool object for the 2008 NCAA tournament
|
@@ -177,8 +191,8 @@ class Tournament::Pool
|
|
177
191
|
pool.set_payout(2, 20)
|
178
192
|
pool.set_payout(3, 10)
|
179
193
|
pool.set_payout(:last, -10)
|
180
|
-
|
181
|
-
b
|
194
|
+
pool.scoring_strategy = Tournament::ScoringStrategy::Upset.new
|
195
|
+
b = pool.tournament_entry.picks
|
182
196
|
picks = (1..num_picks).map {|n| Tournament::Bracket.random_bracket(b.teams)}
|
183
197
|
# Play out the bracket
|
184
198
|
32.times { |n| b.set_winner(1,n+1, b.matchup(1, n+1)[rand(2)])}
|
@@ -189,7 +203,7 @@ class Tournament::Pool
|
|
189
203
|
#1.times { |n| b.set_winner(6,n+1, b.matchup(6, n+1)[rand(2)])}
|
190
204
|
picks.each_with_index {|p, idx| pool.add_entry Tournament::Entry.new("picker_#{idx}", p) }
|
191
205
|
picks.each_with_index do |p, idx|
|
192
|
-
puts "Score #{idx+1}: #{p.score_against(b)}"
|
206
|
+
puts "Score #{idx+1}: #{p.score_against(b, pool.scoring_strategy)}"
|
193
207
|
end
|
194
208
|
pool.region_report
|
195
209
|
pool.leader_report
|
@@ -201,65 +215,86 @@ class Tournament::Pool
|
|
201
215
|
|
202
216
|
# Generate the leader board report. Shows each entry sorted by current
|
203
217
|
# score and gives a breakdown of score by round.
|
204
|
-
def leader_report
|
205
|
-
|
206
|
-
|
218
|
+
def leader_report(out = $stdout)
|
219
|
+
out << "Total games played: #{tournament_entry.picks.games_played}" << "\n"
|
220
|
+
if tournament_entry.picks.complete?
|
221
|
+
out << "Champion: #{tournament_entry.picks.champion.name}" << "\n"
|
222
|
+
end
|
223
|
+
out << "Pool Tie Break: #{tournament_entry.tie_breaker || '-'}" << "\n"
|
224
|
+
out << "Number of entries: #{@entries.size}" << "\n"
|
225
|
+
current_rank = 1
|
207
226
|
if @entries.size > 0
|
208
|
-
|
209
|
-
|
210
|
-
sep ="
|
211
|
-
|
212
|
-
@entries.
|
213
|
-
|
214
|
-
|
227
|
+
out << " | Curr| Max | |Champ| Tie | Round Scores" << "\n"
|
228
|
+
out << "Rank|Score|Score| Name |Live?|Break|" + (1..tournament_entry.picks.rounds).to_a.map{|r| "%3d" % r}.join(" ") << "\n"
|
229
|
+
sep ="----+-----+-----+---------------+-----+-----+" + ("-" * 4 * tournament_entry.picks.rounds)
|
230
|
+
out << sep << "\n"
|
231
|
+
@entries.sort do |e1, e2|
|
232
|
+
s1 = e1.picks.score_against(tournament_entry.picks, self.scoring_strategy)
|
233
|
+
s2 = e2.picks.score_against(tournament_entry.picks, self.scoring_strategy)
|
234
|
+
if s1 == s2 && tournament_entry.tie_breaker
|
235
|
+
s1 = 0 - (e1.tie_breaker - tournament_entry.tie_breaker).abs
|
236
|
+
s2 = 0 - (e2.tie_breaker - tournament_entry.tie_breaker).abs
|
237
|
+
end
|
238
|
+
s2 <=> s1
|
239
|
+
end.inject(nil) do |last_entry, entry|
|
240
|
+
total = entry.picks.score_against(tournament_entry.picks, self.scoring_strategy)
|
241
|
+
max = entry.picks.maximum_score(tournament_entry.picks, self.scoring_strategy)
|
215
242
|
champ = entry.picks.champion
|
216
243
|
round_scores = []
|
217
|
-
1.upto(
|
218
|
-
scores = entry.picks.scores_for_round(round,
|
244
|
+
1.upto(tournament_entry.picks.rounds) do |round|
|
245
|
+
scores = entry.picks.scores_for_round(round, tournament_entry.picks, self.scoring_strategy)
|
219
246
|
round_scores << scores.inject(0) {|sum, arr| sum += (arr[0] ? arr[0] : 0)}
|
220
247
|
end
|
221
|
-
|
222
|
-
|
248
|
+
rank_display = nil
|
249
|
+
if last_entry && !tournament_entry.tie_breaker && total == last_entry.bracket.score_against(tournament_entry.picks, self.scoring_strategy)
|
250
|
+
rank_display = 'TIE'
|
251
|
+
else
|
252
|
+
rank_display = "%4d" % current_rank
|
253
|
+
end
|
254
|
+
out << "%4s|%5d|%5d|%15s|%3s %1s|%5d|%s" % [rank_display, total, max, entry.name,
|
255
|
+
champ.short_name,(tournament_entry.picks.still_alive?(champ) ? 'Y' : 'N'), entry.tie_breaker || '-', round_scores.map {|s| "%3d" % s}.join(" ")] << "\n"
|
256
|
+
current_rank += 1
|
257
|
+
entry
|
223
258
|
end
|
224
|
-
|
259
|
+
out << sep << "\n"
|
225
260
|
end
|
226
261
|
end
|
227
262
|
|
228
263
|
# Shows detailed scores per entry. For each pick in each game, shows
|
229
264
|
# either a positive amount if the pick was correct, 0 if the pick was
|
230
265
|
# incorrect, or a '?' if the game has not yet been played.
|
231
|
-
def score_report
|
266
|
+
def score_report(out = $stdout)
|
232
267
|
# Compute scores
|
233
|
-
|
234
|
-
|
268
|
+
out << "Total games played: #{tournament_entry.picks.games_played}" << "\n"
|
269
|
+
out << "Number of entries: #{@entries.size}" << "\n"
|
235
270
|
sep = "-----+---------------+----------------------------------------------------------------------------------"
|
236
271
|
if @entries.size > 0
|
237
|
-
|
238
|
-
|
272
|
+
out << "Total| Name | Round Scores" << "\n"
|
273
|
+
out << sep << "\n"
|
239
274
|
fmt1 = "%5d|%15s|%d: %3d %s"
|
240
275
|
fmt2 = " | |%d: %3d %s"
|
241
276
|
fmt3 = " | | %s"
|
242
|
-
@entries.sort_by {|e| -e.picks.score_against(
|
243
|
-
total = entry.picks.score_against(
|
244
|
-
1.upto(
|
245
|
-
scores = entry.picks.scores_for_round(round,
|
277
|
+
@entries.sort_by {|e| -e.picks.score_against(tournament_entry.picks, self.scoring_strategy)}.each do |entry|
|
278
|
+
total = entry.picks.score_against(tournament_entry.picks, self.scoring_strategy)
|
279
|
+
1.upto(tournament_entry.picks.rounds) do |round|
|
280
|
+
scores = entry.picks.scores_for_round(round, tournament_entry.picks, self.scoring_strategy)
|
246
281
|
round_total = scores.inject(0) {|sum, arr| sum += (arr[0] ? arr[0] : 0)}
|
247
282
|
scores_str = scores.map{|arr| "#{arr[1].short_name}=#{arr[0] ? arr[0] : '?'}"}.join(" ")
|
248
283
|
if [1,2].include?(round)
|
249
284
|
scores_str_arr = Tournament::Pool.split_line(scores_str, 70)
|
250
285
|
if round == 1
|
251
|
-
|
286
|
+
out << fmt1 % [total, entry.name, round, round_total, scores_str_arr[0]] << "\n"
|
252
287
|
else
|
253
|
-
|
288
|
+
out << fmt2 % [round, round_total, scores_str_arr[0]] << "\n"
|
254
289
|
end
|
255
290
|
scores_str_arr[1..-1].each do |scores_str|
|
256
|
-
|
291
|
+
out << fmt3 % scores_str << "\n"
|
257
292
|
end
|
258
293
|
else
|
259
|
-
|
294
|
+
out << fmt2 % [round, round_total, scores_str] << "\n"
|
260
295
|
end
|
261
296
|
end
|
262
|
-
|
297
|
+
out << sep << "\n"
|
263
298
|
end
|
264
299
|
end
|
265
300
|
end
|
@@ -280,16 +315,16 @@ class Tournament::Pool
|
|
280
315
|
end
|
281
316
|
|
282
317
|
# Shows a report of each entry's picks by round.
|
283
|
-
def entry_report
|
284
|
-
|
318
|
+
def entry_report(out = $stdout)
|
319
|
+
out << "There are #{@entries.size} entries." << "\n"
|
285
320
|
if @entries.size > 0
|
286
|
-
|
287
|
-
|
321
|
+
out << "".center(15) + "|" + "First Round".center(128) << "\n"
|
322
|
+
out << "Name".center(15) + "|" + "Sweet 16".center(64) + "|" + "Elite 8".center(32) +
|
288
323
|
"|" + "Final 4".center(16) + "|" + "Final 2".center(8) + "|" + "Champion".center(15) +
|
289
|
-
"|" + "Tie Break"
|
290
|
-
|
324
|
+
"|" + "Tie Break" << "\n"
|
325
|
+
out << ("-" * 15) + "+" + ("-" * 64) + "+" + ("-" * 32) +
|
291
326
|
"+" + ("-" * 16) + "+" + ("-" * 8) + "+" + ("-" * 15) +
|
292
|
-
"+" + ("-" * 10)
|
327
|
+
"+" + ("-" * 10) << "\n"
|
293
328
|
output = Proc.new do |name, bracket, tie_breaker|
|
294
329
|
first_round = bracket.winners[1].map {|t| "%s" % (t.short_name rescue 'Unk')}.join('-')
|
295
330
|
sweet_16 = bracket.winners[2].map {|t| "%s" % (t.short_name rescue 'Unk')}.join('-')
|
@@ -297,15 +332,15 @@ class Tournament::Pool
|
|
297
332
|
final_4 = bracket.winners[4].map {|t| "%s" % (t.short_name rescue 'Unk')}.join('-')
|
298
333
|
final_2 = bracket.winners[5].map {|t| "%s" % (t.short_name rescue 'Unk')}.join('-')
|
299
334
|
champ = bracket.champion.name rescue 'Unk'
|
300
|
-
|
301
|
-
|
302
|
-
[name, sweet_16, elite_8, final_4, final_2, champ, tie_breaker.to_s]
|
303
|
-
|
335
|
+
out << " |%128s" % first_round << "\n"
|
336
|
+
out << "%15s|%64s|%32s|%16s|%8s|%15s|%s" %
|
337
|
+
[name, sweet_16, elite_8, final_4, final_2, champ, tie_breaker.to_s] << "\n"
|
338
|
+
out << ("-" * 15) + "+" + ("-" * 64) + "+" + ("-" * 32) +
|
304
339
|
"+" + ("-" * 16) + "+" + ("-" * 8) + "+" + ("-" * 15) +
|
305
|
-
"+" + ("-" * 10)
|
340
|
+
"+" + ("-" * 10) << "\n"
|
306
341
|
end
|
307
342
|
|
308
|
-
output.call('Tournament',
|
343
|
+
output.call('Tournament', tournament_entry.picks, tournament_entry.tie_breaker || '-')
|
309
344
|
|
310
345
|
@entries.sort_by{|e| e.name}.each do |entry|
|
311
346
|
output.call(entry.name, entry.picks, entry.tie_breaker)
|
@@ -314,8 +349,8 @@ class Tournament::Pool
|
|
314
349
|
end
|
315
350
|
|
316
351
|
# Displays the regions and teams in the region.
|
317
|
-
def region_report
|
318
|
-
|
352
|
+
def region_report(out = $stdout)
|
353
|
+
out << " Region | Seed | Team " << "\n"
|
319
354
|
current_idx = -1
|
320
355
|
@regions.each_with_index do |region, idx|
|
321
356
|
region[:teams].each do |team|
|
@@ -323,23 +358,23 @@ class Tournament::Pool
|
|
323
358
|
if idx != current_idx
|
324
359
|
region_name = region[:name]
|
325
360
|
current_idx = idx
|
326
|
-
|
361
|
+
out << "--------+------+-------------------------" << "\n"
|
327
362
|
end
|
328
|
-
|
363
|
+
out << "%8s|%6d|%25s" % [region_name, team.seed, "#{team.name} (#{team.short_name})"] << "\n"
|
329
364
|
end
|
330
365
|
end
|
331
366
|
end
|
332
367
|
|
333
368
|
# When there are four teams left, for each of the 16 possible outcomes
|
334
369
|
# shows who will win according to the configured payouts.
|
335
|
-
def final_four_report
|
370
|
+
def final_four_report(out = $stdout)
|
336
371
|
if @entries.size == 0
|
337
|
-
|
372
|
+
out << "There are no entries in the pool." << "\n"
|
338
373
|
return
|
339
374
|
end
|
340
|
-
if self.
|
341
|
-
|
342
|
-
|
375
|
+
if self.tournament_entry.picks.teams_left > 4
|
376
|
+
out << "The final four report should only be run when there" << "\n"
|
377
|
+
out << "are four or fewer teams left in the tournament." << "\n"
|
343
378
|
return
|
344
379
|
end
|
345
380
|
total_payout = @entries.size * @entry_fee
|
@@ -356,23 +391,39 @@ class Tournament::Pool
|
|
356
391
|
end
|
357
392
|
end
|
358
393
|
|
359
|
-
|
360
|
-
|
361
|
-
|
394
|
+
out << "Final Four: #{self.tournament_entry.picks.winners[4][0,2].map{|t| "(#{t.seed}) #{t.name}"}.join(" vs. ")}"
|
395
|
+
out << " #{self.tournament_entry.picks.winners[4][2,2].map{|t| "(#{t.seed}) #{t.name}"}.join(" vs. ")}" << "\n"
|
396
|
+
if self.tournament_entry.picks.teams_left <= 2
|
397
|
+
out << "Championship: #{self.tournament_entry.picks.winners[5][0,2].map{|t| "(#{t.seed}) #{t.name}"}.join(" vs. ")}" << "\n"
|
398
|
+
end
|
399
|
+
out << "Payouts" << "\n"
|
362
400
|
payout_keys.each do |key|
|
363
401
|
amount = if @payouts[key] > 0
|
364
402
|
@payouts[key].to_f / 100.0 * total_payout
|
365
403
|
else
|
366
404
|
-@payouts[key]
|
367
405
|
end
|
368
|
-
|
406
|
+
out << "%4s: $%5.2f" % [key, amount] << "\n"
|
369
407
|
end
|
370
408
|
sep= "--------------+----------------+-----------------------------------------"
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
self.
|
375
|
-
rankings = @entries.map{|p| [p, p.picks.score_against(poss)] }.
|
409
|
+
out << " | | Winners Tie " << "\n"
|
410
|
+
out << " Championship | Champion | Rank Score Break Name" << "\n"
|
411
|
+
out << sep << "\n"
|
412
|
+
self.tournament_entry.picks.each_possible_bracket do |poss|
|
413
|
+
rankings = @entries.map{|p| [p, p.picks.score_against(poss, self.scoring_strategy)] }.sort do |a1, a2|
|
414
|
+
if a1[1] == a2[1]
|
415
|
+
# Use tiebreak
|
416
|
+
if self.tournament_entry.tie_breaker
|
417
|
+
tb1 = (a1[0].tie_breaker - self.tournament_entry.tie_breaker).abs
|
418
|
+
tb2 = (a2[0].tie_breaker - self.tournament_entry.tie_breaker).abs
|
419
|
+
tb1 <=> tb2
|
420
|
+
else
|
421
|
+
0
|
422
|
+
end
|
423
|
+
else
|
424
|
+
a2[1] <=> a1[1]
|
425
|
+
end
|
426
|
+
end
|
376
427
|
finishers = {}
|
377
428
|
@payouts.each do |rank, payout|
|
378
429
|
finishers[rank] = {}
|
@@ -430,7 +481,7 @@ class Tournament::Pool
|
|
430
481
|
winner.name
|
431
482
|
]
|
432
483
|
end
|
433
|
-
|
484
|
+
out << line << "\n"
|
434
485
|
first_line = false
|
435
486
|
end
|
436
487
|
payout_count += finish_hash[:entries].size
|
@@ -442,7 +493,7 @@ class Tournament::Pool
|
|
442
493
|
end
|
443
494
|
end
|
444
495
|
end
|
445
|
-
|
496
|
+
out << sep << "\n"
|
446
497
|
end
|
447
498
|
nil
|
448
499
|
end
|
@@ -450,10 +501,10 @@ class Tournament::Pool
|
|
450
501
|
# Runs through every possible outcome of the tournament and calculates
|
451
502
|
# each entry's chance to win as a percentage of the possible outcomes
|
452
503
|
# the entry would win if the tournament came out that way.
|
453
|
-
def possibility_report
|
504
|
+
def possibility_report(out = $stdout)
|
454
505
|
$stdout.sync = true
|
455
506
|
if @entries.size == 0
|
456
|
-
|
507
|
+
out << "There are no entries in the pool." << "\n"
|
457
508
|
return
|
458
509
|
end
|
459
510
|
max_possible_score = @entries.map{|p| 0}
|
@@ -463,10 +514,10 @@ class Tournament::Pool
|
|
463
514
|
count = 0
|
464
515
|
old_percentage = -1
|
465
516
|
old_remaining = 1_000_000_000_000
|
466
|
-
|
517
|
+
out << "Checking #{self.tournament_entry.picks.number_of_outcomes} possible outcomes" << "\n"
|
467
518
|
start = Time.now.to_f
|
468
|
-
self.
|
469
|
-
poss_scores = @entries.map{|p| p.picks.score_against(poss)}
|
519
|
+
self.tournament_entry.picks.each_possible_bracket do |poss|
|
520
|
+
poss_scores = @entries.map{|p| p.picks.score_against(poss, self.scoring_strategy)}
|
470
521
|
sort_scores = poss_scores.sort.reverse
|
471
522
|
@entries.each_with_index do |entry, i|
|
472
523
|
score = poss_scores[i]
|
@@ -479,18 +530,18 @@ class Tournament::Pool
|
|
479
530
|
end
|
480
531
|
end
|
481
532
|
count += 1
|
482
|
-
percentage = (count * 100.0 / self.
|
533
|
+
percentage = (count * 100.0 / self.tournament_entry.picks.number_of_outcomes)
|
483
534
|
elapsed = Time.now.to_f - start
|
484
535
|
spp = elapsed / count
|
485
|
-
remaining = ((self.
|
536
|
+
remaining = ((self.tournament_entry.picks.number_of_outcomes - count) * spp).to_i
|
486
537
|
if (percentage.to_i != old_percentage) || (remaining < old_remaining)
|
487
538
|
old_remaining = remaining
|
488
539
|
old_percentage = percentage.to_i
|
489
540
|
hashes = '#' * (percentage.to_i/5) + '>'
|
490
|
-
|
541
|
+
out << "\rCalculating: %3d%% +#{hashes.ljust(20, '-')}+ %5d seconds remaining" % [percentage.to_i, remaining]
|
491
542
|
end
|
492
543
|
end
|
493
|
-
|
544
|
+
out << "\n"
|
494
545
|
#puts "\n Max Scores: #{max_possible_score.inspect}"
|
495
546
|
#puts "Highest Place: #{min_ranking.inspect}"
|
496
547
|
#puts " Times Winner: #{times_winner.inspect}"
|
@@ -498,28 +549,28 @@ class Tournament::Pool
|
|
498
549
|
times_winner.each_with_index { |n, i| sort_array << [n, i, min_ranking[i], max_possible_score[i], player_champions[i]] }
|
499
550
|
sort_array = sort_array.sort_by {|arr| arr[0] == 0 ? (arr[2] == 0 ? -arr[3] : arr[2]) : -arr[0]}
|
500
551
|
#puts "SORT: #{sort_array.inspect}"
|
501
|
-
|
502
|
-
|
552
|
+
out << " Entry | Win Chance | Highest Place | Curr Score | Max Score | Tie Break " << "\n"
|
553
|
+
out << "--------------------+------------+---------------+------------+-----------+------------" << "\n"
|
503
554
|
sort_array.each do |arr|
|
504
|
-
chance = arr[0].to_f * 100.0 / self.
|
505
|
-
|
506
|
-
[@entries[arr[1]].name, chance, min_ranking[arr[1]], max_possible_score[arr[1]], @entries[arr[1]].tie_breaker]
|
555
|
+
chance = arr[0].to_f * 100.0 / self.tournament_entry.picks.number_of_outcomes
|
556
|
+
out << "%19s | %10.2f | %13d | %10d | %9d | %7d " %
|
557
|
+
[@entries[arr[1]].name, chance, min_ranking[arr[1]], @entries[arr[1]].picks.score_against(self.tournament_entry.picks, self.scoring_strategy), max_possible_score[arr[1]], @entries[arr[1]].tie_breaker] << "\n"
|
507
558
|
end
|
508
|
-
|
509
|
-
|
510
|
-
|
559
|
+
out << "Possible Champions For Win" << "\n"
|
560
|
+
out << " Entry | Champion | Ocurrences | Chance " << "\n"
|
561
|
+
out << "--------------------+-----------------+---------------+---------" << "\n"
|
511
562
|
sort_array.each do |arr|
|
512
563
|
next if arr[4].size == 0
|
513
564
|
arr[4].sort_by{|k,v| -v}.each_with_index do |harr, idx|
|
514
565
|
team = harr[0]
|
515
566
|
occurences = harr[1]
|
516
567
|
if idx == 0
|
517
|
-
|
568
|
+
out << "%19s | %15s | %13d | %8.2f " % [@entries[arr[1]].name, team.name, occurences, occurences.to_f * 100.0 / arr[0]] << "\n"
|
518
569
|
else
|
519
|
-
|
570
|
+
out << "%19s | %15s | %13d | %8.2f " % ['', team.name, occurences, occurences.to_f * 100.0 / arr[0]] << "\n"
|
520
571
|
end
|
521
572
|
end
|
522
|
-
|
573
|
+
out << "--------------------+-----------------+---------------+---------" << "\n"
|
523
574
|
end
|
524
575
|
nil
|
525
576
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# Module namespace for various scoring strategies for
|
2
|
+
# tournament pools.
|
3
|
+
module Tournament::ScoringStrategy
|
4
|
+
|
5
|
+
# Class representing a scoring strategy where correct picks
|
6
|
+
# are worth 2 X the round number
|
7
|
+
class Basic
|
8
|
+
def score(pick, winner, loser, round)
|
9
|
+
winner != Tournament::Bracket::UNKNOWN_TEAM && pick == winner ? round * 2 : 0
|
10
|
+
end
|
11
|
+
def name
|
12
|
+
'Basic'
|
13
|
+
end
|
14
|
+
def description
|
15
|
+
"Each game is worth 2 times the round number."
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Class representing a scoring strategy where correct picks
|
20
|
+
# are worth a base amount per round (3, 5, 11, 19, 30 and 40)
|
21
|
+
# plus the seed number of the winner.
|
22
|
+
class Upset
|
23
|
+
PER_ROUND = [3, 5, 11, 19, 30, 40]
|
24
|
+
def score(pick, winner, loser, round)
|
25
|
+
if winner != Tournament::Bracket::UNKNOWN_TEAM && pick == winner
|
26
|
+
return PER_ROUND[round-1] + winner.seed
|
27
|
+
end
|
28
|
+
return 0
|
29
|
+
end
|
30
|
+
def name
|
31
|
+
'Upset'
|
32
|
+
end
|
33
|
+
def description
|
34
|
+
"Games are worth #{PER_ROUND.join(', ')} per round plus the seed number of the winning team."
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Class representing a scoring strategy where correct picks are
|
39
|
+
# worth the seed number of the winner times a per round
|
40
|
+
# multiplier (1,2,4,8,16,32)
|
41
|
+
class JoshPatashnik
|
42
|
+
MULTIPLIERS = [1, 2, 4, 8, 16, 32]
|
43
|
+
def score(pick, winner, loser, round)
|
44
|
+
if winner != Tournament::Bracket::UNKNOWN_TEAM && pick == winner
|
45
|
+
return MULTIPLIERS[round-1] * winner.seed
|
46
|
+
end
|
47
|
+
return 0
|
48
|
+
end
|
49
|
+
def name
|
50
|
+
'Josh Patashnik'
|
51
|
+
end
|
52
|
+
def description
|
53
|
+
"Games are worth the seed number of the winning team times a per round multiplier: #{MULTIPLIERS.join(', ')}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Returns names of available strategies. The names returned are suitable
|
58
|
+
# for use in the strategy_for_name method
|
59
|
+
def self.available_strategies
|
60
|
+
return ['basic', 'upset', 'josh_patashnik']
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns an instantiated strategy class for the named strategy.
|
64
|
+
def self.strategy_for_name(name)
|
65
|
+
clazz = Tournament::ScoringStrategy.const_get(name.capitalize.gsub(/_([a-zA-Z])/) {|m| $1.upcase})
|
66
|
+
return clazz.new
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'open3'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
class Tournament::WebguiInstaller
|
7
|
+
attr_accessor :tmp_dir
|
8
|
+
attr_reader :install_dir
|
9
|
+
attr_reader :source_dir
|
10
|
+
PRINCE_TARBALL='http://www.princexml.com/download/prince-6.0r8-linux.tar.gz'
|
11
|
+
RAILS_ENV = ENV['RAILS_ENV'] || 'production'
|
12
|
+
|
13
|
+
def initialize(install_dir)
|
14
|
+
@install_dir = install_dir
|
15
|
+
@source_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'webgui'))
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.download(url, local_file, binary = false)
|
19
|
+
url = URI.parse(url)
|
20
|
+
open_flag = binary ? "wb" : "w"
|
21
|
+
Net::HTTP.start(url.host) do |http|
|
22
|
+
File.open(local_file, open_flag) do |file|
|
23
|
+
resp = http.get(url.path)
|
24
|
+
file.write(resp.body)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def install_webgui
|
30
|
+
raise "Installation target #{@install_dir} exists and is NOT a directory." if File.exist?(@install_dir) && !File.directory?(@install_dir)
|
31
|
+
FileUtils.mkdir_p(@install_dir) unless File.exist?(@install_dir)
|
32
|
+
FileUtils.cp_r("#{@source_dir}/.", @install_dir, :preserve => false, :verbose => true)
|
33
|
+
end
|
34
|
+
|
35
|
+
def adjust_configuration(config_options = {})
|
36
|
+
config_file = File.expand_path(File.join(@source_dir, 'config', 'initializers', 'pool.rb'))
|
37
|
+
target_config = File.expand_path(File.join(@install_dir, 'config', 'initializers', 'pool.rb'))
|
38
|
+
puts " -> Adjusting #{config_file} -> #{target_config}"
|
39
|
+
config_contents = File.read(config_file)
|
40
|
+
if config_options['email-server']
|
41
|
+
smtp_config = {}
|
42
|
+
smtp_config[:address] = config_options['email-server']
|
43
|
+
smtp_config[:port] = config_options['email-port']
|
44
|
+
smtp_config[:domain] = config_options['email-domain'] if config_options['email-domain']
|
45
|
+
smtp_config[:user_name] = config_options['email-user'] if config_options['email-user']
|
46
|
+
smtp_config[:password] = config_options['email-password'] if config_options['email-password']
|
47
|
+
smtp_config[:authentication] = config_options['email-auth'].to_sym if config_options['email-auth']
|
48
|
+
config_options['smtp-configuration'] = smtp_config
|
49
|
+
end
|
50
|
+
[
|
51
|
+
['site-name', 'TOURNAMENT_TITLE'],
|
52
|
+
['admin-email', 'ADMIN_EMAIL'],
|
53
|
+
['relative-root', 'RELATIVE_URL_ROOT'],
|
54
|
+
['smtp-configuration', 'SMTP_CONFIGURATION'],
|
55
|
+
['prince-path', 'PRINCE_PATH']
|
56
|
+
].each do |config_name, constant_name|
|
57
|
+
if config_options[config_name]
|
58
|
+
puts " -> Setting config option #{config_name} to #{config_options[config_name]}"
|
59
|
+
re = /#{constant_name} =([^\n]+)/m
|
60
|
+
config_contents.gsub!(re) do |m|
|
61
|
+
"#{constant_name} = #{config_options[config_name].inspect}\n"
|
62
|
+
end
|
63
|
+
else
|
64
|
+
puts " -> Not setting config option #{config_name}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
puts " -> Writing #{target_config}"
|
69
|
+
File.open(target_config, "w") do |f|
|
70
|
+
f.write config_contents
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def install_prince(prince_install_dir)
|
75
|
+
# install prince-xml if necessary
|
76
|
+
has_prince = ''
|
77
|
+
Open3.popen3('which prince') do |stdin, stdout, stderr|
|
78
|
+
has_prince << stdout.read
|
79
|
+
has_prince << stderr.read
|
80
|
+
end
|
81
|
+
if has_prince.empty? || has_prince =~ /no prince/
|
82
|
+
puts "Installing prince-xml ..."
|
83
|
+
Tournament::WebguiInstaller.download(PRINCE_TARBALL, "#{@tmp_dir}/prince.tgz", true)
|
84
|
+
system "tar xzf #{@tmp_dir}/prince.tgz -C #{@tmp_dir}"
|
85
|
+
|
86
|
+
use_sudo = nil
|
87
|
+
if !File.exist?(prince_install_dir)
|
88
|
+
begin
|
89
|
+
FileUtils.makedirs(prince_install_dir)
|
90
|
+
rescue
|
91
|
+
puts "Could not create install dir for prince, using sudo"
|
92
|
+
use_sudo = "sudo "
|
93
|
+
end
|
94
|
+
elsif !File.writable?(prince_install_dir)
|
95
|
+
puts "Prince install directory is not writable, using sudo. You may be asked for your password."
|
96
|
+
use_sudo = "sudo "
|
97
|
+
end
|
98
|
+
puts "cd #{@tmp_dir}/prince-6.0r8-linux && #{use_sudo}bash install.sh"
|
99
|
+
system "cd #{@tmp_dir}/prince-6.0r8-linux && #{use_sudo}bash install.sh"
|
100
|
+
else
|
101
|
+
puts "prince-xml already installed: #{has_prince}"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# Run migrations
|
107
|
+
# Provide instructions for modrails/phusion integration
|
108
|
+
# Create admin user
|
109
|
+
# Edit config/initializer/pool.rb to fit
|