line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#=============================================================================== |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# FILE: Games::Go::AGA::Parse::Util.pm |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# PODNAME: Games::Go::AGA::Parse::Util |
6
|
|
|
|
|
|
|
# ABSTRACT: Utilities to help Parse lines from AGA format files |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# AUTHOR: Reid Augustin (REID), |
9
|
|
|
|
|
|
|
# COMPANY: LucidPort Technology, Inc. |
10
|
|
|
|
|
|
|
# CREATED: Thu Jan 27 09:22:26 PST 2011 |
11
|
|
|
|
|
|
|
#=============================================================================== |
12
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
68
|
use 5.008; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
125
|
|
14
|
3
|
|
|
3
|
|
15
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
93
|
|
15
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
23
|
|
|
3
|
|
|
|
|
130
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
package Games::Go::AGA::Parse::Util; |
18
|
3
|
|
|
3
|
|
14
|
use parent 'Exporter'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
16
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
21
|
|
|
|
|
|
|
is_ID |
22
|
|
|
|
|
|
|
is_Rank |
23
|
|
|
|
|
|
|
is_Rating |
24
|
|
|
|
|
|
|
is_Rank_or_Rating |
25
|
|
|
|
|
|
|
normalize_ID |
26
|
|
|
|
|
|
|
Rank_to_Rating |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
3
|
|
|
3
|
|
318
|
use Scalar::Util qw( looks_like_number ); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
151
|
|
30
|
3
|
|
|
3
|
|
18
|
use Carp; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
2030
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our $VERSION = '0.042'; # VERSION |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub is_ID { |
35
|
5
|
|
|
5
|
1
|
8
|
my ($token) = @_; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
return ( |
38
|
5
|
|
33
|
|
|
71
|
defined $token and # of course |
39
|
|
|
|
|
|
|
$token =~ /^\w+$/ and # only alphanums and underscore |
40
|
|
|
|
|
|
|
$token =~ /^\D/ # not digit in first position |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub is_Rank { |
45
|
32
|
|
|
32
|
1
|
39
|
my ($token) = @_; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
return ( |
48
|
32
|
|
33
|
|
|
405
|
defined $token and |
49
|
|
|
|
|
|
|
(($token =~ m/^(\d+)[dD]$/ and |
50
|
|
|
|
|
|
|
$1 >= 1 and |
51
|
|
|
|
|
|
|
$1 < 20) |
52
|
|
|
|
|
|
|
or |
53
|
|
|
|
|
|
|
($token =~ m/^(\d+)[kK]$/ and |
54
|
|
|
|
|
|
|
$1 >= 1 and |
55
|
|
|
|
|
|
|
$1 < 100) |
56
|
|
|
|
|
|
|
) |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub is_Rating { |
61
|
51
|
|
|
51
|
1
|
53
|
my ($token) = @_; |
62
|
|
|
|
|
|
|
|
63
|
51
|
|
66
|
|
|
359
|
return (looks_like_number($token) and |
64
|
|
|
|
|
|
|
(($token < 20.0 and |
65
|
|
|
|
|
|
|
$token >= 1.0) or |
66
|
|
|
|
|
|
|
($token <= -1.0 and |
67
|
|
|
|
|
|
|
$token > -100.0))); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub is_Rank_or_Rating { |
71
|
39
|
|
|
39
|
1
|
48
|
my ($token) = @_; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
return ( |
74
|
39
|
|
100
|
|
|
60
|
is_Rating($token) or |
75
|
|
|
|
|
|
|
is_Rank($token) |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub normalize_ID { |
80
|
17
|
|
|
17
|
1
|
27
|
my ($id) = @_; |
81
|
|
|
|
|
|
|
|
82
|
17
|
|
|
|
|
30
|
$id = uc $id; |
83
|
17
|
100
|
|
|
|
65
|
$id = "USA$id" if ($id =~ m/^\d/); |
84
|
|
|
|
|
|
|
# remove preceding 0 from numeric parts: X0010 => X10 |
85
|
17
|
|
|
|
|
66
|
$id =~ s/([\D])0+(\d)/$1$2/g; |
86
|
|
|
|
|
|
|
# shorten remaining sequences of 0: A000B => A0B |
87
|
17
|
|
|
|
|
28
|
$id =~ s/00+(\D)/0$1/g; |
88
|
17
|
|
|
|
|
49
|
return $id; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub Rank_to_Rating { |
92
|
0
|
|
|
0
|
1
|
|
my ($rank) = @_; |
93
|
|
|
|
|
|
|
|
94
|
0
|
0
|
0
|
|
|
|
if (is_Rank($rank) and |
|
|
0
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$rank =~ m/(\d+)([dkDK])/) { |
96
|
0
|
0
|
|
|
|
|
if (lc $2 eq 'k') { |
97
|
0
|
|
|
|
|
|
return -0.5 - $1; |
98
|
|
|
|
|
|
|
} |
99
|
0
|
|
|
|
|
|
return 0.5 + $1; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
elsif (is_Rating($rank)) { |
102
|
0
|
|
|
|
|
|
return $rank; |
103
|
|
|
|
|
|
|
} |
104
|
0
|
|
|
|
|
|
croak("$rank is not a rank or a rating"); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
__END__ |