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]));
- #
- # Get config
- #
- require 'cfv.config';
- #
- # 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] =~ /^\[([YNA])\]\s+(\S+)\s+(.*)/) {
- $p = "$3\n";
- push(@people,$p) if (grep($_ eq $p,@people) == 0);
- $g = $2;
- $v = $1;
- } else {
- print "Bad syntax in vote: <$votes[$i]>\n";
- next;
- }
- if (!defined($vote{$p,$g})) {
- if ($v eq "Y") {
- $vote{$p,$g} = "yes";
- $y++;
- } elsif ($v eq "N") {
- $vote{$p,$g} = "no";
- $n++;
- } elsif ($v eq "A") {
- $vote{$p,$g} = "abs";
- $n++;
- } else {
- print "Bad vote: <$votes[$i]>\n";
- }
- next;
- }
- $first{$p,$g} = $vote{$p,$g} if (!defined($first{$p,$g}));
- if ($v eq "Y") {
- $last{$p,$g} = "yes";
- $y++;
- } elsif ($v eq "N") {
- $last{$p,$g} = "no";
- $n++;
- } elsif ($v eq "A") {
- $last{$p,$g} = "abs";
- $n++;
- } else {
- print "Bad vote: <$votes[$i]>\n";
- }
- $vote{$p,$g} = "dup";
- }
- #
- # Filter the array appropriately
- #
- print "[DAVE'S AUTOMATIC USENET CFV HANDLER - Rev 2]\n";
-
- foreach $group (@groups) {
- @tmass = @people;
- @tyes = grep($vote{$_,$group} eq "yes",@tmass);
- @tno = grep($vote{$_,$group} eq "no",@tmass);
- @tdups = grep($vote{$_,$group} 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,$group} eq "yes");
- push(@tno,$person) if ($last{$person,$group} eq "no");
- $vote{$person,$group} = $last{$person,$group};
- }
- } elsif ($ARGV[0] eq "-f") {
- $method = "First vote taken as valid";
- foreach $person (@tdups) {
- push(@tyes,$person) if ($first{$person,$group} eq "yes");
- push(@tno,$person) if ($first{$person,$group} eq "no");
- $vote{$person,$group} = $first{$person,$group};
- }
- } 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 ($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 "
- NewsGroup: $group
- Total Votes: $tmass\t
- Yes Votes: $tyes\t($pyes%)
- No Votes: $tno\t($pno%)
- Yes-No Votes: $pdiff
- Duplicates: $tdups
- Duplicate Resolution: $method\n";
- }
-
- print "\nVote Key - Number refers to column:\n";
- for $i (0..$#groups) {
- print "\t$i: $groups[$i]\n";
- $k = $i % 10; $m = int($i/10);
- $row1 .= "$m";
- $row2 .= "$k";
- $row3 .= "=";
- }
- print "
- -VOTE COLUMN-
- $row1
- $row2
- $row3
- ";
-
- foreach $p (sort @people) {
- for $i (0..$#groups) {
- print "Y" if ($vote{$p,$groups[$i]} eq "yes");
- print "N" if ($vote{$p,$groups[$i]} eq "no");
- print "A" if ($vote{$p,$groups[$i]} eq "abs");
- }
- print "\t\t$p";
- }
-
-
-
-
-