| 1 | #=============================================================================== | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # FILE: Games::Go::AGA::DataObjects::Register.pm | ||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||
| 5 | # USAGE: use Games::Go::AGA::DataObjects::Register; | ||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||
| 7 | # PODNAME: Games::Go::AGA::DataObjects::Register | ||||||||||||||||||||||||||||
| 8 | # ABSTRACT: models AGA register.tde file information | ||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | # AUTHOR: Reid Augustin (REID), <reid@hellosix.com> | ||||||||||||||||||||||||||||
| 11 | # CREATED: 11/19/2010 03:13:05 PM PST | ||||||||||||||||||||||||||||
| 12 | #=============================================================================== | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | package Games::Go::AGA::DataObjects::Register; | ||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use parent 'Games::Go::AGA::DataObjects::Directives'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use Scalar::Util qw( refaddr looks_like_number ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use IO::File; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 2 | ▶ | use Games::Go::AGA::Parse::Util qw( normalize_ID ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 2 | ▶ | use Games::Go::AGA::Parse::Util qw( Rank_to_Rating ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 2 | ▶ | use Games::Go::AGA::DataObjects::Player; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 2 | ▶ | use Games::Go::AGA::DataObjects::Directives; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 2 | ▶ | use Games::Go::AGA::DataObjects::Types qw( isa_CodeRef isa_ArrayRef isa_HashRef ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 2 | our $VERSION = '0.152'; # VERSION | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | # has 'directives' => ( | ||||||||||||||||||||||||||||
| 36 | # isa => 'Games::Go::AGA::DataObjects::Directives', | ||||||||||||||||||||||||||||
| 37 | # is => 'rw', | ||||||||||||||||||||||||||||
| 38 | # default => sub { | ||||||||||||||||||||||||||||
| 39 | # Games::Go::AGA::DataObjects::Directives->new(); | ||||||||||||||||||||||||||||
| 40 | # }, | ||||||||||||||||||||||||||||
| 41 | # ); | ||||||||||||||||||||||||||||
| 42 | # has 'comments' => ( | ||||||||||||||||||||||||||||
| 43 | # isa => 'ArrayRef', | ||||||||||||||||||||||||||||
| 44 | # is => 'ro', | ||||||||||||||||||||||||||||
| 45 | # default => sub { [] } | ||||||||||||||||||||||||||||
| 46 | # ); | ||||||||||||||||||||||||||||
| 47 | # has 'players' => ( | ||||||||||||||||||||||||||||
| 48 | # isa => 'ArrayRef', | ||||||||||||||||||||||||||||
| 49 | # is => 'ro', | ||||||||||||||||||||||||||||
| 50 | # default => sub { [] } | ||||||||||||||||||||||||||||
| 51 | # ); | ||||||||||||||||||||||||||||
| 52 | has change_callback => ( | ||||||||||||||||||||||||||||
| 53 | isa => \&isa_CodeRef, | ||||||||||||||||||||||||||||
| 54 | is => 'rw', | ||||||||||||||||||||||||||||
| 55 | lazy => 1, | ||||||||||||||||||||||||||||
| 56 | 1 | ▶ | default => sub { sub { } } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 57 | 2 | ); | |||||||||||||||||||||||||||
| 58 | 2 | has _bye_candidates => ( | |||||||||||||||||||||||||||
| 59 | is => 'rw', | ||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||
| 61 | 2 | has _drops => ( | |||||||||||||||||||||||||||
| 62 | is => 'rw', | ||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||
| 64 | 2 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 65 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 66 | 2 | $self->{comments} = []; | |||||||||||||||||||||||||||
| 67 | 2 | $self->{players} = []; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub directive_is_boolean { return $_[0]->is_boolean($_[1]) } # proxy to Directives | ||||||||||||||||||||||||||
|
Subroutine
directive_is_boolean: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # hashref of player IDs, each value true or false | ||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub bye_candidates { | ||||||||||||||||||||||||||
|
Subroutine
bye_candidates: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 74 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if (not $self->_bye_candidates) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | my %bye_candidates = map { $_ => $self->get_player($_) } | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->get_directive_value('BYE_CANDIDATES') || ''
MC/DC0%0/1
$self->get_directive_value('BYE_CANDIDATES') || ''
$self->get_directive_value('BYE_CANDIDATES')
Truth table0%0/2
A
A= $self->get_directive_value('BYE_CANDIDATES')
| |||||||||||||||||||||||||||||
| 78 | split /\s+/, $self->get_directive_value('BYE_CANDIDATES') || ''; | ||||||||||||||||||||||||||||
| 79 | 0 | $self->_bye_candidates(\%bye_candidates); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 0 | return $self->_bye_candidates; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub add_bye_candidates { | ||||||||||||||||||||||||||
|
Subroutine
add_bye_candidates: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 85 | 0 | my ($self, @candidates) = @_; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | my $bye_candidates_hash = $self->bye_candidates; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | for my $candidate (@candidates) { | |||||||||||||||||||||||||||
| 90 | 0 | ▶ | if (not $bye_candidates_hash->{$candidate}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | $self->_find_player_idx($candidate); # croaks if not found | |||||||||||||||||||||||||||
| 92 | 0 | $self->_bye_candidates(undef); # force refresh on next ->bye_candidates | |||||||||||||||||||||||||||
| 93 | 0 | $bye_candidates_hash->{$candidate} = 1; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 0 | ▶ | if (not $self->_bye_candidates) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 0 | $self->set_directive_value('BYE_CANDIDATES', join(' ', keys %{$bye_candidates_hash})); | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub delete_bye_candidates { | ||||||||||||||||||||||||||
|
Subroutine
delete_bye_candidates: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 102 | 0 | my ($self, @candidates) = @_; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | my $bye_candidates_hash = $self->bye_candidates; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | my @deleted; | |||||||||||||||||||||||||||
| 107 | 0 | for my $candidate (@candidates) { | |||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ($bye_candidates_hash->{$candidate}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 0 | $self->_bye_candidates(undef); # force refresh on next ->bye_candidates | |||||||||||||||||||||||||||
| 110 | 0 | ▶ | push @deleted, $candidate if (delete $bye_candidates_hash->{$candidate}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | 0 | ▶ | if (not $self->_bye_candidates) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | $self->set_directive_value('BYE_CANDIDATES', join(' ', keys %{$bye_candidates_hash})); | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | 0 | return @deleted; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | # arrayref of rounds, each entry a hashref of player IDs, true or false | ||||||||||||||||||||||||||||
| 120 | 0 | ▶ | sub drops { | ||||||||||||||||||||||||||
|
Subroutine
drops: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 121 | 0 | my ($self, $round_num) = @_; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if (not $self->_drops) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 0 | my @drops; | |||||||||||||||||||||||||||
| 125 | 0 | ▶ | for my $ii (0 .. ($self->get_directive_value('ROUNDS') || 7)) { | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->get_directive_value('ROUNDS') || 7
MC/DC0%0/1
$self->get_directive_value('ROUNDS') || 7
$self->get_directive_value('ROUNDS')
Truth table0%0/2
A
A= $self->get_directive_value('ROUNDS')
| |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | my $key = $ii ? "DROP_$ii" : 'DROP_ALL'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | my %round_drops = map { $_ => $self->get_player($_) } | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->get_directive_value($key) || ''
MC/DC0%0/1
$self->get_directive_value($key) || ''
$self->get_directive_value($key)
Truth table0%0/2
A
A= $self->get_directive_value($key)
| |||||||||||||||||||||||||||||
| 128 | split /\s+/, $self->get_directive_value($key) || ''; | ||||||||||||||||||||||||||||
| 129 | 0 | push @drops, \%round_drops; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | 0 | $self->_drops(\@drops); | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | 0 | ▶ | return $self->_drops->[$round_num] if (@_ > 1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 0 | return $self->_drops; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub add_drops { | ||||||||||||||||||||||||||
|
Subroutine
add_drops: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 138 | 0 | my ($self, $round_num, @ids) = @_; | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | my $drops_hash = $self->drops($round_num); | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | for my $id (@ids) { | |||||||||||||||||||||||||||
| 143 | 0 | ▶ | if (not $drops_hash->{$id}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 0 | $self->_find_player_idx($id); # croaks if not found | |||||||||||||||||||||||||||
| 145 | 0 | $self->_drops(undef); # force refresh on next ->drops | |||||||||||||||||||||||||||
| 146 | 0 | $drops_hash->{$id} = 1; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | 0 | ▶ | if (not $self->_drops) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | 0 | ▶ | $round_num ||= 'All'; # round 0 means All | ||||||||||||||||||||||||||
|
Condition0%0/2
$round_num ||= "All"
MC/DC0%0/1
$round_num ||= "All"
$round_num
Truth table0%0/2
A
A= $round_num
| |||||||||||||||||||||||||||||
| 151 | 0 | $self->set_directive_value("DROP_$round_num", join(' ', keys %{$drops_hash})); | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 0 | ▶ | sub delete_drops { | ||||||||||||||||||||||||||
|
Subroutine
delete_drops: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 156 | 0 | my ($self, $round_num, @ids) = @_; | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 0 | ▶ | if (not defined $round_num) { # all rounds | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 0 | my @dropped_ary; | |||||||||||||||||||||||||||
| 160 | 0 | my $ii = 0; | |||||||||||||||||||||||||||
| 161 | 0 | for my $drop_round (@{$self->drops}) { | |||||||||||||||||||||||||||
| 162 | 0 | ▶ | $dropped_ary[$ii] = { map { $_ => 1 } $self->delete_drops($ii, @ids) } || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
{map({$_, 1;} $self->delete_drops($ii, @ids))} || {}
MC/DC0%0/1
{map({$_, 1;} $self->delete_drops($ii, @ids))} || {}
{map({$_, 1;} $self->delete_drops($ii, @ids))}
Truth table0%0/2
A
A= {map({$_, 1;} $self->delete_drops($ii, @ids))}
| |||||||||||||||||||||||||||||
| 163 | 0 | $ii++; | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | 0 | return @dropped_ary; | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 0 | my $drops_hash = $self->drops($round_num); | |||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 0 | my @deleted; | |||||||||||||||||||||||||||
| 171 | 0 | for my $id (@ids) { | |||||||||||||||||||||||||||
| 172 | 0 | ▶ | if ($drops_hash->{$id}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | 0 | $self->_drops(undef); # force refresh on next ->drops | |||||||||||||||||||||||||||
| 174 | 0 | ▶ | push @deleted, $id if (delete $drops_hash->{$id}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | 0 | ▶ | if (not $self->_drops) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | 0 | ▶ | $round_num ||= 'All'; # round 0 means All | ||||||||||||||||||||||||||
|
Condition0%0/2
$round_num ||= "All"
MC/DC0%0/1
$round_num ||= "All"
$round_num
Truth table0%0/2
A
A= $round_num
| |||||||||||||||||||||||||||||
| 179 | 0 | $self->set_directive_value("DROP_$round_num", join(' ', keys %{$drops_hash})); | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | return @deleted | ||||||||||||||||||||||||||||
| 182 | 0 | } | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 23 | ▶ | sub changed { | ||||||||||||||||||||||||||
|
Subroutine
changed: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 185 | 23 | my ($self) = @_; | |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 23 | &{$self->change_callback}(@_); | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 0 | ▶ | sub comments { | ||||||||||||||||||||||||||
|
Subroutine
comments: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 191 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 0 | ▶ | return wantarray ? @{$self->{comments}} : $self->{comments}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 0 | ▶ | sub add_comment { | ||||||||||||||||||||||||||
|
Subroutine
add_comment: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 197 | 0 | my ($self, $comment) = @_; | |||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 0 | push @{$self->{comments}}, $comment; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 2 | ▶ | sub players { | ||||||||||||||||||||||||||
|
Subroutine
players: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 203 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 2 | ▶ | return wantarray ? @{$self->{players}} : $self->{players}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 25 | ▶ | sub id_is_duplicate { | ||||||||||||||||||||||||||
|
Subroutine
id_is_duplicate: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 209 | 25 | my ($self, $id, $player) = @_; | |||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | # normalize the ID first. IDs in Players are already normalised. | ||||||||||||||||||||||||||||
| 212 | 25 | $id = normalize_ID($id); | |||||||||||||||||||||||||||
| 213 | 25 | my @matched = grep { $id eq $_->id } @{$self->{players}}; | |||||||||||||||||||||||||||
| 214 | 25 | ▶ | my $my_refaddr = refaddr $player || 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
builtin::refaddr($player) || 0
MC/DC0%0/1
builtin::refaddr($player) || 0
builtin::refaddr($player)
Truth table50%1/2
A
A= builtin::refaddr($player)
| |||||||||||||||||||||||||||||
| 215 | 25 | foreach my $p (@matched) { | |||||||||||||||||||||||||||
| 216 | 2 | ▶ | if (refaddr $p != $my_refaddr) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | 2 | return 1 | |||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | 23 | return 0; | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | 4 | ▶ | sub add_player { shift->insert_player_at_idx(-1, @_) } | ||||||||||||||||||||||||||
|
Subroutine
add_player: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 23 | ▶ | sub insert_player_at_idx { | ||||||||||||||||||||||||||
|
Subroutine
insert_player_at_idx: called CC=6 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||
| 226 | 23 | my ($self, $idx, $player) = @_; | |||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 23 | my $id = $player->id; | |||||||||||||||||||||||||||
| 229 | 23 | ▶ | if (not $id) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | 0 | $id = 1; | |||||||||||||||||||||||||||
| 231 | 0 | ▶ | $id++ while ($self->id_is_duplicate("TMP$id", undef)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | 0 | $id = "TMP$id"; | |||||||||||||||||||||||||||
| 233 | 0 | $player->id($id); | |||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | 23 | ▶ | if ($self->id_is_duplicate($id, undef)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | 1 | croak "duplicate ID: $id\n"; | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | #print "insert_player ", $player->id, " at $idx\n"; | ||||||||||||||||||||||||||||
| 239 | 22 | ▶ | if ($idx < 0 or | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$idx < 0 or $idx > $#{$$self{"players"};}
MC/DC0%0/2
$idx < 0 or $idx > $#{$$self{"players"};}
$idx < 0
$idx > $#{$$self{"players"};}
Truth table33%1/3
A or B
A= $idx < 0B= $idx > $#{$$self{"players"};}
| |||||||||||||||||||||||||||||
| 240 | 0 | $idx > $#{$self->{players}}) { | |||||||||||||||||||||||||||
| 241 | 22 | push (@{$self->{players}}, $player); | |||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | else { | ||||||||||||||||||||||||||||
| 244 | 0 | splice (@{$self->{players}}, $idx, 0, $player); | |||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | 22 | $self->changed; | |||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 0 | ▶ | sub get_player_idx { | ||||||||||||||||||||||||||
|
Subroutine
get_player_idx: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 250 | 0 | my ($self, $idx) = @_; | |||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 0 | return $self->_find_player_idx($idx); | |||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 4 | ▶ | sub get_player { | ||||||||||||||||||||||||||
|
Subroutine
get_player: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 256 | 4 | my ($self, $idx) = @_; | |||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 4 | $idx = $self->_find_player_idx($idx); | |||||||||||||||||||||||||||
| 259 | 4 | return $self->{players}[$idx]; | |||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 0 | ▶ | sub delete_player { | ||||||||||||||||||||||||||
|
Subroutine
delete_player: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 263 | 0 | my ($self, $idx) = @_; | |||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | 0 | $idx = $self->_find_player_idx($idx); | |||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 0 | my $players = $self->{players}; | |||||||||||||||||||||||||||
| 268 | 0 | ▶ | if (@{$players->[$idx]->games}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | 0 | my $id = $players->[$idx]->id; | |||||||||||||||||||||||||||
| 270 | 0 | croak "Games recorded for $id, can't delete\n"; | |||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||
| 272 | 0 | my $player = splice(@{$players}, $idx, 1); # delete and return it | |||||||||||||||||||||||||||
| 273 | 0 | $self->delete_bye_candidates($player->id); | |||||||||||||||||||||||||||
| 274 | 0 | $self->delete_drops(undef, $player->id); | |||||||||||||||||||||||||||
| 275 | #print "delete ", $player->id, "\n"; | ||||||||||||||||||||||||||||
| 276 | 0 | $self->changed; | |||||||||||||||||||||||||||
| 277 | 0 | return $player; | |||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 4 | ▶ | sub _find_player_idx { | ||||||||||||||||||||||||||
|
Subroutine
_find_player_idx: called CC=9 SCAR=29.5
| |||||||||||||||||||||||||||||
| 281 | 4 | my ($self, $idx) = @_; | |||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 4 | my $players = $self->{players}; | |||||||||||||||||||||||||||
| 284 | 4 | ▶ | if (looks_like_number($idx)) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 285 | # already what we need | ||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||
| 287 | elsif (ref $idx) { # must be a Player dataobject | ||||||||||||||||||||||||||||
| 288 | # find Player object with matching refaddr | ||||||||||||||||||||||||||||
| 289 | FIND_REFADDR : { | ||||||||||||||||||||||||||||
| 290 | 0 | my $player = $idx; | |||||||||||||||||||||||||||
| 291 | 0 | my $my_refaddr = refaddr($player); | |||||||||||||||||||||||||||
| 292 | 0 | for my $ii (0 .. $#{$players}) { | |||||||||||||||||||||||||||
| 293 | 0 | ▶ | if (refaddr($players->[$ii]) == $my_refaddr) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 294 | 0 | $idx = $ii; | |||||||||||||||||||||||||||
| 295 | 0 | last FIND_REFADDR; | |||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||
| 298 | 0 | my $id = $player->id; | |||||||||||||||||||||||||||
| 299 | 0 | croak "can't find player at refaddr = $my_refaddr (ID=$id)\n"; | |||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||
| 302 | else { | ||||||||||||||||||||||||||||
| 303 | # find Player with matching ID | ||||||||||||||||||||||||||||
| 304 | FIND_ID : { | ||||||||||||||||||||||||||||
| 305 | 4 | my $id = normalize_ID($idx); | |||||||||||||||||||||||||||
| 306 | 4 | for my $ii (0 .. $#{$players}) { | |||||||||||||||||||||||||||
| 307 | 10 | ▶ | if ($players->[$ii]->id eq $id) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 308 | 4 | $idx = $ii; | |||||||||||||||||||||||||||
| 309 | 4 | last FIND_ID; | |||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||
| 312 | 0 | croak "can't find player matching ID $id\n"; | |||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||
| 315 | 4 | ▶ | if ($idx < 0 or | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$idx < 0 or $idx > $#{$players;}
MC/DC0%0/2
$idx < 0 or $idx > $#{$players;}
$idx < 0
$idx > $#{$players;}
Truth table33%1/3
A or B
A= $idx < 0B= $idx > $#{$players;}
| |||||||||||||||||||||||||||||
| 316 | 4 | $idx > $#{$players}) { | |||||||||||||||||||||||||||
| 317 | 0 | croak "index=$idx is out of bounds\n"; | |||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||
| 319 | 4 | return $idx; | |||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | # override some Directives methods so we can intercept | ||||||||||||||||||||||||||||
| 323 | # setting/getting of certain directives (which requires player info) | ||||||||||||||||||||||||||||
| 324 | 5 | ▶ | sub set_directive_value { | ||||||||||||||||||||||||||
|
Subroutine
set_directive_value: called CC=5 SCAR=25.2
Pod
documented
| |||||||||||||||||||||||||||||
| 325 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 326 | 5 | my ($key, $val) = @_; | |||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | 5 | ▶ | if (uc $key eq 'BYE_CANDIDATES') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 329 | 0 | $self->_bye_candidates(undef); # force refresh on next ->bye_candidates | |||||||||||||||||||||||||||
| 330 | 0 | ▶ | if (not $val) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | 0 | return $self->SUPER::delete_directive(@_); | |||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||
| 334 | elsif ($key =~ m/^DROP_(\d+|ALL)$/i) { | ||||||||||||||||||||||||||||
| 335 | 0 | $self->_drops(undef); # force refresh on next ->drops | |||||||||||||||||||||||||||
| 336 | 0 | ▶ | if (not $val) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 337 | 0 | return $self->SUPER::delete_directive(@_); | |||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||
| 340 | 5 | return $self->SUPER::set_directive_value(@_); | |||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | 20 | ▶ | sub get_directive_value { | ||||||||||||||||||||||||||
|
Subroutine
get_directive_value: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 344 | 20 | my $self = shift; | |||||||||||||||||||||||||||
| 345 | 20 | my ($key) = $_[0]; | |||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | 20 | ▶ | if (uc $key eq 'BAND_BREAKS') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 348 | 19 | return $self->break_bands; | |||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||
| 350 | 1 | return $self->SUPER::get_directive_value(@_); | |||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | # break players into number of bands in BANDS directives | ||||||||||||||||||||||||||||
| 354 | 19 | ▶ | sub break_bands { | ||||||||||||||||||||||||||
|
Subroutine
break_bands: called CC=9 SCAR=22.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 355 | 19 | my ($self) = @_; | |||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | 19 | my $band_breaks = $self->SUPER::get_directive_value('BAND_BREAKS'); | |||||||||||||||||||||||||||
| 358 | 19 | ▶ | return $band_breaks if ($band_breaks); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | 1 | my $num_bands = $self->get_directive_value('BANDS'); | |||||||||||||||||||||||||||
| 361 | 1 | ▶ | return if (not $num_bands # no BANDS directive and not BAND_BREAKS | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $num_bands or $num_bands == 1
MC/DC0%0/2
not $num_bands or $num_bands == 1
not $num_bands
$num_bands == 1
Truth table33%1/3
not(A) or B
A= not $num_bandsB= $num_bands == 1
| |||||||||||||||||||||||||||||
| 362 | or $num_bands == 1); # everyone is in same band | ||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | 1 | my @players = $self->players; | |||||||||||||||||||||||||||
| 365 | 1 | my %entrants_per_rating; | |||||||||||||||||||||||||||
| 366 | 1 | for my $player (@players) { | |||||||||||||||||||||||||||
| 367 | 18 | $entrants_per_rating{int $player->rating}++; # count entrants of each rating | |||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||
| 369 | 1 | my @sorted_ranks = sort {$b <=> $a} keys %entrants_per_rating; | |||||||||||||||||||||||||||
| 370 | 1 | my $running_total = 0; | |||||||||||||||||||||||||||
| 371 | 1 | my $ii = 0; | |||||||||||||||||||||||||||
| 372 | 1 | my @band_breaks; | |||||||||||||||||||||||||||
| 373 | 1 | for my $band (1 .. $num_bands - 1) { | |||||||||||||||||||||||||||
| 374 | 2 | ▶ | last if ($ii >= @sorted_ranks); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 375 | 2 | my $next_break = $band * (@players / $num_bands); | |||||||||||||||||||||||||||
| 376 | 2 | ▶ | while ($running_total + $entrants_per_rating{$sorted_ranks[$ii]} < $next_break) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 377 | 3 | $running_total += $entrants_per_rating{$sorted_ranks[$ii++]}; | |||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||
| 379 | 2 | ▶ | if (($running_total + ($entrants_per_rating{$sorted_ranks[$ii]} / 2) < $next_break)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 380 | 2 | $running_total += $entrants_per_rating{$sorted_ranks[$ii++]}; | |||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||
| 382 | #print "$running_total to band $band=$sorted_ranks[$ii - 1]\n"; | ||||||||||||||||||||||||||||
| 383 | 2 | push(@band_breaks, $sorted_ranks[$ii - 1]); | |||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | 1 | $band_breaks = join ' ', @band_breaks; | |||||||||||||||||||||||||||
| 386 | 1 | $self->set_directive_value('BAND_BREAKS', $band_breaks); | |||||||||||||||||||||||||||
| 387 | 1 | return $band_breaks; | |||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | 18 | ▶ | sub bands { | ||||||||||||||||||||||||||
|
Subroutine
bands: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||
| 391 | 18 | my ($self) = @_; | |||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | 18 | ▶ | my @breaks = split /[^\d\.\-]+/, ($self->get_directive_value('BAND_BREAKS') || ''); | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->get_directive_value('BAND_BREAKS') || ''
MC/DC0%0/1
$self->get_directive_value('BAND_BREAKS') || ''
$self->get_directive_value('BAND_BREAKS')
Truth table50%1/2
A
A= $self->get_directive_value('BAND_BREAKS')
| |||||||||||||||||||||||||||||
| 394 | return wantarray | ||||||||||||||||||||||||||||
| 395 | ? @breaks | ||||||||||||||||||||||||||||
| 396 | 18 | ▶ | : \@breaks; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | 18 | ▶ | sub which_band_is { | ||||||||||||||||||||||||||
|
Subroutine
which_band_is: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 400 | 18 | my ($self, $rating) = @_; | |||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | 18 | my $bands = $self->bands; | |||||||||||||||||||||||||||
| 403 | 18 | ▶ | return 0 if (@{$bands} < 1); # one or no bands defined, all players are in band 0 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | 18 | $rating = Rank_to_Rating($rating); # make sure it's numeric | |||||||||||||||||||||||||||
| 406 | 18 | my $idx; | |||||||||||||||||||||||||||
| 407 | 18 | ▶ | for ($idx = 0; $idx < @{$bands}; $idx++) { # go past the end | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 408 | 30 | my $limit = $bands->[$idx]; | |||||||||||||||||||||||||||
| 409 | 30 | ▶ | if ($limit < 0 and | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$limit < 0 and $limit == int $limit
MC/DC50%1/2
$limit < 0 and $limit == int $limit
$limit < 0
$limit == int $limit
Truth table66%2/3
A and B
A= $limit < 0B= $limit == int $limit
| |||||||||||||||||||||||||||||
| 410 | $limit == int $limit) { # -2.0 means entire 2K range down to -2.9999, | ||||||||||||||||||||||||||||
| 411 | 12 | $limit = $limit - 1; # but -2.5 really means -2.5. | |||||||||||||||||||||||||||
| 412 | 12 | ▶ | last if ($rating > $limit); # dan: -3.0 is a 3 kyu | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||
| 414 | else { | ||||||||||||||||||||||||||||
| 415 | 18 | ▶ | last if ($rating >= $limit); # dan: 3.0 is a 3 dan | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||
| 418 | 18 | return $idx; | |||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | 0 | ▶ | sub fprint { | ||||||||||||||||||||||||||
|
Subroutine
fprint: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 422 | 0 | my ($self, $fh) = @_; | |||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | 0 | $self->SUPER::fprint($fh); # print the directives | |||||||||||||||||||||||||||
| 425 | 0 | foreach my $comment ($self->comments) { | |||||||||||||||||||||||||||
| 426 | 0 | $fh->print("#$comment\n"); | |||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||
| 428 | 0 | foreach my $player ($self->players) { | |||||||||||||||||||||||||||
| 429 | 0 | $player->fprint_register($fh); | |||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | 2 | 1; | |||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | __END__ | ||||||||||||||||||||||||||||