chiark / gitweb /
compute-scottish-stv: make --for-compare list winners too
[appendix-a6.git] / compute-scottish-stv
index 12645fd4d64da0ce5b13aea6f435afc48c8935d9..43d3a7286f3158f8a09277aa6ca60042e9b96274 100755 (executable)
@@ -209,16 +209,24 @@ sub prf {
 }
 
 sub countballots () {
+    my @pr;
+
     foreach my $c (values %cands) {
        next if $c->{NonCont};
        $c->{Total} = 0/1;
        $c->{Total} += $_->{Weight} foreach @{ $c->{Votes} };
        print DEBUG "counted $c->{Cand} $c->{Total}\n";
        $c->{History}[$stage-1] = $c->{Total};
+       push @pr, $c;
+    }
+
+    if ($for_compare) {
+       # for comparison with OpenSTV, which always prints
+       # the quota for every elected candidate
+       push @pr, { %$_, Total => $quota } foreach @elected;
     }
 
-    foreach my $c (reverse sort $display_cmp
-                  grep { !$_->{NonCont} } values %cands) {
+    foreach my $c (reverse sort $display_cmp @pr) {
        prf "candidate %-10s: %s votes\n", $c->{Cand}, sv $c->{Total};
     }
 }