home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume30 / netvote / part01 / multi / official < prev    next >
Encoding:
Text File  |  1992-06-19  |  3.2 KB  |  144 lines

  1. #!/usr/bin/perl
  2. #    OFFICIAL - official status of CFV
  3. #            and deal with duplicates properly
  4. #
  5. die "usage: official [-l|-f|-d]
  6. \twhere -l does last vote priority
  7. \t      -f does first vote priority
  8. \t      -d discards duplicates\n" if (!defined($ARGV[0]));
  9. #
  10. # Get config
  11. require 'cfv.config';
  12. #
  13. # Raw, time-ordered, data
  14. #
  15. @votes = `cat votes`;
  16. #
  17. # This builds an associative array that has cleaned data
  18. #
  19. $y =0; $n = 0;
  20. for ($i=0; $i<=$#votes; $i++) {
  21.     if ($votes[$i] =~ /^\[([YNA])\]\s+(\S+)\s+(.*)/) {
  22.     $p = "$3\n"; 
  23.     push(@people,$p) if (grep($_ eq $p,@people) == 0);
  24.     $g = $2;
  25.     $v = $1;
  26.     } else {
  27.     print "Bad syntax in vote: <$votes[$i]>\n";
  28.     next;
  29.     } 
  30.     if (!defined($vote{$p,$g})) {
  31.     if ($v eq "Y") {
  32.         $vote{$p,$g} = "yes";
  33.         $y++;
  34.     } elsif ($v eq "N") {
  35.         $vote{$p,$g} = "no";
  36.         $n++;
  37.     } elsif ($v eq "A") {
  38.         $vote{$p,$g} = "abs";
  39.         $n++;
  40.     } else { 
  41.         print "Bad vote: <$votes[$i]>\n";
  42.     }
  43.     next;
  44.     }
  45.     $first{$p,$g} = $vote{$p,$g} if (!defined($first{$p,$g}));
  46.     if ($v eq "Y") {
  47.     $last{$p,$g} = "yes";
  48.     $y++;
  49.     } elsif ($v eq "N") {
  50.     $last{$p,$g} = "no";
  51.     $n++;
  52.     } elsif ($v eq "A") {
  53.     $last{$p,$g} = "abs";
  54.     $n++;
  55.     } else { 
  56.     print "Bad vote: <$votes[$i]>\n";
  57.     }
  58.     $vote{$p,$g} = "dup";
  59. }
  60. #
  61. # Filter the array appropriately
  62. #
  63. print "[DAVE'S AUTOMATIC USENET CFV HANDLER - Rev 2]\n";
  64.  
  65. foreach $group (@groups) {
  66.     @tmass = @people;
  67.     @tyes  = grep($vote{$_,$group} eq "yes",@tmass);
  68.     @tno   = grep($vote{$_,$group} eq "no",@tmass);
  69.     @tdups = grep($vote{$_,$group} eq "dup",@tmass);
  70. #
  71. # Now deal with duplicates. 
  72. #
  73.     if ($ARGV[0] eq "-l") {
  74.     $method = "Last vote taken as valid";
  75.     foreach $person (@tdups) {
  76.         push(@tyes,$person) if ($last{$person,$group} eq "yes");
  77.         push(@tno,$person) if ($last{$person,$group} eq "no");
  78.         $vote{$person,$group} = $last{$person,$group};
  79.     }
  80.     } elsif ($ARGV[0] eq "-f") {
  81.     $method = "First vote taken as valid";
  82.     foreach $person (@tdups) {
  83.         push(@tyes,$person) if ($first{$person,$group} eq "yes");
  84.         push(@tno,$person) if ($first{$person,$group} eq "no");
  85.         $vote{$person,$group} = $first{$person,$group};
  86.     }
  87.     } elsif ($ARGV[0] eq "-d") {
  88.     $method = "Duplicates discarded";
  89.     } else {
  90.     die "Illegal argument: $ARGV[0]\n";
  91.     }
  92.  
  93. # Tally ho!
  94. #
  95.     $tyes = $#tyes + 1;
  96.     $tno  = $#tno + 1;
  97.     $tmass = $#tmass + 1;
  98.     $tdups =  $#tdups + 1;
  99.     $tmass -= $tdups if ($tdups > 0);
  100.     $pyes = $tyes/$tmass * 100; $pyes = sprintf("%02.2f",$pyes);
  101.     $pno  = $tno/$tmass * 100;  $pno  = sprintf("%02.2f",$pno);
  102.     $pct  = $tyes + $tno;
  103.     $pdiff = $tyes - $tno;
  104.  
  105.     print "
  106.    NewsGroup: $group
  107. Total  Votes: $tmass\t
  108. Yes    Votes: $tyes\t($pyes%)
  109. No     Votes: $tno\t($pno%)
  110. Yes-No Votes: $pdiff
  111. Duplicates:   $tdups 
  112. Duplicate Resolution: $method\n";
  113. }
  114.  
  115. print "\nVote Key - Number refers to column:\n";
  116. for $i (0..$#groups) {
  117.     print "\t$i: $groups[$i]\n";
  118.     $k = $i % 10; $m = int($i/10);
  119.     $row1 .= "$m";
  120.     $row2 .= "$k";
  121.     $row3 .= "=";
  122. }
  123. print "
  124. -VOTE COLUMN-
  125. $row1
  126. $row2
  127. $row3
  128. ";
  129.  
  130. foreach $p (sort @people) {
  131.     for $i (0..$#groups) {
  132.     print "Y" if ($vote{$p,$groups[$i]} eq "yes");
  133.     print "N" if ($vote{$p,$groups[$i]} eq "no");
  134.     print "A" if ($vote{$p,$groups[$i]} eq "abs");
  135.     }
  136.     print "\t\t$p";
  137. }
  138.  
  139.  
  140.  
  141.  
  142.