line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Jenkins::i18n::Stats; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
73139
|
use 5.014004; |
|
2
|
|
|
|
|
18
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
60
|
|
5
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
63
|
|
6
|
2
|
|
|
2
|
|
11
|
use base qw(Class::Accessor); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1155
|
|
7
|
2
|
|
|
2
|
|
4394
|
use Hash::Util qw(lock_keys); |
|
2
|
|
|
|
|
2890
|
|
|
2
|
|
|
|
|
13
|
|
8
|
2
|
|
|
2
|
|
144
|
use Carp qw(confess); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
78
|
|
9
|
2
|
|
|
2
|
|
463
|
use Set::Tiny; |
|
2
|
|
|
|
|
1326
|
|
|
2
|
|
|
|
|
1370
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my @ATTRIBUTES = qw(files missing unused empty same no_jenkins keys); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
__PACKAGE__->follow_best_practice; |
14
|
|
|
|
|
|
|
__PACKAGE__->mk_ro_accessors(@ATTRIBUTES); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=pod |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 NAME |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Jenkins::i18n::Stats - class to provide translations processing statistics |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use Jenkins::i18n::Stats; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 DESCRIPTION |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
C |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 EXPORT |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
None by default. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 METHODS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 new |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Creates a new instance. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub new { |
46
|
2
|
|
|
2
|
1
|
95
|
my $class = shift; |
47
|
2
|
|
|
|
|
6
|
my $self = {}; |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
5
|
foreach my $attrib (@ATTRIBUTES) { |
50
|
14
|
|
|
|
|
29
|
$self->{$attrib} = 0; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
2
|
|
|
|
|
11
|
$self->{unique_keys} = Set::Tiny->new; |
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
|
|
21
|
bless $self, $class; |
56
|
2
|
|
|
|
|
4
|
lock_keys( %{$self} ); |
|
2
|
|
|
|
|
18
|
|
57
|
2
|
|
|
|
|
32
|
return $self; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 get_keys |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Return the number of all keys retrieve from all files processed, ignoring if |
63
|
|
|
|
|
|
|
they are repeated several times. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 get_files |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Returns the number of found translation files. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 get_missing |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Returns the number of keys that are missing after comparing a language to the |
72
|
|
|
|
|
|
|
original in English. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 get_unused |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Returns the number of keys that are available in the a language but not in the |
77
|
|
|
|
|
|
|
original English. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 get_empty |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Returns the number of keys in the language that are available but doesn't |
82
|
|
|
|
|
|
|
actually have a translated value. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 get_same |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Returns the number of keys that have the same values as the original in |
87
|
|
|
|
|
|
|
English. Not necessarilly an error. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 get_no_jenkins |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Returns the number of keys that are not related to Jenkins, but coming from |
92
|
|
|
|
|
|
|
Hudson. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _inc { |
97
|
13
|
|
|
13
|
|
2050
|
my ( $self, $item ) = @_; |
98
|
13
|
100
|
|
|
|
50
|
confess "item is a required parameter" unless ($item); |
99
|
|
|
|
|
|
|
confess "there is no such counter '$item'" |
100
|
12
|
100
|
|
|
|
49
|
unless ( exists( $self->{$item} ) ); |
101
|
11
|
|
|
|
|
17
|
$self->{$item}++; |
102
|
11
|
|
|
|
|
18
|
return 1; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 inc_files |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Increments the C counter. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub inc_files { |
112
|
2
|
|
|
2
|
1
|
22
|
shift->_inc('files'); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 inc_missing |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Increments the C counter. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub inc_missing { |
122
|
0
|
|
|
0
|
1
|
0
|
shift->_inc('missing'); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 inc_unused |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Increments the C counter. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub inc_unused { |
132
|
0
|
|
|
0
|
1
|
0
|
shift->_inc('unused'); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 inc_empty |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Increments the C counter. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub inc_empty { |
142
|
0
|
|
|
0
|
1
|
0
|
shift->_inc('empty'); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 inc_same |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Increments the C counter. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub inc_same { |
152
|
0
|
|
|
0
|
1
|
0
|
shift->_inc('same'); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 inc_no_jenkins |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Increments the C counter. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub inc_no_jenkins { |
162
|
0
|
|
|
0
|
1
|
0
|
shift->_inc('no_jenkins'); |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head2 add_key |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Increments the keys counters. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
This is required in order to allow the counting of unique keys processed, as |
170
|
|
|
|
|
|
|
well all the keys processed. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=cut |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub add_key { |
175
|
9
|
|
|
9
|
1
|
602
|
my ( $self, $key ) = @_; |
176
|
9
|
|
|
|
|
25
|
$self->_inc('keys'); |
177
|
9
|
|
|
|
|
25
|
$self->{unique_keys}->insert($key); |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 get_unique_keys |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Returns the number of unique keys processed. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=cut |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub get_unique_keys { |
187
|
2
|
|
|
2
|
1
|
862
|
return shift->{unique_keys}->size(); |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub _done { |
191
|
2
|
|
|
2
|
|
6
|
my $self = shift; |
192
|
|
|
|
|
|
|
return ( $self->{keys} |
193
|
|
|
|
|
|
|
- $self->{missing} |
194
|
|
|
|
|
|
|
- $self->{unused} |
195
|
|
|
|
|
|
|
- $self->{empty} |
196
|
|
|
|
|
|
|
- $self->{same} |
197
|
2
|
|
|
|
|
21
|
- $self->{no_jenkins} ); |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head2 perc_done |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Calculates how much of the translation is completed. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Requires no parameters. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Returns a float as the percentage of the translation that is completed. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=cut |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub perc_done { |
211
|
2
|
|
|
2
|
1
|
1275
|
my $self = shift; |
212
|
2
|
|
|
|
|
8
|
return ( ( $self->_done / $self->{keys} ) * 100 ); |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head2 summary |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Returns a summary of all statistics in text format. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
The summary is returned as a hash reference. |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=cut |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
sub summary { |
224
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
225
|
|
|
|
|
|
|
|
226
|
0
|
0
|
|
|
|
|
unless ( $self->{keys} == 0 ) { |
227
|
0
|
|
|
|
|
|
my %summary = ( done => $self->_done, pdone => $self->perc_done ); |
228
|
0
|
|
|
|
|
|
my @wanted = qw(missing unused empty same no_jenkins); |
229
|
|
|
|
|
|
|
|
230
|
0
|
|
|
|
|
|
foreach my $wanted (@wanted) { |
231
|
0
|
|
|
|
|
|
$summary{$wanted} = $self->{$wanted}; |
232
|
0
|
|
|
|
|
|
$summary{"p$wanted"} = $self->{$wanted} / $self->{keys} * 100; |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
0
|
|
|
|
|
|
return \%summary; |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
0
|
|
|
|
|
|
return {}; |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head2 files |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
Getter for the C attribute. |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=cut |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
sub files { |
249
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
250
|
0
|
|
|
|
|
|
return $self->{files}; |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
1; |
254
|
|
|
|
|
|
|
__END__ |