Class: ICU::RatedPlayer::FullRating
- Inherits:
-
ICU::RatedPlayer
- Object
- ICU::RatedPlayer
- ICU::RatedPlayer::FullRating
- Defined in:
- lib/icu_ratings/player.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#bonus ⇒ Object
readonly
Returns the value of attribute bonus.
-
#kfactor ⇒ Object
readonly
Returns the value of attribute kfactor.
-
#pb_performance ⇒ Object
readonly
Returns the value of attribute pb_performance.
-
#pb_rating ⇒ Object
readonly
Returns the value of attribute pb_rating.
-
#rating ⇒ Object
readonly
Returns the value of attribute rating.
Attributes inherited from ICU::RatedPlayer
#desc, #num, #performance, #results, #type
Instance Method Summary collapse
- #calculate_bonus ⇒ Object
-
#initialize(num, desc, rating, kfactor) ⇒ FullRating
constructor
A new instance of FullRating.
- #new_rating(type = nil) ⇒ Object
- #rating_change ⇒ Object
- #reset ⇒ Object
- #update_bonus ⇒ Object
Methods inherited from ICU::RatedPlayer
#==, #add_result, #average_performance, check_games, check_kfactor, check_num, check_rating, #estimate_performance, #expected_score, factory, kfactor, #rate!, #score, #update_performance
Constructor Details
#initialize(num, desc, rating, kfactor) ⇒ FullRating
Returns a new instance of FullRating.
231 232 233 234 235 236 237 |
# File 'lib/icu_ratings/player.rb', line 231 def initialize(num, desc, , kfactor) @type = :rated @rating = @kfactor = kfactor @bonus = 0 super(num, desc) end |
Instance Attribute Details
#bonus ⇒ Object (readonly)
Returns the value of attribute bonus.
229 230 231 |
# File 'lib/icu_ratings/player.rb', line 229 def bonus @bonus end |
#kfactor ⇒ Object (readonly)
Returns the value of attribute kfactor.
229 230 231 |
# File 'lib/icu_ratings/player.rb', line 229 def kfactor @kfactor end |
#pb_performance ⇒ Object (readonly)
Returns the value of attribute pb_performance.
229 230 231 |
# File 'lib/icu_ratings/player.rb', line 229 def pb_performance @pb_performance end |
#pb_rating ⇒ Object (readonly)
Returns the value of attribute pb_rating.
229 230 231 |
# File 'lib/icu_ratings/player.rb', line 229 def @pb_rating end |
#rating ⇒ Object (readonly)
Returns the value of attribute rating.
229 230 231 |
# File 'lib/icu_ratings/player.rb', line 229 def @rating end |
Instance Method Details
#calculate_bonus ⇒ Object
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/icu_ratings/player.rb', line 262 def calculate_bonus return if @kfactor <= 24 || @results.size <= 4 || @rating >= 2100 change = # Remember the key inputs to the calculation @pb_rating = (@rating + change).round @pb_performance = @performance.round # Calculate the bonus. return if change <= 35 || @rating + change >= 2100 threshold = 32 + 3 * (@results.size - 4) bonus = (change - threshold).round return if bonus <= 0 bonus = (1.25 * bonus).round if kfactor >= 40 # Determine if it should be capped or not. [2100, @performance].each { |max| bonus = (max - @rating - change).round if @rating + change + bonus >= max } return if bonus <= 0 # Store the value. @bonus_rating = @rating + change + bonus @bonus = bonus end |
#new_rating(type = nil) ⇒ Object
251 252 253 254 255 256 257 258 259 260 |
# File 'lib/icu_ratings/player.rb', line 251 def (type=nil) case type when :start @rating # the player's start rating when :opponent @bonus_rating || @rating # the rating used for opponents during the calculations else @rating + + @bonus # the player's final rating end end |
#rating_change ⇒ Object
247 248 249 |
# File 'lib/icu_ratings/player.rb', line 247 def @results.inject(0.0) { |c, r| c + (r. || 0.0) } end |
#reset ⇒ Object
239 240 241 242 243 244 245 |
# File 'lib/icu_ratings/player.rb', line 239 def reset @pb_rating = nil @pb_performance = nil @bonus_rating = nil @bonus = 0 super end |
#update_bonus ⇒ Object
282 283 284 |
# File 'lib/icu_ratings/player.rb', line 282 def update_bonus @bonus_rating = @rating + @bonus + if @bonus_rating end |