]> mj.ucw.cz Git - eval.git/blob - bin/mo-score2004
Added.
[eval.git] / bin / mo-score2004
1 #!/usr/bin/perl
2
3 $tex = 0;
4 $theory = 3;
5 $praxis = 2;
6 $usage = "Usage: mo-score2004 [--tex] task1 task2 ...";
7 while (($arg = $ARGV[0]) =~ /^--([a-z]+)$/) {
8         shift @ARGV;
9         $var = "\$$1";
10         if (!eval "defined $var") { die $usage; }
11         eval "$var = 1;";
12 }
13 @ARGV >= $praxis || die $usage;
14
15 print STDERR "Scanning contestants... ";
16 open (CT, "bin/mo-get-users --full |") || die "Cannot get list of contestants";
17 while (<CT>) {
18         chomp;
19         ($u,$f) = split /\t/;
20         ($u eq "somebody") && next;
21         $users{$u}=$f;
22 }
23 close CT;
24 print STDERR 0+keys %users, "\n";
25
26 print STDERR "Scanning teoretical results... ";
27 if (open (EX, "teorie.txt")) {
28         while (<EX>) {
29                 chomp;
30                 (/^$/ || /^#/) && next;
31                 @a = split /\ *\t\ */;
32                 $u = shift @a;
33                 defined $users{$u} || die "Unknown user $u";
34                 $names{$u} = shift @a;
35                 $forms{$u} = shift @a;
36                 $addresses{$u} = "{". (shift @a) ."}";
37                 $i=0;
38                 while (@a) { $tasks{$u}{$i} = shift @a;$i++; }
39         }
40         close EX;
41         print STDERR "OK\n";
42 } else {die "none\n";}
43
44 print STDERR "Scanning task results... ";
45 $need_tasks = join("|", @ARGV);
46 foreach $u (keys %users) {
47         opendir (D, "testing/$u") or next;
48         foreach $t (readdir(D)) {
49                 $t =~ /^\./ && next;
50                 $t =~ /$need_tasks/ || next;
51
52                 $t_num=$praxis;
53                 for (my $t_num2=0;$t_num2<@ARGV;$t_num2++) {if ($t eq $ARGV[$t_num2]) {$t_num=$t_num2;}}
54                 $t_num+=$theory;
55
56                 $tt = "testing/$u/$t/points";
57                 -f $tt || next;
58                 print STDERR "$u/$t ";
59                 open (X, $tt) || die "Unable to open $tt";
60                 while (<X>) {
61                         chomp;
62                         /^\S+ (-?\d+)/ || die "Parse error: $_";
63                         $tasks{$u}{$t_num} += $1;
64                 }
65                 close X;
66         }
67         closedir D;
68 }
69 print STDERR "OK\n";
70
71 print STDERR "Creating table template... ";
72 @body = ('','$names{$u}','$forms{$u}','$addresses{$u}');
73 for ($a=0;$a<$theory+$praxis;$a++) {push @body,"\$tasks{\$u}{$a}";}
74 print STDERR "OK\n";
75
76 print STDERR "Filling in results... ";
77 @table = ();
78 foreach $u (keys %users) {
79         $row = [];
80         $row_index=0;
81         $row_sum=0;
82         foreach my $c (@body) {
83                 $c =~ s/\$(\d+)/\$\$row[$1]/g;
84                 $x = eval $c;
85                 push @$row, (defined $x ? $x : '-');
86                 if ($row_index>3) {
87                     if ((defined $x) && ($x>0)) {$row_sum+=$x;}
88                 }
89                 $row_index++;
90         }
91         push @$row, $row_sum;
92         push @table, $row;
93 }
94 print STDERR "OK\n";
95
96 print STDERR "Sorting... ";
97 $sortcol = @{$table[0]} - 1;
98 $namecol = 1;
99 @table = sort {
100         my $p, $an, $bn;
101         $p = $$b[$sortcol] <=> $$a[$sortcol];
102         ($an = $$a[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
103         ($bn = $$b[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
104         $p ? $p : ($an cmp $bn);
105 } @table;
106 $i=0;
107 while ($i < @table) {
108         $j = $i;
109         while ($i < @table && ${$table[$i]}[$sortcol] == ${$table[$j]}[$sortcol]) {
110                 $i++;
111         }
112         if ($i == $j+1) {
113                 ${table[$j]}[0] = "$i.";
114         } else {
115                 ${table[$j]}[0] = $j+1 . ".-" . $i . ".";
116                 $j_old=$j;
117                 $j++;
118                 while ($j < $i) { ${table[$j++]}[0] = $j_old+1 . ".-" . $i . "."; };
119         }
120 }
121 print STDERR "OK\n";
122
123 if ($tex) {
124         print
125 '\language=\czech
126 \font\head=csr12 scaled \magstephalf
127 \font\hexx=csti12
128 \font\xxit=csti10
129 \def\xit{\xxit\kern-0.1em\relax}
130 \let\hb=\relax
131 \parindent=0pt
132 \nopagenumbers
133 \advance\hsize by 0.2cm
134 \advance\hoffset by 1cm
135
136 \centerline{\head Výsledková listina celostátního kola 53. roèníku MO kategorie P}
137 \bigskip
138 \centerline{\hexx 31. bøezna -- 3. dubna 2004 v Pøerovì}
139 \bigskip
140 \bigskip
141
142 \hrule
143 \bigskip
144
145 \centerline{\vbox{\halign{%
146 #\hfil \enspace&#\hfil\enspace & #\hfil & \quad #\hfil&
147 \hfil # &
148 \hfil # &
149 \hfil # & \kern0.4em
150 \hfil # &
151 \hfil # & \kern1em
152 \hb\quad\hfil # \cr
153 \noalign{\bigskip\bigskip\hbox{\xit Vítìzové}\bigskip}
154 %\noalign{\bigskip\bigskip\hbox{\xit Úspì¹ní øe¹itelé}\bigskip}
155 %\noalign{\bigskip\bigskip\hbox{\xit Ostatní úèastníci}\bigskip}
156 ';
157         foreach $r (@table) { print join('&',@$r), "\\cr\n";}
158
159 print '&&&
160 \hphantom{10} &
161 \hphantom{10} &
162 \hphantom{10} &
163 \hphantom{10} &
164 \hphantom{10} &&
165 \hphantom{10} \cr
166 }}}
167
168 \bye
169 ';
170 } else {
171         foreach $r (@table) { print join("\t",@$r), "\n"; }
172 }