From 811b49bc2044d36eb109bb1a0585255bae2dabe3 Mon Sep 17 00:00:00 2001 From: Absurdon Date: Mon, 12 Feb 2018 23:21:08 +0100 Subject: [PATCH] Make ladders 'work', they are still not rly working like a ladder Change contester ordering: taking amount of played games into account --- app/models/contester.rb | 2 +- app/models/match.rb | 32 +++++++++++++++++++++++--------- app/views/contests/show.html.erb | 4 ++-- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/app/models/contester.rb b/app/models/contester.rb index d216cc8..799514a 100644 --- a/app/models/contester.rb +++ b/app/models/contester.rb @@ -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}} } diff --git a/app/models/match.rb b/app/models/match.rb index 2346c07..c332ccc 100755 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -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 diff --git a/app/views/contests/show.html.erb b/app/views/contests/show.html.erb index 77c432d..758c73c 100644 --- a/app/views/contests/show.html.erb +++ b/app/views/contests/show.html.erb @@ -82,7 +82,7 @@ <% if @contest.contest_type == Contest::TYPE_LADDER %> - <%= match.points1 %> / <%= match.points2 %> + <%= match.points1 || 0 %> / <%= match.points2 || 0 %> <% end %> @@ -118,7 +118,7 @@ <% if @contest.contest_type == Contest::TYPE_LADDER %> - <%= match.points1 %> / <%= match.points2 %> + <%= match.points1 || 0 %> / <%= match.points2 || 0 %> <% end %>