diff --git a/.travis.yml b/.travis.yml index 1f979c1..5d79363 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: ruby rvm: -- 2.3.0 +- 2.4.0 env: - DB=sqlite script: @@ -14,3 +14,4 @@ deploy: on: repo: jcwimer/wrestlingApp branch: master + run: "rake db:migrate RAILS_ENV=production" diff --git a/Gemfile b/Gemfile index 090dcb7..cb9522d 100644 --- a/Gemfile +++ b/Gemfile @@ -1,15 +1,15 @@ source 'https://rubygems.org' -ruby '2.3.0' +ruby '2.4.0' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '4.2.5' +gem 'rails', '5.1.1' # Use sqlite3 as the database for Active Record gem 'sqlite3', :group => :development # Use Uglifier as compressor for JavaScript assets -gem 'uglifier', '>= 1.3.0' +gem 'uglifier' # Use CoffeeScript for .js.coffee assets and views -gem 'coffee-rails', '~> 4.0.0' +gem 'coffee-rails' # See https://github.com/sstephenson/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby @@ -18,9 +18,9 @@ gem 'jquery-rails' # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks gem 'turbolinks' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder -gem 'jbuilder', '~> 2.0' +gem 'jbuilder' # bundle exec rake doc:rails generates the API under doc/api. -gem 'sdoc', '~> 0.4.0', :group => :doc +gem 'sdoc', :group => :doc # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring', :group => :development @@ -39,26 +39,24 @@ gem 'spring', :group => :development #Installed by me - #For Heroku - group :production do - gem 'rails_12factor' - gem 'mysql2' - gem 'passenger' - gem 'therubyracer' - gem 'newrelic_rpm' - gem 'dalli' - end - #Other - gem 'devise' - gem 'cancancan' - gem 'round_robin_tournament' - gem 'rb-readline' - gem 'delayed_job_active_record' - gem 'puma' - gem 'brakeman' - gem 'rails-lineman' - group :development do - - #gem 'bullet' - end +group :production do + gem 'rails_12factor' + gem 'mysql2' + gem 'therubyracer' + gem 'newrelic_rpm' + gem 'dalli' +end + +gem 'devise' +gem 'cancancan' +gem 'round_robin_tournament' +gem 'rb-readline' +gem 'delayed_job_active_record' +gem 'puma' + +group :development do + gem 'rubocop' + gem 'bullet' + gem 'brakeman' +end diff --git a/Gemfile.lock b/Gemfile.lock index c4d6ee0..e78c9a0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,227 +1,220 @@ GEM remote: https://rubygems.org/ specs: - actionmailer (4.2.5) - actionpack (= 4.2.5) - actionview (= 4.2.5) - activejob (= 4.2.5) + actioncable (5.1.1) + actionpack (= 5.1.1) + nio4r (~> 2.0) + websocket-driver (~> 0.6.1) + actionmailer (5.1.1) + actionpack (= 5.1.1) + actionview (= 5.1.1) + activejob (= 5.1.1) mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.5) - actionview (= 4.2.5) - activesupport (= 4.2.5) - rack (~> 1.6) - rack-test (~> 0.6.2) - rails-dom-testing (~> 1.0, >= 1.0.5) + rails-dom-testing (~> 2.0) + actionpack (5.1.1) + actionview (= 5.1.1) + activesupport (= 5.1.1) + rack (~> 2.0) + rack-test (~> 0.6.3) + rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.5) - activesupport (= 4.2.5) + actionview (5.1.1) + activesupport (= 5.1.1) builder (~> 3.1) - erubis (~> 2.7.0) - rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - activejob (4.2.5) - activesupport (= 4.2.5) - globalid (>= 0.3.0) - activemodel (4.2.5) - activesupport (= 4.2.5) - builder (~> 3.1) - activerecord (4.2.5) - activemodel (= 4.2.5) - activesupport (= 4.2.5) - arel (~> 6.0) - activesupport (4.2.5) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (5.1.1) + activesupport (= 5.1.1) + globalid (>= 0.3.6) + activemodel (5.1.1) + activesupport (= 5.1.1) + activerecord (5.1.1) + activemodel (= 5.1.1) + activesupport (= 5.1.1) + arel (~> 8.0) + activesupport (5.1.1) + concurrent-ruby (~> 1.0, >= 1.0.2) i18n (~> 0.7) - json (~> 1.7, >= 1.7.7) minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - arel (6.0.3) - bcrypt (3.1.10) - brakeman (3.1.5) - erubis (~> 2.6) - fastercsv (~> 1.5) - haml (>= 3.0, < 5.0) - highline (>= 1.6.20, < 2.0) - multi_json (~> 1.2) - ruby2ruby (>= 2.1.1, < 2.3.0) - ruby_parser (~> 3.7.0) - safe_yaml (>= 1.0) - sass (~> 3.0) - slim (>= 1.3.6, < 4.0) - terminal-table (~> 1.4) - builder (3.2.2) - cancancan (1.10.1) - coffee-rails (4.0.1) + arel (8.0.0) + ast (2.3.0) + bcrypt (3.1.11) + brakeman (3.7.2) + builder (3.2.3) + bullet (5.6.1) + activesupport (>= 3.0.0) + uniform_notifier (~> 1.10.0) + cancancan (2.0.0) + coffee-rails (4.2.2) coffee-script (>= 2.2.0) - railties (>= 4.0.0, < 5.0) + railties (>= 4.0.0) coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.9.1.1) - concurrent-ruby (1.0.0) - dalli (2.7.5) - delayed_job (4.1.1) - activesupport (>= 3.0, < 5.0) - delayed_job_active_record (4.1.0) - activerecord (>= 3.0, < 5) + coffee-script-source (1.12.2) + concurrent-ruby (1.0.5) + dalli (2.7.6) + delayed_job (4.1.3) + activesupport (>= 3.0, < 5.2) + delayed_job_active_record (4.1.2) + activerecord (>= 3.0, < 5.2) delayed_job (>= 3.0, < 5) - devise (3.4.1) + devise (4.3.0) bcrypt (~> 3.0) orm_adapter (~> 0.1) - railties (>= 3.2.6, < 5) + railties (>= 4.1.0, < 5.2) responders - thread_safe (~> 0.1) warden (~> 1.2.3) - erubis (2.7.0) - execjs (2.5.2) - fastercsv (1.5.5) - globalid (0.3.6) - activesupport (>= 4.1.0) - haml (4.0.7) - tilt - highline (1.7.8) - i18n (0.7.0) - jbuilder (2.2.13) - activesupport (>= 3.0.0, < 5) - multi_json (~> 1.2) - jquery-rails (4.0.3) - rails-dom-testing (~> 1.0) + erubi (1.6.1) + execjs (2.7.0) + globalid (0.4.0) + activesupport (>= 4.2.0) + i18n (0.8.6) + jbuilder (2.7.0) + activesupport (>= 4.2.0) + multi_json (>= 1.2) + jquery-rails (4.3.1) + rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - json (1.8.3) - libv8 (3.16.14.7) + json (1.8.6) + libv8 (3.16.14.19) loofah (2.0.3) nokogiri (>= 1.5.9) - mail (2.6.3) - mime-types (>= 1.16, < 3) - mime-types (2.99) - mini_portile2 (2.0.0) - minitest (5.8.3) - multi_json (1.11.0) - mysql2 (0.3.18) - newrelic_rpm (3.13.2.302) - nokogiri (1.6.7) - mini_portile2 (~> 2.0.0.rc2) + mail (2.6.6) + mime-types (>= 1.16, < 4) + method_source (0.8.2) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) + mini_portile2 (2.2.0) + minitest (5.10.3) + multi_json (1.12.2) + mysql2 (0.4.9) + newrelic_rpm (4.4.0.336) + nio4r (2.1.0) + nokogiri (1.8.0) + mini_portile2 (~> 2.2.0) orm_adapter (0.5.0) - passenger (5.0.7) - rack - rake (>= 0.8.1) - puma (2.11.2) - rack (>= 1.1, < 2.0) - rack (1.6.4) + parallel (1.12.0) + parser (2.4.0.0) + ast (~> 2.2) + powerpack (0.1.1) + puma (3.10.0) + rack (2.0.3) rack-test (0.6.3) rack (>= 1.0) - rails (4.2.5) - actionmailer (= 4.2.5) - actionpack (= 4.2.5) - actionview (= 4.2.5) - activejob (= 4.2.5) - activemodel (= 4.2.5) - activerecord (= 4.2.5) - activesupport (= 4.2.5) + rails (5.1.1) + actioncable (= 5.1.1) + actionmailer (= 5.1.1) + actionpack (= 5.1.1) + actionview (= 5.1.1) + activejob (= 5.1.1) + activemodel (= 5.1.1) + activerecord (= 5.1.1) + activesupport (= 5.1.1) bundler (>= 1.3.0, < 2.0) - railties (= 4.2.5) - sprockets-rails - rails-deprecated_sanitizer (1.0.3) - activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.7) - activesupport (>= 4.2.0.beta, < 5.0) - nokogiri (~> 1.6.0) - rails-deprecated_sanitizer (>= 1.0.1) - rails-html-sanitizer (1.0.2) + railties (= 5.1.1) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.0.3) loofah (~> 2.0) - rails-lineman (0.3.0) - rake rails_12factor (0.0.3) rails_serve_static_assets rails_stdout_logging - rails_serve_static_assets (0.0.4) - rails_stdout_logging (0.0.3) - railties (4.2.5) - actionpack (= 4.2.5) - activesupport (= 4.2.5) + rails_serve_static_assets (0.0.5) + rails_stdout_logging (0.0.5) + railties (5.1.1) + actionpack (= 5.1.1) + activesupport (= 5.1.1) + method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (10.4.2) - rb-readline (0.5.2) - rdoc (4.2.0) - json (~> 1.4) - ref (1.0.5) - responders (2.1.0) - railties (>= 4.2.0, < 5) + rainbow (2.2.2) + rake + rake (12.1.0) + rb-readline (0.5.5) + rdoc (4.3.0) + ref (2.0.0) + responders (2.4.0) + actionpack (>= 4.2.0, < 5.3) + railties (>= 4.2.0, < 5.3) round_robin_tournament (0.0.1) - ruby2ruby (2.2.0) - ruby_parser (~> 3.1) - sexp_processor (~> 4.0) - ruby_parser (3.7.3) - sexp_processor (~> 4.1) - safe_yaml (1.0.4) - sass (3.4.21) - sdoc (0.4.1) + rubocop (0.49.1) + parallel (~> 1.10) + parser (>= 2.3.3.1, < 3.0) + powerpack (~> 0.1) + rainbow (>= 1.99.1, < 3.0) + ruby-progressbar (~> 1.7) + unicode-display_width (~> 1.0, >= 1.0.1) + ruby-progressbar (1.8.1) + sdoc (0.4.2) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) - sexp_processor (4.6.1) - slim (3.0.6) - temple (~> 0.7.3) - tilt (>= 1.3.3, < 2.1) - spring (1.3.5) - sprockets (3.5.0) + spring (2.0.2) + activesupport (>= 4.2) + sprockets (3.7.1) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (2.3.3) - actionpack (>= 3.0) - activesupport (>= 3.0) - sprockets (>= 2.8, < 4.0) - sqlite3 (1.3.10) - temple (0.7.6) - terminal-table (1.5.2) - therubyracer (0.12.2) - libv8 (~> 3.16.14.0) + sprockets-rails (3.2.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + sqlite3 (1.3.13) + therubyracer (0.12.3) + libv8 (~> 3.16.14.15) ref - thor (0.19.1) - thread_safe (0.3.5) - tilt (2.0.2) - turbolinks (2.5.3) - coffee-rails - tzinfo (1.2.2) + thor (0.20.0) + thread_safe (0.3.6) + turbolinks (5.0.1) + turbolinks-source (~> 5) + turbolinks-source (5.0.3) + tzinfo (1.2.3) thread_safe (~> 0.1) - uglifier (2.7.1) - execjs (>= 0.3.0) - json (>= 1.8.0) - warden (1.2.3) + uglifier (3.2.0) + execjs (>= 0.3.0, < 3) + unicode-display_width (1.3.0) + uniform_notifier (1.10.0) + warden (1.2.7) rack (>= 1.0) + websocket-driver (0.6.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.2) PLATFORMS ruby DEPENDENCIES brakeman + bullet cancancan - coffee-rails (~> 4.0.0) + coffee-rails dalli delayed_job_active_record devise - jbuilder (~> 2.0) + jbuilder jquery-rails mysql2 newrelic_rpm - passenger puma - rails (= 4.2.5) - rails-lineman + rails (= 5.1.1) rails_12factor rb-readline round_robin_tournament - sdoc (~> 0.4.0) + rubocop + sdoc spring sqlite3 therubyracer turbolinks - uglifier (>= 1.3.0) + uglifier RUBY VERSION - ruby 2.3.0p0 + ruby 2.4.0p0 BUNDLED WITH - 1.13.5 + 1.15.4 diff --git a/Procfile b/Procfile index 93afc98..2561a76 100644 --- a/Procfile +++ b/Procfile @@ -1,2 +1,2 @@ worker: bundle exec rake jobs:work -web: bundle exec passenger start -p $PORT --max-pool-size 3 \ No newline at end of file +web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development} diff --git a/README.rdoc b/README.rdoc index 7d37e77..f4e5f72 100644 --- a/README.rdoc +++ b/README.rdoc @@ -16,9 +16,9 @@ MIT License Development details: -* Ruby 2.3.0 +* Ruby 2.4.0 -* Rails 4.2.5 +* Rails 5.1.1 * Install gems without production bundle install --without production diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a9f6dc6..3a110d7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception - after_filter :set_csrf_cookie_for_ng + after_action :set_csrf_cookie_for_ng def set_csrf_cookie_for_ng cookies['XSRF-TOKEN'] = form_authenticity_token if protect_against_forgery? diff --git a/app/controllers/mats_controller.rb b/app/controllers/mats_controller.rb index 6b517c9..782c39e 100644 --- a/app/controllers/mats_controller.rb +++ b/app/controllers/mats_controller.rb @@ -1,7 +1,7 @@ class MatsController < ApplicationController before_action :set_mat, only: [:show, :edit, :update, :destroy] - before_filter :check_access, only: [:new,:create,:update,:destroy,:edit,:show] - before_filter :check_for_matches, only: [:show] + before_action :check_access, only: [:new,:create,:update,:destroy,:edit,:show] + before_action :check_for_matches, only: [:show] # GET /mats/1 # GET /mats/1.json diff --git a/app/controllers/schools_controller.rb b/app/controllers/schools_controller.rb index b651c99..41ade29 100644 --- a/app/controllers/schools_controller.rb +++ b/app/controllers/schools_controller.rb @@ -1,7 +1,7 @@ class SchoolsController < ApplicationController before_action :set_school, only: [:show, :edit, :update, :destroy] - before_filter :check_access_director, only: [:new,:create,:destroy] - before_filter :check_access_delegate, only: [:update,:edit] + before_action :check_access_director, only: [:new,:create,:destroy] + before_action :check_access_delegate, only: [:update,:edit] # GET /schools/1 diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 0f443b6..a53c88e 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -1,9 +1,9 @@ class TournamentsController < ApplicationController before_action :set_tournament, only: [:swap,:weigh_in_sheet,:error,:teampointadjust,:remove_teampointadjust,:remove_school_delegate,:remove_delegate,:school_delegate,:delegate,:matches,:weigh_in,:weigh_in_weight,:create_custom_weights,:show,:edit,:update,:destroy,:up_matches,:no_matches,:team_scores,:brackets,:generate_matches,:bracket,:all_brackets] - before_filter :check_access_manage, only: [:swap,:weigh_in_sheet,:teampointadjust,:remove_teampointadjust,:remove_school_delegate,:school_delegate,:weigh_in,:weigh_in_weight,:create_custom_weights,:update,:edit,:generate_matches,:matches] - before_filter :check_access_destroy, only: [:destroy,:delegate,:remove_delegate] - before_filter :check_tournament_errors, only: [:generate_matches] - before_filter :check_for_matches, only: [:up_matches,:bracket,:all_brackets] + before_action :check_access_manage, only: [:swap,:weigh_in_sheet,:teampointadjust,:remove_teampointadjust,:remove_school_delegate,:school_delegate,:weigh_in,:weigh_in_weight,:create_custom_weights,:update,:edit,:generate_matches,:matches] + before_action :check_access_destroy, only: [:destroy,:delegate,:remove_delegate] + before_action :check_tournament_errors, only: [:generate_matches] + before_action :check_for_matches, only: [:up_matches,:bracket,:all_brackets] def weigh_in_sheet @@ -195,7 +195,7 @@ class TournamentsController < ApplicationController end def show - @schools = @tournament.schools(:delegates) + @schools = @tournament.schools.includes(:delegates) @weights = @tournament.weights.sort_by{|x|[x.max]} @mats = @tournament.mats end diff --git a/app/controllers/weights_controller.rb b/app/controllers/weights_controller.rb index 02e17af..cb5cd76 100644 --- a/app/controllers/weights_controller.rb +++ b/app/controllers/weights_controller.rb @@ -1,6 +1,6 @@ class WeightsController < ApplicationController before_action :set_weight, only: [:show, :edit, :update, :destroy,:re_gen] - before_filter :check_access, only: [:new,:create,:update,:destroy,:edit, :re_gen] + before_action :check_access, only: [:new,:create,:update,:destroy,:edit, :re_gen] # GET /weights/1 diff --git a/app/controllers/wrestlers_controller.rb b/app/controllers/wrestlers_controller.rb index e83a7c6..b8526ec 100644 --- a/app/controllers/wrestlers_controller.rb +++ b/app/controllers/wrestlers_controller.rb @@ -1,6 +1,6 @@ class WrestlersController < ApplicationController - before_action :set_wrestler, only: [:show, :edit, :update, :destroy] - before_filter :check_access, only: [:new,:create,:update,:destroy,:edit] + before_action :set_wrestler, only: [:show, :edit, :update, :destroy, :update_pool] + before_action :check_access, only: [:new,:create,:update,:destroy,:edit,:update_pool] @@ -69,6 +69,25 @@ class WrestlersController < ApplicationController end end + def update_pool + @tournament = @wrestler.tournament + @weight = @wrestler.weight + @weights = @tournament.weights.sort_by{|w| w.max} + @school = @wrestler.school + if params[:wrestler]['pool'] + @wrestler.pool = params[:wrestler]['pool'] + respond_to do |format| + if @wrestler.update(wrestler_params) + format.html { redirect_to "/weights/#{@wrestler.weight.id}/", notice: 'Wrestler was successfully updated. Please re-generate this weight classes matches.' } + format.json { head :no_content } + else + format.html { render action: 'edit' } + format.json { render json: @wrestler.errors, status: :unprocessable_entity } + end + end + end + end + # DELETE /wrestlers/1 # DELETE /wrestlers/1.json def destroy @@ -88,14 +107,19 @@ class WrestlersController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def wrestler_params - params.require(:wrestler).permit(:name, :school_id, :weight_id, :seed, :original_seed, :season_win, :season_loss,:criteria,:extra,:offical_weight) + params.require(:wrestler).permit(:name, :school_id, :weight_id, :seed, :original_seed, :season_win, :season_loss,:criteria,:extra,:offical_weight,:pool) end def check_access if params[:school] @school = School.find(params[:school]) #@tournament = Tournament.find(@school.tournament.id) elsif params[:wrestler] - @school = School.find(params[:wrestler]["school_id"]) + if params[:wrestler]["school_id"] + @school = School.find(params[:wrestler]["school_id"]) + else + @wrestler = Wrestler.find(params[:wrestler]["id"]) + @school = @wrestler.school + end #@tournament = Tournament.find(@school.tournament.id) elsif @wrestler @school = @wrestler.school diff --git a/app/models/match.rb b/app/models/match.rb index af655d4..2d5d274 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -4,12 +4,12 @@ class Match < ActiveRecord::Base belongs_to :mat, touch: true has_many :wrestlers, :through => :weight - - after_update do + + after_update do after_update_actions end - + def after_update_actions if self.finished == 1 && self.winner_id != nil if self.w1 && self.w2 @@ -30,9 +30,9 @@ class Match < ActiveRecord::Base if self.w1 && self.w2 wrestler1.school.calcScore wrestler2.school.calcScore - end + end end - + def mat_assigned if self.mat @@ -41,7 +41,7 @@ class Match < ActiveRecord::Base "" end end - + def pinTime if self.win_type == "Pin" time = self.score.delete("") @@ -54,7 +54,7 @@ class Match < ActiveRecord::Base end def advance_wrestlers - if self.w1 && self.w2 + if self.w1 && self.w2 AdvanceWrestler.new(wrestler1).advance AdvanceWrestler.new(wrestler2).advance end @@ -117,7 +117,7 @@ class Match < ActiveRecord::Base def weight_max self.weight.max end - + def replaceLoserNameWithWrestler(w,loserName) if self.loser1_name == loserName self.w1 = w.id @@ -130,9 +130,15 @@ class Match < ActiveRecord::Base end def poolNumber if self.w1? - wrestler1.generatePoolNumber + wrestler1.pool end end - + def list_w2_stats + "#{w2_name}: #{w2_stat}" + end + + def list_w1_stats + "#{w1_name}: #{w1_stat}" + end end diff --git a/app/models/weight.rb b/app/models/weight.rb index 1573b19..10144a1 100644 --- a/app/models/weight.rb +++ b/app/models/weight.rb @@ -17,8 +17,25 @@ class Weight < ActiveRecord::Base # self.tournament.destroyAllMatches end - def wrestlersForPool(pool) - self.wrestlers.select{|w| w.generatePoolNumber == pool} + def pools_with_bye + pool = 1 + pools_with_a_bye = [] + until pool > self.pools do + if wrestlersForPool(pool).first.hasAPoolBye + pools_with_a_bye << pool + end + pool = pool + 1 + end + pools_with_a_bye + end + + def wrestlersForPool(poolNumber) + #For some reason this does not work + # wrestlers.select{|w| w.pool == poolNumber} + + #This does... + weightWrestlers = Wrestler.where(:weight_id => self.id) + weightWrestlers.select{|w| w.pool == poolNumber} end def allPoolMatchesFinished(pool) @@ -43,7 +60,8 @@ class Weight < ActiveRecord::Base end def poolSeedOrder(pool) - wrestlersForPool(pool).sort_by{|w| [w.original_seed ? 0 : 1, w.original_seed || 0]} + # wrestlersForPool(pool).sort_by{|w| [w.original_seed ? 0 : 1, w.original_seed || 0]} + return wrestlersForPool(pool).sort_by{|w|w.seed} end @@ -51,79 +69,6 @@ class Weight < ActiveRecord::Base SwapWrestlers.new.swapWrestlers(wrestler1_id,wrestler2_id) end - def returnPoolNumber(wrestler) - if self.pools == 4 - @wrestlers = fourPoolNumbers(self.wrestlers) - elsif self.pools == 2 - @wrestlers = twoPoolNumbers(self.wrestlers) - elsif self.pools == 1 - @wrestlers = onePoolNumbers(self.wrestlers) - end - @wrestler = @wrestlers.select{|w| w.id == wrestler.id}.first - return @wrestler.poolNumber - end - - def onePoolNumbers(poolWrestlers) - poolWrestlers.sort_by{|x| x.seed }.each do |w| - w.poolNumber = 1 - end - return poolWrestlers - end - - - def twoPoolNumbers(poolWrestlers) - pool = 1 - poolWrestlers.sort_by{|x| x.seed }.reverse.each do |w| - if w.seed == 1 - w.poolNumber = 1 - elsif w.seed == 2 - w.poolNumber = 2 - elsif w.seed == 3 - w.poolNumber = 2 - elsif w.seed == 4 - w.poolNumber = 1 - else - w.poolNumber = pool - end - if pool < 2 - pool = pool + 1 - else - pool = 1 - end - end - return poolWrestlers - end - - def fourPoolNumbers(poolWrestlers) - pool = 1 - poolWrestlers.sort_by{|x| x.seed }.reverse.each do |w| - if w.seed == 1 - w.poolNumber = 1 - elsif w.seed == 2 - w.poolNumber = 2 - elsif w.seed == 3 - w.poolNumber = 3 - elsif w.seed == 4 - w.poolNumber = 4 - elsif w.seed == 8 - w.poolNumber = 1 - elsif w.seed == 7 - w.poolNumber = 2 - elsif w.seed == 6 - w.poolNumber = 3 - elsif w.seed == 5 - w.poolNumber = 4 - else - w.poolNumber = pool - end - if pool < 4 - pool = pool + 1 - else - pool = 1 - end - end - return poolWrestlers - end def bracket_size wrestlers.size @@ -164,5 +109,9 @@ class Weight < ActiveRecord::Base def poolOrder(pool) PoolOrder.new(wrestlersForPool(pool)).getPoolOrder end + + def wrestlersWithoutPool + wrestlers.select{|w| w.pool == nil} + end end diff --git a/app/models/wrestler.rb b/app/models/wrestler.rb index 328f2f8..c20358e 100644 --- a/app/models/wrestler.rb +++ b/app/models/wrestler.rb @@ -4,7 +4,7 @@ class Wrestler < ActiveRecord::Base has_one :tournament, through: :weight has_many :matches, through: :weight has_many :deductedPoints, class_name: "Teampointadjust" - attr_accessor :poolNumber, :poolAdvancePoints, :originalId, :swapId + attr_accessor :poolAdvancePoints, :originalId, :swapId validates :name, :weight_id, :school_id, presence: true @@ -103,10 +103,6 @@ class Wrestler < ActiveRecord::Base end end - def generatePoolNumber - self.weight.returnPoolNumber(self) - end - def boutByRound(round) round_match = allMatches.select{|m| m.round == round}.first if round_match.blank? @@ -122,7 +118,7 @@ class Wrestler < ActiveRecord::Base def poolMatches pool_matches = allMatches.select{|m| m.bracket_position == "Pool"} - pool_matches.select{|m| m.poolNumber == self.generatePoolNumber} + pool_matches.select{|m| m.poolNumber == self.pool} end def hasAPoolBye diff --git a/app/services/bracket_advancement/pool_advance.rb b/app/services/bracket_advancement/pool_advance.rb index 177c292..e708dd9 100644 --- a/app/services/bracket_advancement/pool_advance.rb +++ b/app/services/bracket_advancement/pool_advance.rb @@ -6,7 +6,7 @@ class PoolAdvance end def advanceWrestler - if @wrestler.weight.allPoolMatchesFinished(@wrestler.generatePoolNumber) && @wrestler.finishedBracketMatches.size == 0 + if @wrestler.weight.allPoolMatchesFinished(@wrestler.pool) && @wrestler.finishedBracketMatches.size == 0 poolToBracketAdvancment end if @wrestler.finishedBracketMatches.size > 0 @@ -15,7 +15,7 @@ class PoolAdvance end def poolToBracketAdvancment - pool = @wrestler.generatePoolNumber + pool = @wrestler.pool if @wrestler.weight.wrestlers.size > 6 poolOrder = @wrestler.weight.poolOrder(pool) #Take pool order and move winner and runner up to correct match based on w1_name and w2_name @@ -67,7 +67,7 @@ class PoolAdvance def loserAdvance bout = @wrestler.lastMatch.bout_number - next_match = Match.where("loser1_name = ? OR loser2_name = ? AND weight_id = ?","Loser of #{bout}","Loser of #{bout}",@wrestler.weight_id) + next_match = Match.where("(loser1_name = ? OR loser2_name = ?) AND weight_id = ?","Loser of #{bout}","Loser of #{bout}",@wrestler.weight_id) if next_match.size > 0 next_match.first.replaceLoserNameWithWrestler(@wrestler,"Loser of #{bout}") end diff --git a/app/services/tournament_services/pool_generation.rb b/app/services/tournament_services/pool_generation.rb index 12a3e5c..12e3948 100644 --- a/app/services/tournament_services/pool_generation.rb +++ b/app/services/tournament_services/pool_generation.rb @@ -6,12 +6,13 @@ class PoolGeneration end def generatePools + GeneratePoolNumbers.new(@weight).savePoolNumbers pools = @weight.pools while @pool <= pools roundRobin @pool += 1 end - end + end def roundRobin wrestlers = @weight.wrestlersForPool(@pool) diff --git a/app/services/weight_services/generate_pool_numbers.rb b/app/services/weight_services/generate_pool_numbers.rb new file mode 100644 index 0000000..4844ffe --- /dev/null +++ b/app/services/weight_services/generate_pool_numbers.rb @@ -0,0 +1,77 @@ +class GeneratePoolNumbers + def initialize( weight ) + @weight = weight + end + + def savePoolNumbers + if @weight.pools == 4 + saveFourPoolNumbers(@weight.wrestlersWithoutPool) + elsif @weight.pools == 2 + saveTwoPoolNumbers(@weight.wrestlersWithoutPool) + elsif @weight.pools == 1 + saveOnePoolNumbers(@weight.wrestlersWithoutPool) + end + end + + def saveOnePoolNumbers(poolWrestlers) + poolWrestlers.sort_by{|x| x.seed }.each do |w| + w.pool = 1 + w.save + end + end + + + def saveTwoPoolNumbers(poolWrestlers) + pool = 1 + poolWrestlers.sort_by{|x| x.seed }.reverse.each do |w| + if w.seed == 1 + w.pool = 1 + elsif w.seed == 2 + w.pool = 2 + elsif w.seed == 3 + w.pool = 2 + elsif w.seed == 4 + w.pool = 1 + else + w.pool = pool + end + if pool < 2 + pool = pool + 1 + else + pool = 1 + end + w.save + end + end + + def saveFourPoolNumbers(poolWrestlers) + pool = 1 + poolWrestlers.sort_by{|x| x.seed }.reverse.each do |w| + if w.seed == 1 + w.pool = 1 + elsif w.seed == 2 + w.pool = 2 + elsif w.seed == 3 + w.pool = 3 + elsif w.seed == 4 + w.pool = 4 + elsif w.seed == 8 + w.pool = 1 + elsif w.seed == 7 + w.pool = 2 + elsif w.seed == 6 + w.pool = 3 + elsif w.seed == 5 + w.pool = 4 + else + w.pool = pool + end + if pool < 4 + pool = pool + 1 + else + pool = 1 + end + w.save + end + end +end \ No newline at end of file diff --git a/app/services/wrestler_services/swap_wrestlers.rb b/app/services/wrestler_services/swap_wrestlers.rb index c3a0502..772beaa 100644 --- a/app/services/wrestler_services/swap_wrestlers.rb +++ b/app/services/wrestler_services/swap_wrestlers.rb @@ -11,15 +11,18 @@ class SwapWrestlers w3.weight_id = w1.weight_id w3.original_seed = w1.original_seed w3.seed = w1.seed + w3.pool = w1.pool swapWrestlerMatches(w1.allMatches,w1.id,w3.id) #Swap wrestler 1 and wrestler 2 swapWrestlerMatches(w2.allMatches,w2.id,w1.id) w1.seed = w2.seed + w1.pool = w2.pool swapWrestlerMatches(w3.allMatches,w3.id,w2.id) w2.seed = w3.seed + w2.pool = w3.pool w1.save diff --git a/app/views/mats/_match_edit_form.html.erb b/app/views/mats/_match_edit_form.html.erb index d5dd506..08dbcab 100644 --- a/app/views/mats/_match_edit_form.html.erb +++ b/app/views/mats/_match_edit_form.html.erb @@ -10,15 +10,15 @@ <% end %> -
| <%= @w1.name %> |
|---|