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

Removed single weight match generation, fixed bracket names, reload weight matches for pool order, and auto delete errrored jobs

This commit is contained in:
2024-12-16 00:02:30 -05:00
parent 5f049793c8
commit a851436c0c
12 changed files with 69 additions and 45 deletions

View File

@@ -80,10 +80,6 @@ class WeightsController < ApplicationController
end
end
def re_gen
@tournament = @weight.tournament
GenerateTournamentMatches.new(@tournament).generateWeight(@weight)
end
def pool_order
pool = params[:pool_to_order].to_i

View File

@@ -179,40 +179,34 @@ class Match < ApplicationRecord
return_string_ending = return_string_ending + "</strong>"
end
if self.w1 != nil
if self.round == 1 and (self.bracket_position == "Bracket" or self.bracket_position == "Quarter")
if self.wrestler1.original_seed
return_string = return_string + "[#{wrestler1.original_seed}] "
end
return_string = return_string + "#{w1_name} - #{wrestler1.school.name} (#{wrestler1.season_win}-#{wrestler1.season_loss})"
if self.round == 1
return_string = return_string + "#{wrestler1.long_bracket_name}"
else
return_string = return_string + "#{w1_name} (#{wrestler1.school.abbreviation})"
return_string = return_string + "#{wrestler1.short_bracket_name}"
end
else
return_string = return_string + "#{w1_name}"
return_string = return_string + "#{self.loser1_name}"
end
return return_string + return_string_ending
end
def w2_bracket_name
return_string = ""
return_string_ending = ""
if self.w2 and self.winner_id == self.w2
return_string = return_string + "<strong>"
return_string_ending = return_string_ending + "</strong>"
end
if self.w2 != nil
if self.round == 1 and (self.bracket_position == "Bracket" or self.bracket_position == "Quarter")
if self.wrestler2.original_seed
return_string = return_string + "#{wrestler2.original_seed} "
end
return_string = return_string + "#{w2_name} - #{wrestler2.school.name} (#{wrestler2.season_win}-#{wrestler2.season_loss})"
else
return_string = return_string + "#{w2_name} (#{wrestler2.school.abbreviation})"
end
else
return_string = return_string + "#{w2_name}"
end
return return_string + return_string_ending
return_string = ""
return_string_ending = ""
if self.w2 and self.winner_id == self.w2
return_string = return_string + "<strong>"
return_string_ending = return_string_ending + "</strong>"
end
if self.w2 != nil
if self.round == 1
return_string = return_string + "#{wrestler2.long_bracket_name}"
else
return_string = return_string + "#{wrestler2.short_bracket_name}"
end
else
return_string = return_string + "#{self.loser2_name}"
end
return return_string + return_string_ending
end
def winner_name

View File

@@ -17,6 +17,12 @@ class Tournament < ApplicationRecord
Delayed::Job.where(job_owner_id: self.id)
end
def clear_errored_deferred_jobs
Delayed::Job.where(job_owner_id: self.id, last_error: ! nil).each do |job|
job.destroy
end
end
def self.search_date_name(pattern)
if pattern.blank? # blank? covers both nil and empty string
all

View File

@@ -280,4 +280,19 @@ class Wrestler < ApplicationRecord
end
end
def long_bracket_name
return_string = ""
if self.original_seed
return_string = return_string + "[#{self.original_seed}] "
end
return_string = return_string + "#{self.name} - #{self.school.name}"
if self.season_win && self.season_loss
return_string = return_string + " (#{self.season_win}-#{self.season_loss})"
end
return return_string
end
def short_bracket_name
return "#{self.name} (#{self.school.abbreviation})"
end
end

View File

@@ -14,6 +14,7 @@ class AdvanceWrestler
end
def advance_raw
@tournament.clear_errored_deferred_jobs
if @last_match && @last_match.finished?
pool_to_bracket_advancement if @tournament.tournament_type == "Pool to bracket"
DoubleEliminationAdvance.new(@wrestler, @last_match).bracket_advancement if @tournament.tournament_type.include? "Modified 16 Man Double Elimination" or

View File

@@ -29,6 +29,7 @@ class PoolOrder
def setOriginalPoints
@wrestlers.each do |w|
matches = w.matches.reload
w.pool_placement_tiebreaker = nil
w.pool_placement = nil
w.poolAdvancePoints = w.pool_wins.size

View File

@@ -12,6 +12,7 @@ class GenerateTournamentMatches
end
def generate_weight_raw(weight)
@tournament.clear_errored_deferred_jobs
WipeTournamentMatches.new(@tournament).wipeWeightMatches(weight)
@tournament.curently_generating_matches = 1
@tournament.save

View File

@@ -2,14 +2,6 @@ class PoolToBracketMatchGeneration
def initialize( tournament )
@tournament = tournament
end
def generatePoolToBracketMatchesWeight(weight)
PoolGeneration.new(weight).generatePools()
last_match = @tournament.matches.where(weight: weight).order(round: :desc).limit(1).first
highest_round = last_match.round
PoolBracketGeneration.new(weight, highest_round).generateBracketMatches()
setOriginalSeedsToWrestleLastPoolRound(weight)
end
def generatePoolToBracketMatches
@tournament.weights.order(:max).each do |weight|

View File

@@ -18,7 +18,7 @@
<tbody>
<% @wrestlers.select{|w| w.pool == @pool}.sort_by{|w| w.bracket_line}.each do |w| %>
<tr>
<td>[<%= w.original_seed %>] <%="#{w.name} - #{w.school.name} (#{w.season_win}-#{w.season_loss})" %></td>
<td> <%="#{w.long_bracket_name}" %></td>
<% @round = 1 %>
<% until @matches.select{|m| m.round == @round}.blank? %>
<% if @round <= @pools %>

View File

@@ -1,9 +1,4 @@
<h3>Weight Class:<%= @weight.max %> <% if can? :manage, @tournament %><%= link_to " Edit", edit_weight_path(@weight), :class=>"fas fa-edit" %><% end %></h3>
<% if can? :manage, @tournament %>
<%= form_for(@weight, url: regen_weight_path(@weight.id), :method => "post") do |f| %>
<%= submit_tag "Regenerate Weight Class Matches", :class=>"btn btn-sm btn-default"%>
<% end %>
<% end %>
<br>
<br>
<table class="table table-hover table-condensed">

View File

@@ -62,7 +62,6 @@ Wrestling::Application.routes.draw do
get "/tournaments/:id/brackets" => "tournaments#show"
put "/tournaments/:id/calculate_team_scores", :to => "tournaments#calculate_team_scores"
post 'weights/:id/re_gen' => 'weights#re_gen', :as => :regen_weight
post "/wrestlers/update_pool" => "wrestlers#update_pool"
get "schools/:id/stats" => "schools#stats"

View File

@@ -126,4 +126,28 @@ class MatchTest < ActiveSupport::TestCase
match.save
assert !match.valid?
end
test "Match pin_time_in_seconds should properly handle format mm:ss" do
create_double_elim_tournament_single_weight(14, "Regular Double Elimination 1-8")
matches = @tournament.matches.reload
match = matches.first
match.winner_id = match.w1
match.finished = 1
match.win_type = "Pin"
match.score = "02:03"
match.save
assert_equal 123, match.reload.pin_time_in_seconds
end
test "Match pin_time_in_seconds should properly handle format m:ss" do
create_double_elim_tournament_single_weight(14, "Regular Double Elimination 1-8")
matches = @tournament.matches.reload
match = matches.first
match.winner_id = match.w1
match.finished = 1
match.win_type = "Pin"
match.score = "2:03"
match.save
assert_equal 123, match.reload.pin_time_in_seconds
end
end