Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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