line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Ratings::LogisticElo; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
16426
|
use 5.014000; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
5
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
28
|
|
6
|
1
|
|
|
1
|
|
641
|
use parent qw/Exporter Games::Ratings/; |
|
1
|
|
|
|
|
374
|
|
|
1
|
|
|
|
|
7
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw/multi_elo/; |
9
|
|
|
|
|
|
|
our @EXPORT = qw//; |
10
|
|
|
|
|
|
|
our $VERSION = '0.001'; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
7001
|
use List::Util qw/sum/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
469
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub get_rating_change { |
15
|
8
|
|
|
8
|
1
|
1124
|
my ($self) = @_; |
16
|
|
|
|
|
|
|
|
17
|
8
|
|
|
|
|
19
|
my $own_rating = $self->get_rating; |
18
|
8
|
|
|
|
|
40
|
my $K = $self->get_coefficient; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $expected = sum map { |
21
|
8
|
|
|
|
|
32
|
my $exp = ($_->{opponent_rating} - $own_rating) / 400; |
|
111
|
|
|
|
|
140
|
|
22
|
111
|
|
|
|
|
146
|
1 / (1 + 10 ** $exp) |
23
|
|
|
|
|
|
|
} $self->get_all_games; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $actual = sum map { |
26
|
8
|
|
|
|
|
20
|
Games::Ratings::_get_numerical_result($_->{result}) |
27
|
111
|
|
|
|
|
373
|
} $self->get_all_games; |
28
|
|
|
|
|
|
|
|
29
|
8
|
|
|
|
|
67
|
$K * ($actual - $expected) |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub get_new_rating { |
33
|
6
|
|
|
6
|
1
|
10
|
my ($self) = @_; |
34
|
6
|
|
|
|
|
11
|
$self->get_rating + $self->get_rating_change |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub multi_elo { |
38
|
3
|
|
|
3
|
1
|
2367
|
my @args = @_; |
39
|
3
|
100
|
|
|
|
13
|
my $K = ref $args[0] ? 15 : shift @args; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my @newratings = map { |
42
|
3
|
|
|
|
|
7
|
my $player = __PACKAGE__->new; |
|
5
|
|
|
|
|
25
|
|
43
|
5
|
|
|
|
|
34
|
$player->set_rating($_->[0]); |
44
|
5
|
|
|
|
|
33
|
$player->set_coefficient($K); |
45
|
5
|
|
|
|
|
24
|
for my $opponent (@args) { |
46
|
9
|
100
|
|
|
|
73
|
$player->add_game({ |
|
|
100
|
|
|
|
|
|
47
|
|
|
|
|
|
|
opponent_rating => $opponent->[0], |
48
|
|
|
|
|
|
|
result => |
49
|
|
|
|
|
|
|
$_->[1] > $opponent->[1] ? 'win' : |
50
|
|
|
|
|
|
|
$_->[1] < $opponent->[1] ? 'loss' : 'draw' |
51
|
|
|
|
|
|
|
}) |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
$player->get_new_rating |
54
|
5
|
|
|
|
|
29
|
} @args; |
55
|
|
|
|
|
|
|
|
56
|
3
|
50
|
|
|
|
40
|
wantarray ? @newratings : \@newratings |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
__END__ |