icu_ratings 1.5.1 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/icu_ratings/player.rb +28 -19
- data/lib/icu_ratings/version.rb +1 -1
- data/spec/tournament_spec.rb +27 -0
- metadata +3 -3
data/lib/icu_ratings/player.rb
CHANGED
@@ -128,24 +128,29 @@ module ICU
|
|
128
128
|
# After the <em>rate!</em> method has been called on the ICU::RatedTournament object, the results
|
129
129
|
# of the rating calculations are available via various methods of the player objects:
|
130
130
|
#
|
131
|
-
# _new_rating_::
|
132
|
-
#
|
133
|
-
#
|
134
|
-
#
|
135
|
-
#
|
136
|
-
# _rating_change_::
|
137
|
-
#
|
138
|
-
#
|
139
|
-
# _performance_::
|
140
|
-
#
|
141
|
-
#
|
142
|
-
#
|
143
|
-
# _expected_score_::
|
144
|
-
#
|
145
|
-
#
|
146
|
-
#
|
147
|
-
#
|
148
|
-
# _bonus_::
|
131
|
+
# _new_rating_:: This is the player's new rating. For rated players it is their old rating
|
132
|
+
# plus their _rating_change_ plus their _bonus_ (if any). For provisional players
|
133
|
+
# it is their performance rating including their previous games. For unrated
|
134
|
+
# players it is their tournament performance rating. New ratings are not
|
135
|
+
# calculated for foreign players so this method just returns their start _rating_.
|
136
|
+
# _rating_change_:: This is calculated from a rated player's old rating, their K-factor and the sum
|
137
|
+
# of expected scores in each game. The same as the difference between the old and
|
138
|
+
# new ratings (unless there is a bonus). Not available for other player types.
|
139
|
+
# _performance_:: This returns the tournament rating performance for rated, unrated and
|
140
|
+
# foreign players. For provisional players it returns a weighted average
|
141
|
+
# of the player's tournament performance and their previous games. For
|
142
|
+
# provisional and unrated players it is the same as _new_rating_.
|
143
|
+
# _expected_score_:: This returns the sum of expected scores over all results for all player types.
|
144
|
+
# For rated players, this number times the K-factor gives their rating change.
|
145
|
+
# It is calculated for provisional, unrated and foreign players but not actually
|
146
|
+
# used to estimate new ratings (for provisional and unrated players performance
|
147
|
+
# estimates are used instead).
|
148
|
+
# _bonus_:: The bonus received by a rated player (usually zero). Only available for rated
|
149
|
+
# players.
|
150
|
+
# _pb_rating_:: A rated player's pre-bonus rating (rounded). Only for rated players and
|
151
|
+
# returns nil for players who are ineligible for a bonus.
|
152
|
+
# _pb_performance_:: A rated player's pre-bonus performance (rounded). Only for rated players and
|
153
|
+
# returns nil for players ineligible for a bonus.
|
149
154
|
#
|
150
155
|
# == Unrateable Players
|
151
156
|
#
|
@@ -221,7 +226,7 @@ module ICU
|
|
221
226
|
end
|
222
227
|
|
223
228
|
class FullRating < RatedPlayer # :nodoc:
|
224
|
-
attr_reader :rating, :kfactor, :bonus
|
229
|
+
attr_reader :rating, :kfactor, :bonus, :pb_rating, :pb_performance
|
225
230
|
|
226
231
|
def initialize(num, desc, rating, kfactor)
|
227
232
|
@type = :rated
|
@@ -232,6 +237,8 @@ module ICU
|
|
232
237
|
end
|
233
238
|
|
234
239
|
def reset
|
240
|
+
@pb_rating = nil
|
241
|
+
@pb_performance = nil
|
235
242
|
@bonus_rating = nil
|
236
243
|
@bonus = 0
|
237
244
|
super
|
@@ -255,6 +262,8 @@ module ICU
|
|
255
262
|
def calculate_bonus
|
256
263
|
return if @kfactor <= 24 || @results.size <= 4 || @rating >= 2100
|
257
264
|
change = rating_change
|
265
|
+
@pb_rating = (@rating + change).round
|
266
|
+
@pb_performance = @performance.round
|
258
267
|
return if change <= 35 || @rating + change >= 2100
|
259
268
|
threshold = 32 + 3 * (@results.size - 4)
|
260
269
|
bonus = (change - threshold).round
|
data/lib/icu_ratings/version.rb
CHANGED
data/spec/tournament_spec.rb
CHANGED
@@ -666,6 +666,27 @@ module ICU
|
|
666
666
|
p.bonus.should == bonus
|
667
667
|
end
|
668
668
|
end
|
669
|
+
|
670
|
+
it "players eligible for a bonus should have pre-bonus data" do
|
671
|
+
[
|
672
|
+
[1, false], # Howley
|
673
|
+
[2, false], # O'Brien
|
674
|
+
[3, true], # Eyers
|
675
|
+
[4, true], # Guinan
|
676
|
+
[5, true], # Cooke
|
677
|
+
[6, true], # Benson
|
678
|
+
].each do |item|
|
679
|
+
num, pre_bonus = item
|
680
|
+
p = @t.player(num)
|
681
|
+
if pre_bonus
|
682
|
+
p.pb_rating.should be_kind_of Fixnum
|
683
|
+
p.pb_performance.should be_kind_of Fixnum
|
684
|
+
else
|
685
|
+
p.pb_rating.should be_nil
|
686
|
+
p.pb_performance.should be_nil
|
687
|
+
end
|
688
|
+
end
|
689
|
+
end
|
669
690
|
end
|
670
691
|
|
671
692
|
context "#rate - a tournament with one rated player who got a bonus and the rest foreigners" do
|
@@ -723,6 +744,12 @@ module ICU
|
|
723
744
|
end
|
724
745
|
end
|
725
746
|
end
|
747
|
+
|
748
|
+
it "players eligible for a bonus should have pre-bonus data" do
|
749
|
+
p = @t.player(1)
|
750
|
+
p.pb_rating.should be_kind_of Fixnum
|
751
|
+
p.pb_performance.should be_kind_of Fixnum
|
752
|
+
end
|
726
753
|
end
|
727
754
|
|
728
755
|
context "#rate - a tournament with a one provisional and one player who got a bonus" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: icu_ratings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -111,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
111
|
version: '0'
|
112
112
|
segments:
|
113
113
|
- 0
|
114
|
-
hash:
|
114
|
+
hash: 87268456819351268
|
115
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
version: '0'
|
121
121
|
segments:
|
122
122
|
- 0
|
123
|
-
hash:
|
123
|
+
hash: 87268456819351268
|
124
124
|
requirements: []
|
125
125
|
rubyforge_project: icu_ratings
|
126
126
|
rubygems_version: 1.8.23
|