elo_rating 0.4.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.document +3 -0
- data/README.md +2 -2
- data/lib/elo_rating.rb +1 -1
- data/lib/elo_rating/version.rb +2 -1
- data/spec/elo_rating_spec.rb +13 -3
- data/spec/match_spec.rb +8 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff2c8b533bcb1d0c0f97f9808ad584caa6f9ade1
|
4
|
+
data.tar.gz: 33e45431d2db490023b0171abd6871d6de086bb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1d83200efa29b3365cbac274eedfc0b88a16337341b869d848730315b30ddd2d2fa83a88d2711280fcc91faab0cd0ac46afdfa92662434a88f487d1bf1836b1
|
7
|
+
data.tar.gz: 4e7834dadbaf1306d954cd6fe4e6a1914ed74057c89f200464fd4ada7af4729579e11d44e4f3430c837233e0a3043294681debbbd44548cadfd437ec7dc4da12
|
data/.document
ADDED
data/README.md
CHANGED
@@ -75,7 +75,7 @@ match = EloRating::Match.new
|
|
75
75
|
match.add_player(rating: 1900, place: 1)
|
76
76
|
match.add_player(rating: 2000, place: 2)
|
77
77
|
match.add_player(rating: 2000, place: 3)
|
78
|
-
match.updated_ratings # => [
|
78
|
+
match.updated_ratings # => [1931, 1997, 1973]
|
79
79
|
```
|
80
80
|
|
81
81
|
This is calculated as if the first player beat both of the other players and the second player beat the third.
|
@@ -184,7 +184,7 @@ Thanks to:
|
|
184
184
|
|
185
185
|
* Divergent Informatics for their [multiplayer Elo
|
186
186
|
calculator](http://elo.divergentinformatics.com/) used to verify calculations used in the development of this gem
|
187
|
-
* [Ian Hecker](https://github.com/iain) for the original [Elo](https://github.com/iain/elo).
|
187
|
+
* [Ian Hecker](https://github.com/iain) for the original [Elo](https://github.com/iain/elo) gem.
|
188
188
|
|
189
189
|
## License
|
190
190
|
|
data/lib/elo_rating.rb
CHANGED
data/lib/elo_rating/version.rb
CHANGED
data/spec/elo_rating_spec.rb
CHANGED
@@ -4,19 +4,22 @@ describe EloRating do
|
|
4
4
|
after(:each) do
|
5
5
|
EloRating::k_factor = 24
|
6
6
|
end
|
7
|
+
|
7
8
|
describe '::k_factor' do
|
8
9
|
it 'defaults to 24' do
|
9
10
|
expect(EloRating::k_factor).to eql(24)
|
10
11
|
end
|
11
12
|
end
|
13
|
+
|
12
14
|
describe '::k_factor=' do
|
13
15
|
it 'sets the K-factor to an integer' do
|
14
16
|
EloRating::k_factor = 10
|
15
17
|
expect(EloRating::k_factor).to eql(10)
|
16
18
|
end
|
17
19
|
end
|
20
|
+
|
18
21
|
describe '::set_k_factor' do
|
19
|
-
it
|
22
|
+
it "takes a block to determine the K-factor based on a player's rating" do
|
20
23
|
EloRating::set_k_factor do |rating|
|
21
24
|
if rating && rating > 1000
|
22
25
|
15
|
@@ -26,7 +29,8 @@ describe EloRating do
|
|
26
29
|
end
|
27
30
|
expect(EloRating::k_factor(1001)).to eql 15
|
28
31
|
end
|
29
|
-
|
32
|
+
|
33
|
+
context "given a block that doesn't handle nil ratings" do
|
30
34
|
it 'raises an error' do
|
31
35
|
expect do
|
32
36
|
EloRating::set_k_factor do |rating|
|
@@ -36,20 +40,24 @@ describe EloRating do
|
|
36
40
|
end
|
37
41
|
end
|
38
42
|
end
|
43
|
+
|
39
44
|
describe '.expected_score' do
|
40
|
-
it
|
45
|
+
it "returns the odds of a player winning given their rating and their opponent's rating" do
|
41
46
|
expect(EloRating.expected_score(1200, 1000)).to be_within(0.0001).of(0.7597)
|
42
47
|
end
|
43
48
|
end
|
49
|
+
|
44
50
|
describe '.rating_adjustment' do
|
45
51
|
it 'returns the amount a rating should change given an expected score and an actual score' do
|
46
52
|
expect(EloRating.rating_adjustment(0.75, 0)).to be_within(0.0001).of(-18.0)
|
47
53
|
end
|
54
|
+
|
48
55
|
it 'uses the K-factor' do
|
49
56
|
expect(EloRating).to receive(:k_factor).and_return(24)
|
50
57
|
|
51
58
|
EloRating.rating_adjustment(0.75, 0)
|
52
59
|
end
|
60
|
+
|
53
61
|
context 'custom numeric k-factor' do
|
54
62
|
it 'uses the custom k-factor' do
|
55
63
|
EloRating::k_factor = 10
|
@@ -57,6 +65,7 @@ describe EloRating do
|
|
57
65
|
expect(EloRating.rating_adjustment(0.75, 0)).to be_within(0.0001).of(-7.5)
|
58
66
|
end
|
59
67
|
end
|
68
|
+
|
60
69
|
context 'custom k-factor function' do
|
61
70
|
it 'calls the function with the provided rating to determine the k-factor' do
|
62
71
|
EloRating::set_k_factor do |rating|
|
@@ -75,6 +84,7 @@ describe EloRating do
|
|
75
84
|
expect(EloRating.rating_adjustment(0.75, 0, rating: 2500)).to be_within(0.0001).of(-12.0)
|
76
85
|
end
|
77
86
|
end
|
87
|
+
|
78
88
|
context 'provided with a nonce numeric k-factor' do
|
79
89
|
it 'uses the provided k-factor' do
|
80
90
|
expect(EloRating.rating_adjustment(0.75, 0, k_factor: 24)).to be_within(0.0001).of(-18.0)
|
data/spec/match_spec.rb
CHANGED
@@ -10,6 +10,7 @@ describe EloRating::Match do
|
|
10
10
|
expect(match.updated_ratings).to eql [1988, 2012]
|
11
11
|
end
|
12
12
|
end
|
13
|
+
|
13
14
|
context 'match with 3 players and one winner' do
|
14
15
|
it 'returns the updated ratings of all the players' do
|
15
16
|
match = EloRating::Match.new
|
@@ -19,6 +20,7 @@ describe EloRating::Match do
|
|
19
20
|
expect(match.updated_ratings).to eql [1931, 1985, 1985]
|
20
21
|
end
|
21
22
|
end
|
23
|
+
|
22
24
|
context 'ranked game with 3 players' do
|
23
25
|
it 'returns the updated ratings of all the players' do
|
24
26
|
match = EloRating::Match.new
|
@@ -28,6 +30,7 @@ describe EloRating::Match do
|
|
28
30
|
expect(match.updated_ratings).to eql [1931, 1997, 1973]
|
29
31
|
end
|
30
32
|
end
|
33
|
+
|
31
34
|
context 'custom K-factor function' do
|
32
35
|
it 'uses the custom K-factor function' do
|
33
36
|
EloRating::set_k_factor do |rating|
|
@@ -42,6 +45,7 @@ describe EloRating::Match do
|
|
42
45
|
EloRating::k_factor = 24
|
43
46
|
end
|
44
47
|
end
|
48
|
+
|
45
49
|
context 'multiple winners specified' do
|
46
50
|
it 'raises an error' do
|
47
51
|
match = EloRating::Match.new
|
@@ -50,6 +54,7 @@ describe EloRating::Match do
|
|
50
54
|
expect { match.updated_ratings }.to raise_error ArgumentError
|
51
55
|
end
|
52
56
|
end
|
57
|
+
|
53
58
|
context 'place specified for one player but not all' do
|
54
59
|
it 'raises an error' do
|
55
60
|
match = EloRating::Match.new
|
@@ -68,12 +73,14 @@ describe EloRating::Match do
|
|
68
73
|
|
69
74
|
match.add_player(rating: 2000)
|
70
75
|
end
|
71
|
-
|
76
|
+
|
77
|
+
it "appends the new player to the match's player" do
|
72
78
|
match = EloRating::Match.new
|
73
79
|
match.add_player(rating: 2000)
|
74
80
|
|
75
81
|
expect(match.players.size).to eql 1
|
76
82
|
end
|
83
|
+
|
77
84
|
it 'returns the match itself so multiple calls can be chained' do
|
78
85
|
match = EloRating::Match.new
|
79
86
|
match.add_player(rating: 1000).add_player(rating: 2000)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elo_rating
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Holder
|
@@ -88,6 +88,7 @@ executables: []
|
|
88
88
|
extensions: []
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
|
+
- ".document"
|
91
92
|
- ".gitignore"
|
92
93
|
- Gemfile
|
93
94
|
- LICENSE
|