From 999703ae47aae9efbd418f181da4abf2b6218a3d Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Mon, 1 Aug 2011 17:13:15 +0200 Subject: [PATCH] Prepare dataset to include author-specific data --- git-chart | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/git-chart b/git-chart index 65d64ec..c6450f8 100755 --- a/git-chart +++ b/git-chart @@ -100,6 +100,7 @@ sub gather_data($) { my %dataset; for my $commit (@commits) { my $date = $commit->{date}; + my $author = $commit->{author}; my $key; if (exists $trunc{$step}) { # LOL -- no, seriously, is there a smarter way to do this? @@ -114,15 +115,19 @@ sub gather_data($) { } else { $key = $date - ($date % $step); } - if (exists $dataset{$key}) { - $dataset{$key} += 1; - } else { - $dataset{$key} = 1; - } + + # make sure the value is a hash + $dataset{$key} = {_commits => 0} unless exists $dataset{$key}; + $dataset{_authors} = { $author => 0} unless exists $dataset{_authors}; + + $dataset{$key}{_commits} += 1; + $dataset{$key}{$author} += 1; + $dataset{_authors}{$author} += 1; } # fill missing steps and find max my @keys = sort keys %dataset; + pop @keys; # get rid of _authors # ensure numeric step, taking into account # that our numerical steps are approximate @@ -135,13 +140,13 @@ sub gather_data($) { my $max = 0; my $key = shift @keys; while (1) { - $max = $dataset{$key} if $max < $dataset{$key}; + $max = $dataset{$key}{_commits} if $max < $dataset{$key}{_commits}; my $next_step = $key + $step; my $next = shift @keys; last unless $next; while (abs($next - $next_step) > $tolerance) { # next step is too far away - $dataset{$next_step} = 0; + $dataset{$next_step} = {_commits => 0}; $next_step += $step; } $key = $next; @@ -172,12 +177,14 @@ sub google_chart($;$) { my $max = $options->{max}; my @keys = sort keys %$dataset; + pop @keys; # get rid of _authors + my $from = $keys[0]; my $to = $keys[@keys-1]; my @data; while (my $key = shift @keys) { - push @data, $dataset->{$key}; + push @data, $dataset->{$key}{_commits}; } my $width=ceil(4*$height/3); @@ -198,14 +205,27 @@ sub gnuplot_chart($;$) { $dataset = gather_data($options); } + my $authors = delete $dataset->{_authors}; + my @authors = sort { $authors->{$a} <=> $authors->{$b} } keys %$authors; + $authors = join "\t", map { "\"$_\"" } @authors; + my @keys = sort keys %$dataset; + my $step=$options->{step}; my $from = $keys[0]; my $to = $keys[$#keys]; - my $data = "date\tcommits\n"; + my $data = "date\tcommits\t$authors\n"; while (my $key = shift @keys) { - $data .= "$key\t$dataset->{$key}\n"; + $data .= "$key\t$dataset->{$key}{_commits}"; + foreach my $author (@authors) { + if (exists $dataset->{$key}{$author}) { + $data .= "\t$dataset->{$key}{$author}"; + } else { + $data .= "\t0"; + } + } + $data .= "\n"; } my $max = $options->{max} + 1; @@ -216,7 +236,11 @@ sub gnuplot_chart($;$) { } else { $to += $step; } - $data .="$to\t0\n"; + $data .="$to\t0"; + foreach my $author (@authors) { + $data .= "\t0"; + } + $data .= "\n"; # TODO allow customization # in particular, detect (lack of) display and set term to dumb accordingly -- 2.32.0.93.g670b81a890