mirror of
https://github.com/ENSL/ensl.org.git
synced 2025-02-04 15:31:09 +00:00
Make ladders 'work', they are still not rly working like a ladder
Change contester ordering: taking amount of played games into account
This commit is contained in:
parent
8a29678907
commit
811b49bc20
3 changed files with 26 additions and 12 deletions
|
@ -28,7 +28,7 @@ class Contester < ActiveRecord::Base
|
|||
|
||||
scope :active, :include => :team, :conditions => {"contesters.active" => true}
|
||||
# ranked is used for ladder. lower score the higher the rank
|
||||
scope :ranked, :select => "contesters.*", :order => "score ASC, win DESC, loss ASC"
|
||||
scope :ranked, :select => "contesters.*", :order => "score ASC, win ASC, win + draw + loss DESC"
|
||||
scope :ordered, :select => "contesters.*, (score + extra) AS total_score", :order => "total_score DESC, score DESC, win DESC, loss ASC"
|
||||
scope :chronological, :order => "created_at DESC"
|
||||
scope :of_contest, lambda { |contest| {:conditions => {"contesters.contest_id" => contest.id}} }
|
||||
|
|
|
@ -273,21 +273,35 @@ class Match < ActiveRecord::Base
|
|||
self.diff = diff ? diff : (contester2.score - contester1.score)
|
||||
|
||||
if contest.contest_type == Contest::TYPE_LADDER
|
||||
self.points1 = contest.elo_score score1, score2, diff
|
||||
self.points2 = contest.elo_score score2, score1, -(diff)
|
||||
# Dunno what all this is but its not working anyways
|
||||
# self.points1 = contest.elo_score score1, score2, diff
|
||||
# self.points2 = contest.elo_score score2, score1, -(diff)
|
||||
# contester1.extra = contester1.extra + contest.modulus_base / 10
|
||||
# contester2.extra = contester2.extra + contest.modulus_base / 10
|
||||
|
||||
score_diff = score2 - score1
|
||||
if score_diff == 0 # Draw
|
||||
if diff < 0 # contester2 has higher rank
|
||||
# set contester1s rank one below contester2
|
||||
contest.update_ranks(contester1, contester1.score, contester2.score - 1)
|
||||
else
|
||||
# set contester2s rank one below contester1
|
||||
contest.update_ranks(contester2, contester2.score, contester1.score - 1)
|
||||
end
|
||||
elsif score_diff < 0 && diff < 0 # contester1 won and contester2 has higher rank
|
||||
contest.update_ranks(contester1, contester1.score, contester2.score)
|
||||
elsif score_diff > 0 && diff > 0 # contester2 won and contester1 has higher rank
|
||||
contest.update_ranks(contester2, contester2.score, contester1.score)
|
||||
end
|
||||
|
||||
elsif contest.contest_type == Contest::TYPE_LEAGUE
|
||||
self.points1 = score1
|
||||
self.points2 = score2
|
||||
end
|
||||
|
||||
if contest.contest_type == Contest::TYPE_LADDER
|
||||
contester1.extra = contester1.extra + contest.modulus_base / 10
|
||||
contester2.extra = contester2.extra + contest.modulus_base / 10
|
||||
contester1.score = contester1.score + points1 < 0 ? 0 : contester1.score + points1
|
||||
contester2.score = contester2.score + points2 < 0 ? 0 : contester2.score + points2
|
||||
end
|
||||
|
||||
unless contest.contest_type == Contest::TYPE_BRACKET
|
||||
contester1.score = contester1.score + points1 < 0 ? 0 : contester1.score + points1
|
||||
contester2.score = contester2.score + points2 < 0 ? 0 : contester2.score + points2
|
||||
contester1.save!
|
||||
contester2.save!
|
||||
end
|
||||
|
|
|
@ -82,7 +82,7 @@
|
|||
</td>
|
||||
<% if @contest.contest_type == Contest::TYPE_LADDER %>
|
||||
<td class="points">
|
||||
<%= match.points1 %> / <%= match.points2 %>
|
||||
<%= match.points1 || 0 %> / <%= match.points2 || 0 %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
|
@ -118,7 +118,7 @@
|
|||
</td>
|
||||
<% if @contest.contest_type == Contest::TYPE_LADDER %>
|
||||
<td>
|
||||
<%= match.points1 %> / <%= match.points2 %>
|
||||
<%= match.points1 || 0 %> / <%= match.points2 || 0 %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
|
|
Loading…
Reference in a new issue