Skip to content

Instantly share code, notes, and snippets.

@davidalbertonogueira
Last active July 26, 2019 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidalbertonogueira/dfc1b114285523cf4367351a7ab92896 to your computer and use it in GitHub Desktop.
Save davidalbertonogueira/dfc1b114285523cf4367351a7ab92896 to your computer and use it in GitHub Desktop.
Script to generate data similar to what's shown in post 'At what time of day does famous programmers work? Part 2. Workweek vs Weekend.', but with daily statistics — based on https://ivan.bessarabov.com/blog/famous-programmers-work-time-part-2-workweek-vs-weekend
#!/usr/bin/perl
#this script is made to show graphs with git commit time made on monday vs tuesday vs wednesday vs thursday vs friday vs saturday vs sunday
#
# The desription of this script and results of its usage is avaliable at:
# https://ivan.bessarabov.com/blog/famous-programmers-work-time-part-2-workweek-vs-weekend
#
# 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 %monday;
my %tuesday;
my %wednesday;
my %thursday;
my %friday;
my %saturday;
my %sunday;
sub is_monday {
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 == 1;
}
sub is_tuesday {
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 == 2;
}
sub is_wednesday {
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 == 3;
}
sub is_thursday {
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 == 4;
}
sub is_friday {
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 == 5;
}
sub is_saturday {
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 == 6;
}
sub 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 ;
}
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_monday($date)) {
$monday{$hour}++;
} elsif (is_tuesday($date)) {
$tuesday{$hour}++;
} elsif (is_wednesday($date)) {
$wednesday{$hour}++;
} elsif (is_thursday($date)) {
$thursday{$hour}++;
} elsif (is_friday($date)) {
$friday{$hour}++;
} elsif (is_saturday($date)) {
$saturday{$hour}++;
} elsif (is_sunday($date)) {
$sunday{$hour}++;
}
}
my $max = max(values(%monday),values(%tuesday),values(%wednesday),values(%thursday),values(%friday),values(%saturday), values(%sunday));
my $format = "%6s %6s %-30s %6s %-30s %6s %-30s %6s %-30s %6s %-30s %6s %-30s %6s %-30s",
say '';
say sprintf $format, 'hour', '', 'Monday', '', 'Tuesday', '', 'Wednesday', '', 'Thursday', '', 'Friday', '', 'Saturday', '', 'Sunday';
foreach my $hour (0..23) {
$monday{$hour} //= 0;
$tuesday{$hour} //= 0;
$wednesday{$hour} //= 0;
$thursday{$hour} //= 0;
$friday{$hour} //= 0;
$saturday{$hour} //= 0;
$sunday{$hour} //= 0;
say sprintf $format,
sprintf('%02d', $hour),
$monday{$hour},
'*' x ($monday{$hour} / $max * 25),
$tuesday{$hour},
'*' x ($tuesday{$hour} / $max * 25),
$wednesday{$hour},
'*' x ($wednesday{$hour} / $max * 25),
$thursday{$hour},
'*' x ($thursday{$hour} / $max * 25),
$friday{$hour},
'*' x ($friday{$hour} / $max * 25),
$saturday{$hour},
'*' x ($saturday{$hour} / $max * 25),
$sunday{$hour},
'*' x ($sunday{$hour} / $max * 25),
;
}
my $total_commits_monday = sum(values %monday);
my $total_commits_tuesday = sum(values %tuesday);
my $total_commits_wednesday = sum(values %wednesday);
my $total_commits_thursday = sum(values %thursday);
my $total_commits_friday = sum(values %friday);
my $total_commits_saturday = sum(values %saturday);
my $total_commits_sunday = sum(values %sunday);
my $total_commits = $total_commits_monday + $total_commits_tuesday + $total_commits_wednesday + $total_commits_thursday + $total_commits_friday + $total_commits_saturday + $total_commits_sunday;
say '';
say sprintf $format,
'Total:',
$total_commits_monday,
sprintf('(%.1f%%)', $total_commits_monday * 100 / $total_commits),
$total_commits_tuesday,
sprintf('(%.1f%%)', $total_commits_tuesday * 100 / $total_commits),
$total_commits_wednesday,
sprintf('(%.1f%%)', $total_commits_wednesday * 100 / $total_commits),
$total_commits_thursday,
sprintf('(%.1f%%)', $total_commits_thursday * 100 / $total_commits),
$total_commits_friday,
sprintf('(%.1f%%)', $total_commits_friday * 100 / $total_commits),
$total_commits_saturday,
sprintf('(%.1f%%)', $total_commits_saturday * 100 / $total_commits),
$total_commits_sunday,
sprintf('(%.1f%%)', $total_commits_sunday* 100 / $total_commits),
;
say '';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment