1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-25 01:14:43 +00:00

Fixed swap wrestlers logic

This commit is contained in:
2020-01-24 08:11:37 -05:00
parent 21b023f195
commit bc136ae356
2 changed files with 47 additions and 48 deletions

View File

@@ -5,40 +5,41 @@ class SwapWrestlers
def swap_wrestlers_bracket_lines(wrestler1_id,wrestler2_id) def swap_wrestlers_bracket_lines(wrestler1_id,wrestler2_id)
w1 = Wrestler.find(wrestler1_id) w1 = Wrestler.find(wrestler1_id)
w2 = Wrestler.find(wrestler2_id) w2 = Wrestler.find(wrestler2_id)
weight_matches = w1.weight.matches w1_matches = w1.all_matches
w2_matches = w2.all_matches
#placeholder guy #placeholder guy for w1
w3 = Wrestler.new w3 = Wrestler.new
w3.weight_id = w1.weight_id w3.weight_id = w1.weight_id
w3.original_seed = w1.original_seed w3.original_seed = w1.original_seed
w3.bracket_line = w1.bracket_line w3.bracket_line = w1.bracket_line
w3.pool = w1.pool w3.pool = w1.pool
weight_matches = swapWrestlerMatches(weight_matches,w1.id,w3.id)
#Swap wrestler 1 and wrestler 2 # placeholder guy for w2
weight_matches = swapWrestlerMatches(weight_matches,w2.id,w1.id) w4 = Wrestler.new
w1.bracket_line = w2.bracket_line w4.weight_id = w2.weight_id
w1.pool = w2.pool w4.original_seed = w2.original_seed
w4.bracket_line = w2.bracket_line
w4.pool = w2.pool
# swap w4 line and pool to w1
w1.bracket_line = w4.bracket_line
w1.pool = w4.pool
weight_matches = swapWrestlerMatches(weight_matches,w3.id,w2.id) # swap w3 line and pool to w2
w2.bracket_line = w3.bracket_line w2.bracket_line = w3.bracket_line
w2.pool = w3.pool w2.pool = w3.pool
save_matches(weight_matches) # Swap matches
swapWrestlerMatches(w1_matches,w1.id,w2.id)
swapWrestlerMatches(w2_matches,w2.id,w1.id)
w1.save w1.save
w2.save w2.save
end end
def save_matches(matches)
matches.each do |match|
match.save
end
end
def swapWrestlerMatches(matchesToSwap,from_id,to_id) def swapWrestlerMatches(matchesToSwap,from_id,to_id)
matchesToSwap.select{|m| m.w1 == from_id or m.w2 == from_id}.each do |m| matchesToSwap.each do |m|
# if m.bracket_position == "Pool" or (m.bracket_position == "Bracket" and m.round == 1)
if m.w1 == from_id if m.w1 == from_id
m.w1 = to_id m.w1 = to_id
elsif m.w2 == from_id elsif m.w2 == from_id
@@ -47,9 +48,7 @@ class SwapWrestlers
if m.winner_id == from_id if m.winner_id == from_id
m.winner_id = to_id m.winner_id = to_id
end end
# m.save m.save
# end end
end
return matchesToSwap
end end
end end

View File

@@ -3,6 +3,6 @@
<% end %> <% end %>
<% if @tournament.tournament_type == "Pool to bracket" %> <% if @tournament.tournament_type == "Pool to bracket" %>
<%= render 'pool_bracket_director_actions' %> <%= render 'pool_bracket_director_actions' %>
<% elsif @tournament.tournament_type == "Modified 16 Man Double Elimination" %> <% elsif @tournament.tournament_type == "Modified 16 Man Double Elimination" or @tournament.tournament_type == "Double Elimination 1-6" %>
<%= render 'bracket_director_actions' %> <%= render 'bracket_director_actions' %>
<% end %> <% end %>