File Coverage

blib/lib/Algorithm/RankAggregate.pm
Criterion Covered Total %
statement 74 74 100.0
branch 6 6 100.0
condition 3 3 100.0
subroutine 9 9 100.0
pod 0 7 0.0
total 92 99 92.9


line stmt bran cond sub pod time code
1             package Algorithm::RankAggregate;
2              
3 23     23   8145 use strict;
  23         39  
  23         907  
4 23     23   120 use warnings;
  23         42  
  23         20115  
5             our $VERSION = '0.0.3_00';
6              
7             sub get_ranked_list {
8 78     78 0 122 my ($this, $score_list) = @_;
9 78         106 my @ranked_list = ();
10 78         83 my %real_num_hash;
11 78         105 my $i = 1;
12 78         83 foreach my $real_num (@{$score_list}) {
  78         159  
13 333         522 $real_num_hash{$i} = $real_num;
14 333         442 $i++;
15             }
16 78         123 my $current_num = 0;
17 78         97 my $same_rank = 0;
18 78         90 my $j = 0;
19 78         308 foreach my $k (sort {$real_num_hash{$b} <=> $real_num_hash{$a}} keys %real_num_hash) {
  432         673  
20 333 100 100     1226 if (($current_num) && ($current_num == $real_num_hash{$k})) {
21 2         3 $same_rank++;
22             }
23             else {
24 331         385 $j = $j + $same_rank + 1;
25 331         342 $same_rank = 0;
26 331         444 $current_num = $real_num_hash{$k};
27             }
28 333         682 $ranked_list[$k - 1] = $j;
29             }
30 78         348 return \@ranked_list;
31             }
32              
33             sub get_reverse_ranked_list {
34 11     11 0 25 my ($this, $score_list) = @_;
35 11         20 for (my $i = 0; $i <= $#{$score_list}; $i++) {
  60         129  
36 49         98 $score_list->[$i] = $score_list->[$i] * -1;
37             }
38 11         20 my @ranked_list = @{$this->get_ranked_list($score_list)};
  11         55  
39 11         53 return \@ranked_list;
40             }
41              
42             sub get_ranked_lists_list {
43 16     16 0 35 my ($this, $score_lists_list) = @_;
44 16         32 my @lists_list = ();
45 16         27 my $i = 0;
46 16         24 foreach my $score_list (@{$score_lists_list}) {
  16         46  
47 60         180 my $ranked_list = $this->get_ranked_list($score_list);
48 60         91 push @lists_list, $ranked_list;
49 60         101 $i++;
50             }
51 16         59 return \@lists_list;
52             }
53              
54             sub validate_lists_list {
55 13     13 0 29 my ($this, $lists_list) = @_;
56 13         23 my $result = 1;
57 13         19 my $colmun_count = -1;
58 13         25 foreach my $list (@{$lists_list}) {
  13         32  
59 43 100       111 if ($colmun_count > -1) {
60 30 100       33 if ($colmun_count != $#{$list}) {
  30         117  
61 3         4 $result = 0;
62 3         6 last;
63             }
64             }
65             else {
66 13         23 $colmun_count = $#{$list};
  13         34  
67             }
68             }
69 13         65 return $result;
70             }
71              
72             sub get_weighted_count_list {
73 57     57 0 120 my ($this, $count_list, $row_num) = @_;
74 57         82 my @weighted_count_list = ();
75 57         75 foreach my $count_num (@{$count_list}) {
  57         114  
76 237         353 my $weighted_count_num = $count_num * $this->{weight}->[$row_num];
77 237         425 push @weighted_count_list, $weighted_count_num;
78             }
79 57         191 return \@weighted_count_list;
80             }
81              
82             sub get_weighted_count_lists_list {
83 13     13 0 34 my ($this, $count_lists_list) = @_;
84 13         30 my @lists_list = ();
85 13         30 my $i = 0;
86 13         22 foreach my $count_list (@{$count_lists_list}) {
  13         72  
87 51         213 my $weighted_count_list = $this->get_weighted_count_list($count_list, $i);
88 51         81 push @lists_list, $weighted_count_list;
89 51         104 $i++;
90             }
91 13         53 return \@lists_list;
92             }
93              
94             sub new {
95 33     33 0 722 my ($class, $weight_list) = @_;
96 33         116 my %hash = (
97             'weight' => $weight_list,
98             );
99 33         151 bless \%hash, $class;
100             }
101              
102             1;
103             __END__