CPANTS-Weight
view release on metacpan or search on metacpan
lib/CPANTS/Weight.pm view on Meta::CPAN
my $SELECT_IDS = <<'END_SQL';
select
id
from
dist
where
id > 0
END_SQL
my $SELECT_DEPENDS = <<'END_SQL';
select
dist,
in_dist
from
prereq
where
in_dist is not null
and
dist > 0
and
in_dist > 0
END_SQL
#####################################################################
# Main Methods
# Only used internally, for caching reasons
sub new {
my $class = shift;
my $self = bless { }, $class;
return $self;
}
=pod
=head2 run
CPANTS::Weight->run;
The main C<run> method does a complete generation cycle for the CPANTS
weighting database. It will retrieve the CPANTS data (if needed) calculate
the weights, and then (re)populate the CPANTS-Weight.sqlite database.
Once completed, the C<CPANTS::Weight-E<gt>sqlite> method can be used to
locate the completed SQLite database file.
=cut
sub run {
my $self = ref($_[0]) ? shift : shift->new;
# Run import if we haven't already
ref($self)->import;
# Skip if the output database is newer than the input database
# (but is not a new database)
my $input_t = (stat(ORDB::CPANTS->sqlite ))[9];
my $output_t = (stat(CPANTS::Weight->sqlite))[9];
# if ( $output_t > $input_t and CPANTS::Weight::AuthorWeight->count ) {
# return 1;
# }
# Prefetch the author and dist lists
trace("Loading CPANTS Authors...");
my @authors = ORDB::CPANTS::Author->select(
'where pauseid is not null'
);
trace("Loading CPANTS Distributions...");
my @dists = ORDB::CPANTS::Dist->select(
'where author not in ( select id from author where pauseid is null )'
);
trace("Loading Kwalitee...");
my $kwalitee = ORDB::CPANTS->selectall_hashref(
'select * from kwalitee',
'dist',
);
# Indexed table of weighting scores
trace("Precalculating weight...");
my $weight = $self->algorithm_weight->weight_all;
trace("Precalculating volatility...");
my $volatility = $self->algorithm_volatility->weight_all;
trace("Generating FAIL counts");
my $fails = CPANTS::Weight->fail_report;
# Populate the AuthorWeight objects
trace("Populating Author metrics...");
CPANTS::Weight->begin;
CPANTS::Weight::AuthorWeight->truncate;
foreach my $author ( @authors ) { ### Authors [===| ] % done
# Find the list of distros for this author
my $id = $author->id;
# my @ids = grep { $_->author } @dists;
CPANTS::Weight::AuthorWeight->create(
id => $author->id,
pauseid => $author->pauseid,
);
}
CPANTS::Weight->commit;
# Populate the DistWeight objects
trace("Populating Distribution metrics...");
CPANTS::Weight->begin;
CPANTS::Weight::DistWeight->truncate;
foreach my $dist ( @dists ) { ### Distributions [===| ] % done
my $id = $dist->id;
# Does this distribution make life difficult
# for downstream packagers.
my $k = $kwalitee->{$id} || {};
my $enemy_downstream = $k->{easily_repackagable} ? 0 : 1;
# Is this distribution popular, but NOT provided in
# Debian, making it a good candidate for packaging.
my $debian_candidate = $k->{distributed_by_debian} ? 0 : 1;
( run in 1.743 second using v1.01-cache-2.11-cpan-98e64b0badf )