Skip to content

Instantly share code, notes, and snippets.

@dolmen
Created August 30, 2010 22:29
Show Gist options
  • Save dolmen/558153 to your computer and use it in GitHub Desktop.
Save dolmen/558153 to your computer and use it in GitHub Desktop.
Kwalitee rank for an Acme::CPANAuthors list (from CPANTS)
#!/usr/bin/perl
# Author: Olivier Mengué
# 2010-08-21
use utf8;
use strict;
use warnings;
use Acme::CPANAuthors;
use ORDB::CPANTS 0.05;
use List::Util qw(reduce);
my $cat = $ARGV[0];
my $authors = Acme::CPANAuthors->new($cat);
sub get_kwalitee_rank_online
{
my $pauseid = shift;
my $k = $authors->kwalitee($_);
($k->{info}{Rank}, 0+keys %{$k->{distributions}}, 0)
}
sub get_kwalitee_rank_cache
{
my $pauseid = shift;
my ($a) = ORDB::CPANTS::Author->select('where pauseid = ?', $pauseid);
($a->rank, $a->num_dists, $a->average_kwalitee)
}
my @ids = $authors->id;
#our ($a, $b);
my $max_id_len = reduce { my $l = length $b; $l > $a ? $l : $a } 0, @ids;
my @table =
# [ Rank, Dists, AvgKwalitee, ID, Name ]
sort { $a->[0] <=> $b->[0] || $b->[1] <=> $a->[1] || $a->[2] cmp $b->[3] }
map {
my ($rank, $dists, $kwal) = get_kwalitee_rank_cache($_);
$dists ? ([ $rank, $dists, $kwal, $_, $authors->name($_) ]) : ()
}
@ids;
printf "Rang Dists Kwal \%${max_id_len}s Nom\n", "ID";
foreach (@table) {
printf "%4d %5d %6.2f \%${max_id_len}s %s\n", @{$_};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment