4 $usage = "Usage: mo-score2004 [--tex] theoretical_tasks_nr praxis_tasks_nr task1 task2 ...";
5 while (($arg = $ARGV[0]) =~ /^--([a-z]+)$/) {
8 if (!eval "defined $var") { die $usage; }
11 @ARGV >=2 || die $usage;
14 @ARGV >= $praxis || die $usage;
15 $pos_delim=$tex ? '--' : '-';
17 print STDERR "Scanning contestants... ";
18 open (CT, "bin/mo-get-users --full |") || die "Cannot get list of contestants";
22 ($u eq "somebody") && next;
26 print STDERR 0+keys %users, "\n";
28 print STDERR "Scanning teoretical results... ";
29 if (open (EX, "teorie.txt")) {
32 (/^$/ || /^#/) && next;
33 @a = split /\ *\t\ */;
35 defined $users{$u} || die "Unknown user $u";
36 $names{$u} = shift @a;
37 $forms{$u} = shift @a;
38 $addresses{$u} = "{". (shift @a) ."}";
40 while (@a) { $tasks{$u}{$i} = shift @a;$i++; }
44 } else {die "none\n";}
46 print STDERR "Scanning task results... ";
47 $need_tasks = join("|", @ARGV);
48 foreach $u (keys %users) {
49 opendir (D, "testing/$u") or next;
50 foreach $t (readdir(D)) {
52 $t =~ /$need_tasks/ || next;
55 for (my $t_num2=0;$t_num2<@ARGV;$t_num2++) {if ($t eq $ARGV[$t_num2]) {$t_num=$t_num2;}}
58 $tt = "testing/$u/$t/points";
60 print STDERR "$u/$t ";
61 open (X, $tt) || die "Unable to open $tt";
64 /^\S+ (-?\d+)/ || die "Parse error: $_";
65 $tasks{$u}{$t_num} += $1;
73 print STDERR "Creating table template... ";
74 @body = ('','$names{$u}','$forms{$u}','$addresses{$u}');
75 for ($a=0;$a<$theory+$praxis;$a++) {push @body,"\$tasks{\$u}{$a}";}
78 print STDERR "Filling in results... ";
80 foreach $u (keys %users) {
84 foreach my $c (@body) {
85 $c =~ s/\$(\d+)/\$\$row[$1]/g;
87 push @$row, (defined $x ? $x : '-');
89 if ((defined $x) && ($x>0)) {$row_sum+=$x;}
98 print STDERR "Sorting... ";
99 $sortcol = @{$table[0]} - 1;
103 $p = $$b[$sortcol] <=> $$a[$sortcol];
104 ($an = $$a[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
105 ($bn = $$b[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
106 $p ? $p : ($an cmp $bn);
109 while ($i < @table) {
111 while ($i < @table && ${$table[$i]}[$sortcol] == ${$table[$j]}[$sortcol]) {
115 ${table[$j]}[0] = "$i.";
117 ${table[$j]}[0] = $j+1 . '.' . $pos_delim . $i . ".";
120 while ($j < $i) { ${table[$j++]}[0] = $j_old+1 . '.' . $pos_delim . $i . "."; };
126 open HDR,"teorie.hdr" or die "Cannot open file teorie.hdr with TeX template!";
127 while (<HDR>) {print; }
130 foreach $r (@table) { print join('&',@$r), "\\cr\n";}
137 foreach $r (@table) { print join("\t",@$r), "\n"; }