| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WWW::GoKGS::Scraper::TournEntrants; |
|
2
|
9
|
|
|
9
|
|
1537
|
use strict; |
|
|
9
|
|
|
|
|
19
|
|
|
|
9
|
|
|
|
|
371
|
|
|
3
|
9
|
|
|
9
|
|
53
|
use warnings; |
|
|
9
|
|
|
|
|
21
|
|
|
|
9
|
|
|
|
|
273
|
|
|
4
|
9
|
|
|
9
|
|
49
|
use parent qw/WWW::GoKGS::Scraper/; |
|
|
9
|
|
|
|
|
20
|
|
|
|
9
|
|
|
|
|
65
|
|
|
5
|
9
|
|
|
9
|
|
611
|
use WWW::GoKGS::Scraper::Declare; |
|
|
9
|
|
|
|
|
17
|
|
|
|
9
|
|
|
|
|
76
|
|
|
6
|
9
|
|
|
9
|
|
636
|
use WWW::GoKGS::Scraper::Filters qw/datetime/; |
|
|
9
|
|
|
|
|
30
|
|
|
|
9
|
|
|
|
|
497
|
|
|
7
|
9
|
|
|
9
|
|
52
|
use WWW::GoKGS::Scraper::TournLinks; |
|
|
9
|
|
|
|
|
34
|
|
|
|
9
|
|
|
|
|
13667
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
10
|
|
|
10
|
1
|
51
|
sub base_uri { 'http://www.gokgs.com/tournEntrants.jsp' } |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub __build_scraper { |
|
12
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
|
13
|
1
|
|
|
|
|
6
|
my $links = $self->__build_tourn_links; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my %user = ( |
|
16
|
0
|
|
|
0
|
|
0
|
name => [ 'TEXT', sub { s/ \[[^\]]+\]$// } ], |
|
17
|
1
|
0
|
|
0
|
|
12
|
rank => [ 'TEXT', sub { m/ \[([^\]]+)\]$/ && $1 } ], |
|
|
0
|
|
|
|
|
0
|
|
|
18
|
|
|
|
|
|
|
); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
scraper { |
|
21
|
0
|
|
|
0
|
|
|
process '//h1', 'name' => [ 'TEXT', sub { s/ Players$// } ]; |
|
|
0
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
process '//a[@href="tzList.jsp"]', 'time_zone' => 'TEXT'; |
|
23
|
|
|
|
|
|
|
process '//table[tr/th[3]/text()="Score"]//following-sibling::tr', |
|
24
|
|
|
|
|
|
|
'entrants[]' => scraper { # Swiss or McMahon |
|
25
|
0
|
|
|
|
|
|
process '//td[1]', 'position' => 'TEXT'; |
|
26
|
0
|
|
|
|
|
|
process '//td[2]', %user; |
|
27
|
0
|
|
|
|
|
|
process '//td[3]', 'score' => 'TEXT'; |
|
28
|
0
|
|
|
|
|
|
process '//td[4]', 'sos' => 'TEXT'; |
|
29
|
0
|
|
|
|
|
|
process '//td[5]', 'sodos' => 'TEXT'; |
|
30
|
0
|
|
|
|
|
|
process '//td[6]', 'notes' => 'TEXT'; }; |
|
|
0
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
process '//table[tr/th[1]/text()="Name"]//following-sibling::tr', |
|
32
|
|
|
|
|
|
|
'entrants[]' => scraper { # Single or Double Elimination |
|
33
|
0
|
|
|
|
|
|
process '//td[1]', %user; |
|
34
|
0
|
|
|
|
|
|
process '//td[2]', 'standing' => 'TEXT'; }; |
|
|
0
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
process '//table[tr/th[3]/text()="#"]//following-sibling::tr', |
|
36
|
|
|
|
|
|
|
'entrants[]' => scraper { # Round Robin |
|
37
|
0
|
|
|
|
|
|
process '//td', 'columns[]' => 'TEXT'; |
|
38
|
0
|
|
|
|
|
|
result 'columns'; }; |
|
|
0
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
process '//div[@class="tournData"]', 'links' => $links; |
|
40
|
1
|
|
|
|
|
9
|
}; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub scrape { |
|
44
|
0
|
|
|
0
|
1
|
|
my ( $self, @args ) = @_; |
|
45
|
0
|
|
|
|
|
|
my $result = $self->SUPER::scrape( @args ); |
|
46
|
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
return $result unless $result->{entrants}; |
|
48
|
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
if ( !$result->{entrants}->[0] ) { # Round Robin |
|
|
|
0
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
shift @{$result->{entrants}}; |
|
|
0
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my @entrants; |
|
53
|
0
|
|
|
|
|
|
my $size = @{$result->{entrants}->[0]}; |
|
|
0
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
for my $entrant ( @{$result->{entrants}} ) { |
|
|
0
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$entrant->[0] =~ s/\(tie\)$//; |
|
56
|
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
push @entrants, { |
|
58
|
|
|
|
|
|
|
position => @$entrant == $size ? int shift @$entrant : $entrants[-1]{position}, |
|
59
|
|
|
|
|
|
|
name => shift @$entrant, |
|
60
|
|
|
|
|
|
|
number => shift @$entrant, |
|
61
|
|
|
|
|
|
|
notes => pop @$entrant, |
|
62
|
|
|
|
|
|
|
score => pop @$entrant, |
|
63
|
|
|
|
|
|
|
results => $entrant, |
|
64
|
|
|
|
|
|
|
}; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
for my $entrant ( @entrants ) { |
|
68
|
0
|
|
|
|
|
|
$entrant->{name} =~ /^([a-zA-Z0-9]+)(?: \[([^\]]+)\])?$/; |
|
69
|
0
|
|
|
|
|
|
$entrant->{name} = $1; |
|
70
|
0
|
|
|
|
|
|
$entrant->{rank} = $2; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my %results; |
|
74
|
0
|
|
|
|
|
|
for my $a ( @entrants ) { |
|
75
|
0
|
0
|
|
|
|
|
next unless $a->{number}; |
|
76
|
0
|
|
|
|
|
|
for my $b ( @entrants ) { |
|
77
|
0
|
0
|
|
|
|
|
next if $b == $a; |
|
78
|
0
|
0
|
|
|
|
|
next unless $b->{number}; |
|
79
|
0
|
|
0
|
|
|
|
$results{$a->{name}}{$b->{name}} |
|
80
|
|
|
|
|
|
|
= $a->{results}->[$b->{number}-1] || q{}; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
delete @{$_}{qw/number results/} for @entrants; |
|
|
0
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
$result->{entrants} = \@entrants; |
|
87
|
0
|
0
|
|
|
|
|
$result->{results} = \%results if %results; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
elsif ( exists $result->{entrants}->[0]->{score} ) { # Swiss or McMahon |
|
90
|
0
|
|
|
|
|
|
my $preceding; |
|
91
|
0
|
|
|
|
|
|
for my $entrant ( @{$result->{entrants}} ) { |
|
|
0
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
$entrant->{position} =~ s/\(tie\)$//; |
|
93
|
0
|
0
|
0
|
|
|
|
next if !$preceding or exists $entrant->{notes}; |
|
94
|
0
|
|
|
|
|
|
$entrant->{notes} = $entrant->{sodos}; |
|
95
|
0
|
|
|
|
|
|
$entrant->{sodos} = $entrant->{sos}; |
|
96
|
0
|
|
|
|
|
|
$entrant->{sos} = $entrant->{score}; |
|
97
|
0
|
|
|
|
|
|
$entrant->{score} = $entrant->{name}; |
|
98
|
0
|
|
|
|
|
|
$entrant->{position} =~ /^([a-zA-Z0-9]+)(?: \[([^\]]+)\])?$/; |
|
99
|
0
|
|
|
|
|
|
$entrant->{name} = $1; |
|
100
|
0
|
|
|
|
|
|
$entrant->{rank} = $2; |
|
101
|
0
|
|
|
|
|
|
$entrant->{position} = $preceding->{position}; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
continue { |
|
104
|
0
|
|
|
|
|
|
$preceding = $entrant; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
else { # Single or Double Elimination |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
for my $entrant ( @{$result->{entrants}} ) { |
|
|
0
|
|
|
|
|
|
|
|
111
|
0
|
0
|
|
|
|
|
delete $entrant->{rank} unless $entrant->{rank}; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
$result; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
__END__ |