Skip to content

Instantly share code, notes, and snippets.

@ehershey
Created October 13, 2017 21:50
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 ehershey/b02168d44b25b18a63a3a0c1af572727 to your computer and use it in GitHub Desktop.
Save ehershey/b02168d44b25b18a63a3a0c1af572727 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
# input is TSV in format with headers below from spreadsheet e.g. https://docs.google.com/spreadsheets/d/19itb2SErcZXT8AeCPylTZ0pXaTyZMwl5ncsGZ0ajsJM/edit#gid=0
# month, project, distro, cost, hours, tasks
#
# Output is TSV with column per distro suitable for stacked area chart
#
#
use Data::Dumper;
my $data = {};
while(<>) {
($month,$project,$distro,$cost,$hours,$tasks) = split(/\t/);
$data->{$month}->{$distro} += $cost;
}
print "Month\t";
@months = keys $data;
@distros = sort keys $data->{$months[0]};
for $distro (@distros) {
print "$distro\t";
}
print "\n";
# print Dumper \@distros;
# print Dumper($data);
#
for $month (sort keys $data) {
# skip header data, numeric month lines only
#next unless $month =~ /^\d/;
print "$month\t";
for $distro (@distros) {
if(! $data->{$month}->{$distro}) {
print "0";
}
else {
print $data->{$month}->{$distro};
}
print "\t";
}
print "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment