mirror of
https://github.com/ENSL/ensl.org.git
synced 2025-01-18 15:32:23 +00:00
Remove old points before adding new points them on updates of matches. Also remove points if match gets deleted.
This commit is contained in:
parent
0c00697ed0
commit
85a2092a7c
1 changed files with 26 additions and 0 deletions
|
@ -123,6 +123,8 @@ class Match < ActiveRecord::Base
|
||||||
before_create :set_hltv
|
before_create :set_hltv
|
||||||
after_create :send_notifications
|
after_create :send_notifications
|
||||||
before_save :set_motm, :if => Proc.new {|match| match.motm_name and !match.motm_name.empty?}
|
before_save :set_motm, :if => Proc.new {|match| match.motm_name and !match.motm_name.empty?}
|
||||||
|
before_update :reset_contest, :if => Proc.new {|match| match.score1_changed? or match.score2_changed?}
|
||||||
|
before_destroy :reset_contest
|
||||||
after_save :recalculate, :if => Proc.new {|match| match.score1_changed? or match.score2_changed?}
|
after_save :recalculate, :if => Proc.new {|match| match.score1_changed? or match.score2_changed?}
|
||||||
after_save :set_predictions, :if => Proc.new {|match| match.score1_changed? or match.score2_changed?}
|
after_save :set_predictions, :if => Proc.new {|match| match.score1_changed? or match.score2_changed?}
|
||||||
|
|
||||||
|
@ -215,6 +217,30 @@ class Match < ActiveRecord::Base
|
||||||
contest.recalculate
|
contest.recalculate
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#Since ladders are broken anyway, they are not handled here
|
||||||
|
def reset_contest
|
||||||
|
return if score1_was.nil? or score2_was.nil?
|
||||||
|
return if contest.contest_type == Contest::TYPE_LEAGUE and !contester2.active or !contester1.active
|
||||||
|
|
||||||
|
if score1_was == score2_was
|
||||||
|
contester1.draw = contester1.draw - 1
|
||||||
|
contester2.draw = contester2.draw - 1
|
||||||
|
elsif score1_was > score2_was
|
||||||
|
contester1.win = contester1.win - 1
|
||||||
|
contester2.loss = contester2.loss - 1
|
||||||
|
elsif score1_was < score2_was
|
||||||
|
contester1.loss = contester1.loss - 1
|
||||||
|
contester2.win = contester2.win - 1
|
||||||
|
end
|
||||||
|
|
||||||
|
unless contest.contest_type == Contest::TYPE_BRACKET
|
||||||
|
contester1.score = contester1.score-score1_was
|
||||||
|
contester2.score = contester2.score-score2_was
|
||||||
|
contester1.save!
|
||||||
|
contester2.save!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def recalculate
|
def recalculate
|
||||||
return if score1.nil? or score2.nil?
|
return if score1.nil? or score2.nil?
|
||||||
return if contest.contest_type == Contest::TYPE_LEAGUE and !contester2.active or !contester1.active
|
return if contest.contest_type == Contest::TYPE_LEAGUE and !contester2.active or !contester1.active
|
||||||
|
|
Loading…
Reference in a new issue