Count/Helper/NthApproval.pm

filter: Statementstmt 100% 33 / 33 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 95.7% 45 / 47 CC 5 SCAR 10.4
CC
5
Cov
97%
NthApproval
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.8
« Count/Method/STAR.pm ↑ Summary buildpod.pl »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use 5.024;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Vote::Count::Helper::NthApproval;
6 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶no warnings 'experimental';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use feature qw /postderef signatures/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 # use Vote::Count::TextTableTiny qw/generate_table/;
10  
11 2 our $VERSION='2.02';
12  
13 # ABSTRACT: Nth Approval Defeat rule for STV elections.
14  
15 =head1 NAME
16  
17 Vote::Count::Helper::NthApproval
18  
19 =head1 VERSION 2.02
20  
21 =cut
22  
23 =pod
24  
25 =head1 SYNOPSIS
26  
27 package MySTVElection;
28 use Moose;
29 extends 'Vote::Count::Charge';
30 with 'Vote::Count::Charge::NthApproval';
31 for my $defeat ( NthApproval( $STV_Election ) ) {
32 $STV_Election->Defeat( $defeat );
33 }
34  
35 =head1 NthApproval
36  
37 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.
38  
39 Results are logged to the verbose log.
40  
41 This rule is not strictly LNH safe.
42  
43 =cut
44  
45 ▶sub NthApproval ( $I ) {
Subroutine NthApproval: called CC=5 SCAR=16.1
Pod undocumented
46 4 my $tc = $I->TopCount();
47 4 my $ac = $I->Approval();
48 4 my $seats = $I->Seats() - $I->Elected();
49 4 my @defeat = ();
50 4 my $bottomrunning = $tc->HashByRank()->{$seats}[0];
51 4 my $bar = $tc->RawCount()->{$bottomrunning};
52 4 for my $A ( $I->GetActiveList ) {
53 25 ▶ next if $A eq $bottomrunning;
Branch: 1 branch
BranchTrueFalseTotal
if $A eq $bottomrunning 4 21 25
54 21 my $avv = $ac->{'rawcount'}{$A};
55 21 ▶ push @defeat, ($A) if $avv <= $bar;
Branch: 1 branch
BranchTrueFalseTotal
if $avv <= $bar 10 11 21
56 }
57 4 ▶ if (@defeat) {
Branch: 1 branch
BranchTrueFalseTotal
if (@defeat) 4 0 4
58 4 $I->logv( qq/
59 Seats: $seats Choice $seats: $bottomrunning ( $bar )
60 4 Choices Not Over $bar by Weighted Approval: ${\ join( ', ', @defeat ) }
61 /);
62 }
63 4 return @defeat;
64 }
65  
66 2 1;
67  
68 #FOOTER
69  
70 =pod
71  
72 BUG TRACKER
73  
74 L<https://github.com/brainbuz/Vote-Count/issues>
75  
76 AUTHOR
77  
78 John Karr (BRAINBUZ) brainbuz@cpan.org
79  
80 CONTRIBUTORS
81  
82 Copyright 2019-2021 by John Karr (BRAINBUZ) brainbuz@cpan.org.
83  
84 LICENSE
85  
86 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>.
87  
88 SUPPORT
89  
90 This software is provided as is, per the terms of the GNU Public License. Professional support and customisation services are available from the author.
91  
92 =cut
93  
« Count/Method/STAR.pm ↑ Summary buildpod.pl »