mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-12-25 12:01:03 +00:00
Bring back ELO score func, fix ladder view
This commit is contained in:
parent
96a7135b76
commit
0ea0bca438
3 changed files with 21 additions and 1 deletions
|
@ -41,6 +41,7 @@ class ContestsController < ApplicationController
|
|||
def recalc
|
||||
raise AccessError unless @contest.can_update? cuser
|
||||
@contest.recalculate
|
||||
flash[:notice] = "Contest points recalculated."
|
||||
redirect_to_back
|
||||
end
|
||||
|
||||
|
|
|
@ -112,6 +112,25 @@ class Contest < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def elo_score score1, score2, diff, level = self.modulus_base, weight = self.weight, moduluses = [self.modulus_even, self.modulus_3to1, self.modulus_4to0]
|
||||
points = (score2-score1).abs
|
||||
modulus = moduluses[0].to_f if points <= 1
|
||||
modulus = moduluses[1].to_f if points == 2
|
||||
modulus = moduluses[2].to_f if points >= 3
|
||||
|
||||
if score1 == score2
|
||||
result = 0.5
|
||||
elsif score1 > score2
|
||||
result = 1.0
|
||||
elsif score2 > score1
|
||||
result = 0.0
|
||||
end
|
||||
|
||||
prob = 1.0/(10**(diff.to_f/weight.to_f)+1.0)
|
||||
total = (level.to_f*modulus*(result-prob)).round
|
||||
return total
|
||||
end
|
||||
|
||||
def update_ranks contester, old_rank, new_rank
|
||||
if old_rank < new_rank
|
||||
Contester.update_all(["score = score -1, trend = ?", Contester::TREND_UP],
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
<% end %>
|
||||
<% end %>
|
||||
</td>
|
||||
<% if match.contest.contest_type == Contest::TYPE_LADDER and !(max_columns < 4 if (defined? max_columns)) %>
|
||||
<% if match.contest.contest_type == Contest::TYPE_LADDER and (max_columns > 4 if (defined? max_columns)) %>
|
||||
<td>
|
||||
<% if match.get_friendly(:points) > 0 %>
|
||||
<%= icon 'chevron-up' %>
|
||||
|
|
Loading…
Reference in a new issue