blib/lib/Git/PunchCard.pm

filter: Statementstmt 28.5% 16 / 56 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 62.5% 5 / 8 Podpod 33.3% 1 / 3 totaltotal 24.4% 22 / 90 CC 14 SCAR 47.3
CC
14
Cov
21%
dir
182.0
get_card
6.0
new
2.0
CRAP 113.6
↑ Summary
1 package Git::PunchCard;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use base 'Error::Helper';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 Git::PunchCard - Gathers info for making punchcard style graphs for git.
12  
13 =head1 VERSION
14  
15 Version 0.1.0
16  
17 =cut
18  
19 1 our $VERSION = '0.1.0';
20  
21  
22 =head1 SYNOPSIS
23  
24 Quick summary of what the module does.
25  
26 Perhaps a little code snippet.
27  
28 use Git::PunchCard;
29 use Data::Dumper;
30 use Text::Table;
31
32 my $gpc = Git::PunchCard->new();
33
34 $gpc->dir($some_git_repo_dir);
35 if ( $gpc->error ){
36 print "Could not process the directory.\n";
37 }
38
39 my $card=$gpc->get_card;
40
41 print Dumper( $card );
42
43 # The various keys for the hashes.
44 my @days=('Sun','Mon','Tue','Wed','Thu','Fri','Sat', );
45 my @hours=('00','01','02','03','04','05','06','07','08','09','10', '11','12','13','14','15','16','17','18','19','20','21','22','23');
46
47 # Stores the lines to for the table.
48 my @data;
49  
50 # Process each day hash in $card.
51 foreach my $day ( @days ){
52 my @line;
53
54 # Add the day coloumn to the current line of the table.
55 push( @line, $day );
56
57 # Add each hour entry to the current line of the table.
58 foreach my $hour ( @hours ){
59 push( @line, $card->{$day}{$hour} );
60 }
61
62 # Finally add the total number of entries for that day.
63 push( @line, $card->{$day}{total}.color('WHITE') );
64
65 # add the new line to the table data
66 push( @data, \@line );
67 }
68
69 # Init the Text::Table object and add our headers.
70 my $table=Text::Table->new('','00','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','Total');
71  
72 # Loads the data into the table
73 $table->load( @data );
74
75 # produce some useful? output
76 print $table."\nTotal: ".$card->{total}."\n";
77  
78 =head1 METHODS
79  
80 =head2 new
81  
82 Inits the object.
83  
84 my $gpc->new;
85  
86 =cut
87  
88 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
89 0 my $self={
90 perror=>undef,
91 error=>undef,
92 errorString=>'',
93 errorExtra=>{
94 flags=>{
95 1=>'gitError',
96 },
97 },
98 card=>{
99 total=>0,
100 max=>0,
101 average=>0,
102 min=>9999999999999999999999999999999999,
103 Sun=>{
104 total=>0,
105 max=>0,
106 average=>0,
107 min=>9999999999999999999999999999999999,
108 '00'=>0,
109 '01'=>0,
110 '02'=>0,
111 '03'=>0,
112 '04'=>0,
113 '05'=>0,
114 '06'=>0,
115 '07'=>0,
116 '08'=>0,
117 '09'=>0,
118 '10'=>0,
119 '11'=>0,
120 '12'=>0,
121 '13'=>0,
122 '14'=>0,
123 '15'=>0,
124 '16'=>0,
125 '17'=>0,
126 '18'=>0,
127 '19'=>0,
128 '20'=>0,
129 '21'=>0,
130 '22'=>0,
131 '23'=>0,
132 },
133 Mon=>{
134 total=>0,
135 max=>0,
136 average=>0,
137 min=>9999999999999999999999999999999999,
138 '00'=>0,
139 '01'=>0,
140 '02'=>0,
141 '03'=>0,
142 '04'=>0,
143 '05'=>0,
144 '06'=>0,
145 '07'=>0,
146 '08'=>0,
147 '09'=>0,
148 '10'=>0,
149 '11'=>0,
150 '12'=>0,
151 '13'=>0,
152 '14'=>0,
153 '15'=>0,
154 '16'=>0,
155 '17'=>0,
156 '18'=>0,
157 '19'=>0,
158 '20'=>0,
159 '21'=>0,
160 '22'=>0,
161 '23'=>0,
162 },
163 Tue=>{
164 total=>0,
165 max=>0,
166 average=>0,
167 min=>9999999999999999999999999999999999,
168 '00'=>0,
169 '01'=>0,
170 '02'=>0,
171 '03'=>0,
172 '04'=>0,
173 '05'=>0,
174 '06'=>0,
175 '07'=>0,
176 '08'=>0,
177 '09'=>0,
178 '10'=>0,
179 '11'=>0,
180 '12'=>0,
181 '13'=>0,
182 '14'=>0,
183 '15'=>0,
184 '16'=>0,
185 '17'=>0,
186 '18'=>0,
187 '19'=>0,
188 '20'=>0,
189 '21'=>0,
190 '22'=>0,
191 '23'=>0,
192 },
193 Wed=>{
194 total=>0,
195 max=>0,
196 average=>0,
197 min=>9999999999999999999999999999999999,
198 '00'=>0,
199 '01'=>0,
200 '02'=>0,
201 '03'=>0,
202 '04'=>0,
203 '05'=>0,
204 '06'=>0,
205 '07'=>0,
206 '08'=>0,
207 '09'=>0,
208 '10'=>0,
209 '11'=>0,
210 '12'=>0,
211 '13'=>0,
212 '14'=>0,
213 '15'=>0,
214 '16'=>0,
215 '17'=>0,
216 '18'=>0,
217 '19'=>0,
218 '20'=>0,
219 '21'=>0,
220 '22'=>0,
221 '23'=>0,
222 },
223 Thu=>{
224 total=>0,
225 max=>0,
226 average=>0,
227 min=>9999999999999999999999999999999999,
228 '00'=>0,
229 '01'=>0,
230 '02'=>0,
231 '03'=>0,
232 '04'=>0,
233 '05'=>0,
234 '06'=>0,
235 '07'=>0,
236 '08'=>0,
237 '09'=>0,
238 '10'=>0,
239 '11'=>0,
240 '12'=>0,
241 '13'=>0,
242 '14'=>0,
243 '15'=>0,
244 '16'=>0,
245 '17'=>0,
246 '18'=>0,
247 '19'=>0,
248 '20'=>0,
249 '21'=>0,
250 '22'=>0,
251 '23'=>0,
252 },
253 Fri=>{
254 total=>0,
255 max=>0,
256 average=>0,
257 min=>9999999999999999999999999999999999,
258 '00'=>0,
259 '01'=>0,
260 '02'=>0,
261 '03'=>0,
262 '04'=>0,
263 '05'=>0,
264 '06'=>0,
265 '07'=>0,
266 '08'=>0,
267 '09'=>0,
268 '10'=>0,
269 '11'=>0,
270 '12'=>0,
271 '13'=>0,
272 '14'=>0,
273 '15'=>0,
274 '16'=>0,
275 '17'=>0,
276 '18'=>0,
277 '19'=>0,
278 '20'=>0,
279 '21'=>0,
280 '22'=>0,
281 '23'=>0,
282 },
283 Sat=>{
284 total=>0,
285 max=>0,
286 average=>0,
287 min=>9999999999999999999999999999999999,
288 '00'=>0,
289 '01'=>0,
290 '02'=>0,
291 '03'=>0,
292 '04'=>0,
293 '05'=>0,
294 '06'=>0,
295 '07'=>0,
296 '08'=>0,
297 '09'=>0,
298 '10'=>0,
299 '11'=>0,
300 '12'=>0,
301 '13'=>0,
302 '14'=>0,
303 '15'=>0,
304 '16'=>0,
305 '17'=>0,
306 '18'=>0,
307 '19'=>0,
308 '20'=>0,
309 '21'=>0,
310 '22'=>0,
311 '23'=>0,
312 },
313 },
314 };
315 0 bless $self;
316  
317 0 return $self;
318 }
319  
320  
321 =head2 card
322  
323 One argument is taken and that is the directory to parse in.
324  
325 If one is not passed, the current directory will be used.
326  
327 IF this is called multiple times, each new instance will be added
328 to the current values.
329  
330 $gpc->dir( $dir )
331 if ( $gpc->error ){
332 print "Errored!\n";
333 }
334  
335 =cut
336  
337 0 ▶sub dir {
Subroutine dir: not called CC=13 SCAR=52.0
Pod undocumented
338 0 my $self=$_[0];
339 0 my $dir=$_[1];
340  
341 0 ▶ if( ! $self->errorblank ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
342 0 return undef;
343 }
344  
345 0 ▶ if (! defined( $dir ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dir) 0 0 0
346 0 $dir=getcwd;
347 }
348  
349 0 chdir( $dir );
350  
351 0 my $output=`env LC_ALL=C git log --pretty=format:"%ad" --date=local --date=format:'%a %H'`;
352 0 ▶ if ( $? != 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
353 0 $self->{error}=1;
354 0 $self->{errorString}='"--pretty=format:\"%ad\" --date=local --date=format:\'%a %H\'" exited with a non-zero value';
355 0 $self->warn;
356 }
357  
358 0 my @lines=split(/\n/, $output);
359  
360 0 foreach my $line ( @lines ){
361 0 my ($day, $hour)=split(/\ +/, $line);
362  
363 # Should never be undef, but just make sure.
364 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $day and defined $hour) 0 0 0
Condition0%0/3
defined $day and defined $hour
!ll&&!rl&&r
000
MC/DC0%0/2
defined $day and defined $hour
defined $day defined $hour
Truth table0%0/3
A and B
A= defined $dayB= defined $hour
ABresult
0X0
100
111
365 defined( $day ) &&
366 defined( $hour )
367 ){
368 # increment the one we hit on
369 0 $self->{card}{$day}{$hour}++;
370 0 $self->{card}{$day}{total}++;
371 0 $self->{card}{total}++;
372  
373 0 ▶ if ( $self->{card}{$day}{$hour} > $self->{card}{max}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"card"}{$day}{$hour} > $self->{"card"}{"max"}) 0 0 0
374 0 $self->{card}{max}=$self->{card}{$day}{$hour};
375 }
376 0 ▶ if ( $self->{card}{$day}{$hour} > $self->{card}{$day}{max}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"card"}{$day}{$hour} > $self->{"card"}{$day}{"max"}) 0 0 0
377 0 $self->{card}{$day}{max}=$self->{card}{$day}{$hour};
378 }
379 }
380  
381 0 $self->{card}{$day}{average}= $self->{card}{$day}{total} / 24;
382 }
383  
384 0 $self->{card}{average}= $self->{card}{total} / 168 ;
385  
386 0 foreach my $day ( 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ){
387 0 for my $hour ( '00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23' ){
388 0 ▶ if ( $self->{card}{$day}{$hour} < $self->{card}{$day}{min} ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"card"}{$day}{$hour} < $self->{"card"}{$day}{"min"}) 0 0 0
389 0 $self->{card}{$day}{min}=$self->{card}{$day}{$hour};
390 }
391 0 ▶ if ( $self->{card}{$day}{$hour} < $self->{card}{min} ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"card"}{$day}{$hour} < $self->{"card"}{"min"}) 0 0 0
392 0 $self->{card}{min}=$self->{card}{$day}{$hour};
393 }
394 }
395 }
396  
397
398 0 return 1;
399 }
400  
401 =head get_card
402  
403 This returns the current card data.
404  
405 The returned value is a hashref.
406  
407 The first level keys are the three letter
408 day names the the second level keys are the
409 two digit hour.
410  
411 There are two special keys 'total', 'max', min, and
412 avagerage.
413  
414 'total' represents the total level of commits. So
415 at the primary level it is all the commits made to that
416 repo while and the secondary level it is all the comits
417 made to that repo on that day of the week.
418  
419 'max' is the largest number of commits made. At the primary
420 level it is any hour on any day of the week while at the secondary
421 level it is the max made during any given hour that day.
422  
423 'min' and 'average' is similar as max, but representing the min
424 and average instead.
425  
426 For examples of making use of this, see the SYNOPSIS or check
427 out the script punchard-git.
428  
429 my $card=$gpc->get_card;
430  
431 =cut
432  
433 0 ▶sub get_card{
Subroutine get_card: not called CC=2 SCAR=17.9
Pod undocumented
434 0 my $self=$_[0];
435 0 my $dir=$_[1];
436  
437 0 ▶ if( ! $self->errorblank ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
438 0 return undef;
439 }
440  
441 0 return $self->{card};
442 }
443  
444 =head1 ERROR NUMBERS/FLAGS
445  
446 Error handling is provided by L<Error::Helper>.
447  
448 =head2 1 / gitError
449  
450 Git exited with a non-zero value.
451  
452 =head1 AUTHOR
453  
454 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
455  
456 =head1 BUGS
457  
458 Please report any bugs or feature requests to C<bug-git-punchcard at rt.cpan.org>, or through
459 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Git-PunchCard>. I will be notified, and then you'll
460 automatically be notified of progress on your bug as I make changes.
461  
462  
463  
464  
465 =head1 SUPPORT
466  
467 You can find documentation for this module with the perldoc command.
468  
469 perldoc Git::PunchCard
470  
471  
472 You can also look for information at:
473  
474 =over 4
475  
476 =item * RT: CPAN's request tracker (report bugs here)
477  
478 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Git-PunchCard>
479  
480 =item * AnnoCPAN: Annotated CPAN documentation
481  
482 L<http://annocpan.org/dist/Git-PunchCard>
483  
484 =item * CPAN Ratings
485  
486 L<https://cpanratings.perl.org/d/Git-PunchCard>
487  
488 =item * Search CPAN
489  
490 L<https://metacpan.org/release/Git-PunchCard>
491  
492 =item * Primary Repo
493  
494 L<https://gitea.eesdp.org/vvelox/Git-PunchCard/>
495  
496 =back
497  
498  
499 =head1 ACKNOWLEDGEMENTS
500  
501  
502 =head1 LICENSE AND COPYRIGHT
503  
504 This software is Copyright (c) 2019 by Zane C. Bowers-Hadley.
505  
506 This is free software, licensed under:
507  
508 The Artistic License 2.0 (GPL Compatible)
509  
510  
511 =cut
512  
513 1 1; # End of Git::PunchCard
↑ Summary