File Coverage

blib/lib/Vote/Count/Floor.pm
Criterion Covered Total %
statement 68 68 100.0
branch 3 4 75.0
condition n/a
subroutine 13 13 100.0
pod 0 3 0.0
total 84 88 95.4


line stmt bran cond sub pod time code
1 9     9   4592 use strict;
  9         19  
  9         253  
2 9     9   44 use warnings;
  9         16  
  9         229  
3 9     9   168 use 5.022;
  9         26  
4 9     9   41 use feature qw /postderef signatures/;
  9         16  
  9         925  
5              
6             package Vote::Count::Floor;
7             $Vote::Count::Floor::VERSION = '0.007'; # TRIAL
8 9     9   55 use namespace::autoclean;
  9         14  
  9         110  
9 9     9   859 use Moose::Role;
  9         19  
  9         62  
10              
11 9     9   44166 use Data::Printer;
  9         18  
  9         91  
12              
13 9     9   598 no warnings 'experimental';
  9         19  
  9         5602  
14              
15             # load the roles providing the underlying ops.
16             with 'Vote::Count::Approval',
17             'Vote::Count::TopCount',
18             ;
19              
20 3     3   11 sub _FloorMin( $self, $floorpct ) {
  3         7  
  3         7  
  3         4  
21 3 50       13 my $pct = $floorpct > .2 ? $floorpct / 100 : $floorpct;
22 3         13 return int( $self->CountBallots() * $pct );
23             }
24              
25              
26 3     3   5 sub _DoFloor( $self, $ranked, $cutoff ) {
  3         5  
  3         5  
  3         5  
  3         5  
27 3         5 my @active = ();
28 3         4 my @remove = ();
29 3         11 for my $s ( keys $ranked->%* ) {
30 36 100       55 if ( $ranked->{$s} >= $cutoff) { push @active, $s }
  16         21  
31             else {
32 20         33 push @remove, $s;
33 20         62 $self->logv(
34             "Removing: $s: $ranked->{$s}, minimum is $cutoff."
35             );
36             }
37             }
38             $self->logt(
39 3         18 "Floor Rule Eliminated: ",
40             join( ', ', @remove ),
41             "Remaining: ",
42             join( ', ', @active ),
43             );
44 3         8 return { map { $_ => 1 } @active };
  16         41  
45             }
46              
47             # Approval Floor is Approval votes vs total
48             # votes cast -- not total of approval votes.
49             # so floor is the same as for topcount floor.
50 1     1 0 3 sub ApprovalFloor( $self, $floorpct=5 ) {
  1         2  
  1         3  
  1         8  
51 1         5 my $votescast = $self->CountBallots();
52 1         8 $self->logt(
53             "Applying Floor Rule of $floorpct\% " .
54             "Approval Count. vs Ballots Cast of $votescast.");
55 1         8 return $self->_DoFloor(
56             $self->Approval()->RawCount(),
57             $self->_FloorMin($floorpct )
58             );
59             }
60              
61 1     1 0 1657 sub TopCountFloor( $self, $floorpct=2 ) {
  1         2  
  1         3  
  1         2  
62 1         8 $self->logt( "Applying Floor Rule of $floorpct\% First Choice Votes.");
63 1         7 return $self->_DoFloor(
64             $self->TopCount()->RawCount(),
65             $self->_FloorMin($floorpct )
66             );
67             }
68              
69 1     1 0 1082 sub TCA( $self ) {
  1         3  
  1         2  
70 1         6 $self->logt( 'Applying Floor Rule: Approval Must be at least ',
71             '50% of the Most First Choice votes for any Choice.');
72 1         6 my $tc = $self->TopCount();
73             # arraytop returns a list in case of tie.
74 1         4 my $winner = shift( $tc->ArrayTop->@* );
75 1         6 my $tcraw = $tc->RawCount()->{$winner};
76 1         4 my $cutoff = int( $tcraw /2 );
77 1         9 $self->logv(
78             "The most first choice votes for any choice is $tcraw.",
79             "Cutoff will be $cutoff");
80 1         7 my $ac = $self->Approval()->RawCount();
81 1         7 return $self->_DoFloor(
82             $self->Approval()->RawCount(),
83             $cutoff );
84             }
85              
86              
87             1;
88              
89             =pod
90