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

Deducted points pool tie breaker added

This commit is contained in:
2015-11-16 13:31:27 +00:00
parent 34a04be4bf
commit 934ccc28ee
9 changed files with 199 additions and 26 deletions

View File

@@ -2,11 +2,10 @@ class Poolorder
def initialize(wrestlers)
@wrestlers = wrestlers
end
attr_accessor :wrestlersWithSamePoints
def getPoolOrder
setOriginalPoints
until checkForTieBreakers == false
while checkForTieBreakers == true
breakTie
end
@wrestlers.sort_by{|w| w.poolAdvancePoints}.reverse!
@@ -19,28 +18,67 @@ class Poolorder
end
def checkForTieBreakers
@wrestlers.each do |w|
self.wrestlersWithSamePoints = @wrestlers.select{|wr| wr.poolAdvancePoints == w.poolAdvancePoints}
if self.wrestlersWithSamePoints.size > 1
return true
end
end
if wrestlersWithSamePoints.size > 1
return true
end
return false
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
headToHead
originalTieSize = wrestlersWithSamePoints.size
if originalTieSize == 2
ifWrestlersWithSamePointsIsSameAsOriginal(originalTieSize) { headToHead }
end
ifWrestlersWithSamePointsIsSameAsOriginal(originalTieSize) { deductedPoints }
end
def headToHead
self.wrestlersWithSamePoints.each do |wr|
@otherWrestlers = self.wrestlersWithSamePoints.select{|w| w.id != wr.id}
@otherWrestlers.each do |ow|
if wr.matchAgainst(ow).first.winner_id == wr.id
wr.poolAdvancePoints = wr.poolAdvancePoints + 1
end
wrestlersWithSamePoints.each do |wr|
otherWrestler = wrestlersWithSamePoints.select{|w| w.id != wr.id}.first
if wr.matchAgainst(otherWrestler).first.winner_id == wr.id
addPointsToWrestlersAhead(wr)
addPoints(wr)
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

View File

@@ -1,6 +1,7 @@
class School < ActiveRecord::Base
belongs_to :tournament
has_many :wrestlers, dependent: :destroy
has_many :deductedPoints, through: :wrestlers
#calculate score here
@@ -8,4 +9,60 @@ class School < ActiveRecord::Base
#Add score per wrestler. Calculate score in wrestler model.
return 0
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

View File

@@ -0,0 +1,3 @@
class Teampointadjust < ActiveRecord::Base
belongs_to :wrestler
end

View File

@@ -3,14 +3,23 @@ class Wrestler < ActiveRecord::Base
belongs_to :weight
has_one :tournament, through: :weight
has_many :matches, through: :weight
has_many :deductedPoints, class_name: "Teampointadjust"
attr_accessor :poolNumber, :poolAdvancePoints
before_save do
self.tournament.destroyAllMatches
end
def totalDeductedPoints
points = 0
self.deductedPoints.each do |d|
points = points + d.points
end
points
end
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
return ""
end

View 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

View File

@@ -11,7 +11,7 @@
#
# 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|
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", ["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|
t.string "name"
@@ -57,6 +57,15 @@ ActiveRecord::Schema.define(version: 20151023123932) do
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|
t.string "name"
t.string "address"
@@ -70,7 +79,6 @@ ActiveRecord::Schema.define(version: 20151023123932) do
end
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|
t.string "email", default: "", null: false
@@ -114,7 +122,6 @@ ActiveRecord::Schema.define(version: 20151023123932) do
t.decimal "offical_weight"
end
add_index "wrestlers", ["offical_weight"], name: "index_wrestlers_on_offical_weight"
add_index "wrestlers", ["weight_id"], name: "index_wrestlers_on_weight_id"
end

9
test/fixtures/teampointadjusts.yml vendored Normal file
View 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

View File

@@ -45,6 +45,26 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
endMatch(2004,"Guy4",@matches)
endMatch(2005,"Guy9",@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)
end
@@ -65,7 +85,6 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
test "nine man outright finals advance" do
nineManBracketPoolOneOutrightWinner
@wrestler = Wrestler.where("name = ?", "Guy2").first
@match = Match.where("bout_number = ?",6000).first
assert_equal 6000, @wrestler.boutByRound(6)
end
@@ -78,26 +97,40 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
test "nine man pool 2 man to man tie breaker finalist guy 9" do
@wrestler = Wrestler.where("name = ?", "Guy9").first
nineManBracketPoolTwoGuyNineHeadToHead
@match = Match.where("bout_number = ?",6000).first
assert_equal 6000, @wrestler.boutByRound(6)
end
test "nine man pool 2 man to man tie breaker finalist guy 3" do
@wrestler = Wrestler.where("name = ?", "Guy3").first
nineManBracketPoolTwoGuyThreeHeadToHead
@match = Match.where("bout_number = ?",6000).first
assert_equal 6000, @wrestler.boutByRound(6)
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
@wrestler = Wrestler.where("name = ?", "Guy3").first
assert_equal 6001, @wrestler.boutByRound(6)
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
@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)
end

View File

@@ -0,0 +1,7 @@
require 'test_helper'
class TeampointadjustTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end