Count/Score.pm

filter: Statementstmt 100% 42 / 42 Branchbran 100% 8 / 8 Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 100% 67 / 67 CC 11 SCAR 14.3
CC
11
Cov
100%
Score
6.0
RangeBallotPair
6.0
BEGIN
1.0
CRAP 4.2
« Count/Borda.pm ↑ Summary Count/Floor.pm »
1 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 25 ▶use 5.022;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 25 ▶use feature qw /postderef signatures/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Vote::Count::Score;
7  
8 25 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # use Storable 3.15 qw(dclone);
11 # use Try::Tiny;
12  
13 25 our $VERSION='1.10';
14  
15 =head1 NAME
16  
17 Vote::Count::Score
18  
19 =head1 VERSION 1.10
20  
21 =cut
22  
23 # ABSTRACT: Provides Score Method for Range Ballots to Vote::Count objects
24  
25 25 ▶no warnings 'experimental';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 25 ▶use Vote::Count::RankCount;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 # use Try::Tiny;
28 # use boolean;
29  
30 =pod
31  
32 =head1 Synopsis
33  
34 my $RangeElection = Vote::Count->new(
35 BallotSet => read_range_ballots('t/data/tennessee.range.json')
36 );
37 my $scored = $RangeElection->Score();
38  
39 =head1 Range Score Methods
40  
41 When Range (Cardinal) Ballots are used, it is simple and obvious to total the scores provided by the voters. This contrasts to the related Borda Method which assigns scores based on position on a Ranked Ballot.
42  
43 =head2 Score
44  
45 Returns a RankCount Object with the choices scored using the scores set by the voters, for Range Ballots.
46  
47 =cut
48  
49 11 ▶sub Score ( $self, $active = undef ) {
Subroutine Score: called CC=6 SCAR=17.9
Pod documented
50 11 my $depth = $self->BallotSet()->{'depth'};
51 # my @Ballots = $self->BallotSet()->{'ballots'}->@*;
52 11 ▶ $active = $self->Active() unless defined $active;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $active 3 8 11
53 11 my %scores = ( map { $_ => 0 } keys( $active->%* ) );
54 11 for my $ballot ( $self->BallotSet()->{'ballots'}->@* ) {
55 48 for my $choice ( keys %scores ) {
56 272 ▶ if ( defined $ballot->{'votes'}{$choice} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ballot->{"votes"}{$choice}) 122 150 272
57 122 $scores{$choice} += $ballot->{'count'} * $ballot->{'votes'}{$choice};
58 }
59 }
60 }
61 11 return Vote::Count::RankCount->Rank( \%scores );
62 }
63  
64 =head2 RangeBallotPair
65  
66 Used for pairings against Range Ballots. Used by Condorcet and STAR.
67  
68 where $I is a Vote::Count object created with a Range Ballot Set.
69  
70 my ( $countA, $countB ) = $I->RangeBallotPair( $A, $B) ;
71  
72 =cut
73  
74 ▶sub RangeBallotPair ( $self, $A, $B ) {
Subroutine RangeBallotPair: called CC=6 SCAR=17.9
Pod documented
75 141 my $countA = 0;
76 141 my $countB = 0;
77 141 my $approval = $self->Approval();
78 141 for my $ballot ( $self->BallotSet()->{'ballots'}->@* ) {
79 836 ▶ my $prefA = $ballot->{'votes'}{$A} || 0;
Condition100%2/2
$ballot->{'votes'}{$A} || 0
l!l
240596
MC/DC100%1/1
$ballot->{'votes'}{$A} || 0
$ballot->{'votes'}{$A}
Truth table100%2/2
A
A= $ballot->{'votes'}{$A}
Aresult
11
00
80 836 ▶ my $prefB = $ballot->{'votes'}{$B} || 0;
Condition100%2/2
$ballot->{'votes'}{$B} || 0
l!l
285551
MC/DC100%1/1
$ballot->{'votes'}{$B} || 0
$ballot->{'votes'}{$B}
Truth table100%2/2
A
A= $ballot->{'votes'}{$B}
Aresult
11
00
81 836 ▶ if ( $prefA > $prefB ) { $countA += $ballot->{'count'} }
Branch: 2 branches
BranchTrueFalseTotal
if ($prefA > $prefB) { } 188 648 836
elsif ($prefA < $prefB) { } 213 435 648
82 213 elsif ( $prefA < $prefB ) { $countB += $ballot->{'count'} }
83 else { }
84 }
85 141 return ( $countA, $countB );
86 }
87  
88 25 1;
89  
90 #FOOTER
91  
92 =pod
93  
94 BUG TRACKER
95  
96 L<https://github.com/brainbuz/Vote-Count/issues>
97  
98 AUTHOR
99  
100 John Karr (BRAINBUZ) brainbuz@cpan.org
101  
102 CONTRIBUTORS
103  
104 Copyright 2019 by John Karr (BRAINBUZ) brainbuz@cpan.org.
105  
106 LICENSE
107  
108 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>.
109  
110 =cut
« Count/Borda.pm ↑ Summary Count/Floor.pm »