mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Re-generating one weight classes matches - NEED TO REFACTOR and NEED TO WRITE TESTS
Code is repeated in the following classes: GenerateTournamentMatches PoolToBracketMatchGeneration PoolToBracketGenerateLoserNames WipeTournamentMatches
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
class WeightsController < ApplicationController
|
class WeightsController < ApplicationController
|
||||||
before_action :set_weight, only: [:show, :edit, :update, :destroy]
|
before_action :set_weight, only: [:show, :edit, :update, :destroy,:re_gen]
|
||||||
before_filter :check_access, only: [:new,:create,:update,:destroy,:edit]
|
before_filter :check_access, only: [:new,:create,:update,:destroy,:edit, :re_gen]
|
||||||
|
|
||||||
|
|
||||||
# GET /weights/1
|
# GET /weights/1
|
||||||
@@ -70,6 +70,11 @@ class WeightsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def re_gen
|
||||||
|
@tournament = @weight.tournament
|
||||||
|
GenerateTournamentMatches.new(@tournament).generateWeight(@weight)
|
||||||
|
end
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
@@ -3,6 +3,19 @@ class GenerateTournamentMatches
|
|||||||
@tournament = tournament
|
@tournament = tournament
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def generateWeight(weight)
|
||||||
|
WipeTournamentMatches.new(@tournament).wipeWeightMatches(weight)
|
||||||
|
@tournament.curently_generating_matches = 1
|
||||||
|
@tournament.save
|
||||||
|
unAssignBouts
|
||||||
|
PoolToBracketMatchGeneration.new(@tournament).generatePoolToBracketMatchesWeight(weight) if @tournament.tournament_type == "Pool to bracket"
|
||||||
|
postMatchCreationActions
|
||||||
|
PoolToBracketGenerateLoserNames.new(@tournament).assignLoserNamesWeight(weight) if @tournament.tournament_type == "Pool to bracket"
|
||||||
|
end
|
||||||
|
if Rails.env.production?
|
||||||
|
handle_asynchronously :generateWeight
|
||||||
|
end
|
||||||
|
|
||||||
def generate
|
def generate
|
||||||
standardStartingActions
|
standardStartingActions
|
||||||
PoolToBracketMatchGeneration.new(@tournament).generatePoolToBracketMatches if @tournament.tournament_type == "Pool to bracket"
|
PoolToBracketMatchGeneration.new(@tournament).generatePoolToBracketMatches if @tournament.tournament_type == "Pool to bracket"
|
||||||
@@ -57,7 +70,13 @@ class GenerateTournamentMatches
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def unAssignBouts
|
||||||
|
bout_counts = Hash.new(0)
|
||||||
|
@tournament.matches.each do |m|
|
||||||
|
m.bout_number = nil
|
||||||
|
m.save!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,18 @@ class PoolToBracketGenerateLoserNames
|
|||||||
@tournament = tournament
|
@tournament = tournament
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assignLoserNamesWeight(weight)
|
||||||
|
matches_by_weight = @tournament.matches.where(weight_id: weight.id)
|
||||||
|
if weight.pool_bracket_type == "twoPoolsToSemi"
|
||||||
|
twoPoolsToSemiLoser(matches_by_weight)
|
||||||
|
elsif weight.pool_bracket_type == "fourPoolsToQuarter"
|
||||||
|
fourPoolsToQuarterLoser(matches_by_weight)
|
||||||
|
elsif weight.pool_bracket_type == "fourPoolsToSemi"
|
||||||
|
fourPoolsToSemiLoser(matches_by_weight)
|
||||||
|
end
|
||||||
|
saveMatches(matches_by_weight)
|
||||||
|
end
|
||||||
|
|
||||||
def assignLoserNames
|
def assignLoserNames
|
||||||
matches_by_weight = nil
|
matches_by_weight = nil
|
||||||
@tournament.weights.each do |w|
|
@tournament.weights.each do |w|
|
||||||
|
|||||||
@@ -3,7 +3,13 @@ class PoolToBracketMatchGeneration
|
|||||||
@tournament = tournament
|
@tournament = tournament
|
||||||
end
|
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
|
def generatePoolToBracketMatches
|
||||||
@tournament.weights.order(:max).each do |weight|
|
@tournament.weights.order(:max).each do |weight|
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ class WipeTournamentMatches
|
|||||||
resetSchoolScores
|
resetSchoolScores
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def wipeWeightMatches(weight)
|
||||||
|
weight.matches.destroy_all
|
||||||
|
end
|
||||||
|
|
||||||
def wipeMatches
|
def wipeMatches
|
||||||
@tournament.matches.destroy_all
|
@tournament.matches.destroy_all
|
||||||
end
|
end
|
||||||
|
|||||||
3
app/views/weights/re_gen.html.erb
Normal file
3
app/views/weights/re_gen.html.erb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<%= link_to "Back to #{@weight.tournament.name}", "/tournaments/#{@weight.tournament.id}", :class=>"btn btn-default" %>
|
||||||
|
<br><br>
|
||||||
|
<%= @weight.max %> lbs Matches are being generated. This can take anywhere from 1-5 minutes to finish. It is recommended to delete all delegated school permissions to prevent lineup changes after the tournament has started.
|
||||||
@@ -4,6 +4,9 @@
|
|||||||
<%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}", :class=>"btn btn-default" %>
|
<%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}", :class=>"btn btn-default" %>
|
||||||
<% if can? :manage, @tournament %>
|
<% if can? :manage, @tournament %>
|
||||||
| <%= link_to "Edit #{@weight.max} Weight Class", edit_weight_path(@weight), :class=>"btn btn-primary" %>
|
| <%= link_to "Edit #{@weight.max} Weight Class", edit_weight_path(@weight), :class=>"btn btn-primary" %>
|
||||||
|
| <%= form_for(@weight, url: regen_weight_path(@weight.id), :method => "post") do |f| %>
|
||||||
|
<%= submit_tag "Regenerate Weight Class Matches", :class=>"btn"%>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ Wrestling::Application.routes.draw do
|
|||||||
get 'tournaments/:id/error' => 'tournaments#error'
|
get 'tournaments/:id/error' => 'tournaments#error'
|
||||||
post "/tournaments/:id/swap" => "tournaments#swap", :as => :swap_wrestlers
|
post "/tournaments/:id/swap" => "tournaments#swap", :as => :swap_wrestlers
|
||||||
|
|
||||||
|
post 'weights/:id/re_gen' => 'weights#re_gen', :as => :regen_weight
|
||||||
|
|
||||||
#API
|
#API
|
||||||
get "/api/tournaments" => "api#tournaments"
|
get "/api/tournaments" => "api#tournaments"
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20160126173424) do
|
ActiveRecord::Schema.define(version: 20160112152946) do
|
||||||
|
|
||||||
create_table "delayed_jobs", force: :cascade do |t|
|
create_table "delayed_jobs", force: :cascade do |t|
|
||||||
t.integer "priority", default: 0, null: false
|
t.integer "priority", default: 0, null: false
|
||||||
|
|||||||
Reference in New Issue
Block a user