script_files/pairstately

filter: Statementstmt 80.1% 129 / 161 Branchbran 40.6% 26 / 64 Conditioncond 34.2% 13 / 38 MC/DCmcdc 13.6% 3 / 22 Subroutinesub 100% 10 / 10 Podpod n/a totaltotal 61.3% 181 / 295 CC 2 SCAR 1.9
CC
2
Cov
64%
__ANON__
2.1
__ANON__
1.1
BEGIN
1.0
CRAP 1.2
« script_files/pairingtable ↑ Summary script_files/pair »
1 #!/usr/bin/perl
2  
3 # Last Edit: 2010 11月 14, 14時41分13秒
4 # $Id: /swiss/trunk/script_files/pairstately 1472 2007-10-13T02:03:22.823448Z greg $
5  
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use YAML qw/LoadFile DumpFile/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use List::Util qw/first/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use List::MoreUtils qw/all any/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶use Games::Tournament::Swiss::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 my $swiss = Games::Tournament::Swiss::Config->new;
16 2 my $league = LoadFile "../../league.yaml";
17 2 ▶die 'round.yaml already exists' if -e 'round.yaml';
Branch: 1 branch
BranchTrueFalseTotal
if -e "round.yaml" 0 2 2
18  
19 2 ▶my $roles = $league->{roles} || [$swiss->roles];
Condition50%1/2
$league->{'roles'} || [$swiss->roles]
l!l
02
MC/DC0%0/1
$league->{'roles'} || [$swiss->roles]
$league->{'roles'}
Truth table50%1/2
A
A= $league->{'roles'}
Aresult
11
00
20 my $scores = $league->{scores} ||
21 2 ▶ { win => 1, loss => 0, draw => 0.5, absent => 0, bye => 1 };
Condition50%1/2
$league->{'scores'} || {'win', 1, 'loss', 0, 'draw', 0.5, 'absent', 0, 'bye', 1}
l!l
02
MC/DC0%0/1
$league->{'scores'} || {'win', 1, 'loss', 0, 'draw', 0.5, 'absent', 0, 'bye', 1}
$league->{'scores'}
Truth table50%1/2
A
A= $league->{'scores'}
Aresult
11
00
22 2 ▶my $firstround = $league->{firstround} || $swiss->firstround;
Condition33%1/3
$league->{'firstround'} || $swiss->firstround
l!l&&r!l&&!r
020
MC/DC0%0/2
$league->{'firstround'} || $swiss->firstround
$league->{'firstround'} $swiss->firstround
Truth table33%1/3
A || B
A= $league->{'firstround'}B= $swiss->firstround
ABresult
1X1
011
000
23 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
24 my $abbrev = $league->{abbreviation} ||
25 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
26 0.5 => 'Draw', '=' => 'Draw' };
27  
28 2 $swiss->frisk($scores, $roles, $firstround, $algorithm, $abbrev);
29  
30 2 $Games::Tournament::Swiss::Config::firstround = $firstround;
31 2 %Games::Tournament::Swiss::Config::scores = %$scores;
32 2 @Games::Tournament::Swiss::Config::roles = @$roles;
33 2 $Games::Tournament::Swiss::Config::algorithm = $algorithm;
34  
35 2 require Games::Tournament::Swiss;
36 2 require Games::Tournament::Contestant::Swiss;
37 2 require Games::Tournament::Card;
38  
39 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 2 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 2 my $directory = File::Spec->rel2abs( '.' );
42 2 my $next = basename( $directory );
43 2 ▶die "round $next directory name not a round number" unless
Branch: 1 branch
BranchTrueFalseTotal
unless $next =~ /^\d+$/ 0 2 2
44 $next =~ m/^\d+$/;
45 2 my $previous = $next-1;
46 2 my $round = $previous;
47 2 my $n = 0;
48  
49 2 my $results;
50 2 ▶unless ($round < $firstround)
Branch: 1 branch
BranchTrueFalseTotal
unless ($round < $firstround) 1 1 2
51 {
52 1 my $scoresdirectory;
53 1 ▶ $scoresdirectory = exists $league->{compcomp}? $league->{compcomp} : "../comp";
Branch: 1 branch
BranchTrueFalseTotal
exists $league->{'compcomp'} ? : 0 1 1
54 1 $results = LoadFile( "../$previous/scores.yaml" );
55 1 my @tables;
56 1 ▶ if ( @tables = (keys %$results) and all {ref} @{$results}{@tables} ) {
Subroutine __ANON__: called CC=1 SCAR=0.5
Branch: 1 branch
BranchTrueFalseTotal
if (@tables = keys %$results and &all(sub { ref $_; } , @{$results;}{@tables})) 1 0 1
Condition33%1/3
@tables = keys %$results and &all(sub { ref $_; } , @{$results;}{@tables})
!ll&&!rl&&r
001
MC/DC0%0/2
@tables = keys %$results and &all(sub { ref $_; } , @{$results;}{@tables})
@tables = keys %$results &all(sub { ref $_; } , @{$results;}{@tables})
Truth table33%1/3
A and B
A= @tables = keys %$resultsB= &all(sub { ref $_; } , @{$results;}{@tables})
ABresult
0X0
100
111
57 1 for my $table ( @tables ) {
58 2 for my $player ( keys %{$results->{$table}} ) {
59 4 my $result = $results->{$table}->{$player};
60 4 ▶ if ( exists $scores->{$result} )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $scores->{$result}) { } 0 4 4
elsif ($abbrev->{$result}) { } 4 0 4
61 0 { $results->{$player} = $result; }
62 elsif ( $abbrev->{$result} )
63 4 { $results->{$player} = $abbrev->{$result}; }
64 0 else { die
65 "Player $player on table $table in round $round got $result?";
66 }
67 }
68 }
69 }
70 1 DumpFile "scores.yaml.bak", $results;
71 }
72  
73 2 my $oldlist;
74 my $lineup;
75 2 my $newplayers;
76 0 ▶my @absentees = @{ $league->{absent} } if $league->{absent};
Branch: 1 branch
BranchTrueFalseTotal
if $league->{"absent"} 0 2 2
77 2 ▶if ( -e "../$previous/player.yaml" and $round >= $firstround ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "../$previous/player.yaml" and $round >= $firstround) 1 1 2
Condition66%2/3
-e "../$previous/player.yaml" and $round >= $firstround
!ll&&!rl&&r
101
MC/DC50%1/2
-e "../$previous/player.yaml" and $round >= $firstround
-e "../$previous/player.yaml" $round >= $firstround
Truth table66%2/3
A and B
A= -e "../$previous/player.yaml"B= $round >= $firstround
ABresult
0X0
100
111
78 1 $oldlist = LoadFile qq{../$previous/player.yaml};
79 1 for my $player (@$oldlist) {
80 0 ▶ push @$lineup, $player unless grep {$player->{name} eq $_} @absentees;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$player->{"name"} eq $_;} @absentees 4 0 4
81 }
82 }
83 # else {
84 2 for my $member ( @{ $league->{member} } ) {
85 0 ▶ next if grep {$member->{name} eq $_} @absentees;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$member->{"name"} eq $_;} @absentees 0 8 8
86 8 ▶ next if $lineup and grep {$_->{name} eq $member->{name}} @$lineup;
Branch: 1 branch
BranchTrueFalseTotal
if $lineup and grep {$_->{"name"} eq $member->{"name"};} @$lineup 4 4 8
Condition100%3/3
$lineup and grep {$_->{"name"} eq $member->{"name"};} @$lineup
!ll&&!rl&&r
134
MC/DC100%2/2
$lineup and grep {$_->{"name"} eq $member->{"name"};} @$lineup
$lineup grep {$_->{"name"} eq $member->{"name"};} @$lineup
Truth table100%3/3
A and B
A= $lineupB= grep {$_->{"name"} eq $member->{"name"};} @$lineup
ABresult
0X0
100
111
87 4 $newplayers++;
88 4 push @$lineup, Games::Tournament::Contestant::Swiss->new( %$member );
89 }
90 # }
91  
92 2 my $tourney;
93 2 ▶if ( $round < $firstround)
Branch: 2 branches
BranchTrueFalseTotal
if ($round < $firstround) { } 1 1 2
elsif (-e "../$previous/tourney.yaml") { } 1 0 1
94 {
95 1 $tourney = Games::Tournament::Swiss->new(
96 entrants => $lineup );
97 1 $tourney->entrants($lineup);
98 1 $tourney->round( $round );
99 1 $tourney->assignPairingNumbers;
100 1 $tourney->initializePreferences;
101 }
102 elsif ( -e "../$previous/tourney.yaml" )
103 {
104 1 $tourney = LoadFile "../$round/tourney.yaml";
105 1 $tourney->entrants($lineup);
106 0 $tourney->round( $round );
107 }
108 else {
109 0 die "round $round not first round, but no tourney.yaml setup\n";
110 }
111  
112 1 my $playedGames;
113 1 ▶if ( -e "../$previous/matches.yaml" and $round >= $firstround ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "../$previous/matches.yaml" and $round >= $firstround) 0 1 1
Condition33%1/3
-e "../$previous/matches.yaml" and $round >= $firstround
!ll&&!rl&&r
100
MC/DC0%0/2
-e "../$previous/matches.yaml" and $round >= $firstround
-e "../$previous/matches.yaml" $round >= $firstround
Truth table33%1/3
A and B
A= -e "../$previous/matches.yaml"B= $round >= $firstround
ABresult
0X0
100
111
114 0 $playedGames = LoadFile "../$previous/matches.yaml";
115 0 ▶ if ( my @games = $tourney->unmarkedCards(@$playedGames) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@games) = $tourney->unmarkedCards(@$playedGames)) 0 0 0
116 0 for my $game (@games) {
117 0 my @contestants = map {$_->id} values %{$game->contestants};
118 0 my (%score, %result);
119 0 my $total;
120 0 for my $role ( @$roles, "Bye" ) {
121 0 my $player = $game->contestants->{$role};
122 0 ▶ next unless $player
Branch: 1 branch
BranchTrueFalseTotal
unless $player and $player->isa("Games::Tournament::Contestant") 0 0 0
Condition0%0/3
$player and $player->isa("Games::Tournament::Contestant")
!ll&&!rl&&r
000
MC/DC0%0/2
$player and $player->isa("Games::Tournament::Contestant")
$player $player->isa("Games::Tournament::Contestant")
Truth table0%0/3
A and B
A= $playerB= $player->isa("Games::Tournament::Contestant")
ABresult
0X0
100
111
123 and $player->isa('Games::Tournament::Contestant');
124 0 my $result = $results->{ $player->name };
125 0 ▶ warn "$player->{name}, $player->{id} playing $role got $result in round $game->{round}"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result 0 0 0
126 unless defined $result;
127 0 $result{$role} = $result;
128 $score{$role} =
129 $role =~ m/Bye/i ? $scores->{bye}
130 : $result =~ m/Win/i ? $scores->{win}
131 : $result =~ m/Draw/i ? $scores->{draw}
132 : $result =~ m/Loss/i ? $scores->{loss}
133 : $result =~ m/Absent/i ? $scores->{absent}
134 0 ▶ : "Error";
Branch: 5 branches
BranchTrueFalseTotal
$role =~ /Bye/i ? : 0 0 0
$result =~ /Win/i ? : 0 0 0
$result =~ /Draw/i ? : 0 0 0
$result =~ /Loss/i ? : 0 0 0
$result =~ /Absent/i ? : 0 0 0
135 0 ▶ die "Error: $player->{name} $player->{id}'s result in round $round is $result?" if $score{$role} eq 'Error';
Branch: 1 branch
BranchTrueFalseTotal
if $score{$role} eq "Error" 0 0 0
136 0 $total += $score{$role};
137 }
138 warn "total scores in round $round with players @contestants = $total?"
139 unless $total == $scores->{win} + $scores->{loss} or
140 $total == 2 * $scores->{draw} or
141 $total == $scores->{draw} + $scores->{absent} or
142 0 ▶ $total == 2 * $scores->{absent};
Branch: 1 branch
BranchTrueFalseTotal
unless $total == $scores->{"win"} + $scores->{"loss"} or $total == 2 * $scores->{"draw"} or $total == $scores->{"draw"} + $scores->{"absent"} or $total == 2 * $scores->{"absent"} 0 0 0
Condition0%0/9
$total == $scores->{"win"} + $scores->{"loss"} or $total == 2 * $scores->{"draw"} or $total == $scores->{"draw"} + $scores->{"absent"} or $total == 2 * $scores->{"absent"}
l!l&&r!l&&!r
000
$total == $scores->{"win"} + $scores->{"loss"} or $total == 2 * $scores->{"draw"} or $total == $scores->{"draw"} + $scores->{"absent"}
l!l&&r!l&&!r
000
$total == $scores->{"win"} + $scores->{"loss"} or $total == 2 * $scores->{"draw"}
l!l&&r!l&&!r
000
MC/DC0%0/4
$total == $scores->{"win"} + $scores->{"loss"} or $total == 2 * $scores->{"draw"} or $total == $scores->{"draw"} + $scores->{"absent"} or $total == 2 * $scores->{"absent"}
$total == $scores->{"win"} + $scores->{"loss"} $total == 2 * $scores->{"draw"} $total == $scores->{"draw"} + $scores->{"absent"} $total == 2 * $scores->{"absent"}
Truth table0%0/5
A or B or C or D
A= $total == $scores->{"win"} + $scores->{"loss"}B= $total == 2 * $scores->{"draw"}C= $total == $scores->{"draw"} + $scores->{"absent"}D= $total == 2 * $scores->{"absent"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
143 0 $game->result( \%result );
144 # $game->canonize;
145 }
146 }
147 0 $tourney->collectCards(@$playedGames);
148 }
149  
150 1 my %brackets = $tourney->formBrackets;
151 1 my $pairing = $tourney->pairing( \%brackets );
152 1 my $paired = $pairing->matchPlayers;
153 1 my $matches = $paired->{matches};
154 1 my @games;
155  
156 1 for my $bracket ( reverse sort keys %$matches )
157 {
158 1 my $bracketmatches = $matches->{$bracket};
159 1 ▶ push @games, grep { $_ if ref eq 'Games::Tournament::Card' }
Branch: 1 branch
BranchTrueFalseTotal
if ref $_ eq "Games::Tournament::Card" 2 0 2
160 @$bracketmatches;
161 }
162 1 $tourney->round($next);
163 1 $tourney->publishCards(@games);
164  
165 1 my $schedule;
166 $schedule->{Warning} =
167 1 "# This file, $directory/round.yaml, was created for round $next by pairstately on "
168 . localtime() . '.';
169 1 ▶if ( -e '../assistants.yaml' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "../assistants.yaml") 0 1 1
170 0 my $assistantFile = LoadFile '../assistants.yaml';
171 0 $schedule->{assistant} = $assistantFile->{$next};
172 }
173 1 $n = 1;
174 1 for my $game (@games) {
175 4 my %group = map { $_ => $game->{contestants}->{$_}->{name} }
176 2 keys %{ $game->{contestants} };
177 2 $schedule->{group}->{ $n++ } = \%group;
178 }
179  
180 1 ▶if ( $newplayers ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newplayers) 1 0 1
181 1 DumpFile '../../league.yaml.bak', $league;
182 1 for my $member ( @{$league->{member}} )
183 {
184 0 ▶ next if grep { $_ eq $member->{name} } @absentees;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $member->{"name"};} @absentees 0 4 4
185 next if $member->{pairingnumber} and
186 0 ▶ grep { $_->pairingNumber == $member->{pairingnumber} } @$lineup;
Branch: 1 branch
BranchTrueFalseTotal
if $member->{"pairingnumber"} and grep {$_->pairingNumber == $member->{"pairingnumber"};} @$lineup 0 4 4
Condition33%1/3
$member->{"pairingnumber"} and grep {$_->pairingNumber == $member->{"pairingnumber"};} @$lineup
!ll&&!rl&&r
400
MC/DC0%0/2
$member->{"pairingnumber"} and grep {$_->pairingNumber == $member->{"pairingnumber"};} @$lineup
$member->{"pairingnumber"} grep {$_->pairingNumber == $member->{"pairingnumber"};} @$lineup
Truth table33%1/3
A and B
A= $member->{"pairingnumber"}B= grep {$_->pairingNumber == $member->{"pairingnumber"};} @$lineup
ABresult
0X0
100
111
187 4 my $ided;
188 4 ▶ if ($ided = first { $_->oldId and $_->oldId eq $member->{id} } @$lineup)
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 2 branches
BranchTrueFalseTotal
if ($ided = &first(sub { $_->oldId and $_->oldId eq $member->{"id"}; } , @$lineup)) 0 4 4
$_->oldId and $_->oldId eq $member->{"id"} 0 16 16
189 {
190 0 $member->{pairingnumber} = $ided->pairingNumber;
191 }
192 }
193 1 DumpFile '../../league.yaml', $league;
194 }
195  
196  
197 1 $schedule->{firstround} = $swiss->firstround($firstround);
198 1 $schedule->{scores} = $swiss->scores($scores);
199 1 $schedule->{roles} = $swiss->roles($roles);
200 1 $schedule->{algorithm} = $swiss->algorithm($algorithm);
201 1 $schedule->{round} = $next;
202 1 $schedule->{week} = $next . ' perhaps. Change if wrong.';
203  
204 1 DumpFile 'player.yaml', $tourney->entrants;
205 1 DumpFile 'tourney.yaml', $tourney;
206 1 DumpFile 'pairing.yaml', $pairing;
207 1 DumpFile 'matches.yaml', \@games;
208 1 DumpFile 'brackets.yaml', \%brackets;
209 1 DumpFile 'round.yaml', $schedule;
210  
211 __END__
« script_files/pairingtable ↑ Summary script_files/pair »