mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-24 17:04:43 +00:00
Refactored match winner and wrestlers matches and fixed slow tests.
This commit is contained in:
@@ -14,9 +14,9 @@ class ApiController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def tournament
|
def tournament
|
||||||
@tournament = Tournament.where(:id => params[:tournament]).includes(:schools,:weights,:mats,:matches,:user,:wrestlers).first
|
@tournament = Tournament.where(:id => params[:tournament]).includes(:user, :mats, :schools, :weights, :matches, wrestlers: [:school, :weight, :matches_as_w1, :matches_as_w2]).first
|
||||||
@schools = @tournament.schools.includes(:wrestlers)
|
@schools = @tournament.schools.includes(wrestlers: [:weight, :matches_as_w1, :matches_as_w2])
|
||||||
@weights = @tournament.weights.includes(:wrestlers)
|
@weights = @tournament.weights.includes(wrestlers: [:school, :matches_as_w1, :matches_as_w2])
|
||||||
@matches = @tournament.matches.includes(:wrestlers,:schools)
|
@matches = @tournament.matches.includes(:wrestlers,:schools)
|
||||||
@mats = @tournament.mats.includes(:matches)
|
@mats = @tournament.mats.includes(:matches)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class SchoolsController < ApplicationController
|
|||||||
# GET /schools/1.json
|
# GET /schools/1.json
|
||||||
def show
|
def show
|
||||||
session.delete(:return_path)
|
session.delete(:return_path)
|
||||||
@wrestlers = @school.wrestlers.includes(:deductedPoints,:matches,:weight,:school)
|
@wrestlers = @school.wrestlers.includes(:deductedPoints, :weight, :school, :matches_as_w1, :matches_as_w2)
|
||||||
@tournament = @school.tournament
|
@tournament = @school.tournament
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ class SchoolsController < ApplicationController
|
|||||||
private
|
private
|
||||||
# Use callbacks to share common setup or constraints between actions.
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
def set_school
|
def set_school
|
||||||
@school = School.where(:id => params[:id]).includes(:tournament,:wrestlers,:deductedPoints,:delegates).first
|
@school = School.includes(:tournament, :delegates, :deductedPoints, wrestlers: [:weight, :deductedPoints, :matches_as_w1, :matches_as_w2]).find_by(id: params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Never trust parameters from the scary internet, only allow the white list through.
|
# Never trust parameters from the scary internet, only allow the white list through.
|
||||||
|
|||||||
@@ -164,15 +164,16 @@ class TournamentsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def bracket
|
def bracket
|
||||||
if params[:weight]
|
if params[:weight]
|
||||||
@weight = Weight.where(:id => params[:weight]).includes(:matches,:wrestlers).first
|
@weight = Weight.includes(:matches, wrestlers: [:school, :matches_as_w1, :matches_as_w2]).find_by(id: params[:weight])
|
||||||
@matches = @weight.matches.includes(:schools,:wrestlers)
|
@matches = @weight.matches
|
||||||
@wrestlers = @weight.wrestlers.includes(:school)
|
@wrestlers = @weight.wrestlers
|
||||||
if @tournament.tournament_type == "Pool to bracket"
|
|
||||||
@pools = @weight.pool_rounds(@matches)
|
if @tournament.tournament_type == "Pool to bracket"
|
||||||
@bracketType = @weight.pool_bracket_type
|
@pools = @weight.pool_rounds(@matches)
|
||||||
end
|
@bracketType = @weight.pool_bracket_type
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def all_results
|
def all_results
|
||||||
@@ -303,7 +304,7 @@ class TournamentsController < ApplicationController
|
|||||||
private
|
private
|
||||||
# Use callbacks to share common setup or constraints between actions.
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
def set_tournament
|
def set_tournament
|
||||||
@tournament = Tournament.where(:id => params[:id]).includes(:schools,:weights,:mats,:matches,:user,:wrestlers).first
|
@tournament = Tournament.includes(:user, :mats, :schools, :weights, :matches, wrestlers: [:school, :weight, :matches_as_w1, :matches_as_w2]).find_by(id: params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Never trust parameters from the scary internet, only allow the white list through.
|
# Never trust parameters from the scary internet, only allow the white list through.
|
||||||
|
|||||||
@@ -98,7 +98,8 @@ class WeightsController < ApplicationController
|
|||||||
private
|
private
|
||||||
# Use callbacks to share common setup or constraints between actions.
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
def set_weight
|
def set_weight
|
||||||
@weight = Weight.where(:id => params[:id]).includes(:tournament,:wrestlers).first
|
# Add nested includes for wrestlers
|
||||||
|
@weight = Weight.includes(:tournament, wrestlers: [:school, :matches_as_w1, :matches_as_w2]).find_by(id: params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Never trust parameters from the scary internet, only allow the white list through.
|
# Never trust parameters from the scary internet, only allow the white list through.
|
||||||
|
|||||||
@@ -86,7 +86,11 @@ class WrestlersController < ApplicationController
|
|||||||
private
|
private
|
||||||
|
|
||||||
def set_wrestler
|
def set_wrestler
|
||||||
@wrestler = Wrestler.includes(:school, :weight, :tournament, :matches).find_by(id: params[:id])
|
@wrestler = Wrestler.includes(:school, :weight, :tournament, :matches_as_w1, :matches_as_w2).find_by(id: params[:id])
|
||||||
|
|
||||||
|
if @wrestler.nil?
|
||||||
|
redirect_to root_path, alert: "Wrestler not found"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def wrestler_params
|
def wrestler_params
|
||||||
|
|||||||
@@ -1,18 +1,11 @@
|
|||||||
class AdvanceWrestlerJob < ApplicationJob
|
class AdvanceWrestlerJob < ApplicationJob
|
||||||
queue_as :default
|
queue_as :default
|
||||||
|
|
||||||
# Class method for direct execution in test environment
|
|
||||||
def self.perform_sync(wrestler, match)
|
|
||||||
# Execute directly on provided objects
|
|
||||||
service = AdvanceWrestler.new(wrestler, match)
|
|
||||||
service.advance_raw
|
|
||||||
end
|
|
||||||
|
|
||||||
def perform(wrestler, match)
|
def perform(wrestler, match)
|
||||||
# Add a small delay to increase chance of transaction commit
|
# Add a small delay to increase chance of transaction commit
|
||||||
# without this some matches were getting a deserialization error when running the rake task
|
# without this some matches were getting a deserialization error when running the rake task
|
||||||
# to finish tournaments
|
# to finish tournaments
|
||||||
sleep(0.5)
|
sleep(0.5) unless Rails.env.test?
|
||||||
|
|
||||||
# Get tournament from wrestler
|
# Get tournament from wrestler
|
||||||
tournament = wrestler.tournament
|
tournament = wrestler.tournament
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
class CalculateSchoolScoreJob < ApplicationJob
|
class CalculateSchoolScoreJob < ApplicationJob
|
||||||
queue_as :default
|
queue_as :default
|
||||||
|
|
||||||
# Class method for direct execution in test environment
|
# Need for TournamentJobStatusIntegrationTest
|
||||||
def self.perform_sync(school)
|
def self.perform_sync(school)
|
||||||
# Execute directly on provided objects
|
# Execute directly on provided objects
|
||||||
school.calculate_score_raw
|
school.calculate_score_raw
|
||||||
|
|||||||
@@ -1,13 +1,6 @@
|
|||||||
class GenerateTournamentMatchesJob < ApplicationJob
|
class GenerateTournamentMatchesJob < ApplicationJob
|
||||||
queue_as :default
|
queue_as :default
|
||||||
|
|
||||||
# Class method for direct execution in test environment
|
|
||||||
def self.perform_sync(tournament)
|
|
||||||
# Execute directly on provided objects
|
|
||||||
generator = GenerateTournamentMatches.new(tournament)
|
|
||||||
generator.generate_raw
|
|
||||||
end
|
|
||||||
|
|
||||||
def perform(tournament)
|
def perform(tournament)
|
||||||
# Log information about the job
|
# Log information about the job
|
||||||
Rails.logger.info("Starting tournament match generation for tournament ##{tournament.id}")
|
Rails.logger.info("Starting tournament match generation for tournament ##{tournament.id}")
|
||||||
|
|||||||
@@ -1,13 +1,6 @@
|
|||||||
class TournamentBackupJob < ApplicationJob
|
class TournamentBackupJob < ApplicationJob
|
||||||
queue_as :default
|
queue_as :default
|
||||||
|
|
||||||
# Class method for direct execution in test environment
|
|
||||||
def self.perform_sync(tournament, reason = nil)
|
|
||||||
# Execute directly on provided objects
|
|
||||||
service = TournamentBackupService.new(tournament, reason)
|
|
||||||
service.create_backup_raw
|
|
||||||
end
|
|
||||||
|
|
||||||
def perform(tournament, reason = nil)
|
def perform(tournament, reason = nil)
|
||||||
# Log information about the job
|
# Log information about the job
|
||||||
Rails.logger.info("Creating backup for tournament ##{tournament.id} (#{tournament.name}), reason: #{reason || 'manual'}")
|
Rails.logger.info("Creating backup for tournament ##{tournament.id} (#{tournament.name}), reason: #{reason || 'manual'}")
|
||||||
|
|||||||
@@ -1,14 +1,6 @@
|
|||||||
class WrestlingdevImportJob < ApplicationJob
|
class WrestlingdevImportJob < ApplicationJob
|
||||||
queue_as :default
|
queue_as :default
|
||||||
|
|
||||||
# Class method for direct execution in test environment
|
|
||||||
def self.perform_sync(tournament, import_data = nil)
|
|
||||||
# Execute directly on provided objects
|
|
||||||
importer = WrestlingdevImporter.new(tournament)
|
|
||||||
importer.import_data = import_data if import_data
|
|
||||||
importer.import_raw
|
|
||||||
end
|
|
||||||
|
|
||||||
def perform(tournament, import_data = nil)
|
def perform(tournament, import_data = nil)
|
||||||
# Log information about the job
|
# Log information about the job
|
||||||
Rails.logger.info("Starting import for tournament ##{tournament.id} (#{tournament.name})")
|
Rails.logger.info("Starting import for tournament ##{tournament.id} (#{tournament.name})")
|
||||||
|
|||||||
@@ -230,10 +230,10 @@ class Match < ApplicationRecord
|
|||||||
if self.finished != 1
|
if self.finished != 1
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
if self.winner_id == self.w1
|
if self.winner == self.wrestler1
|
||||||
return self.w1_name
|
return self.w1_name
|
||||||
end
|
end
|
||||||
if self.winner_id == self.w2
|
if self.winner == self.wrestler2
|
||||||
return self.w2_name
|
return self.w2_name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -242,20 +242,28 @@ class Match < ApplicationRecord
|
|||||||
if self.finished != 1
|
if self.finished != 1
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
if self.winner_id == self.w1
|
winning_wrestler = self.winner
|
||||||
winning_wrestler = self.wrestler1
|
if winning_wrestler == self.wrestler1
|
||||||
losing_wrestler = self.wrestler2
|
losing_wrestler = self.wrestler2
|
||||||
end
|
elsif winning_wrestler == self.wrestler2
|
||||||
if self.winner_id == self.w2
|
|
||||||
winning_wrestler = self.wrestler2
|
|
||||||
losing_wrestler = self.wrestler1
|
losing_wrestler = self.wrestler1
|
||||||
|
else
|
||||||
|
# Handle cases where winner is not w1 or w2 (e.g., BYE, DQ where opponent might be nil)
|
||||||
|
# Or maybe the match hasn't been fully populated yet after a win?
|
||||||
|
# Returning an empty string for now, but this might need review based on expected scenarios.
|
||||||
|
return ""
|
||||||
end
|
end
|
||||||
return "#{self.weight.max} lbs - #{winning_wrestler.name} (#{winning_wrestler.school.name}) #{self.win_type} #{losing_wrestler.name} (#{losing_wrestler.school.name}) #{self.score}"
|
# Ensure losing_wrestler is not nil before accessing its properties
|
||||||
|
losing_wrestler_name = losing_wrestler ? losing_wrestler.name : "Unknown"
|
||||||
|
losing_wrestler_school = losing_wrestler ? losing_wrestler.school.name : "Unknown"
|
||||||
|
|
||||||
|
return "#{self.weight.max} lbs - #{winning_wrestler.name} (#{winning_wrestler.school.name}) #{self.win_type} #{losing_wrestler_name} (#{losing_wrestler_school}) #{self.score}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def bracket_winner_name
|
def bracket_winner_name
|
||||||
if winner_name != ""
|
# Use the winner association directly
|
||||||
return "#{winner_name} (#{Wrestler.find(winner_id).school.abbreviation})"
|
if self.winner
|
||||||
|
return "#{self.winner.name} (#{self.winner.school.abbreviation})"
|
||||||
else
|
else
|
||||||
""
|
""
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ class Wrestler < ApplicationRecord
|
|||||||
belongs_to :school, touch: true
|
belongs_to :school, touch: true
|
||||||
belongs_to :weight, touch: true
|
belongs_to :weight, touch: true
|
||||||
has_one :tournament, through: :weight
|
has_one :tournament, through: :weight
|
||||||
has_many :matches, through: :weight
|
has_many :matches_as_w1, ->(wrestler){ where(weight_id: wrestler.weight_id) }, class_name: 'Match', foreign_key: 'w1'
|
||||||
|
has_many :matches_as_w2, ->(wrestler){ where(weight_id: wrestler.weight_id) }, class_name: 'Match', foreign_key: 'w2'
|
||||||
has_many :deductedPoints, class_name: "Teampointadjust", dependent: :destroy
|
has_many :deductedPoints, class_name: "Teampointadjust", dependent: :destroy
|
||||||
attr_accessor :poolAdvancePoints, :originalId, :swapId
|
attr_accessor :poolAdvancePoints, :originalId, :swapId
|
||||||
|
|
||||||
@@ -59,7 +60,7 @@ class Wrestler < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def winner_of_last_match?
|
def winner_of_last_match?
|
||||||
if last_match.winner_id == self.id
|
if last_match && last_match.winner == self # Keep winner association change
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
@@ -87,28 +88,28 @@ class Wrestler < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def result_by_bout(bout)
|
def result_by_bout(bout)
|
||||||
bout_match = all_matches.select{|m| m.bout_number == bout and m.finished == 1}
|
bout_match_results = all_matches.select{|m| m.bout_number == bout and m.finished == 1}
|
||||||
if bout_match.size == 0
|
if bout_match_results.empty?
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
if bout_match.first.winner_id == self.id
|
bout_match = bout_match_results.first
|
||||||
return "W #{bout_match.first.bracket_score_string}"
|
if bout_match.winner == self # Keep winner association change
|
||||||
end
|
return "W #{bout_match.bracket_score_string}"
|
||||||
if bout_match.first.winner_id != self.id
|
else
|
||||||
return "L #{bout_match.first.bracket_score_string}"
|
return "L #{bout_match.bracket_score_string}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def result_by_id(id)
|
def result_by_id(id)
|
||||||
bout_match = all_matches.select{|m| m.id == id and m.finished == 1}
|
bout_match_results = all_matches.select{|m| m.id == id and m.finished == 1}
|
||||||
if bout_match.size == 0
|
if bout_match_results.empty?
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
if bout_match.first.winner_id == self.id
|
bout_match = bout_match_results.first
|
||||||
return "W #{bout_match.first.bracket_score_string}"
|
if bout_match.winner == self # Keep winner association change
|
||||||
end
|
return "W #{bout_match.bracket_score_string}"
|
||||||
if bout_match.first.winner_id != self.id
|
else
|
||||||
return "L #{bout_match.first.bracket_score_string}"
|
return "L #{bout_match.bracket_score_string}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -120,7 +121,8 @@ class Wrestler < ApplicationRecord
|
|||||||
if all_matches.blank?
|
if all_matches.blank?
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
return true
|
# Original logic checked blank?, not specific round. Reverting to that.
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -142,8 +144,12 @@ class Wrestler < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Restore all_matches method
|
||||||
def all_matches
|
def all_matches
|
||||||
return matches.select{|m| m.w1 == self.id or m.w2 == self.id}
|
# Combine the two specific associations.
|
||||||
|
# This returns an Array, similar to the previous select method.
|
||||||
|
# Add .uniq for safety and sort for consistent order.
|
||||||
|
(matches_as_w1 + matches_as_w2).uniq.sort_by(&:bout_number)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pool_matches
|
def pool_matches
|
||||||
@@ -152,7 +158,9 @@ class Wrestler < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def has_a_pool_bye
|
def has_a_pool_bye
|
||||||
if weight.pool_rounds(matches) > pool_matches.size
|
# Revert back to using all_matches here too? Seems complex.
|
||||||
|
# Sticking with original: uses `matches` (all weight) and `pool_matches` (derived from all_matches)
|
||||||
|
if weight.pool_rounds(all_matches) > pool_matches.size
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
@@ -188,7 +196,8 @@ class Wrestler < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def matches_won
|
def matches_won
|
||||||
all_matches.select{|m| m.winner_id == self.id}
|
# Revert, but keep using winner association check
|
||||||
|
all_matches.select{|m| m.winner == self}
|
||||||
end
|
end
|
||||||
|
|
||||||
def pool_wins
|
def pool_wins
|
||||||
@@ -268,11 +277,17 @@ class Wrestler < ApplicationRecord
|
|||||||
def season_win_percentage
|
def season_win_percentage
|
||||||
win = self.season_win.to_f
|
win = self.season_win.to_f
|
||||||
loss = self.season_loss.to_f
|
loss = self.season_loss.to_f
|
||||||
|
# Revert to original logic
|
||||||
if win > 0 and loss != nil
|
if win > 0 and loss != nil
|
||||||
match_total = win + loss
|
match_total = win + loss
|
||||||
percentage_dec = win / match_total
|
if match_total > 0
|
||||||
percentage = percentage_dec * 100
|
percentage_dec = win / match_total
|
||||||
return percentage.to_i
|
percentage = percentage_dec * 100
|
||||||
|
return percentage.to_i
|
||||||
|
else
|
||||||
|
# Avoid division by zero if somehow win > 0 but total <= 0
|
||||||
|
return 0
|
||||||
|
end
|
||||||
elsif self.season_win == 0
|
elsif self.season_win == 0
|
||||||
return 0
|
return 0
|
||||||
elsif self.season_win == nil or self.season_loss == nil
|
elsif self.season_win == nil or self.season_loss == nil
|
||||||
@@ -281,6 +296,7 @@ class Wrestler < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def long_bracket_name
|
def long_bracket_name
|
||||||
|
# Revert to original logic
|
||||||
return_string = ""
|
return_string = ""
|
||||||
if self.original_seed
|
if self.original_seed
|
||||||
return_string = return_string + "[#{self.original_seed}] "
|
return_string = return_string + "[#{self.original_seed}] "
|
||||||
@@ -293,10 +309,12 @@ class Wrestler < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def short_bracket_name
|
def short_bracket_name
|
||||||
|
# Revert to original logic
|
||||||
return "#{self.name} (#{self.school.abbreviation})"
|
return "#{self.name} (#{self.school.abbreviation})"
|
||||||
end
|
end
|
||||||
|
|
||||||
def name_with_school
|
def name_with_school
|
||||||
|
# Revert to original logic
|
||||||
return "#{self.name} - #{self.school.name}"
|
return "#{self.name} - #{self.school.name}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,17 +7,22 @@ class DoubleEliminationAdvance
|
|||||||
end
|
end
|
||||||
|
|
||||||
def bracket_advancement
|
def bracket_advancement
|
||||||
if @last_match.winner_id == @wrestler.id
|
advance_wrestler
|
||||||
winner_advance
|
|
||||||
end
|
|
||||||
if @last_match.winner_id != @wrestler.id
|
|
||||||
loser_advance
|
|
||||||
end
|
|
||||||
advance_double_byes
|
advance_double_byes
|
||||||
set_bye_for_placement
|
set_bye_for_placement
|
||||||
end
|
end
|
||||||
|
|
||||||
def winner_advance
|
def advance_wrestler
|
||||||
|
# Advance winner
|
||||||
|
if @last_match.winner == @wrestler
|
||||||
|
winners_bracket_advancement
|
||||||
|
# Advance loser
|
||||||
|
elsif @last_match.winner != @wrestler
|
||||||
|
losers_bracket_advancement
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def winners_bracket_advancement
|
||||||
if (@last_match.loser1_name == "BYE" or @last_match.loser2_name == "BYE") and @last_match.is_championship_match
|
if (@last_match.loser1_name == "BYE" or @last_match.loser2_name == "BYE") and @last_match.is_championship_match
|
||||||
update_consolation_bye
|
update_consolation_bye
|
||||||
end
|
end
|
||||||
@@ -77,7 +82,7 @@ class DoubleEliminationAdvance
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def loser_advance
|
def losers_bracket_advancement
|
||||||
bout = @last_match.bout_number
|
bout = @last_match.bout_number
|
||||||
next_match = Match.where("(loser1_name = ? OR loser2_name = ?) AND weight_id = ?", "Loser of #{bout}", "Loser of #{bout}", @wrestler.weight_id).first
|
next_match = Match.where("(loser1_name = ? OR loser2_name = ?) AND weight_id = ?", "Loser of #{bout}", "Loser of #{bout}", @wrestler.weight_id).first
|
||||||
|
|
||||||
|
|||||||
@@ -7,17 +7,20 @@ class ModifiedDoubleEliminationAdvance
|
|||||||
end
|
end
|
||||||
|
|
||||||
def bracket_advancement
|
def bracket_advancement
|
||||||
if @last_match.winner_id == @wrestler.id
|
advance_wrestler
|
||||||
winner_advance
|
|
||||||
end
|
|
||||||
if @last_match.winner_id != @wrestler.id
|
|
||||||
loser_advance
|
|
||||||
end
|
|
||||||
advance_double_byes
|
advance_double_byes
|
||||||
set_bye_for_placement
|
set_bye_for_placement
|
||||||
end
|
end
|
||||||
|
|
||||||
def winner_advance
|
def advance_wrestler
|
||||||
|
if @last_match.winner == @wrestler
|
||||||
|
winners_bracket_advancement
|
||||||
|
elsif @last_match.winner != @wrestler
|
||||||
|
losers_bracket_advancement
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def winners_bracket_advancement
|
||||||
if (@last_match.loser1_name == "BYE" or @last_match.loser2_name == "BYE") and @last_match.is_championship_match
|
if (@last_match.loser1_name == "BYE" or @last_match.loser2_name == "BYE") and @last_match.is_championship_match
|
||||||
update_consolation_bye
|
update_consolation_bye
|
||||||
end
|
end
|
||||||
@@ -69,7 +72,7 @@ class ModifiedDoubleEliminationAdvance
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def loser_advance
|
def losers_bracket_advancement
|
||||||
bout = @last_match.bout_number
|
bout = @last_match.bout_number
|
||||||
next_match = Match.where("(loser1_name = ? OR loser2_name = ?) AND weight_id = ?", "Loser of #{bout}", "Loser of #{bout}", @wrestler.weight_id).first
|
next_match = Match.where("(loser1_name = ? OR loser2_name = ?) AND weight_id = ?", "Loser of #{bout}", "Loser of #{bout}", @wrestler.weight_id).first
|
||||||
|
|
||||||
|
|||||||
@@ -30,15 +30,20 @@ class PoolAdvance
|
|||||||
end
|
end
|
||||||
|
|
||||||
def bracketAdvancment
|
def bracketAdvancment
|
||||||
if @last_match.winner_id == @wrestler.id
|
advance_wrestlers
|
||||||
winnerAdvance
|
|
||||||
end
|
|
||||||
if @last_match.winner_id != @wrestler.id
|
|
||||||
loserAdvance
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def winnerAdvance
|
def advance_wrestlers
|
||||||
|
# Advance winner
|
||||||
|
if @last_match.winner == @wrestler
|
||||||
|
winner_advance
|
||||||
|
# Advance loser
|
||||||
|
elsif @last_match.winner != @wrestler
|
||||||
|
loser_advance
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def winner_advance
|
||||||
if @wrestler.last_match.bracket_position == "Quarter"
|
if @wrestler.last_match.bracket_position == "Quarter"
|
||||||
new_match = Match.where("bracket_position = ? AND bracket_position_number = ? AND weight_id = ?","Semis",@wrestler.next_match_position_number.ceil,@wrestler.weight_id).first
|
new_match = Match.where("bracket_position = ? AND bracket_position_number = ? AND weight_id = ?","Semis",@wrestler.next_match_position_number.ceil,@wrestler.weight_id).first
|
||||||
updateNewMatch(new_match)
|
updateNewMatch(new_match)
|
||||||
@@ -65,7 +70,7 @@ class PoolAdvance
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def loserAdvance
|
def loser_advance
|
||||||
bout = @wrestler.last_match.bout_number
|
bout = @wrestler.last_match.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
|
if next_match.size > 0
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class PoolOrder
|
|||||||
|
|
||||||
def setOriginalPoints
|
def setOriginalPoints
|
||||||
@wrestlers.each do |w|
|
@wrestlers.each do |w|
|
||||||
matches = w.matches.reload
|
matches = w.reload.all_matches
|
||||||
w.pool_placement_tiebreaker = nil
|
w.pool_placement_tiebreaker = nil
|
||||||
w.pool_placement = nil
|
w.pool_placement = nil
|
||||||
w.poolAdvancePoints = w.pool_wins.size
|
w.poolAdvancePoints = w.pool_wins.size
|
||||||
@@ -80,10 +80,13 @@ class PoolOrder
|
|||||||
def headToHead(wrestlers_with_same_points)
|
def headToHead(wrestlers_with_same_points)
|
||||||
wrestlers_with_same_points.each do |wr|
|
wrestlers_with_same_points.each do |wr|
|
||||||
otherWrestler = wrestlers_with_same_points.select{|w| w.id != wr.id}.first
|
otherWrestler = wrestlers_with_same_points.select{|w| w.id != wr.id}.first
|
||||||
if otherWrestler and wr.match_against(otherWrestler).select{|match| match.bracket_position == "Pool"}.first.winner_id == wr.id
|
if otherWrestler
|
||||||
addPointsToWrestlersAhead(wr)
|
matches = wr.match_against(otherWrestler).select { |match| match.bracket_position == "Pool" }
|
||||||
wr.pool_placement_tiebreaker = "Head to Head"
|
if matches.any? && matches.first.winner == wr
|
||||||
|
addPointsToWrestlersAhead(wr)
|
||||||
|
wr.pool_placement_tiebreaker = "Head to Head"
|
||||||
addPoints(wr)
|
addPoints(wr)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -54,11 +54,11 @@ class TournamentBackupService
|
|||||||
end,
|
end,
|
||||||
matches: @tournament.matches.sort_by(&:bout_number).map do |match|
|
matches: @tournament.matches.sort_by(&:bout_number).map do |match|
|
||||||
match.attributes.merge(
|
match.attributes.merge(
|
||||||
w1_name: Wrestler.find_by(id: match.w1)&.name,
|
w1_name: match.wrestler1&.name,
|
||||||
w2_name: Wrestler.find_by(id: match.w2)&.name,
|
w2_name: match.wrestler2&.name,
|
||||||
winner_name: Wrestler.find_by(id: match.winner_id)&.name,
|
winner_name: match.winner&.name,
|
||||||
weight: Weight.find_by(id: match.weight_id)&.attributes,
|
weight: match.weight&.attributes,
|
||||||
mat: Mat.find_by(id: match.mat_id)&.attributes
|
mat: match.mat&.attributes
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ class CalculateWrestlerTeamScore
|
|||||||
end
|
end
|
||||||
|
|
||||||
def totalScore
|
def totalScore
|
||||||
if @wrestler.extra or @wrestler.matches.count == 0
|
if @wrestler.extra or @wrestler.all_matches.count == 0
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
earnedPoints - deductedPoints
|
earnedPoints - deductedPoints
|
||||||
|
|||||||
@@ -27,10 +27,22 @@ class DoubleEliminationPlacementPoints
|
|||||||
end
|
end
|
||||||
|
|
||||||
def bracket_position_size(bracket_position_name)
|
def bracket_position_size(bracket_position_name)
|
||||||
@wrestler.all_matches.select{|m| m.bracket_position == bracket_position_name}.size
|
@wrestler.all_matches.select{|m| m.bracket_position == bracket_position_name}.size
|
||||||
end
|
end
|
||||||
|
|
||||||
def won_bracket_position_size(bracket_position_name)
|
def won_bracket_position_size(bracket_position_name)
|
||||||
@wrestler.matches_won.select{|m| m.bracket_position == bracket_position_name}.size
|
@wrestler.matches_won.select{|m| m.bracket_position == bracket_position_name}.size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def bracket_placement_points(bracket_position_name)
|
||||||
|
if bracket_position_name == "Did not place"
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
if @wrestler.participating_matches.where(bracket_position: bracket_position_name).count > 0
|
||||||
|
points = Teampointadjust.find_by(tournament_id: @wrestler.tournament.id, points_for_placement: bracket_position_name)
|
||||||
|
if points
|
||||||
|
# ... existing code ...
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@@ -88,7 +88,7 @@
|
|||||||
<td><%= m.bout_number %></td>
|
<td><%= m.bout_number %></td>
|
||||||
<td><%= m.bracket_position %></td>
|
<td><%= m.bracket_position %></td>
|
||||||
<td><%= m.list_w1_stats %><br><%= m.list_w2_stats %></td>
|
<td><%= m.list_w1_stats %><br><%= m.list_w2_stats %></td>
|
||||||
<td><%= @wrestler.result_by_id(m.id) %>
|
<td><%= @wrestler.result_by_id(m.id) %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
Reference in New Issue
Block a user