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

3 Commits

16 changed files with 210 additions and 86 deletions

View File

@@ -149,7 +149,7 @@ SolidQueue plugin enabled in Puma
```
I have deployed Mission Control as a UI for SolidQueue. The uri for mission control is `/jobs`.
For the development environment, the user/password is dev/secret. For the production environment, it is defined by environment variables.
For the development environment, the user/password is dev/secret. For the production environment, it is defined by environment variables WRESTLINGDEV_MISSION_CONTROL_USER/WRESTLINGDEV_MISSION_CONTROL_PASSWORD. You can see this in `config/environments/production.rb` and `config/environments/development.rb`.
## Environment Variables

View File

@@ -1,7 +1,9 @@
class AdvanceWrestlerJob < ApplicationJob
queue_as :default
# associations are not available here so we had to pass tournament_id when creating the job
limits_concurrency to: 1, key: ->(_wrestler, _match, tournament_id) { "tournament:#{tournament_id}" }
def perform(wrestler, match)
def perform(wrestler, match, tournament_id)
# Get tournament from wrestler
tournament = wrestler.tournament
@@ -29,4 +31,4 @@ class AdvanceWrestlerJob < ApplicationJob
raise e
end
end
end
end

View File

@@ -1,5 +1,6 @@
class CalculateSchoolScoreJob < ApplicationJob
queue_as :default
limits_concurrency to: 1, key: ->(school) { "tournament:#{school.tournament_id}" }
# Need for TournamentJobStatusIntegrationTest
def self.perform_sync(school)
@@ -35,4 +36,4 @@ class CalculateSchoolScoreJob < ApplicationJob
raise e
end
end
end
end

View File

@@ -1,5 +1,6 @@
class GenerateTournamentMatchesJob < ApplicationJob
queue_as :default
limits_concurrency to: 1, key: ->(tournament) { "tournament:#{tournament.id}" }
def perform(tournament)
# Log information about the job
@@ -17,4 +18,4 @@ class GenerateTournamentMatchesJob < ApplicationJob
raise # Re-raise the error so it's properly recorded
end
end
end
end

View File

@@ -1,5 +1,6 @@
class TournamentBackupJob < ApplicationJob
queue_as :default
limits_concurrency to: 1, key: ->(tournament) { "tournament:#{tournament.id}" }
def perform(tournament, reason = nil)
# Log information about the job
@@ -29,4 +30,4 @@ class TournamentBackupJob < ApplicationJob
raise e
end
end
end
end

View File

@@ -17,7 +17,8 @@ class TournamentCleanupJob < ApplicationJob
has_real_matches = tournament.matches.where(finished: 1).where.not(win_type: 'BYE').exists?
if has_real_matches
tournament.tournament_backups.destroy_all
# 1. Remove all school delegates
tournament.schools.each do |school|
school.delegates.destroy_all
@@ -33,4 +34,4 @@ class TournamentCleanupJob < ApplicationJob
end
end
end
end
end

View File

@@ -1,5 +1,6 @@
class WrestlingdevImportJob < ApplicationJob
queue_as :default
limits_concurrency to: 1, key: ->(tournament) { "tournament:#{tournament.id}" }
def perform(tournament, import_data = nil)
# Log information about the job
@@ -30,4 +31,4 @@ class WrestlingdevImportJob < ApplicationJob
raise e
end
end
end
end

View File

@@ -8,7 +8,7 @@ class AdvanceWrestler
def advance
# Use perform_later which will execute based on centralized adapter config
# This will be converted to inline execution in test environment by ActiveJob
AdvanceWrestlerJob.perform_later(@wrestler, @last_match)
AdvanceWrestlerJob.perform_later(@wrestler, @last_match, @tournament.id)
end
def advance_raw
@@ -29,4 +29,4 @@ class AdvanceWrestler
PoolAdvance.new(@wrestler).advanceWrestler
end
end
end

View File

@@ -19,14 +19,19 @@ class TournamentSeeding
half_of_bracket = bracket_size / 2
available_bracket_lines = (1..bracket_size).to_a
first_half_available_bracket_lines = (1..half_of_bracket).to_a
first_line_of_second_half_of_bracket = half_of_bracket + 1
second_half_available_bracket_lines = (first_line_of_second_half_of_bracket..bracket_size).to_a
# remove bracket lines that are taken from available_bracket_lines
wrestlers_with_bracket_lines = wrestlers.select{|w| w.bracket_line != nil }
wrestlers_with_bracket_lines.each do |wrestler|
available_bracket_lines.delete(wrestler.bracket_line)
first_half_available_bracket_lines.delete(wrestler.bracket_line)
second_half_available_bracket_lines.delete(wrestler.bracket_line)
end
available_bracket_lines_to_use = set_random_seeding_bracket_line_order(first_half_available_bracket_lines, second_half_available_bracket_lines)
wrestlers_without_bracket_lines = wrestlers.select{|w| w.bracket_line == nil }
if @tournament.tournament_type == "Pool to bracket"
wrestlers_without_bracket_lines.shuffle.each do |wrestler|
@@ -38,15 +43,10 @@ class TournamentSeeding
else
# Iterrate over the list randomly
wrestlers_without_bracket_lines.shuffle.each do |wrestler|
if first_half_available_bracket_lines.size > 0
random_available_bracket_line = first_half_available_bracket_lines.sample
wrestler.bracket_line = random_available_bracket_line
available_bracket_lines.delete(random_available_bracket_line)
first_half_available_bracket_lines.delete(random_available_bracket_line)
else
random_available_bracket_line = available_bracket_lines.sample
wrestler.bracket_line = random_available_bracket_line
available_bracket_lines.delete(random_available_bracket_line)
if available_bracket_lines_to_use.size > 0
bracket_line_to_use = available_bracket_lines_to_use.first
wrestler.bracket_line = bracket_line_to_use
available_bracket_lines_to_use.delete(bracket_line_to_use)
end
end
end
@@ -81,4 +81,35 @@ class TournamentSeeding
end
return wrestlers
end
private
def set_random_seeding_bracket_line_order(first_half_lines, second_half_lines)
# This method prevents double BYEs in round 1
# It also evenly distributes matches from the top half of the bracket to the bottom half
# It does both of these while keeping the randomness of the line assignment
odd_or_even = [0, 1]
odd_or_even_sample = odd_or_even.sample
# sort by odd or even based on the sample above
if odd_or_even_sample == 1
# odd numbers first
sorted_first_half_lines = first_half_lines.sort_by { |n| n.even? ? 1 : 0 }
sorted_second_half_lines = second_half_lines.sort_by { |n| n.even? ? 1 : 0 }
else
# even numbers first
sorted_first_half_lines = first_half_lines.sort_by { |n| n.odd? ? 1 : 0 }
sorted_second_half_lines = second_half_lines.sort_by { |n| n.odd? ? 1 : 0 }
end
# zip requires either even arrays or the receiver to be the bigger list
if first_half_lines.size >= second_half_lines.size
result = sorted_first_half_lines.zip(sorted_second_half_lines).flatten
else
result = sorted_second_half_lines.zip(sorted_first_half_lines).flatten
end
result.compact
result.delete(nil)
result
end
end

View File

@@ -41,7 +41,6 @@ class WrestlingdevImporter
@tournament.matches.destroy_all
@tournament.mat_assignment_rules.destroy_all # Explicitly destroy rules (might be redundant if Mat cascades)
@tournament.delegates.destroy_all
@tournament.tournament_backups.destroy_all
@tournament.tournament_job_statuses.destroy_all
# Note: Teampointadjusts are deleted via School/Wrestler cascade
end

View File

@@ -76,8 +76,12 @@
<% delete_wrestler_path_with_key = wrestler_path(wrestler) %>
<% delete_wrestler_path_with_key += "?school_permission_key=#{params[:school_permission_key]}" if params[:school_permission_key].present? %>
<%= link_to '', edit_wrestler_path_with_key, class: "fas fa-edit" %>
<%= link_to '', delete_wrestler_path_with_key, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete #{wrestler.name}? This will delete all of his matches." }, class: "fas fa-trash-alt" %>
<%= link_to edit_wrestler_path_with_key, class: "text-decoration-none" do %>
<span class="fas fa-edit" aria-hidden="true"></span>
<% end %>
<%= link_to delete_wrestler_path_with_key, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete #{wrestler.name}? This will delete all of his matches." }, class: "text-decoration-none" do %>
<span class="fas fa-trash-alt" aria-hidden="true"></span>
<% end %>
</td>
<% end %>
</tr>
@@ -101,8 +105,12 @@
<% delete_wrestler_path_with_key = wrestler_path(wrestler) %>
<% delete_wrestler_path_with_key += "?school_permission_key=#{params[:school_permission_key]}" if params[:school_permission_key].present? %>
<%= link_to '', edit_wrestler_path_with_key, class: "fas fa-edit" %>
<%= link_to '', delete_wrestler_path_with_key, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete #{wrestler.name}? This will delete all of his matches." }, class: "fas fa-trash-alt" %>
<%= link_to edit_wrestler_path_with_key, class: "text-decoration-none" do %>
<span class="fas fa-edit" aria-hidden="true"></span>
<% end %>
<%= link_to delete_wrestler_path_with_key, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete #{wrestler.name}? This will delete all of his matches." }, class: "text-decoration-none" do %>
<span class="fas fa-trash-alt" aria-hidden="true"></span>
<% end %>
</td>
<% end %>
</tr>

View File

@@ -27,12 +27,3 @@ and will also delete all of your current data. It's best to use the create backu
</tbody>
</table>
<br><br>
<h3>Import Manual Backup</h3>
<p>Paste the backup text here. Note, if this is formatted wrong, you'll need to restore a backup from above to fix it and you'll see an error in your background jobs.</p>
<%= form_for(:tournament, url: import_manual_tournament_tournament_backups_path(@tournament)) do |f| %>
<div class="field">
<%= f.label 'Import text' %><br>
<%= f.text_area :import_text, cols: "30", rows: "20" %>
</div>
<%= submit_tag "Import", class: "btn btn-success", data: { turbo_confirm: 'Are you sure? This will delete everything for the current tournament and restore it with the backup text pasted below.' } %>
<% end %>

View File

@@ -70,9 +70,13 @@
</td>
<td>
<% if can? :manage, school %>
<%= link_to '', edit_school_path(school), :class=>"fas fa-edit" %>
<%= link_to edit_school_path(school), class: "text-decoration-none" do %>
<span class="fas fa-edit" aria-hidden="true"></span>
<% end %>
<% if can? :manage, @tournament %>
<%= link_to '', school, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete #{school.name}?" }, :class=>"fas fa-trash-alt" %>
<%= link_to school, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete #{school.name}?" }, class: "text-decoration-none" do %>
<span class="fas fa-trash-alt" aria-hidden="true"></span>
<% end %>
<% end %>
<% end %>
</td>
@@ -105,8 +109,12 @@
<td><%= weight.bracket_size %></td>
<% if can? :manage, @tournament %>
<td>
<%= link_to '', edit_weight_path(weight), :class=>"fas fa-edit" %>
<%= link_to '', weight, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete the #{weight.max} weight class?" }, :class=>"fas fa-trash-alt" %>
<%= link_to edit_weight_path(weight), class: "text-decoration-none" do %>
<span class="fas fa-edit" aria-hidden="true"></span>
<% end %>
<%= link_to weight, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete the #{weight.max} weight class?" }, class: "text-decoration-none" do %>
<span class="fas fa-trash-alt" aria-hidden="true"></span>
<% end %>
</td>
<% end %>
</tr>
@@ -130,7 +138,9 @@
<td><%= link_to "Mat #{mat.name}", mat %></td>
<% if can? :manage, @tournament %>
<td>
<%= link_to '', mat, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete Mat #{mat.name}?" }, :class=>"fas fa-trash-alt" %>
<%= link_to mat, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete Mat #{mat.name}?" }, class: "text-decoration-none" do %>
<span class="fas fa-trash-alt" aria-hidden="true"></span>
<% end %>
<%= link_to '', "/mats/#{mat.id}/assign_next_match", data: { turbo_method: :post }, :class=>"fas fa-solid fa-arrow-right" %>
</td>
<% end %>

View File

@@ -5,7 +5,23 @@
// } );
</script>
<script>
setTimeout("location.reload(true);",30000);
const setUpMatchesRefresh = () => {
if (window.__upMatchesRefreshTimeout) {
clearTimeout(window.__upMatchesRefreshTimeout);
}
window.__upMatchesRefreshTimeout = setTimeout(() => {
window.location.reload(true);
}, 30000);
};
document.addEventListener("turbo:load", setUpMatchesRefresh);
// turbo:before-cache stops the timer refresh from occurring if you navigate away from up_matches
document.addEventListener("turbo:before-cache", () => {
if (window.__upMatchesRefreshTimeout) {
clearTimeout(window.__upMatchesRefreshTimeout);
window.__upMatchesRefreshTimeout = null;
}
});
</script>
<br>
<br>
@@ -28,10 +44,34 @@
<% @mats.each.map do |m| %>
<tr>
<td><%= m.name %></td>
<td><% if m.unfinished_matches.first %><strong><%=m.unfinished_matches.first.bout_number%></strong> - <%= m.unfinished_matches.first.weight_max %><br><%= m.unfinished_matches.first.w1_bracket_name %> vs. <%= m.unfinished_matches.first.w2_bracket_name %><% end %></td>
<td><% if m.unfinished_matches.second %><strong><%=m.unfinished_matches.second.bout_number%></strong> - <%= m.unfinished_matches.second.weight_max %><br><%= m.unfinished_matches.second.w1_bracket_name %> vs. <%= m.unfinished_matches.second.w2_bracket_name %><% end %></td>
<td><% if m.unfinished_matches.third %><strong><%=m.unfinished_matches.third.bout_number%></strong> - <%= m.unfinished_matches.third.weight_max %><br><%= m.unfinished_matches.third.w1_bracket_name %> vs. <%= m.unfinished_matches.third.w2_bracket_name %><% end %></td>
<td><% if m.unfinished_matches.fourth %><strong><%=m.unfinished_matches.fourth.bout_number%></strong> - <%= m.unfinished_matches.fourth.weight_max %><br><%= m.unfinished_matches.fourth.w1_bracket_name %> vs. <%= m.unfinished_matches.fourth.w2_bracket_name %><% end %></td>
<td>
<% if m.unfinished_matches.first %><strong><%=m.unfinished_matches.first.bout_number%></strong> (<%= m.unfinished_matches.first.bracket_position %>)<br>
<%= m.unfinished_matches.first.weight_max %> lbs
<br><%= m.unfinished_matches.first.w1_bracket_name %> vs. <br>
<%= m.unfinished_matches.first.w2_bracket_name %>
<% end %>
</td>
<td>
<% if m.unfinished_matches.second %><strong><%=m.unfinished_matches.second.bout_number%></strong> (<%= m.unfinished_matches.second.bracket_position %>)<br>
<%= m.unfinished_matches.second.weight_max %> lbs
<br><%= m.unfinished_matches.second.w1_bracket_name %> vs. <br>
<%= m.unfinished_matches.second.w2_bracket_name %>
<% end %>
</td>
<td>
<% if m.unfinished_matches.third %><strong><%=m.unfinished_matches.third.bout_number%></strong> (<%= m.unfinished_matches.third.bracket_position %>)<br>
<%= m.unfinished_matches.third.weight_max %> lbs
<br><%= m.unfinished_matches.third.w1_bracket_name %> vs. <br>
<%= m.unfinished_matches.third.w2_bracket_name %>
<% end %>
</td>
<td>
<% if m.unfinished_matches.fourth %><strong><%=m.unfinished_matches.fourth.bout_number%></strong> (<%= m.unfinished_matches.fourth.bracket_position %>)<br>
<%= m.unfinished_matches.fourth.weight_max %> lbs
<br><%= m.unfinished_matches.fourth.w1_bracket_name %> vs. <br>
<%= m.unfinished_matches.fourth.w2_bracket_name %>
<% end %>
</td>
</tr>
<% end %>
</tbody>

View File

@@ -1,48 +1,50 @@
<h3>Weight Class:<%= @weight.max %> <% if can? :manage, @tournament %><%= link_to " Edit", edit_weight_path(@weight), :class=>"fas fa-edit" %><% end %></h3>
<h3>Weight Class:<%= @weight.max %> <% if can? :manage, @tournament %><%= link_to edit_weight_path(@weight), class: "text-decoration-none" do %><span class="fas fa-edit" aria-hidden="true"></span><% end %><% end %></h3>
<br>
<br>
<table class="table table-hover table-condensed">
<thead>
<tr>
<th>Name</th>
<th>School</th>
<th>Seed</th>
<th>Record</th>
<th>Seed Criteria</th>
<th>Extra?</th>
</tr>
</thead>
<tbody>
<%= form_tag @wrestlers_update_path do %>
<% @wrestlers.sort_by{|w| [w.original_seed ? 0 : 1, w.original_seed || 0]}.each do |wrestler| %>
<% if wrestler.weight_id == @weight.id %>
<tr>
<td><%= link_to "#{wrestler.name}", wrestler %></td>
<td><%= wrestler.school.name %></td>
<td>
<% if can? :manage, @tournament %>
<%= fields_for "wrestler[]", wrestler do |w| %>
<%= w.text_field :original_seed %>
<% end %>
<% else %>
<%= wrestler.original_seed %>
<% end %>
</td>
<td><%= wrestler.season_win %>-<%= wrestler.season_loss %></td>
<td><%= wrestler.criteria %> Win <%= wrestler.season_win_percentage %>%</td>
<td><% if wrestler.extra? == true %>
Yes
<% end %></td>
<% if can? :manage, @tournament %>
<td>
<%= link_to '', wrestler, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete #{wrestler.name}? THIS WILL DELETE ALL MATCHES." } , :class=>"fas fa-trash-alt" %>
<%= form_tag @wrestlers_update_path do %>
<table class="table table-hover table-condensed">
<thead>
<tr>
<th>Name</th>
<th>School</th>
<th>Seed</th>
<th>Record</th>
<th>Seed Criteria</th>
<th>Extra?</th>
</tr>
</thead>
<tbody>
<% @wrestlers.sort_by{|w| [w.original_seed ? 0 : 1, w.original_seed || 0]}.each do |wrestler| %>
<% if wrestler.weight_id == @weight.id %>
<tr>
<td><%= link_to "#{wrestler.name}", wrestler %></td>
<td><%= wrestler.school.name %></td>
<td>
<% if can? :manage, @tournament %>
<%= fields_for "wrestler[]", wrestler do |w| %>
<%= w.text_field :original_seed %>
<% end %>
<% else %>
<%= wrestler.original_seed %>
<% end %>
</td>
<% end %>
</tr>
<% end %>
<% end %>
</tbody>
</table>
<td><%= wrestler.season_win %>-<%= wrestler.season_loss %></td>
<td><%= wrestler.criteria %> Win <%= wrestler.season_win_percentage %>%</td>
<td><% if wrestler.extra? == true %>
Yes
<% end %></td>
<% if can? :manage, @tournament %>
<td>
<%= link_to wrestler, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete #{wrestler.name}? THIS WILL DELETE ALL MATCHES." }, class: "text-decoration-none" do %>
<span class="fas fa-trash-alt" aria-hidden="true"></span>
<% end %>
</td>
<% end %>
</tr>
<% end %>
<% end %>
</tbody>
</table>
<br><p>*All wrestlers without a seed (determined by tournament director) will be assigned a random bracket line.</p>
<% if can? :manage, @tournament %>
<br>

View File

@@ -0,0 +1,36 @@
require 'test_helper'
class RandomSeedingTest < ActionDispatch::IntegrationTest
def setup
end
def clean_up_original_seeds(tournament)
tournament.wrestlers.select{|w| w.original_seed > 12}.each do |wrestler|
wrestler.original_seed = nil
wrestler.save
end
tournament.wrestlers.reload.each do |wrestler|
wrestler.bracket_line = nil
wrestler.save
end
GenerateTournamentMatches.new(tournament).generate
end
test "There are no double byes in a double elimination tournament round 1" do
create_double_elim_tournament_single_weight(18, "Regular Double Elimination 1-8")
clean_up_original_seeds(@tournament)
round_one_matches = @tournament.matches.reload.select{|m| m.round == 1}
assert round_one_matches.select{|m| m.w1.nil? and m.w2.nil? }.size == 0
end
test "There are the same number of matches in the top half and bottom half of a double elimination tournament in round 1" do
create_double_elim_tournament_single_weight(18, "Regular Double Elimination 1-8")
clean_up_original_seeds(@tournament)
round_one_matches = @tournament.matches.reload.select{|m| m.round == 1}
# 32 man bracket there are 16 matches so top half is bracket_position_number 1-8 and bottom is 9-16
round_one_top_half = round_one_matches.select{|m| !m.w1.nil? and !m.w2.nil? and m.bracket_position_number < 9}
round_one_bottom_half = round_one_matches.select{|m| !m.w1.nil? and !m.w2.nil? and m.bracket_position_number > 8}
assert round_one_top_half.size == round_one_bottom_half.size
end
end