From ef8289c7f153736041594819b1fa112a2a37d862 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Fri, 23 Jun 2023 19:16:14 -0700 Subject: [PATCH] allow for rating single-rating teams --- lib/rank_king.rb | 4 ++-- lib/rank_king/open_skill.rb | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/rank_king.rb b/lib/rank_king.rb index 858bfa2..de7e0e4 100644 --- a/lib/rank_king.rb +++ b/lib/rank_king.rb @@ -13,7 +13,7 @@ module RankKing ratings = combo.map {|item| Rating.first(axis:, item:) || OS.rating } Math.sqrt( [ratings, ratings.reverse] - .map {|game| [game, OS.rate(game.map {[_1]}).flatten] } + .map {|game| [game, OS.rate(game).flatten] } .sum {|pre,post| pre.zip(post).sum { (_1.sigma - _2.sigma)**2 }} ) }.last @@ -23,7 +23,7 @@ module RankKing fail unless [winner, loser].all? { _1.pool == axis.pool } game = [winner, loser].map { Rating.first(axis:, item: _1) || OS.rating } - result = OS.rate(game.map { [_1] }).flatten + result = OS.rate(game).flatten DB.transaction do Ranking.create(axis:, winner:, loser:) diff --git a/lib/rank_king/open_skill.rb b/lib/rank_king/open_skill.rb index 5598e5b..5234be3 100644 --- a/lib/rank_king/open_skill.rb +++ b/lib/rank_king/open_skill.rb @@ -18,8 +18,10 @@ module RankKing end # TODO take an implicit array - # TODO array-ify elements def rate(teams) + # allow for passing in single-rating teams + teams = teams.map { Array(_1) } + # tau keeps sigma from dropping too low so that ratings stay pliable # after many games tau_sq = @tau ** 2