use variable params for rating

main
Alpha Chen 1 year ago
parent ef8289c7f1
commit 92e8901f2c
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -13,7 +13,7 @@ module RankKing
ratings = combo.map {|item| Rating.first(axis:, item:) || OS.rating } ratings = combo.map {|item| Rating.first(axis:, item:) || OS.rating }
Math.sqrt( Math.sqrt(
[ratings, ratings.reverse] [ratings, ratings.reverse]
.map {|game| [game, OS.rate(game).flatten] } .map {|game| [game, OS.rate(*game).flatten] }
.sum {|pre,post| pre.zip(post).sum { (_1.sigma - _2.sigma)**2 }} .sum {|pre,post| pre.zip(post).sum { (_1.sigma - _2.sigma)**2 }}
) )
}.last }.last
@ -23,7 +23,7 @@ module RankKing
fail unless [winner, loser].all? { _1.pool == axis.pool } fail unless [winner, loser].all? { _1.pool == axis.pool }
game = [winner, loser].map { Rating.first(axis:, item: _1) || OS.rating } game = [winner, loser].map { Rating.first(axis:, item: _1) || OS.rating }
result = OS.rate(game).flatten result = OS.rate(*game).flatten
DB.transaction do DB.transaction do
Ranking.create(axis:, winner:, loser:) Ranking.create(axis:, winner:, loser:)

@ -17,8 +17,7 @@ module RankKing
@beta = @sigma / 2.0 @beta = @sigma / 2.0
end end
# TODO take an implicit array def rate(*teams)
def rate(teams)
# allow for passing in single-rating teams # allow for passing in single-rating teams
teams = teams.map { Array(_1) } teams = teams.map { Array(_1) }

@ -18,7 +18,7 @@ class TestRate < Minitest::Test
end end
def test_rate def test_rate
a2, b2, c2, d2 = @os.rate([[@a1], [@b1], [@c1], [@d1]]).flatten a2, b2, c2, d2 = @os.rate([@a1], [@b1], [@c1], [@d1]).flatten
assert_rating a2, OpenSkill::Rating.new(mu: 30.209971908310553, sigma: 4.764898977359521) assert_rating a2, OpenSkill::Rating.new(mu: 30.209971908310553, sigma: 4.764898977359521)
assert_rating b2, OpenSkill::Rating.new(mu: 27.64460833689499, sigma: 4.882789305097372) assert_rating b2, OpenSkill::Rating.new(mu: 27.64460833689499, sigma: 4.882789305097372)

Loading…
Cancel
Save