blib/lib/Games/Ratings/LogisticElo.pm

filter: Statementstmt 100% 39 / 39 Branchbran 87.5% 7 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 98.2% 57 / 58 CC 6 SCAR 12.0
CC
6
Cov
98%
multi_elo
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.3
↑ Summary
1 package Games::Ratings::LogisticElo;
2  
3 1 ▶use 5.014000;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use parent qw/Exporter Games::Ratings/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our @EXPORT_OK = qw/multi_elo/;
9 1 our @EXPORT = qw//;
10 1 our $VERSION = '0.001';
11  
12 1 ▶use List::Util qw/sum/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 8 ▶sub get_rating_change {
Subroutine get_rating_change: called CC=1 SCAR=0.0
Pod documented
15 8 my ($self) = @_;
16  
17 8 my $own_rating = $self->get_rating;
18 8 my $K = $self->get_coefficient;
19  
20 my $expected = sum map {
21 8 my $exp = ($_->{opponent_rating} - $own_rating) / 400;
22 111 1 / (1 + 10 ** $exp)
23 } $self->get_all_games;
24  
25 my $actual = sum map {
26 8 Games::Ratings::_get_numerical_result($_->{result})
27 111 } $self->get_all_games;
28  
29 8 $K * ($actual - $expected)
30 }
31  
32 6 ▶sub get_new_rating {
Subroutine get_new_rating: called CC=1 SCAR=0.0
Pod documented
33 6 my ($self) = @_;
34 6 $self->get_rating + $self->get_rating_change
35 }
36  
37 3 ▶sub multi_elo {
Subroutine multi_elo: called CC=6 SCAR=17.9
Pod documented
38 3 my @args = @_;
39 3 ▶ my $K = ref $args[0] ? 15 : shift @args;
Branch: 1 branch
BranchTrueFalseTotal
ref $args[0] ? : 2 1 3
40  
41 my @newratings = map {
42 3 my $player = __PACKAGE__->new;
43 5 $player->set_rating($_->[0]);
44 5 $player->set_coefficient($K);
45 5 for my $opponent (@args) {
46 9 ▶ $player->add_game({
Branch: 2 branches
BranchTrueFalseTotal
$_->[1] > $opponent->[1] ? : 2 7 9
$_->[1] < $opponent->[1] ? : 2 5 7
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 } @args;
55  
56 3 ▶ wantarray ? @newratings : \@newratings
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 0 3
57 }
58  
59 1 1;
60 __END__
↑ Summary