10 $usage = "Usage: mo-score [--detail] [--alt] [--extras] [--html] [--tex] [--merged] [<directory>/]<task> ...";
11 while (($arg = $ARGV[0]) =~ /^--([a-z]+)$/) {
14 if (!eval "defined $var") { die $usage; }
19 print STDERR "Scanning contestants... ";
20 open (CT, "bin/mo-get-users --full |") || die "Cannot get list of contestants";
24 ($u eq "somebody") && next;
28 print STDERR 0+keys %users, "\n";
30 print STDERR "Scanning exceptions... ";
31 if ($extras && open (EX, "exceptions")) {
34 (/^$/ || /^#/) && next;
37 defined $users{$u} || die "Unknown user $u";
38 while (@a) { $extra{$u} += shift @a; }
42 } else { print STDERR "none\n"; }
44 print STDERR "Scanning task results... ";
47 foreach $u (keys %users) {
48 foreach $task (@ARGV) {
49 my ($dir, $t) = ("testing", $task);
50 if ($task =~ m@^(.*)/([^/]*)$@) {
55 $tt = "$dir/$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: $_";
66 ($ttest_merged = $ttest) =~ s/[^0-9]//g;
67 $ttest = $ttest_merged if $merged;
68 $known_tests{$t}{$ttest} = 1;
70 if ($tpts == 0 && $trem ne "OK") {
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 if (!defined $messages{$trem}) {
79 $messages{$trem} = $cmt;
80 if (!defined $error_codes{$cmt}) {
81 $error_codes{$cmt} = $trem;
83 $error_codes{$cmt} .= ", $trem";
87 if (!defined($results{$u}{$t}{$ttest}) || $results{$u}{$t}{$ttest} > $tpts) {
88 $results{$u}{$t}{$ttest} = $tpts;
89 $comment{$u}{$t}{$ttest} = $cmt;
91 if (!defined($results_merged{$u}{$t}{$ttest_merged}) || $results_merged{$u}{$t}{$ttest_merged} > $tpts) {
92 $results_merged{$u}{$t}{$ttest_merged} = $tpts;
97 foreach my $t (keys %known_tasks) {
99 foreach my $pts (values %{$results_merged{$u}{$t}}) { $total{$u}{$t} += $pts; }
104 print STDERR "Creating table template... ";
105 @header = ("Rank","User","Name");
106 @body = ('','$u','$users{$u}');
108 @footer = ('"Total"','','');
110 push @header, "Extra";
111 push @body, '$extra{$u}';
113 push @bodysums, $col;
114 push @footer, "sum($col)";
117 foreach $task (@ARGV) {
118 my $t = ($task =~ m@/([^/]*)$@) ? $1 : $task;
119 defined $known_tasks{$t} || die "Unknown task $t";
121 push @header, substr($t, 0, 4);
122 push @body, "(\$xx = \$total{\$u}{'$t'}) > 0 ? \$xx : 0";
124 push @footer, "sum($col)";
125 push @bodysums, $col;
127 foreach $s (sort { $a <=> $b } keys %{$known_tests{$t}}) {
129 push @body, "\$comment{\$u}{'$t'}{'$s'}";
131 push @footer, "sum($col)";
135 push @header, "Total";
136 push @body, join('+', map { $_ = "\$$_" } @bodysums);
138 push @footer, "sum($col)";
141 print STDERR "h: ", join(':',@header), "\n" if $debug;
142 print STDERR "b: ", join(':',@body), "\n" if $debug;
143 print STDERR "f: ", join(':',@footer), "\n" if $debug;
145 print STDERR "Filling in results... ";
147 foreach $u (keys %users) {
149 foreach my $c (@body) {
150 $c =~ s/\$(\d+)/\$\$row[$1]/g;
152 push @$row, (defined $x ? $x : '-');
154 print STDERR "row: ", join(':',@$row), "\n" if $debug;
159 print STDERR "Sorting... ";
160 $sortcol = @{$table[0]} - 1;
164 $p = $$b[$sortcol] <=> $$a[$sortcol];
165 ($an = $$a[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
166 ($bn = $$b[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
167 $p ? $p : ($an cmp $bn);
170 while ($i < @table) {
172 while ($i < @table && ${$table[$i]}[$sortcol] == ${$table[$j]}[$sortcol]) {
176 ${table[$j]}[0] = "$i.";
178 ${table[$j]}[0] = $j+1 . ".-" . $i . ".";
180 while ($j < $i) { ${table[$j++]}[0] = ""; };
185 print STDERR "Attaching headers and footers... ";
186 sub sum { my $col=shift @_; my $t=0; foreach my $z (0..@table-1) { $t += ${$table[$z]}[$col]; } $t; }
187 map { $_ = eval $_; } @footer;
188 push @table, \@footer;
189 unshift @table, \@header;
193 foreach $r (@table) { print join(':',@$r), "\n"; }
195 print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html40/strict.dtd">', "\n";
196 print "<HTML><HEAD><TITLE>Rank list</TITLE></HEAD><BODY>\n";
197 print "<H1>Rank list</H1>\n";
200 &printHtmlHeader(\@perm);
203 foreach $r (@table[1..($#table - 1)]) {
204 &printHtmlRow(@{$r}[@perm]);
208 &printHtmlRow(@{$table[$#table]}[@perm]);
212 print "<H2>Error codes</H2><UL>\n";
213 foreach $r (sort keys %error_codes) { print "<LI>$r: $error_codes{$r}\n"; }
216 print "</BODY></HTML>\n";
218 print "\\error{TeX output not supported yet!}\n";
220 foreach $r (@table) { print join("\t",@$r), "\n"; }
222 foreach $r (sort keys %error_codes) { print "$r: $error_codes{$r}\n"; }
227 print "<TR>", join('',map {
228 if ($hdr) { $_ = "<TH>$_"; }
229 else { $_ = "<TD align=" . (/^[0-9A-Z-]+$/ ? "right" : "left") . (length($_) > 14 ? " width=150" : "") . ">$_"; }
234 sub printHtmlHeader {
238 my $colspec = "<colgroup span=3>";
246 $hdr1 = "<th rowspan=2>Rank<th rowspan=2>User<th rowspan=2>Name";
247 $extras and $p++ and push @$perm, 3 and $hdr1.="<th rowspan=2>Extra" and $colspec.="<colgroup span=1>"; ##Extra hack
248 for my $task (@tasks) {
250 my $nSub = scalar(keys %{$known_tests{$task}});
253 map { push @$perm, $p++ } (1..$nSub);
254 push @$perm, $p - $nSub - 1;
256 $colspec .= "<colgroup span='" . $nSub . "'>\n";
257 $colspec .= "<colgroup span='1'>\n";
258 $hdr1 .= "<th colspan='" . ($nSub + 1) . "' style='border-bottom:1px solid black;'>$task";
259 $hdr2 .= join("", map { "<th>$_" } sort {$a <=> $b} keys %{$known_tests{$task}});
260 $hdr2 .= "<th>Total";
263 $hdr1 .= "<th rowspan='2'>Total";
265 } else { ## no detail
267 $hdr1 = "<th>Rank<th>User<th>Name";
268 $extras and $p++ and push @$perm, 3 and $hdr1.="<th>Extra" and $colspec.="<colgroup span=1>"; ##Extra hack
270 for my $task (@tasks) {
272 $hdr1 .= "<th>$task";
274 $hdr1 .= "<th>Total";
275 $colspec .= "<colgroup span='" . scalar (@tasks) . "'>";
280 print "<TABLE rules=groups frame=all border='1' cellpadding='2'>\n";
281 print "$colspec<colgroup span='1'>\n";
282 print "<tr>$hdr1</tr>\n";
283 print "<tr>$hdr2</tr>\n" if $detail;