1
0
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:
2016-09-09 17:51:00 +00:00
parent a14d750f13
commit bbb745564e
9 changed files with 58 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
class WeightsController < ApplicationController
before_action :set_weight, only: [:show, :edit, :update, :destroy]
before_filter :check_access, only: [:new,:create,:update,:destroy,:edit]
before_action :set_weight, only: [:show, :edit, :update, :destroy,:re_gen]
before_filter :check_access, only: [:new,:create,:update,:destroy,:edit, :re_gen]
# GET /weights/1
@@ -69,6 +69,11 @@ class WeightsController < ApplicationController
format.json { head :no_content }
end
end
def re_gen
@tournament = @weight.tournament
GenerateTournamentMatches.new(@tournament).generateWeight(@weight)
end
private
# Use callbacks to share common setup or constraints between actions.

View File

@@ -2,6 +2,19 @@ class GenerateTournamentMatches
def initialize( tournament )
@tournament = tournament
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
standardStartingActions
@@ -57,7 +70,13 @@ class GenerateTournamentMatches
end
end
def unAssignBouts
bout_counts = Hash.new(0)
@tournament.matches.each do |m|
m.bout_number = nil
m.save!
end
end

View File

@@ -3,6 +3,18 @@ class PoolToBracketGenerateLoserNames
@tournament = tournament
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
matches_by_weight = nil
@tournament.weights.each do |w|

View File

@@ -3,7 +3,13 @@ class PoolToBracketMatchGeneration
@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

@@ -9,6 +9,10 @@ class WipeTournamentMatches
resetSchoolScores
end
def wipeWeightMatches(weight)
weight.matches.destroy_all
end
def wipeMatches
@tournament.matches.destroy_all
end

View 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.

View File

@@ -4,6 +4,9 @@
<%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}", :class=>"btn btn-default" %>
<% if can? :manage, @tournament %>
| <%= 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 %>
<br>

View File

@@ -51,6 +51,7 @@ Wrestling::Application.routes.draw do
get 'tournaments/:id/error' => 'tournaments#error'
post "/tournaments/:id/swap" => "tournaments#swap", :as => :swap_wrestlers
post 'weights/:id/re_gen' => 'weights#re_gen', :as => :regen_weight
#API
get "/api/tournaments" => "api#tournaments"

View File

@@ -11,7 +11,7 @@
#
# 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|
t.integer "priority", default: 0, null: false