aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2010-06-16 19:27:05 +0000
committerRobin H. Johnson <robbat2@gentoo.org>2010-06-16 19:27:05 +0000
commitf21224453059fddce05aca52e1ea1b1d741d1e27 (patch)
tree6ebd61082a0420f8d42174868811fc5d9617b7d3 /countify
downloadelections-f21224453059fddce05aca52e1ea1b1d741d1e27.tar.gz
elections-f21224453059fddce05aca52e1ea1b1d741d1e27.tar.bz2
elections-f21224453059fddce05aca52e1ea1b1d741d1e27.zip
Copy in all of the elections stuff.
Diffstat (limited to 'countify')
-rwxr-xr-xcountify141
1 files changed, 141 insertions, 0 deletions
diff --git a/countify b/countify
new file mode 100755
index 0000000..e089584
--- /dev/null
+++ b/countify
@@ -0,0 +1,141 @@
+#!/usr/bin/perl -w
+# $Id: countify,v 1.3 2005/05/16 18:10:46 agriffis Exp $
+#
+# Copyright 2005 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+#
+# countify: collect, tabulate and announce ballot results
+#
+
+#BEGIN { push @INC, (getpwnam 'fox2mike')[7].'/elections' }
+BEGIN { push @INC, '/etc/elections/current' }
+
+use POSIX;
+use Getopt::Long;
+use List::Util;
+use Votify 'official';
+use strict;
+
+######################################################################
+# Global vars
+######################################################################
+
+(my $zero = $0) =~ s,.*/,,;
+(my $version = '$Revision: 1.3 $') =~ s/.*?(\d.*\d).*/$zero version $1\n/;
+my %opt;
+my $usage = <<EOT;
+
+usage: $zero <command> <election>
+
+where <command> is one of:
+
+ --collect Collect the submitted ballots from home directories
+ --rank Show ranking based on master ballot
+ --help Show this help message
+ --version Show version information
+
+and <election> is one of the elections currently in-progress. The following
+elections are currently open:
+
+ trustees2005
+
+EOT
+
+######################################################################
+# Main
+######################################################################
+
+package main;
+
+# Make sure umask is secure before we do anything
+umask 077;
+
+# Parse the options on the cmdline. Put the short versions first in
+# each optionstring so that the hash keys are created using the short
+# versions. For example, use 'q|qar', not 'qar|q'.
+my ($result) = GetOptions(
+ \%opt,
+ 'collect', # collect the submitted ballots from home directories
+ 'rank', # show the ranking based on a master ballot
+ 'help', # help message
+ 'version', # version information
+);
+if ($opt{'help'} or not %opt) { print STDERR $usage; exit 0 }
+if ($opt{'version'}) { print STDERR $version; exit 0 }
+die "$zero: only one command allowed; use --help for help\n" if 1 < keys %opt;
+die "$zero: election required; use --help for help\n" unless @ARGV == 1;
+
+my ($election) = $ARGV[0];
+my ($vl) = VoterList->new($election);
+
+if ($opt{'collect'}) {
+ my ($ol) = OfficialList->new($election);
+ my ($master) = MasterBallot->new($election, $vl);
+ $master->collect($vl->voters);
+ for my $o ($ol->officials) {
+ my ($uid, $home) = (getpwnam $o)[2,7];
+ mkdir "$home/results-$election";
+ $master->write("$home/results-$election/master-$election");
+ $vl->write("$home/results-$election/confs-$election");
+ chown $uid, -1, "$home/results-$election",
+ "$home/results-$election/master-$election",
+ "$home/results-$election/confs-$election";
+ }
+ exit 0;
+}
+
+if ($opt{'rank'}) {
+ my ($master) = MasterBallot->new($election, $vl);
+ my (@candidates, @winner, @ranked, @ranks);
+ $master->read("$ENV{HOME}/results-$election/master-$election");
+ $master->generate_candidates();
+ @candidates = sort keys %{$master->{'candidates'}};
+
+ while (1) {
+ $master->tabulate();
+
+ # this is a hack :-(
+ #print "\n";
+ for my $r (@ranked) {
+ #print "$r is already ranked\n";
+ for my $c (@candidates) {
+ $master->{'table'}{"$r+$c"} = -1;
+ }
+ $master->{'table'}{"$r+$r"} = '+++';
+ }
+
+ # now display the table
+ print "\n";
+ $master->display_table();
+
+ @winner = $master->cssd();
+ if (@winner == @candidates) {
+ print "\n*** No additional winners to add to the list ***\n";
+ last;
+ }
+
+ push @ranks, [ @winner ];
+ push @ranked, @winner;
+ if (@ranked == @candidates) {
+ print "\n*** Finished ranking candidates ***\n";
+ last;
+ }
+
+ print "\n*** Running another pass to find the next winners... ***\n";
+ }
+
+ print "\nFinal ranked list:\n";
+ print map "@$_\n", @ranks;
+}
+
+__END__
+
+$Log: countify,v $
+Revision 1.3 2005/05/16 18:10:46 agriffis
+ranking works completely now, even if it needs badly to be refactored
+
+Revision 1.2 2005/05/16 04:03:46 agriffis
+add first pass at countify --rank
+
+
+# vim:sw=4 et