Skip to content

Instantly share code, notes, and snippets.

@neilb
Last active August 29, 2015 13:56
Show Gist options
  • Save neilb/9083411 to your computer and use it in GitHub Desktop.
Save neilb/9083411 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/perl
#
# cpan-user-release-history - take a PAUSE id and generate an ascii graph of their # releases by year
#
use strict;
use warnings;
use CPAN::ReleaseHistory 0.02;
my $MAX_BAR_SIZE = 50;
my $iterator = CPAN::ReleaseHistory->new()->release_iterator();
my %by_year;
die "usage: $0 <PAUSE-ID>\n" unless @ARGV == 1;
my $user = uc($ARGV[0]);
while (my $release = $iterator->next_release) {
next unless defined($release->distinfo)
&& defined($release->distinfo->cpanid)
&& $release->distinfo->cpanid eq $user;
my $year = (gmtime($release->timestamp))[5] + 1900;
$by_year{$year}++;
}
my $max = (sort { $b <=> $a } values %by_year)[0];
my $scale = $max < $MAX_BAR_SIZE ? 1 : $max / $MAX_BAR_SIZE;
my ($first_year, $last_year) = (sort keys %by_year)[0,-1];
foreach my $year ($first_year .. $last_year) {
printf " %d (%3d) %s\n", $year, $by_year{$year}//0, '#' x (($by_year{$year}//0) / $scale);
}
@book
Copy link

book commented Feb 19, 2014

I went the ad-hoc way, and used the cpan-once-a-week-data repository and the following command-line (I'm user 1306):

grep ^1306, releases.csv  \
| perl -lanF, -MPOSIX=strftime -le 'print strftime "%Y", gmtime $F[2]' \
| uniq -c \
| perl -lan -e 'printf "    %d (%2d) %s\n", $F[1],$F[0], "*"x ($F[0]/1.5)'

I hope all those scripts you write end up in the distribution (possibly with a main script as the entry point).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment