script_files/pairingtable

filter: Statementstmt 83.9% 136 / 162 Branchbran 34.4% 20 / 58 Conditioncond 37.8% 14 / 37 MC/DCmcdc 0.0% 0 / 22 Subroutinesub 85.7% 12 / 14 Podpod n/a totaltotal 62.1% 182 / 293 CC 3 SCAR 6.2
CC
3
Cov
66%
__ANON__
6.0
__ANON__
2.4
__ANON__
2.0
CRAP 1.9
« blib/lib/Games/Tournament/Swiss/Procedure/Dummy.pm ↑ Summary script_files/pairstately »
1 #!/usr/bin/perl
2  
3 =head1 NAME
4  
5 pairingtable - Show player scoregroups for next round of swiss tournament
6  
7 =cut
8  
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use YAML qw/LoadFile DumpFile/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use List::Util qw/reduce first max/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Scalar::Util qw/looks_like_number/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use List::MoreUtils qw/any all/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 ▶use Games::Tournament::Swiss::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 my $swiss = Games::Tournament::Swiss::Config->new;
21  
22 2 my $league = LoadFile "./league.yaml";
23 2 ▶my $roles = $league->{roles} || [qw/White Black/];
Condition50%1/2
$league->{'roles'} || ['White', 'Black']
l!l
02
MC/DC0%0/1
$league->{'roles'} || ['White', 'Black']
$league->{'roles'}
Truth table50%1/2
A
A= $league->{'roles'}
Aresult
11
00
24 my $scores = $league->{scores} ||
25 2 ▶ { win => 1, loss => 0, draw => 0.5, forfeit => 0, bye => 1 };
Condition50%1/2
$league->{'scores'} || {'win', 1, 'loss', 0, 'draw', 0.5, 'forfeit', 0, 'bye', 1}
l!l
02
MC/DC0%0/1
$league->{'scores'} || {'win', 1, 'loss', 0, 'draw', 0.5, 'forfeit', 0, 'bye', 1}
$league->{'scores'}
Truth table50%1/2
A
A= $league->{'scores'}
Aresult
11
00
26 2 ▶my $firstround = $league->{firstround} || 1;
Condition50%1/2
$league->{'firstround'} || 1
l!l
02
MC/DC0%0/1
$league->{'firstround'} || 1
$league->{'firstround'}
Truth table50%1/2
A
A= $league->{'firstround'}
Aresult
11
00
27 2 ▶my $algorithm = $league->{algorithm} || 'Games::Tournament::Swiss::Procedure::FIDE';
Condition50%1/2
$league->{'algorithm'} || 'Games::Tournament::Swiss::Procedure::FIDE'
l!l
02
MC/DC0%0/1
$league->{'algorithm'} || 'Games::Tournament::Swiss::Procedure::FIDE'
$league->{'algorithm'}
Truth table50%1/2
A
A= $league->{'algorithm'}
Aresult
11
00
28 my $abbrev = $league->{abbreviation} ||
29 2 ▶ { W => 'White', B => 'Black', 1 => 'Win', 0 => 'Loss',
Condition50%1/2
$league->{'abbreviation'} || {'W', 'White', 'B', 'Black', 1, 'Win', 0, 'Loss', 0.5, 'Draw', '=', 'Draw'}
l!l
02
MC/DC0%0/1
$league->{'abbreviation'} || {'W', 'White', 'B', 'Black', 1, 'Win', 0, 'Loss', 0.5, 'Draw', '=', 'Draw'}
$league->{'abbreviation'}
Truth table50%1/2
A
A= $league->{'abbreviation'}
Aresult
11
00
30 0.5 => 'Draw', '=' => 'Draw' };
31  
32 2 $swiss->frisk($scores, $roles, $firstround, $algorithm, $abbrev);
33  
34 2 $Games::Tournament::Swiss::Config::firstround = $firstround;
35 2 %Games::Tournament::Swiss::Config::scores = %$scores;
36 2 @Games::Tournament::Swiss::Config::roles = @$roles;
37 2 $Games::Tournament::Swiss::Config::algorithm = $algorithm;
38  
39 2 require Games::Tournament::Swiss;
40 2 require Games::Tournament::Contestant::Swiss;
41 2 require Games::Tournament::Card;
42  
43 2 my ($tourney, $lineup, $games, @rounds);
44  
45 2 my $nextRound = $ARGV[0];
46 2 my ($previous, $round);
47 2 ▶if ( $nextRound and $nextRound =~ /^\d+$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($nextRound and $nextRound =~ /^\d+$/) { } 2 0 2
elsif ($nextRound) { } 0 0 0
Condition33%1/3
$nextRound and $nextRound =~ /^\d+$/
!ll&&!rl&&r
002
MC/DC0%0/2
$nextRound and $nextRound =~ /^\d+$/
$nextRound $nextRound =~ /^\d+$/
Truth table33%1/3
A and B
A= $nextRoundB= $nextRound =~ /^\d+$/
ABresult
0X0
100
111
48 2 @rounds = ($Games::Tournament::Swiss::Config::firstround .. $nextRound-1);
49 2 $previous = $nextRound-1;
50 2 $round = $previous;
51 }
52 0 elsif ( $nextRound ) { die "Round \"$nextRound\" not a round number"; }
53 else {
54 0 ▶ for my $number ( glob ('./comp/*') ) {
Subroutine BEGIN: called CC=1 SCAR=0.2
55 0 ▶ push @rounds, $1 if -d $number and $number =~ m/\/(\d+)$/
Branch: 1 branch
BranchTrueFalseTotal
if -d $number and $number =~ m[/(\d+)$] and -e "$number/scores.yaml" 0 0 0
Condition0%0/6
-d $number and $number =~ m[/(\d+)$] and -e "$number/scores.yaml"
!ll&&!rl&&r
000
-d $number and $number =~ m[/(\d+)$]
!ll&&!rl&&r
000
MC/DC0%0/3
-d $number and $number =~ m[/(\d+)$] and -e "$number/scores.yaml"
-d $number $number =~ m[/(\d+)$] -e "$number/scores.yaml"
Truth table0%0/4
A and B and C
A= -d $numberB= $number =~ m[/(\d+)$]C= -e "$number/scores.yaml"
ABCresult
0XX0
10X0
1100
1111
56 and -e "$number/scores.yaml";
57 }
58 0 @rounds = sort { $a <=> $b } @rounds;
59 0 $previous = $rounds[-1];
60 0 $nextRound = $previous + 1;
61 0 $round = $previous;
62 }
63  
64 2 my $members = $league->{member};
65 2 my $absentees = $league->{absent};
66 2 my $out = $league->{out};
67 2 for my $member ( @$members, @$absentees ) {
68 push @$lineup, Games::Tournament::Contestant::Swiss->new( %$member )
69 8 ▶ unless any { $member eq $_ } @$lineup;
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
unless &any(sub { $member eq $_; } , @$lineup) 8 0 8
70 }
71  
72 2 $tourney = Games::Tournament::Swiss->new( entrants => $lineup,
73 round => $Games::Tournament::Swiss::Config::firstround);
74  
75 2 $lineup = $tourney->entrants;
76  
77 2 $tourney->idNameCheck;
78  
79 2 $tourney->assignPairingNumbers;
80  
81 2 my $table;
82 2 for my $round ( @rounds )
83 {
84 3 ▶ next unless -d "./comp/$round/";
Branch: 1 branch
BranchTrueFalseTotal
unless -d "./comp/$round/" 0 3 3
85 3 $tourney->round($round);
86 3 my $schedule = LoadFile "./comp/$round/round.yaml";
87 3 my $allresults = LoadFile( "./comp/$round/scores.yaml" );
88 3 my ($results, %playerGames);
89 3 ▶ if (all {ref eq 'HASH' and all {not ref} values %$_} values %$allresults) {
Subroutine __ANON__: called CC=2 SCAR=8.5
Subroutine __ANON__: called CC=1 SCAR=0.8
Branch: 3 branches
BranchTrueFalseTotal
if (&all(sub { ref $_ eq 'HASH' and &all(sub { not ref $_; } , values %$_); } , values %$allresults)) { } 3 0 3
elsif (&all(sub { not ref $_; } , values %$allresults)) { } 0 0 0
ref $_ eq "HASH" and &all(sub { not ref $_; } , values %$_) 6 0 6
90 3 for my $table ( keys %$allresults ) {
91 6 my $card = $allresults->{$table};
92 6 my @players = keys %$card;
93 6 for my $player ( @players ) {
94 12 my $personalresult = $card->{$player};
95 12 ▶ if ( defined $scores->{lc $personalresult} ) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $$scores{lc $personalresult}) { } 0 12 12
elsif ($abbrev->{$personalresult}) { } 12 0 12
elsif (&looks_like_number($personalresult)) { } 0 0 0
96 0 $results->{$player} = $personalresult;
97 }
98 elsif ( $abbrev->{$personalresult} ) {
99 12 $results->{$player} = $abbrev->{$personalresult};
100 }
101 elsif ( looks_like_number( $personalresult ) ) {
102 0 ▶ my $other = reduce { $a == $b? $a: $b } values %$card;
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$a == $b ? : 0 0 0
103 0 ▶ if ( looks_like_number( $other ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_number($other)) { } 0 0 0
104 0 ▶ $results->{$player} =
Branch: 2 branches
BranchTrueFalseTotal
$personalresult > $other ? : 0 0 0
$personalresult < $other ? : 0 0 0
105 ( $personalresult > $other )?
106 "Win": ( $personalresult < $other )?
107 "Loss": "Draw";
108 }
109 0 else { die
110 "Partner to $player on table $table in round $round got $other?";
111 }
112 }
113 else {
114 0 die
115 "Player $player on table $table in round $round got $personalresult?";
116 }
117 }
118 }
119 }
120 0 ▶ elsif ( all { not ref } values %$allresults ) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
121 0 for my $player ( keys %$allresults ) {
122 0 my $personalresult = $allresults->{$player};
123 0 ▶ if ( defined $scores->{lc $personalresult} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $$scores{lc $personalresult}) { } 0 0 0
elsif ($abbrev->{$personalresult}) { } 0 0 0
124 0 $results->{$player} = $personalresult;
125 }
126 elsif ( $abbrev->{$personalresult} ) {
127 0 $results->{$player} = $abbrev->{$personalresult};
128 }
129 else {
130 0 die "Player $player in round $round got $personalresult?";
131 }
132 }
133 }
134 0 else { die "Unknown format or invalid/incomplete results in round $round" }
135 3 my @games;
136  
137 3 my $groups = $schedule->{group};
138 3 my $maxn = max keys %$groups;
139 3 ▶ $groups->{++$maxn} = { Bye => $schedule->{bye} } if $schedule->{bye};
Branch: 1 branch
BranchTrueFalseTotal
if $schedule->{"bye"} 0 3 3
140 3 for my $n ( keys %$groups ) {
141 6 my $group = $groups->{$n};
142 6 my (%group, @players);
143 6 for my $role ( keys %$group ) {
144 12 my $id = $group->{$role};
145 12 my $player = $tourney->ided( $id );
146 12 ▶die "Player $id, $role at table $n in round $round is not in tournament" unless
Branch: 1 branch
BranchTrueFalseTotal
unless $player 0 12 12
147 $player;
148 12 my $name = $player->name;
149 12 push @players, $player;
150 12 $group{contestants}->{$role} = $player;
151 12 my $result = $results->{ $id };
152 12 ▶ $result ||= $results->{ $name };
Condition33%1/3
$result ||= $results->{$name}
l!l&&r!l&&!r
0120
MC/DC0%0/2
$result ||= $results->{$name}
$result $results->{$name}
Truth table33%1/3
A ||= B
A= $resultB= $results->{$name}
ABresult
1X1
011
000
153 12 ▶ $result = "Bye" if $role eq 'Bye';
Branch: 1 branch
BranchTrueFalseTotal
if $role eq "Bye" 0 12 12
154 12 ▶ die "$id got $result in round $round"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result 0 12 12
155 unless defined $result;
156 12 $group{result}->{$role} = $result;
157 12 $group{round} = $round;
158 }
159 6 my $game = Games::Tournament::Card->new( %group );
160 6 push @games, $game;
161 6 $playerGames{$_} = $game for map { $_->id } @players;
162 }
163 3 $tourney->collectCards( @games );
164 3 for my $player (@$lineup) {
165 12 my $id = $player->id;
166 12 $table->{$id}->{id} = $id;
167 12 my $game = $playerGames{$id};
168 12 ▶ if ( defined $game ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $game) { } 12 0 12
169 12 ▶ my $opponent = $player->myOpponent($game)
Condition33%1/3
$player->myOpponent($game) || 'Games::Tournament::Contestant::Swiss'->new('name', 'Bye', 'pairingNumber', '-')
l!l&&r!l&&!r
1200
MC/DC0%0/2
$player->myOpponent($game) || 'Games::Tournament::Contestant::Swiss'->new('name', 'Bye', 'pairingNumber', '-')
$player->myOpponent($game) 'Games::Tournament::Contestant::Swiss'->new('name', 'Bye', 'pairingNumber', '-')
Truth table33%1/3
A || B
A= $player->myOpponent($game)B= 'Games::Tournament::Contestant::Swiss'->new('name', 'Bye', 'pairingNumber', '-')
ABresult
1X1
011
000
170 || Games::Tournament::Contestant::Swiss->new( name => "Bye", pairingNumber => "-" );
171 12 $table->{$id}->{opponents} .= $opponent->pairingNumber . ",";
172 12 my $role = $game->myRole($player);
173 0 ▶ if ( $role eq 'Bye' ) { $role = '-'; }
Branch: 1 branch
BranchTrueFalseTotal
if ($role eq 'Bye') { } 0 12 12
174 12 else { $role =~ s/^(.).*$/$1/; }
175 12 $table->{$id}->{roles} .= $role;
176 }
177 else {
178 0 $table->{$id}->{opponents} .= "-,";
179 0 $table->{$id}->{roles} .= "-";
180 }
181 }
182  
183 }
184  
185 2 my %brackets = $tourney->formBrackets;
186 2 my $playerN = 0;
187  
188 2 print "
189 Round $nextRound Pairing Groups
190 -------------------------------------------------------------------------
191 Place No Opponents Roles Float Score
192 ";
193 2 for my $index ( reverse sort { $a <=> $b } keys %brackets )
194 {
195 5 $playerN++;
196 5 my $place = $playerN;
197 5 my @members = @{$brackets{$index}->members};
198 5 ▶ $place .= '-' . ($playerN+$#members) if $#members;
Branch: 1 branch
BranchTrueFalseTotal
if $#members 3 2 5
199 5 $playerN += $#members;
200 5 print "$place\n";
201 5 foreach my $member ( @members )
202 {
203 8 my $id = $member->id;
204 8 my $no = $member->pairingNumber;
205 8 chop $table->{$id}->{opponents};
206 8 my $floats = $member->floats;
207 8 my $float = '';
208 8 ▶ $float = 'd' if $floats->[-2] and $floats->[-2] eq 'Down';
Branch: 1 branch
BranchTrueFalseTotal
if $floats->[-2] and $floats->[-2] eq "Down" 0 8 8
Condition66%2/3
$floats->[-2] and $floats->[-2] eq "Down"
!ll&&!rl&&r
440
MC/DC0%0/2
$floats->[-2] and $floats->[-2] eq "Down"
$floats->[-2] $floats->[-2] eq "Down"
Truth table66%2/3
A and B
A= $floats->[-2]B= $floats->[-2] eq "Down"
ABresult
0X0
100
111
209 8 ▶ $float = 'u' if $floats->[-2] and $floats->[-2] eq 'Up';
Branch: 1 branch
BranchTrueFalseTotal
if $floats->[-2] and $floats->[-2] eq "Up" 0 8 8
Condition66%2/3
$floats->[-2] and $floats->[-2] eq "Up"
!ll&&!rl&&r
440
MC/DC0%0/2
$floats->[-2] and $floats->[-2] eq "Up"
$floats->[-2] $floats->[-2] eq "Up"
Truth table66%2/3
A and B
A= $floats->[-2]B= $floats->[-2] eq "Up"
ABresult
0X0
100
111
210 8 ▶ $float .= 'D' if $floats->[-1] and $floats->[-1] eq 'Down';
Branch: 1 branch
BranchTrueFalseTotal
if $floats->[-1] and $floats->[-1] eq "Down" 0 8 8
Condition33%1/3
$floats->[-1] and $floats->[-1] eq "Down"
!ll&&!rl&&r
080
MC/DC0%0/2
$floats->[-1] and $floats->[-1] eq "Down"
$floats->[-1] $floats->[-1] eq "Down"
Truth table33%1/3
A and B
A= $floats->[-1]B= $floats->[-1] eq "Down"
ABresult
0X0
100
111
211 8 ▶ $float .= 'U' if $floats->[-1] and $floats->[-1] eq 'Up';
Branch: 1 branch
BranchTrueFalseTotal
if $floats->[-1] and $floats->[-1] eq "Up" 0 8 8
Condition33%1/3
$floats->[-1] and $floats->[-1] eq "Up"
!ll&&!rl&&r
080
MC/DC0%0/2
$floats->[-1] and $floats->[-1] eq "Up"
$floats->[-1] $floats->[-1] eq "Up"
Truth table33%1/3
A and B
A= $floats->[-1]B= $floats->[-1] eq "Up"
ABresult
0X0
100
111
212 8 ▶ my $score = defined $member->score? $member->score: '-';
Branch: 1 branch
BranchTrueFalseTotal
defined $member->score ? : 8 0 8
213  
214 # no warnings;
215 format STDOUT =
216 @<<<< @<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<< @<<<
217 " ", $no, $table->{$id}->{opponents}, $table->{$id}->{roles}, $float, $score
218 .
219 8 write;
220 # use warnings;
221 }
222 }
223  
224 __END__
« blib/lib/Games/Tournament/Swiss/Procedure/Dummy.pm ↑ Summary script_files/pairstately »