mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-08 23:34:51 +00:00
Deducted points pool tie breaker added
This commit is contained in:
@@ -2,11 +2,10 @@ class Poolorder
|
|||||||
def initialize(wrestlers)
|
def initialize(wrestlers)
|
||||||
@wrestlers = wrestlers
|
@wrestlers = wrestlers
|
||||||
end
|
end
|
||||||
attr_accessor :wrestlersWithSamePoints
|
|
||||||
|
|
||||||
def getPoolOrder
|
def getPoolOrder
|
||||||
setOriginalPoints
|
setOriginalPoints
|
||||||
until checkForTieBreakers == false
|
while checkForTieBreakers == true
|
||||||
breakTie
|
breakTie
|
||||||
end
|
end
|
||||||
@wrestlers.sort_by{|w| w.poolAdvancePoints}.reverse!
|
@wrestlers.sort_by{|w| w.poolAdvancePoints}.reverse!
|
||||||
@@ -19,28 +18,67 @@ class Poolorder
|
|||||||
end
|
end
|
||||||
|
|
||||||
def checkForTieBreakers
|
def checkForTieBreakers
|
||||||
@wrestlers.each do |w|
|
if wrestlersWithSamePoints.size > 1
|
||||||
self.wrestlersWithSamePoints = @wrestlers.select{|wr| wr.poolAdvancePoints == w.poolAdvancePoints}
|
return true
|
||||||
if self.wrestlersWithSamePoints.size > 1
|
end
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def wrestlersWithSamePoints
|
||||||
|
@wrestlers.each do |w|
|
||||||
|
wrestlersWithSamePoints = @wrestlers.select{|wr| wr.poolAdvancePoints == w.poolAdvancePoints}
|
||||||
|
if wrestlersWithSamePoints.size > 0
|
||||||
|
return wrestlersWithSamePoints
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def ifWrestlersWithSamePointsIsSameAsOriginal(originalTieSize)
|
||||||
|
if wrestlersWithSamePoints.size == originalTieSize
|
||||||
|
yield
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def breakTie
|
def breakTie
|
||||||
headToHead
|
originalTieSize = wrestlersWithSamePoints.size
|
||||||
|
if originalTieSize == 2
|
||||||
|
ifWrestlersWithSamePointsIsSameAsOriginal(originalTieSize) { headToHead }
|
||||||
|
end
|
||||||
|
ifWrestlersWithSamePointsIsSameAsOriginal(originalTieSize) { deductedPoints }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def headToHead
|
def headToHead
|
||||||
self.wrestlersWithSamePoints.each do |wr|
|
wrestlersWithSamePoints.each do |wr|
|
||||||
@otherWrestlers = self.wrestlersWithSamePoints.select{|w| w.id != wr.id}
|
otherWrestler = wrestlersWithSamePoints.select{|w| w.id != wr.id}.first
|
||||||
@otherWrestlers.each do |ow|
|
if wr.matchAgainst(otherWrestler).first.winner_id == wr.id
|
||||||
if wr.matchAgainst(ow).first.winner_id == wr.id
|
addPointsToWrestlersAhead(wr)
|
||||||
wr.poolAdvancePoints = wr.poolAdvancePoints + 1
|
addPoints(wr)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def addPoints(wrestler)
|
||||||
|
wrestler.poolAdvancePoints = wrestler.poolAdvancePoints + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
def addPointsToWrestlersAhead(wrestler)
|
||||||
|
wrestlersAhead = @wrestlers.select{|w| w.poolAdvancePoints > wrestler.poolAdvancePoints}
|
||||||
|
wrestlersAhead.each do |wr|
|
||||||
|
wr.poolAdvancePoints = wr.poolAdvancePoints + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def deductedPoints
|
||||||
|
pointsArray = []
|
||||||
|
wrestlersWithSamePoints.each do |w|
|
||||||
|
pointsArray << w.totalDeductedPoints
|
||||||
|
end
|
||||||
|
leastPoints = pointsArray.min
|
||||||
|
wrestlersWithLeastDeductedPoints = wrestlersWithSamePoints.select{|w| w.totalDeductedPoints == leastPoints}
|
||||||
|
addPointsToWrestlersAhead(wrestlersWithLeastDeductedPoints.first)
|
||||||
|
wrestlersWithLeastDeductedPoints.each do |wr|
|
||||||
|
addPoints(wr)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
class School < ActiveRecord::Base
|
class School < ActiveRecord::Base
|
||||||
belongs_to :tournament
|
belongs_to :tournament
|
||||||
has_many :wrestlers, dependent: :destroy
|
has_many :wrestlers, dependent: :destroy
|
||||||
|
has_many :deductedPoints, through: :wrestlers
|
||||||
|
|
||||||
|
|
||||||
#calculate score here
|
#calculate score here
|
||||||
@@ -8,4 +9,60 @@ class School < ActiveRecord::Base
|
|||||||
#Add score per wrestler. Calculate score in wrestler model.
|
#Add score per wrestler. Calculate score in wrestler model.
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def calcScore
|
||||||
|
#calc and save score
|
||||||
|
end
|
||||||
|
|
||||||
|
def totalDeductedPoints
|
||||||
|
points = 0
|
||||||
|
self.deductedPoints.each do |d|
|
||||||
|
points = points + d.points
|
||||||
|
end
|
||||||
|
points
|
||||||
|
end
|
||||||
|
|
||||||
|
def poolWins
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def pinDefaultDqWins
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def techFallWins
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def majorWins
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def firstPlace
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def secondPlace
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def thirdPlace
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def fourthPlace
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def fifthPlace
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def sixthPlace
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def seventhPlace
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
3
app/models/teampointadjust.rb
Normal file
3
app/models/teampointadjust.rb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
class Teampointadjust < ActiveRecord::Base
|
||||||
|
belongs_to :wrestler
|
||||||
|
end
|
||||||
@@ -3,14 +3,23 @@ class Wrestler < ActiveRecord::Base
|
|||||||
belongs_to :weight
|
belongs_to :weight
|
||||||
has_one :tournament, through: :weight
|
has_one :tournament, through: :weight
|
||||||
has_many :matches, through: :weight
|
has_many :matches, through: :weight
|
||||||
|
has_many :deductedPoints, class_name: "Teampointadjust"
|
||||||
attr_accessor :poolNumber, :poolAdvancePoints
|
attr_accessor :poolNumber, :poolAdvancePoints
|
||||||
|
|
||||||
before_save do
|
before_save do
|
||||||
self.tournament.destroyAllMatches
|
self.tournament.destroyAllMatches
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def totalDeductedPoints
|
||||||
|
points = 0
|
||||||
|
self.deductedPoints.each do |d|
|
||||||
|
points = points + d.points
|
||||||
|
end
|
||||||
|
points
|
||||||
|
end
|
||||||
|
|
||||||
def resultByBout(bout)
|
def resultByBout(bout)
|
||||||
@match = Match.where("bout_number = ? AND finished = ?",bout,1)
|
@match = allMatches.select{|m| m.bout_number == bout and m.finished == 1}
|
||||||
if @match.size == 0
|
if @match.size == 0
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
|
|||||||
10
db/migrate/20151111130227_create_teampointadjusts.rb
Normal file
10
db/migrate/20151111130227_create_teampointadjusts.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
class CreateTeampointadjusts < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :teampointadjusts do |t|
|
||||||
|
t.integer :points
|
||||||
|
t.integer :wrestler_id
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
add_index :teampointadjusts, :wrestler_id
|
||||||
|
end
|
||||||
|
end
|
||||||
15
db/schema.rb
15
db/schema.rb
@@ -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: 20151023123932) do
|
ActiveRecord::Schema.define(version: 20151111130227) do
|
||||||
|
|
||||||
create_table "matches", force: :cascade do |t|
|
create_table "matches", force: :cascade do |t|
|
||||||
t.integer "w1"
|
t.integer "w1"
|
||||||
@@ -37,7 +37,7 @@ ActiveRecord::Schema.define(version: 20151023123932) do
|
|||||||
|
|
||||||
add_index "matches", ["mat_id"], name: "index_matches_on_mat_id"
|
add_index "matches", ["mat_id"], name: "index_matches_on_mat_id"
|
||||||
add_index "matches", ["tournament_id"], name: "index_matches_on_tournament_id"
|
add_index "matches", ["tournament_id"], name: "index_matches_on_tournament_id"
|
||||||
add_index "matches", ["w1", "w2"], name: "index_matches_on_w1_and_w2", unique: true
|
add_index "matches", ["w1", "w2"], name: "index_matches_on_w1_and_w2"
|
||||||
|
|
||||||
create_table "mats", force: :cascade do |t|
|
create_table "mats", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
@@ -57,6 +57,15 @@ ActiveRecord::Schema.define(version: 20151023123932) do
|
|||||||
|
|
||||||
add_index "schools", ["tournament_id"], name: "index_schools_on_tournament_id"
|
add_index "schools", ["tournament_id"], name: "index_schools_on_tournament_id"
|
||||||
|
|
||||||
|
create_table "teampointadjusts", force: :cascade do |t|
|
||||||
|
t.integer "points"
|
||||||
|
t.integer "wrestler_id"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "teampointadjusts", ["wrestler_id"], name: "index_teampointadjusts_on_wrestler_id"
|
||||||
|
|
||||||
create_table "tournaments", force: :cascade do |t|
|
create_table "tournaments", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.string "address"
|
t.string "address"
|
||||||
@@ -70,7 +79,6 @@ ActiveRecord::Schema.define(version: 20151023123932) do
|
|||||||
end
|
end
|
||||||
|
|
||||||
add_index "tournaments", ["user_id"], name: "index_tournaments_on_user_id"
|
add_index "tournaments", ["user_id"], name: "index_tournaments_on_user_id"
|
||||||
add_index "tournaments", ["weigh_in_ref"], name: "index_tournaments_on_weigh_in_ref"
|
|
||||||
|
|
||||||
create_table "users", force: :cascade do |t|
|
create_table "users", force: :cascade do |t|
|
||||||
t.string "email", default: "", null: false
|
t.string "email", default: "", null: false
|
||||||
@@ -114,7 +122,6 @@ ActiveRecord::Schema.define(version: 20151023123932) do
|
|||||||
t.decimal "offical_weight"
|
t.decimal "offical_weight"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "wrestlers", ["offical_weight"], name: "index_wrestlers_on_offical_weight"
|
|
||||||
add_index "wrestlers", ["weight_id"], name: "index_wrestlers_on_weight_id"
|
add_index "wrestlers", ["weight_id"], name: "index_wrestlers_on_weight_id"
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
9
test/fixtures/teampointadjusts.yml
vendored
Normal file
9
test/fixtures/teampointadjusts.yml
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
points: 1
|
||||||
|
wrestler_id: 1
|
||||||
|
|
||||||
|
two:
|
||||||
|
points: 1
|
||||||
|
wrestler_id: 1
|
||||||
@@ -45,6 +45,26 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
|
|||||||
endMatch(2004,"Guy4",@matches)
|
endMatch(2004,"Guy4",@matches)
|
||||||
endMatch(2005,"Guy9",@matches)
|
endMatch(2005,"Guy9",@matches)
|
||||||
endMatch(3004,"Guy7",@matches)
|
endMatch(3004,"Guy7",@matches)
|
||||||
|
#DEDUCTED POINTS SHOULD NOT MATTER FOR HEAD TO HEAD
|
||||||
|
@deduct = Teampointadjust.new
|
||||||
|
@deduct.wrestler_id = translateNameToId("Guy3")
|
||||||
|
@deduct.points = 1
|
||||||
|
@deduct.save
|
||||||
|
endMatch(3005,"Guy3",@matches)
|
||||||
|
end
|
||||||
|
|
||||||
|
def nineManBracketPoolTwoGuyThreeDeductedPoints
|
||||||
|
@matches = @tournament.matches.select{|m| m.weight_id == 3 && m.bracket_position == "Pool"}
|
||||||
|
endMatch(1004,"Guy9",@matches)
|
||||||
|
endMatch(1005,"Guy7",@matches)
|
||||||
|
endMatch(2004,"Guy3",@matches)
|
||||||
|
endMatch(2005,"Guy9",@matches)
|
||||||
|
#DEDUCT HAS TO HAPPEN BEFORE LAST MATCH IN POOL OR ELSE ITS NOT AVAILABLE FOR POOLORDER TO CHECK
|
||||||
|
@deduct = Teampointadjust.new
|
||||||
|
@deduct.wrestler_id = translateNameToId("Guy7")
|
||||||
|
@deduct.points = 1
|
||||||
|
@deduct.save
|
||||||
|
endMatch(3004,"Guy7",@matches)
|
||||||
endMatch(3005,"Guy3",@matches)
|
endMatch(3005,"Guy3",@matches)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -65,7 +85,6 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
|
|||||||
test "nine man outright finals advance" do
|
test "nine man outright finals advance" do
|
||||||
nineManBracketPoolOneOutrightWinner
|
nineManBracketPoolOneOutrightWinner
|
||||||
@wrestler = Wrestler.where("name = ?", "Guy2").first
|
@wrestler = Wrestler.where("name = ?", "Guy2").first
|
||||||
@match = Match.where("bout_number = ?",6000).first
|
|
||||||
assert_equal 6000, @wrestler.boutByRound(6)
|
assert_equal 6000, @wrestler.boutByRound(6)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -78,26 +97,40 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
|
|||||||
test "nine man pool 2 man to man tie breaker finalist guy 9" do
|
test "nine man pool 2 man to man tie breaker finalist guy 9" do
|
||||||
@wrestler = Wrestler.where("name = ?", "Guy9").first
|
@wrestler = Wrestler.where("name = ?", "Guy9").first
|
||||||
nineManBracketPoolTwoGuyNineHeadToHead
|
nineManBracketPoolTwoGuyNineHeadToHead
|
||||||
@match = Match.where("bout_number = ?",6000).first
|
|
||||||
assert_equal 6000, @wrestler.boutByRound(6)
|
assert_equal 6000, @wrestler.boutByRound(6)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "nine man pool 2 man to man tie breaker finalist guy 3" do
|
test "nine man pool 2 man to man tie breaker finalist guy 3" do
|
||||||
@wrestler = Wrestler.where("name = ?", "Guy3").first
|
@wrestler = Wrestler.where("name = ?", "Guy3").first
|
||||||
nineManBracketPoolTwoGuyThreeHeadToHead
|
nineManBracketPoolTwoGuyThreeHeadToHead
|
||||||
@match = Match.where("bout_number = ?",6000).first
|
|
||||||
assert_equal 6000, @wrestler.boutByRound(6)
|
assert_equal 6000, @wrestler.boutByRound(6)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "nine man outright conso finals man to man tie breaker guy 3" do
|
test "nine man conso finals man to man tie breaker guy 3" do
|
||||||
nineManBracketPoolTwoGuyNineHeadToHead
|
nineManBracketPoolTwoGuyNineHeadToHead
|
||||||
@wrestler = Wrestler.where("name = ?", "Guy3").first
|
@wrestler = Wrestler.where("name = ?", "Guy3").first
|
||||||
assert_equal 6001, @wrestler.boutByRound(6)
|
assert_equal 6001, @wrestler.boutByRound(6)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "nine man outright conso finals man to man tie breaker guy 9" do
|
test "nine man conso finals man to man tie breaker guy 9" do
|
||||||
nineManBracketPoolTwoGuyThreeHeadToHead
|
nineManBracketPoolTwoGuyThreeHeadToHead
|
||||||
@wrestler = Wrestler.where("name = ?", "Guy9").first
|
@wrestler = Wrestler.where("name = ?", "Guy9").first
|
||||||
|
# @match = Match.where(bout_number: 6001).first
|
||||||
|
# puts "#{@match.w1_name} v #{@match.w2_name}"
|
||||||
|
assert_equal 6001, @wrestler.boutByRound(6)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "nine man pool 2 deductedPoints tie breaker finalist guy 3" do
|
||||||
|
@wrestler = Wrestler.where("name = ?", "Guy3").first
|
||||||
|
nineManBracketPoolTwoGuyThreeDeductedPoints
|
||||||
|
assert_equal 6000, @wrestler.boutByRound(6)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "nine man conso finals deductedPoints tie breaker guy 9" do
|
||||||
|
nineManBracketPoolTwoGuyThreeDeductedPoints
|
||||||
|
@wrestler = Wrestler.where("name = ?", "Guy9").first
|
||||||
|
# @match = Match.where(bout_number: 6001).first
|
||||||
|
# puts "#{@match.w1_name} v #{@match.w2_name}"
|
||||||
assert_equal 6001, @wrestler.boutByRound(6)
|
assert_equal 6001, @wrestler.boutByRound(6)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
7
test/models/teampointadjust_test.rb
Normal file
7
test/models/teampointadjust_test.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class TeampointadjustTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user