File:  [Local Repository] / processmail / createtable.pl
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Mon Feb 4 15:44:51 2002 UTC (22 years, 5 months ago) by boris
Initial revision

#!/usr/local/bin/perl
#$Id: createtable.pl,v 1.1 2002/02/04 15:44:51 boris Exp $
#
#
#
# Исходные файлы и параметры
#

    use Getopt::Std; 

$usage = 'createtable.pl $Revision: 1.1 $, $Date: 2002/02/04 15:44:51 $'. "\n".
"Usage: createtable.pl [-d] [-t answers_file] [-m mail_file]  [-o results] \n";

require 'parameters.pl';
require 'subroutines.pl';

die $usage unless getopts('t:m:o:d');

$DEBUG=$opt_d;

my %teams;
my @answers;
my @ratings;
#
# Читаем старые результаты
#
if ($opt_t)
{
    die "Cannot open $opt_t\n" unless open(INFILE,$opt_t);
    readhash(\@answers);
    close(INFILE);
}

#
# Читаем ответы команд
#
if ($opt_m)
{
    die "Cannot open $opt_m\n" unless open(INFILE,$opt_m)
}
else
{
    *INFILE=*STDIN;
}
readmail(\%teams);
close(INFILE);
#
# Чистим хэш %answers
#
collect_answers(\%teams,\@answers);
#
# Подсчитываем рейтинги вопросов
#
rate_questions(\%teams,\@answers,\@ratings);
#
# Вычисляем число ответов и рейтинги команд
#
find_scores(\%teams,\@answers,\@ratings);
#
# Ну а теперь печатаем саму таблицу...
#
if ($opt_o)
{ 
    die "Cannot open $opt_o\n" unless open(OUTFILE,">$opt_o");
    select OUTFILE;
}
#
# Печатаем заголовок
#
printf "%5s", "N";
for ($i=1;$i<=$MAXQUEST;$i++)
{
    printf "%3d",$i;
}
printf "%3s","О";
printf "%4s","Р";
printf " КОМАНДА";
print "\n";
#
# Печатаем команды построчно
#
foreach $team (sort 
	        {
		    $teams{$b}->{score} <=> $teams{$a}->{score}
		    or
			$teams{$b}->{rating} <=> $teams{$a}->{rating}
		} keys %teams
	       )
{
    printf "%5d",$teams{$team}->{regnum};
    for ($i=1;$i<=$MAXQUEST;$i++)
    {
	my $answer = $teams{$team}->{answers}[$i];
	my $score = $answers[$i]->{$answer}->{score};
	$score = '-' unless $score;
	    printf "%3s", $score;
    }
    printf "%3s",$teams{$team}->{score};
    printf "%4s",$teams{$team}->{rating};
    print " $team";
    print "\n";
}
#
# Печатаем последнюю строку таблицы
# в ней рейтинги вопросов
#
printf "%5s", "Р";
for ($i=1; $i<=$MAXQUEST;$i++)
{
        printf "%3s", $ratings[$i];
}
print "\n";


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>