parses it all now properly and script produces pretty output
This commit is contained in:
parent
0105e7a763
commit
d431e31f69
|
@ -1,2 +1,143 @@
|
|||
#!/usr/local/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Getopt::Long;
|
||||
use Git::PunchCard;
|
||||
use Term::ANSIColor;
|
||||
use Text::Table;
|
||||
|
||||
sub help{
|
||||
&version;
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
sub version{
|
||||
print "punchcard-git v. 0.0.0\n";
|
||||
}
|
||||
|
||||
my @colors=(
|
||||
'WHITE',
|
||||
'BRIGHT_WHITE',
|
||||
'BLUE',
|
||||
'BRIGHT_BLUE',
|
||||
'GREEN',
|
||||
'BRIGHT_GREEN',
|
||||
'CYAN',
|
||||
'BRIGHT_CYAN',
|
||||
'YELLOW',
|
||||
'BRIGHT_YELLOW',
|
||||
'MAGENTA',
|
||||
'BRIGHT_MAGENTA',
|
||||
'RED',
|
||||
'BRIGHT_RED'
|
||||
);
|
||||
|
||||
my @days=(
|
||||
'Sun',
|
||||
'Mon',
|
||||
'Tue',
|
||||
'Wed',
|
||||
'Thu',
|
||||
'Fri',
|
||||
'Sat',
|
||||
);
|
||||
|
||||
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',
|
||||
);
|
||||
|
||||
my $help;
|
||||
my $version;
|
||||
|
||||
GetOptions(
|
||||
'help' => \$help,
|
||||
'version' => \$version,
|
||||
);
|
||||
|
||||
if ($version){
|
||||
&version;
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($help){
|
||||
&help;
|
||||
}
|
||||
|
||||
my $gpc=Git::PunchCard->new;
|
||||
$gpc->dir( $ARGV[0] );
|
||||
|
||||
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'
|
||||
);
|
||||
|
||||
my $card=$gpc->get_card;
|
||||
my @data;
|
||||
|
||||
foreach my $day ( @days ){
|
||||
my @line;
|
||||
|
||||
push( @line, $day );
|
||||
|
||||
foreach my $hour ( @hours ){
|
||||
my $color_to_use=13*($card->{$day}{$hour}/$card->{hourly_max});
|
||||
push( @line, color($colors[$color_to_use]).$card->{$day}{$hour}.color('WHITE') );
|
||||
}
|
||||
|
||||
push( @line, $card->{$day}{total}.color('WHITE') );
|
||||
|
||||
push( @data, \@line );
|
||||
}
|
||||
|
||||
$table->load( @data );
|
||||
|
||||
print $table;
|
||||
|
|
|
@ -3,18 +3,20 @@ package Git::PunchCard;
|
|||
use 5.006;
|
||||
use strict;
|
||||
use warnings;
|
||||
use base 'Error::Helper';
|
||||
use Cwd;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Git::PunchCard - The great new Git::PunchCard!
|
||||
Git::PunchCard - Gathers info for making punchcard style graphs for git.
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
Version 0.01
|
||||
Version 0.0.0
|
||||
|
||||
=cut
|
||||
|
||||
our $VERSION = '0.01';
|
||||
our $VERSION = '0.0.0';
|
||||
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
@ -24,9 +26,15 @@ Quick summary of what the module does.
|
|||
Perhaps a little code snippet.
|
||||
|
||||
use Git::PunchCard;
|
||||
use Data::Dumper;
|
||||
|
||||
my $foo = Git::PunchCard->new();
|
||||
...
|
||||
my $gpc = Git::PunchCard->new();
|
||||
|
||||
$gpc->dir($some_git_repo_dir);
|
||||
if ( $gpc->error ){
|
||||
print "Could not process the directory.\n";
|
||||
}
|
||||
print Dumper( $gpc );
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
|
@ -35,18 +43,277 @@ if you don't export anything, such as for a purely object-oriented module.
|
|||
|
||||
=head1 SUBROUTINES/METHODS
|
||||
|
||||
=head2 function1
|
||||
=head2 new
|
||||
|
||||
Inits the object.
|
||||
|
||||
=cut
|
||||
|
||||
sub function1 {
|
||||
sub new {
|
||||
my $self={
|
||||
perror=>undef,
|
||||
error=>undef,
|
||||
errorString=>'',
|
||||
errorExtra=>{
|
||||
flags=>{
|
||||
1=>'gitError',
|
||||
},
|
||||
},
|
||||
card=>{
|
||||
total=>0,
|
||||
hourly_max=>0,
|
||||
Sun=>{
|
||||
total=>0,
|
||||
'00'=>0,
|
||||
'01'=>0,
|
||||
'02'=>0,
|
||||
'03'=>0,
|
||||
'04'=>0,
|
||||
'05'=>0,
|
||||
'06'=>0,
|
||||
'07'=>0,
|
||||
'08'=>0,
|
||||
'09'=>0,
|
||||
'10'=>0,
|
||||
'11'=>0,
|
||||
'12'=>0,
|
||||
'13'=>0,
|
||||
'14'=>0,
|
||||
'15'=>0,
|
||||
'16'=>0,
|
||||
'17'=>0,
|
||||
'18'=>0,
|
||||
'19'=>0,
|
||||
'20'=>0,
|
||||
'21'=>0,
|
||||
'22'=>0,
|
||||
'23'=>0,
|
||||
},
|
||||
Mon=>{
|
||||
total=>0,
|
||||
'00'=>0,
|
||||
'01'=>0,
|
||||
'02'=>0,
|
||||
'03'=>0,
|
||||
'04'=>0,
|
||||
'05'=>0,
|
||||
'06'=>0,
|
||||
'07'=>0,
|
||||
'08'=>0,
|
||||
'09'=>0,
|
||||
'10'=>0,
|
||||
'11'=>0,
|
||||
'12'=>0,
|
||||
'13'=>0,
|
||||
'14'=>0,
|
||||
'15'=>0,
|
||||
'16'=>0,
|
||||
'17'=>0,
|
||||
'18'=>0,
|
||||
'19'=>0,
|
||||
'20'=>0,
|
||||
'21'=>0,
|
||||
'22'=>0,
|
||||
'23'=>0,
|
||||
},
|
||||
Tue=>{
|
||||
total=>0,
|
||||
'00'=>0,
|
||||
'01'=>0,
|
||||
'02'=>0,
|
||||
'03'=>0,
|
||||
'04'=>0,
|
||||
'05'=>0,
|
||||
'06'=>0,
|
||||
'07'=>0,
|
||||
'08'=>0,
|
||||
'09'=>0,
|
||||
'10'=>0,
|
||||
'11'=>0,
|
||||
'12'=>0,
|
||||
'13'=>0,
|
||||
'14'=>0,
|
||||
'15'=>0,
|
||||
'16'=>0,
|
||||
'17'=>0,
|
||||
'18'=>0,
|
||||
'19'=>0,
|
||||
'20'=>0,
|
||||
'21'=>0,
|
||||
'22'=>0,
|
||||
'23'=>0,
|
||||
},
|
||||
Wed=>{
|
||||
total=>0,
|
||||
'00'=>0,
|
||||
'01'=>0,
|
||||
'02'=>0,
|
||||
'03'=>0,
|
||||
'04'=>0,
|
||||
'05'=>0,
|
||||
'06'=>0,
|
||||
'07'=>0,
|
||||
'08'=>0,
|
||||
'09'=>0,
|
||||
'10'=>0,
|
||||
'11'=>0,
|
||||
'12'=>0,
|
||||
'13'=>0,
|
||||
'14'=>0,
|
||||
'15'=>0,
|
||||
'16'=>0,
|
||||
'17'=>0,
|
||||
'18'=>0,
|
||||
'19'=>0,
|
||||
'20'=>0,
|
||||
'21'=>0,
|
||||
'22'=>0,
|
||||
'23'=>0,
|
||||
},
|
||||
Thu=>{
|
||||
total=>0,
|
||||
'00'=>0,
|
||||
'01'=>0,
|
||||
'02'=>0,
|
||||
'03'=>0,
|
||||
'04'=>0,
|
||||
'05'=>0,
|
||||
'06'=>0,
|
||||
'07'=>0,
|
||||
'08'=>0,
|
||||
'09'=>0,
|
||||
'10'=>0,
|
||||
'11'=>0,
|
||||
'12'=>0,
|
||||
'13'=>0,
|
||||
'14'=>0,
|
||||
'15'=>0,
|
||||
'16'=>0,
|
||||
'17'=>0,
|
||||
'18'=>0,
|
||||
'19'=>0,
|
||||
'20'=>0,
|
||||
'21'=>0,
|
||||
'22'=>0,
|
||||
'23'=>0,
|
||||
},
|
||||
Fri=>{
|
||||
total=>0,
|
||||
'00'=>0,
|
||||
'01'=>0,
|
||||
'02'=>0,
|
||||
'03'=>0,
|
||||
'04'=>0,
|
||||
'05'=>0,
|
||||
'06'=>0,
|
||||
'07'=>0,
|
||||
'08'=>0,
|
||||
'09'=>0,
|
||||
'10'=>0,
|
||||
'11'=>0,
|
||||
'12'=>0,
|
||||
'13'=>0,
|
||||
'14'=>0,
|
||||
'15'=>0,
|
||||
'16'=>0,
|
||||
'17'=>0,
|
||||
'18'=>0,
|
||||
'19'=>0,
|
||||
'20'=>0,
|
||||
'21'=>0,
|
||||
'22'=>0,
|
||||
'23'=>0,
|
||||
},
|
||||
Sat=>{
|
||||
total=>0,
|
||||
'00'=>0,
|
||||
'01'=>0,
|
||||
'02'=>0,
|
||||
'03'=>0,
|
||||
'04'=>0,
|
||||
'05'=>0,
|
||||
'06'=>0,
|
||||
'07'=>0,
|
||||
'08'=>0,
|
||||
'09'=>0,
|
||||
'10'=>0,
|
||||
'11'=>0,
|
||||
'12'=>0,
|
||||
'13'=>0,
|
||||
'14'=>0,
|
||||
'15'=>0,
|
||||
'16'=>0,
|
||||
'17'=>0,
|
||||
'18'=>0,
|
||||
'19'=>0,
|
||||
'20'=>0,
|
||||
'21'=>0,
|
||||
'22'=>0,
|
||||
'23'=>0,
|
||||
},
|
||||
},
|
||||
};
|
||||
bless $self;
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
=head2 function2
|
||||
|
||||
=cut
|
||||
|
||||
sub function2 {
|
||||
sub dir {
|
||||
my $self=$_[0];
|
||||
my $dir=$_[1];
|
||||
|
||||
if( ! $self->errorblank ){
|
||||
return undef;
|
||||
}
|
||||
|
||||
if (! defined( $dir ) ){
|
||||
$dir=getcwd;
|
||||
}
|
||||
|
||||
chdir( $dir );
|
||||
|
||||
my $output=`git log --pretty=format:"%ad" --date=local --date=format:'%a %H'`;
|
||||
if ( $? != 0){
|
||||
$self->{error}=1;
|
||||
$self->{errorString}='"--pretty=format:\"%ad\" --date=local --date=format:\'%a %H\'" exited with a non-zero value';
|
||||
$self->warn;
|
||||
}
|
||||
|
||||
my @lines=split(/\n/, $output);
|
||||
|
||||
foreach my $line ( @lines ){
|
||||
my ($day, $hour)=split(/\ +/, $line);
|
||||
|
||||
# Should never be undef, but just make sure.
|
||||
if (
|
||||
defined( $day ) &&
|
||||
defined( $hour )
|
||||
){
|
||||
# increment the one we hit on
|
||||
$self->{card}{$day}{$hour}++;
|
||||
$self->{card}{$day}{total}++;
|
||||
$self->{card}{total}++;
|
||||
|
||||
if ( $self->{card}{$day}{$hour} > $self->{card}{hourly_max}){
|
||||
$self->{card}{hourly_max}=$self->{card}{$day}{$hour};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub get_card{
|
||||
my $self=$_[0];
|
||||
my $dir=$_[1];
|
||||
|
||||
if( ! $self->errorblank ){
|
||||
return undef;
|
||||
}
|
||||
|
||||
return $self->{card};
|
||||
}
|
||||
|
||||
=head1 AUTHOR
|
||||
|
|
Loading…
Reference in New Issue