9 $usage = "Usage: mo-score [--detail] [--alt] [--extras] [--html] [--tex] <task1> <task2> ...";
10 while (($arg = $ARGV[0]) =~ /^--([a-z]+)$/) {
13 if (!eval "defined $var") { die $usage; }
20 print STDERR "Scanning contestants... ";
21 open (CT, "bin/mo-get-users --full |") || die "Cannot get list of contestants";
25 ($u eq "somebody") && next;
29 print STDERR 0+keys %users, "\n";
31 print STDERR "Scanning exceptions... ";
32 if ($extras && open (EX, "exceptions")) {
35 (/^$/ || /^#/) && next;
38 defined $users{$u} || die "Unknown user $u";
39 while (@a) { $extra{$u} += shift @a; }
43 } else { print STDERR "none\n"; }
45 print STDERR "Scanning task results... ";
46 $need_tasks = join("|", @ARGV);
49 foreach $u (keys %users) {
50 opendir (D, "testing/$u") or next;
51 foreach $t (readdir(D)) {
53 $t =~ /$need_tasks/ || next;
55 $tt = "testing/$u/$t/points" . ($alt ? ".alt" : "");
57 print STDERR "$u/$t ";
58 open (X, $tt) || die "Unable to open $tt";
61 /^(\S+) (-?\d+)\s*(.*)/ || die "Parse error: $_";
65 $ttest =~ s/[^0-9]//g;
66 $known_tests{$t}{$ttest} = 1;
67 $results{$u}{$t}{$ttest} = $tpts;
68 $remarks{$u}{$t}{$ttest} = $trem;
71 if ($trem =~ /^Compile /) { $cmt = "CE"; }
72 elsif ($trem =~ /^Time limit exceeded/) { $cmt = "TO"; }
73 elsif ($trem =~ /^Exited with error /) { $cmt = "RE"; }
74 elsif ($trem =~ /^Caught fatal signal /) { $cmt = "SG"; }
75 elsif ($trem =~ /^([A-Za-z])\S*\s+([A-Za-z])/) {
76 ($cmt = "$1$2") =~ tr/a-z/A-Z/;
78 elsif ($trem =~ /^Wrong answer/) { $cmt = "WA"; }
79 if (!defined $messages{$trem}) {
80 $messages{$trem} = $cmt;
81 if (!defined $error_codes{$cmt}) {
82 $error_codes{$cmt} = $trem;
84 $error_codes{$cmt} .= ", $trem";
88 $comment{$u}{$t}{$ttest} = $cmt;
89 $total{$u}{$t} += $tpts;
97 print STDERR "Creating table template... ";
98 @header = ("Rank","User","Name");
99 @body = ('','$u','$users{$u}');
101 @footer = ('"Total"','','');
103 push @header, "Extra";
104 push @body, '$extra{$u}';
106 push @bodysums, $col;
107 push @footer, "sum($col)";
110 defined $known_tasks{$t} || die "Unknown task $t";
111 push @header, substr($t, 0, 4);
112 push @body, "(\$xx = \$total{\$u}{'$t'}) > 0 ? \$xx : 0";
114 push @footer, "sum($col)";
115 push @bodysums, $col;
117 foreach $s (sort { $a <=> $b } keys %{$known_tests{$t}}) {
119 push @body, "\$comment{\$u}{'$t'}{'$s'}";
121 push @footer, "sum($col)";
125 push @header, "Total";
126 push @body, join('+', map { $_ = "\$$_" } @bodysums);
128 push @footer, "sum($col)";
131 print STDERR "h: ", join(':',@header), "\n" if $debug;
132 print STDERR "b: ", join(':',@body), "\n" if $debug;
133 print STDERR "f: ", join(':',@footer), "\n" if $debug;
135 print STDERR "Filling in results... ";
137 foreach $u (keys %users) {
139 foreach my $c (@body) {
140 $c =~ s/\$(\d+)/\$\$row[$1]/g;
142 push @$row, (defined $x ? $x : '-');
144 print STDERR "row: ", join(':',@$row), "\n" if $debug;
149 print STDERR "Sorting... ";
150 $sortcol = @{$table[0]} - 1;
154 $p = $$b[$sortcol] <=> $$a[$sortcol];
155 ($an = $$a[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
156 ($bn = $$b[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
157 $p ? $p : ($an cmp $bn);
160 while ($i < @table) {
162 while ($i < @table && ${$table[$i]}[$sortcol] == ${$table[$j]}[$sortcol]) {
166 ${table[$j]}[0] = "$i.";
168 ${table[$j]}[0] = $j+1 . ".-" . $i . ".";
170 while ($j < $i) { ${table[$j++]}[0] = ""; };
175 print STDERR "Attaching headers and footers... ";
176 sub sum { my $col=shift @_; my $t=0; foreach my $z (0..@table-1) { $t += ${$table[$z]}[$col]; } $t; }
177 map { $_ = eval $_; } @footer;
178 push @table, \@footer;
179 unshift @table, \@header;
183 foreach $r (@table) { print join(':',@$r), "\n"; }
185 print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html40/strict.dtd">', "\n";
186 print "<HTML><HEAD><TITLE>Rank list</TITLE></HEAD><BODY>\n";
187 print "<H1>Rank list</H1>\n";
190 &printHtmlHeader(\@perm);
193 foreach $r (@table[1..($#table - 1)]) {
194 &printHtmlRow(@{$r}[@perm]);
198 &printHtmlRow(@{$table[$#table]}[@perm]);
202 print "<H2>Error codes</H2><UL>\n";
203 foreach $r (sort keys %error_codes) { print "<LI>$r: $error_codes{$r}\n"; }
206 print "</BODY></HTML>\n";
208 print "\\error{TeX output not supported yet!}\n";
210 foreach $r (@table) { print join("\t",@$r), "\n"; }
212 foreach $r (sort keys %error_codes) { print "$r: $error_codes{$r}\n"; }
217 print "<TR>", join('',map {
218 if ($hdr) { $_ = "<TH>$_"; }
219 else { $_ = "<TD align=" . (/^[0-9A-Z-]+$/ ? "right" : "left") . (length($_) > 14 ? " width=150" : "") . ">$_"; }
224 sub printHtmlHeader {
228 my $colspec = "<colgroup span=3>";
236 $hdr1 = "<th rowspan=2>Rank<th rowspan=2>User<th rowspan=2>Name";
237 for my $task (@tasks) {
239 my $nSub = scalar(keys %{$known_tests{$task}});
242 map { push @$perm, $p++ } (1..$nSub);
243 push @$perm, $p - $nSub - 1;
245 $colspec .= "<colgroup span='" . $nSub . "'>\n";
246 $colspec .= "<colgroup span='1'>\n";
247 $hdr1 .= "<th colspan='" . ($nSub + 1) . "' style='border-bottom:1px solid black;'>$task";
248 $hdr2 .= join("", map { "<th>$_" } sort {$a <=> $b} keys %{$known_tests{$task}});
249 $hdr2 .= "<th>Total";
252 $hdr1 .= "<th rowspan='2'>Total";
254 } else { ## no detail
256 $hdr1 = "<th>Rank<th>User<th>Name";
258 for my $task (@tasks) {
260 $hdr1 .= "<th>$task";
262 $hdr1 .= "<th>Total";
263 $colspec .= "<colgroup span='" . scalar (@tasks) . "'>";
268 print "<TABLE rules=groups frame=all border='1' cellpadding='2'>\n";
269 print "$colspec<colgroup span='1'>\n";
270 print "<tr>$hdr1</tr>\n";
271 print "<tr>$hdr2</tr>\n" if $detail;