]> mj.ucw.cz Git - moe.git/blob - bin/mo-score2004
The Big Cleanup.
[moe.git] / bin / mo-score2004
1 #!/usr/bin/perl
2
3 $tex = 0;
4 $usage = "Usage: mo-score2004 [--tex] theoretical_tasks_nr praxis_tasks_nr task1 task2 ...";
5 while (($arg = $ARGV[0]) =~ /^--([a-z]+)$/) {
6         shift @ARGV;
7         $var = "\$$1";
8         if (!eval "defined $var") { die $usage; }
9         eval "$var = 1;";
10 }
11 @ARGV >=2 || die $usage;
12 $theory=shift @ARGV;
13 $praxis=shift @ARGV;
14 @ARGV >= $praxis || die $usage;
15
16 print STDERR "Scanning contestants... ";
17 open (CT, "bin/mo-get-users --full |") || die "Cannot get list of contestants";
18 while (<CT>) {
19         chomp;
20         ($u,$f) = split /\t/;
21         ($u eq "somebody") && next;
22         $users{$u}=$f;
23 }
24 close CT;
25 print STDERR 0+keys %users, "\n";
26
27 print STDERR "Scanning teoretical results... ";
28 if (open (EX, "teorie.txt")) {
29         while (<EX>) {
30                 chomp;
31                 (/^$/ || /^#/) && next;
32                 @a = split /\ *\t\ */;
33                 $u = shift @a;
34                 defined $users{$u} || die "Unknown user $u";
35                 $names{$u} = shift @a;
36                 $forms{$u} = shift @a;
37                 $addresses{$u} = "{". (shift @a) ."}";
38                 $i=0;
39                 while (@a) { $tasks{$u}{$i} = shift @a;$i++; }
40         }
41         close EX;
42         print STDERR "OK\n";
43 } else {die "none\n";}
44
45 print STDERR "Scanning task results... ";
46 $need_tasks = join("|", @ARGV);
47 foreach $u (keys %users) {
48         opendir (D, "testing/$u") or next;
49         foreach $t (readdir(D)) {
50                 $t =~ /^\./ && next;
51                 $t =~ /$need_tasks/ || next;
52
53                 $t_num=$praxis;
54                 for (my $t_num2=0;$t_num2<@ARGV;$t_num2++) {if ($t eq $ARGV[$t_num2]) {$t_num=$t_num2;}}
55                 $t_num+=$theory;
56
57                 $tt = "testing/$u/$t/points";
58                 -f $tt || next;
59                 print STDERR "$u/$t ";
60                 open (X, $tt) || die "Unable to open $tt";
61                 while (<X>) {
62                         chomp;
63                         /^\S+ (-?\d+)/ || die "Parse error: $_";
64                         $tasks{$u}{$t_num} += $1;
65                 }
66                 close X;
67         }
68         closedir D;
69 }
70 print STDERR "OK\n";
71
72 print STDERR "Creating table template... ";
73 @body = ('','$names{$u}','$forms{$u}','$addresses{$u}');
74 for ($a=0;$a<$theory+$praxis;$a++) {push @body,"\$tasks{\$u}{$a}";}
75 print STDERR "OK\n";
76
77 print STDERR "Filling in results... ";
78 @table = ();
79 foreach $u (keys %users) {
80         $row = [];
81         $row_index=0;
82         $row_sum=0;
83         foreach my $c (@body) {
84                 $c =~ s/\$(\d+)/\$\$row[$1]/g;
85                 $x = eval $c;
86                 push @$row, (defined $x ? $x : '-');
87                 if ($row_index>3) {
88                     if ((defined $x) && ($x>0)) {$row_sum+=$x;}
89                 }
90                 $row_index++;
91         }
92         push @$row, $row_sum;
93         push @table, $row;
94 }
95 print STDERR "OK\n";
96
97 print STDERR "Sorting... ";
98 $sortcol = @{$table[0]} - 1;
99 $namecol = 1;
100 @table = sort {
101         my $p, $an, $bn;
102         $p = $$b[$sortcol] <=> $$a[$sortcol];
103         ($an = $$a[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
104         ($bn = $$b[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
105         $p ? $p : ($an cmp $bn);
106 } @table;
107 $i=0;
108 while ($i < @table) {
109         $j = $i;
110         while ($i < @table && ${$table[$i]}[$sortcol] == ${$table[$j]}[$sortcol]) {
111                 $i++;
112         }
113         if ($i == $j+1) {
114                 ${table[$j]}[0] = "$i.";
115         } else {
116                 ${table[$j]}[0] = $j+1 . ".-" . $i . ".";
117                 $j_old=$j;
118                 $j++;
119                 while ($j < $i) { ${table[$j++]}[0] = $j_old+1 . ".-" . $i . "."; };
120         }
121 }
122 print STDERR "OK\n";
123
124 if ($tex) {
125         print
126 '\language=\czech
127 \frenchspacing
128 \font\head=csr12 scaled \magstephalf
129 \font\hexx=csti12
130 \font\xxit=csti10
131 \def\xit{\xxit\kern-0.1em\relax}
132 \let\hb=\relax
133 \parindent=0pt
134 \nopagenumbers
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 &~~#\hfil &\quad #\hfil &~~#\hfil&\quad
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 }