home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume30 / netvote / part01 / single / official < prev    next >
Text File  |  1992-06-19  |  2KB  |  110 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. # Raw, time-ordered, data
  11. #
  12. @votes = `cat votes`;
  13. #
  14. # This builds an associative array that has cleaned data
  15. #
  16. $y =0; $n = 0;
  17. for ($i=0; $i<=$#votes; $i++) {
  18.     if ($votes[$i] =~ /^\[([YN])\]\s+(.*)/) {
  19.     $p = "$2\n";
  20.     $v = $1;
  21.     } else {
  22.     print "Bad syntax in vote: <$votes[$i]>\n";
  23.     next;
  24.     } 
  25.     if (!defined($vote{$p})) {
  26.     if ($v eq "Y") {
  27.         $vote{$p} = "yes";
  28.         $y++;
  29.     } elsif ($v eq "N") {
  30.         $vote{$p} = "no";
  31.         $n++;
  32.     } else { 
  33.         print "Bad vote: <$votes[$i]>\n";
  34.     }
  35.     next;
  36.     }
  37.     $first{$p} = $vote{$p} if (!defined($first{$p}));
  38.     if ($v eq "Y") {
  39.     $last{$p} = "yes";
  40.     $y++;
  41.     } elsif ($v eq "N") {
  42.     $last{$p} = "no";
  43.     $n++;
  44.     } else { 
  45.     print "Bad vote: <$votes[$i]>\n";
  46.     }
  47.     $vote{$p} = "dup";
  48. }
  49. #
  50. # Filter the array appropriately
  51. #
  52. @tmass = keys(%vote);
  53. @tyes  = grep($vote{$_} eq "yes",@tmass);
  54. @tno   = grep($vote{$_} eq "no",@tmass);
  55. @tdups = grep($vote{$_} eq "dup",@tmass);
  56. #
  57. # Now deal with duplicates. 
  58. #
  59. if ($ARGV[0] eq "-l") {
  60.     $method = "Last vote taken as valid";
  61.     foreach $person (@tdups) {
  62.     push(@tyes,$person) if ($last{$person} eq "yes");
  63.     push(@tno,$person) if ($last{$person} eq "no");
  64.     }
  65. } elsif ($ARGV[0] eq "-f") {
  66.     $method = "First vote taken as valid";
  67.     foreach $person (@tdups) {
  68.     push(@tyes,$person) if ($first{$person} eq "yes");
  69.     push(@tno,$person) if ($first{$person} eq "no");
  70.     }
  71. } elsif ($ARGV[0] eq "-d") {
  72.     $method = "Duplicates discarded";
  73. } else {
  74.     die "Illegal argument: $ARGV[0]\n";
  75. }
  76. #
  77. # Tally ho!
  78. #
  79. $tyes = $#tyes + 1;
  80. $tno  = $#tno + 1;
  81. $tmass = $#tmass + 1;
  82. $tdups =  $#tdups + 1;
  83. $tmass -= $tdups if ($ARGV[0] eq "-d" && $tdups > 0);
  84. $pyes = $tyes/$tmass * 100; $pyes = sprintf("%02.2f",$pyes);
  85. $pno  = $tno/$tmass * 100;  $pno  = sprintf("%02.2f",$pno);
  86. $pct  = $tyes + $tno;
  87. $pdiff = $tyes - $tno;
  88.  
  89. print "
  90. [DAVE'S AUTOMATIC USENET CFV HANDLER]
  91.  
  92. Total  Votes: $tmass\t
  93. Yes    Votes: $tyes\t($pyes%)
  94. No     Votes: $tno\t($pno%)
  95. Yes-No Votes: $pdiff
  96.  
  97. Duplicates:   $tdups 
  98. Duplicate Resolution: $method\n\n";
  99.  
  100. if ($ARGV[0] eq "-d" && $tdups > 0) {
  101.     print "DUPLICATES:\n"; print @tdups; print "\n\n";
  102. }
  103.  
  104. print "YES VOTES:\n"; print (sort @tyes);
  105. print "\n\nNO VOTES:\n"; print (sort @tno);
  106.  
  107.  
  108.  
  109.