Skip to content

Instantly share code, notes, and snippets.

@ehershey
Created October 13, 2017 21:50
Show Gist options
  • Save ehershey/b02168d44b25b18a63a3a0c1af572727 to your computer and use it in GitHub Desktop.
Save ehershey/b02168d44b25b18a63a3a0c1af572727 to your computer and use it in GitHub Desktop.

Revisions

  1. ehershey created this gist Oct 13, 2017.
    47 changes: 47 additions & 0 deletions pivot-distros.pl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    #!/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";
    }