From 5eccca2f5455743d0b5048f3cd64ac931cf54188 Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Tue, 10 Mar 2015 13:22:33 -0700 Subject: [PATCH] support votes without a default option --- scripts/pocket-devotee | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/scripts/pocket-devotee b/scripts/pocket-devotee index 6046aa9..d176de8 100755 --- a/scripts/pocket-devotee +++ b/scripts/pocket-devotee @@ -98,6 +98,7 @@ sub main { my %options; GetOptions(\%options, 'option=s@', + 'default_option|default-option!', ); if (not exists $options{option} or not ref($options{option}) or @{$options{option}} < 2 @@ -113,7 +114,9 @@ sub main { majority => $majority, }; } - winner(options=>\@options); + winner(options=>\@options, + default_option => exists $options{default_option} ? $options{default_option} : 1, + ); } sub encode_base64{ @@ -134,6 +137,9 @@ sub winner { tally_fh => {type => HANDLE, optional => 1, }, + default_option => {default => 1, + type => BOOLEAN, + }, }, ); # options is an array to keep it ordered @@ -293,18 +299,20 @@ EOM my %Drop = (); - foreach my $i (0..($max_choices - 2)) { - if ($K > $Beat_Matrix[$i][$max_choices - 1]) { - $Drop{$i}++; - print {$RESULTS} "Dropping Option", $order_to_options{$i + 1}{key}, - " \"", $order_to_options{$i + 1}{name}, - "\" because of Quorum\n"; - } else { - print {$RESULTS} "Option ", $order_to_options{$i + 1}{key}, - " Reached quorum: $Beat_Matrix[$i][$max_choices - 1] > $K\n"; + if ($params{default_option}) { + foreach my $i (0..($max_choices - 2)) { + if ($K > $Beat_Matrix[$i][$max_choices - 1]) { + $Drop{$i}++; + print {$RESULTS} "Dropping Option", $order_to_options{$i + 1}{key}, + " \"", $order_to_options{$i + 1}{name}, + "\" because of Quorum\n"; + } else { + print {$RESULTS} "Option ", $order_to_options{$i + 1}{key}, + " Reached quorum: $Beat_Matrix[$i][$max_choices - 1] > $K\n"; + } } + print {$RESULTS} "\n\n"; } - print {$RESULTS} "\n\n"; # Record Majority my %Ratio = (); -- 2.39.5