File Coverage

blib/lib/Algorithm/RankAggregate/AverageRating.pm
Criterion Covered Total %
statement 43 43 100.0
branch 6 10 60.0
condition 2 3 66.6
subroutine 7 7 100.0
pod 1 4 25.0
total 59 67 88.0


line stmt bran cond sub pod time code
1             package Algorithm::RankAggregate::AverageRating;
2              
3 7     7   6305 use strict;
  7         13  
  7         254  
4 7     7   35 use warnings;
  7         11  
  7         343  
5             our $VERSION = '0.0.3_00';
6              
7 7     7   36 use base qw/Algorithm::RankAggregate/;
  7         14  
  7         4290  
8              
9             sub get_averagerating_result {
10 15     15 0 29 my ($this, $ranked_lists_list) = @_;
11 15         26 my @lists_list = ();
12 15         32 for (my $i = 0; $i <= $#{$ranked_lists_list->[0]}; $i++) {
  78         212  
13 63         78 my $result = 0;
14 63         77 for (my $j = 0; $j <= $#{$ranked_lists_list}; $j++) {
  300         606  
15 237         351 $result = $result + $ranked_lists_list->[$j]->[$i];
16             }
17 63         87 $result = $result / ($#{$ranked_lists_list} + 1);
  63         94  
18 63         118 push @lists_list, $result;
19             }
20 15         75 return \@lists_list;
21             }
22              
23             sub aggregate_rank_to_rating {
24 14     14 0 37 my ($this, $ranked_lists_list) = @_;
25 14         19 my @result = ();
26 14 100 66     158 if ((exists $this->{weight}) && (exists $this->{weight}->[0])) {
27 6         60 $ranked_lists_list = $this->get_weighted_count_lists_list($ranked_lists_list);
28             }
29 14 50       17 @result = @{$this->get_averagerating_result($ranked_lists_list)} if (@{$ranked_lists_list});
  14         63  
  14         44  
30 14         67 return \@result;
31             }
32              
33             sub aggregate_score_to_rating {
34 5     5 0 13 my ($this, $score_lists_list) = @_;
35 5         8 my @result = ();
36 5         23 my $ranked_lists_list = $this->get_ranked_lists_list($score_lists_list);
37 5 50       7 @result = @{$this->aggregate_rank_to_rating($ranked_lists_list)} if (@{$ranked_lists_list});
  5         16  
  5         21  
38 5         41 return \@result;
39              
40             }
41              
42             sub aggregate {
43 3     3 1 21 my ($this, $score_lists_list) = @_;
44 3         5 my @result = ();
45 3 50       16 return \@result unless ($this->validate_lists_list($score_lists_list));
46 3 50       4 @result = @{$this->aggregate_score_to_rating($score_lists_list)} if (@{$score_lists_list});
  3         8  
  3         10  
47 3         11 return \@result;
48             }
49              
50             1;
51             __END__