File Coverage

blib/lib/Vote/Count/Helper/NthApproval.pm
Criterion Covered Total %
statement 34 34 100.0
branch 5 6 83.3
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 46 48 95.8


line stmt bran cond sub pod time code
1 2     2   13774 use strict;
  2         5  
  2         72  
2 2     2   10 use warnings;
  2         5  
  2         71  
3 2     2   55 use 5.024;
  2         13  
4              
5             use Moose::Role;
6 2     2   11 no warnings 'experimental';
  2         4  
  2         18  
7 2     2   11005 use feature qw /postderef signatures/;
  2         6  
  2         94  
8 2     2   11 # use Vote::Count::TextTableTiny qw/generate_table/;
  2         3  
  2         774  
9              
10             our $VERSION='2.02';
11              
12             # ABSTRACT: Nth Approval Defeat rule for STV elections.
13              
14             =head1 NAME
15              
16             Vote::Count::Helper::NthApproval
17              
18             =head1 VERSION 2.02
19              
20             =cut
21              
22             =pod
23              
24             =head1 SYNOPSIS
25              
26             package MySTVElection;
27             use Moose;
28             extends 'Vote::Count::Charge';
29             with 'Vote::Count::Charge::NthApproval';
30             for my $defeat ( NthApproval( $STV_Election ) ) {
31             $STV_Election->Defeat( $defeat );
32             }
33              
34             =head1 NthApproval
35              
36             Finds the choice that would fill the last seat if the remaining seats were to be filled by highest Top Count, and sets the Vote Value for that Choice as the requirement. All Choices that do not have a weighted Approval greater than that requirement are returned, they will never be elected and are safe to defeat immediately.
37              
38             Results are logged to the verbose log.
39              
40             This rule is not strictly LNH safe.
41              
42             =cut
43              
44             my $tc = $I->TopCount();
45 4     4 0 117 my $ac = $I->Approval();
  4         11  
  4         7  
46 4         47 my $seats = $I->Seats() - $I->Elected();
47 4         42 my @defeat = ();
48 4         130 my $bottomrunning = $tc->HashByRank()->{$seats}[0];
49 4         9 my $bar = $tc->RawCount()->{$bottomrunning};
50 4         19 for my $A ( $I->GetActiveList ) {
51 4         18 next if $A eq $bottomrunning;
52 4         24 my $avv = $ac->{'rawcount'}{$A};
53 25 100       49 push @defeat, ($A) if $avv <= $bar;
54 21         33 }
55 21 100       44 if (@defeat) {
56             $I->logv( qq/
57 4 50       15 Seats: $seats Choice $seats: $bottomrunning ( $bar )
58 4         30 Choices Not Over $bar by Weighted Approval: ${\ join( ', ', @defeat ) }
59             /);
60 4         35 }
61             return @defeat;
62             }
63 4         101  
64             1;
65              
66             #FOOTER
67              
68             =pod
69              
70             BUG TRACKER
71              
72             L<https://github.com/brainbuz/Vote-Count/issues>
73              
74             AUTHOR
75              
76             John Karr (BRAINBUZ) brainbuz@cpan.org
77              
78             CONTRIBUTORS
79              
80             Copyright 2019-2021 by John Karr (BRAINBUZ) brainbuz@cpan.org.
81              
82             LICENSE
83              
84             This module is released under the GNU Public License Version 3. See license file for details. For more information on this license visit L<http://fsf.org>.
85              
86             SUPPORT
87              
88             This software is provided as is, per the terms of the GNU Public License. Professional support and customisation services are available from the author.
89              
90             =cut
91