Class: Glicko2::RatingPeriod
- Inherits:
-
Object
- Object
- Glicko2::RatingPeriod
- Defined in:
- lib/glicko2/rating_period.rb
Overview
Glicko ratings are calculated in bulk at the end of arbitrary, but fixed length, periods named rating periods. Where a period is fixed to be long enough that the average number of games that each player has played in is about 5 to 10 games. It could be weekly, monthly or more as required.
Instance Attribute Summary collapse
-
#players ⇒ Object
readonly
Returns the value of attribute players.
Class Method Summary collapse
-
.from_objs(objs) ⇒ RatingPeriod
Create rating period from list of seed objects.
Instance Method Summary collapse
-
#game(game_seeds, ranks) ⇒ Object
Register a game with this rating period.
-
#generate_next(tau) ⇒ RatingPeriod
Generate a new RatingPeriod with a new list of updated Player.
-
#initialize(players) ⇒ RatingPeriod
constructor
A new instance of RatingPeriod.
-
#player(obj) ⇒ Player
Fetch the player associated with a seed object.
- #to_s ⇒ Object
Constructor Details
#initialize(players) ⇒ RatingPeriod
Returns a new instance of RatingPeriod.
10 11 12 13 14 15 16 17 18 |
# File 'lib/glicko2/rating_period.rb', line 10 def initialize(players) @players = players @cache = players.reduce({}) do |memo, player| raise DuplicatePlayerError unless memo[player.obj].nil? memo[player.obj] = player memo end @raters = players.map { |p| Rater.new(p.) } end |
Instance Attribute Details
#players ⇒ Object (readonly)
Returns the value of attribute players.
7 8 9 |
# File 'lib/glicko2/rating_period.rb', line 7 def players @players end |
Class Method Details
.from_objs(objs) ⇒ RatingPeriod
Create rating period from list of seed objects
24 25 26 |
# File 'lib/glicko2/rating_period.rb', line 24 def self.from_objs(objs) new(objs.map { |obj| Player.from_obj(obj) }) end |
Instance Method Details
#game(game_seeds, ranks) ⇒ Object
Register a game with this rating period
32 33 34 35 36 37 38 39 |
# File 'lib/glicko2/rating_period.rb', line 32 def game(game_seeds, ranks) game_seeds.each_with_index do |iseed, i| game_seeds.each_with_index do |jseed, j| next if i == j @raters[i].add(player(jseed)., Util.ranks_to_score(ranks[i], ranks[j])) end end end |
#generate_next(tau) ⇒ RatingPeriod
Generate a new Glicko2::RatingPeriod with a new list of updated Player
44 45 46 47 48 49 50 |
# File 'lib/glicko2/rating_period.rb', line 44 def generate_next(tau) p = [] @raters.each_with_index do |rater, i| p << Player.new(rater.rate(tau), @players[i].obj) end self.class.new(p) end |
#player(obj) ⇒ Player
Fetch the player associated with a seed object
56 57 58 |
# File 'lib/glicko2/rating_period.rb', line 56 def player(obj) @cache[obj] end |
#to_s ⇒ Object
60 61 62 |
# File 'lib/glicko2/rating_period.rb', line 60 def to_s "#<RatingPeriod players=#{@players}" end |