-
-
Save wallacesilva/c5136012ad2b5fb0d7a7a4a84163e0e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# usage: | |
# | |
# git log --author="Sebastian Riedel" --format="%H %ai" | perl script.pl | |
# | |
use strict; | |
use warnings FATAL => 'all'; | |
use utf8; | |
use open qw(:std :utf8); | |
use feature qw(say); | |
use List::Util qw(max sum); | |
use Time::Local; | |
my %workweek; | |
my %weekend; | |
sub is_saturday_or_is_sunday { | |
my ($yyyy_mm_dd) = @_; | |
my ($year, $month, $day) = split /-/, $yyyy_mm_dd; | |
my $timestamp = timegm( | |
0, | |
0, | |
0, | |
$day, | |
$month - 1, | |
$year, | |
); | |
my $wday = [gmtime($timestamp)]->[6]; | |
return $wday == 0 || $wday == 6; | |
} | |
while (my $line = <>) { | |
# 181971ff7774853fceb0459966177d51eeab032c 2019-04-26 19:53:58 +0200 | |
my ($commit_hash, $date, $time, $timezone) = split / /, $line; | |
my ($hour, $minute, $second) = split /:/, $time; | |
$hour += 0; | |
if (is_saturday_or_is_sunday($date)) { | |
$weekend{$hour}++; | |
} else { | |
$workweek{$hour}++; | |
} | |
} | |
my $max = max(values(%workweek), values(%weekend)); | |
my $format = "%6s %6s %-30s %6s %-30s", | |
say ''; | |
say sprintf $format, 'hour', '', 'Monday to Friday', '', 'Saturday and Sunday'; | |
foreach my $hour (0..23) { | |
$workweek{$hour} //= 0; | |
$weekend{$hour} //= 0; | |
say sprintf $format, | |
sprintf('%02d', $hour), | |
$workweek{$hour}, | |
'*' x ($workweek{$hour} / $max * 25), | |
$weekend{$hour}, | |
'*' x ($weekend{$hour} / $max * 25), | |
; | |
} | |
my $total_commits_workweek = sum(values %workweek); | |
my $total_commits_weekend = sum(values %weekend); | |
my $total_commits = $total_commits_workweek + $total_commits_weekend; | |
say ''; | |
say sprintf $format, | |
'Total:', | |
$total_commits_workweek, | |
sprintf('(%.1f%%)', $total_commits_workweek * 100 / $total_commits), | |
$total_commits_weekend, | |
sprintf('(%.1f%%)', $total_commits_weekend* 100 / $total_commits), | |
; | |
say ''; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment