mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-05-08 23:11:00 +00:00
Cut the runtime by queueing the changes in memory and deferring database writes
Made some unspecified behavior explicit
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
class Pool
|
||||
def initialize(weight)
|
||||
@weight = weight
|
||||
@tournament = @weight.tournament
|
||||
@pool = 1
|
||||
end
|
||||
|
||||
@@ -23,7 +24,7 @@ class Pool
|
||||
bouts = b.map
|
||||
bouts.each do |bout|
|
||||
if bout[0] != nil and bout[1] != nil
|
||||
match = Match.new(
|
||||
match = @tournament.matches.create(
|
||||
w1: bout[0].id,
|
||||
w2: bout[1].id,
|
||||
weight_id: @weight.id,
|
||||
|
||||
@@ -16,13 +16,11 @@ class Tournament < ActiveRecord::Base
|
||||
def createCustomWeights(value)
|
||||
self.weights.destroy_all
|
||||
if value == 'hs'
|
||||
@weights = [106,113,120,132,138,145,152,160,170,182,195,220,285]
|
||||
end
|
||||
@weights.each do |w|
|
||||
newWeight = Weight.new
|
||||
newWeight.max = w
|
||||
newWeight.tournament_id = self.id
|
||||
newWeight.save
|
||||
Weight::HS_WEIGHT_CLASSES.each do |w|
|
||||
self.weights.create(max: w)
|
||||
end
|
||||
else
|
||||
raise "Unspecified behavior"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ class Tournamentmatchgen
|
||||
end
|
||||
|
||||
def saveMatches
|
||||
@tournament.save!
|
||||
@matches.each do |m|
|
||||
m.tournament_id = @tournament.id
|
||||
m.save
|
||||
|
||||
@@ -4,6 +4,8 @@ class Weight < ActiveRecord::Base
|
||||
|
||||
attr_accessor :pools
|
||||
|
||||
HS_WEIGHT_CLASSES = [106,113,120,132,138,145,152,160,170,182,195,220,285]
|
||||
|
||||
before_save do
|
||||
self.tournament.destroyAllMatches
|
||||
end
|
||||
|
||||
@@ -82,13 +82,19 @@ class PoolbracketMatchupsTest < ActionDispatch::IntegrationTest
|
||||
refute_nil @tournament
|
||||
end
|
||||
|
||||
test "tournament can be set to high school weight classes" do
|
||||
@tournament.weights.destroy_all
|
||||
@tournament.createCustomWeights("hs")
|
||||
assert_equal Weight::HS_WEIGHT_CLASSES.size, @tournament.weights.size
|
||||
end
|
||||
|
||||
test "tests bout_number matches round" do
|
||||
@matchup_to_test = @genMatchups.select{|m| m.bout_number == 4000}.first
|
||||
assert_equal 4, @matchup_to_test.round
|
||||
end
|
||||
|
||||
test "tests bout_numbers are generated with smallest weight first regardless of id" do
|
||||
@weight = @tournament.weights.map.sort_by{|x|[x.max]}.first
|
||||
@weight = @tournament.weights.order(:max).limit(1).first
|
||||
@matchup = @genMatchups.select{|m| m.bout_number == 1000}.first
|
||||
assert_equal @weight.max, @matchup.weight_max
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user