home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
- #
- # OFFICIAL - official status of CFV
- # and deal with duplicates properly
- #
- die "usage: official [-l|-f|-d]
- \twhere -l does last vote priority
- \t -f does first vote priority
- \t -d discards duplicates\n" if (!defined($ARGV[0]));
- #
- # Raw, time-ordered, data
- #
- @votes = `cat votes`;
- #
- # This builds an associative array that has cleaned data
- #
- $y =0; $n = 0;
- for ($i=0; $i<=$#votes; $i++) {
- if ($votes[$i] =~ /^\[([YN])\]\s+(.*)/) {
- $p = "$2\n";
- $v = $1;
- } else {
- print "Bad syntax in vote: <$votes[$i]>\n";
- next;
- }
- if (!defined($vote{$p})) {
- if ($v eq "Y") {
- $vote{$p} = "yes";
- $y++;
- } elsif ($v eq "N") {
- $vote{$p} = "no";
- $n++;
- } else {
- print "Bad vote: <$votes[$i]>\n";
- }
- next;
- }
- $first{$p} = $vote{$p} if (!defined($first{$p}));
- if ($v eq "Y") {
- $last{$p} = "yes";
- $y++;
- } elsif ($v eq "N") {
- $last{$p} = "no";
- $n++;
- } else {
- print "Bad vote: <$votes[$i]>\n";
- }
- $vote{$p} = "dup";
- }
- #
- # Filter the array appropriately
- #
- @tmass = keys(%vote);
- @tyes = grep($vote{$_} eq "yes",@tmass);
- @tno = grep($vote{$_} eq "no",@tmass);
- @tdups = grep($vote{$_} eq "dup",@tmass);
- #
- # Now deal with duplicates.
- #
- if ($ARGV[0] eq "-l") {
- $method = "Last vote taken as valid";
- foreach $person (@tdups) {
- push(@tyes,$person) if ($last{$person} eq "yes");
- push(@tno,$person) if ($last{$person} eq "no");
- }
- } elsif ($ARGV[0] eq "-f") {
- $method = "First vote taken as valid";
- foreach $person (@tdups) {
- push(@tyes,$person) if ($first{$person} eq "yes");
- push(@tno,$person) if ($first{$person} eq "no");
- }
- } elsif ($ARGV[0] eq "-d") {
- $method = "Duplicates discarded";
- } else {
- die "Illegal argument: $ARGV[0]\n";
- }
- #
- # Tally ho!
- #
- $tyes = $#tyes + 1;
- $tno = $#tno + 1;
- $tmass = $#tmass + 1;
- $tdups = $#tdups + 1;
- $tmass -= $tdups if ($ARGV[0] eq "-d" && $tdups > 0);
- $pyes = $tyes/$tmass * 100; $pyes = sprintf("%02.2f",$pyes);
- $pno = $tno/$tmass * 100; $pno = sprintf("%02.2f",$pno);
- $pct = $tyes + $tno;
- $pdiff = $tyes - $tno;
-
- print "
- [DAVE'S AUTOMATIC USENET CFV HANDLER]
-
- Total Votes: $tmass\t
- Yes Votes: $tyes\t($pyes%)
- No Votes: $tno\t($pno%)
- Yes-No Votes: $pdiff
-
- Duplicates: $tdups
- Duplicate Resolution: $method\n\n";
-
- if ($ARGV[0] eq "-d" && $tdups > 0) {
- print "DUPLICATES:\n"; print @tdups; print "\n\n";
- }
-
- print "YES VOTES:\n"; print (sort @tyes);
- print "\n\nNO VOTES:\n"; print (sort @tno);
-
-
-
-