chiark / gitweb /
stv: wip debug
[appendix-a6.git] / stv
diff --git a/stv b/stv
index bd952628c01ba1021a2294ef5295f24b4a585222..7059906ccb810b37f8cb06d58ab4253b8d33710d 100755 (executable)
--- a/stv
+++ b/stv
@@ -140,17 +140,18 @@ for (;;) {
     }
     $sorted{$_}{Cand} = $_ foreach keys %sorted;
     foreach my $firstpref (sort keys %sorted) {
-       $sorted{$firstpref}{Total} = 0; # recount
        foreach my $vote (@{ $sorted{$firstpref}{Votes} }) {
            votelog $vote, "counted $vote->{Weight} for $firstpref";
-           $sorted{$firstpref}{Total} += $vote->{Weight};
        }
     }
     my @sorted;
-    my $sort_update = sub {
+    my $things_update = sub {
+       foreach my $s (@surpluses, values %sorted) {
+           $s->{Total} = sum0 map { $_->{Weight} } @{ $s->{Votes } };
+       }
        @sorted = nsort_by { -$_->{Total} } values %sorted;
     };
-    $sort_update->();
+    $things_update->();
 
     print DEBUG "SORTED\n", Dumper(\@sorted);
 
@@ -209,7 +210,9 @@ for (;;) {
        delete $sorted{ $s->{Cand} };
        delete $continuing{ $s->{Cand} };
 
-       $sort_update->();
+       $things_update->();
+       printf "%7s %10s %s\n", 'surplus', $s->{Cand}, pr $s->{Total};
+
        $need_to_transfer_surplus = 0;
        # before actually transferring a surplus, we will consider
        # eliminating, and then reconsider with a lower quota
@@ -261,7 +264,7 @@ for (;;) {
            push @unsorted, @$votes;
        }
        
-       $sort_update->();
+       $things_update->();
        $need_to_transfer_surplus = 0;
     }