10 $usage = "Usage: mo-score [--detail] [--alt] [--extras] [--html] [--tex] [--split] <task1> <task2> ...";
11 while (($arg = $ARGV[0]) =~ /^--([a-z]+)$/) {
14 if (!eval "defined $var") { die $usage; }
21 print STDERR "Scanning contestants... ";
22 open (CT, "bin/mo-get-users --full |") || die "Cannot get list of contestants";
26 ($u eq "somebody") && next;
30 print STDERR 0+keys %users, "\n";
32 print STDERR "Scanning exceptions... ";
33 if ($extras && open (EX, "exceptions")) {
36 (/^$/ || /^#/) && next;
39 defined $users{$u} || die "Unknown user $u";
40 while (@a) { $extra{$u} += shift @a; }
44 } else { print STDERR "none\n"; }
46 print STDERR "Scanning task results... ";
47 $need_tasks = join("|", @ARGV);
50 foreach $u (keys %users) {
51 opendir (D, "testing/$u") or next;
52 foreach $t (readdir(D)) {
54 $t =~ /$need_tasks/ || next;
56 $tt = "testing/$u/$t/points" . ($alt ? ".alt" : "");
58 print STDERR "$u/$t ";
59 open (X, $tt) || die "Unable to open $tt";
62 /^(\S+) (-?\d+)\s*(.*)/ || die "Parse error: $_";
67 $ttest =~ s/[^0-9]//g unless $split;
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;
94 foreach my $t (keys %known_tasks) {
96 foreach my $pts (values %{$results{$u}{$t}}) { $total{$u}{$t} += $pts; }
102 print STDERR "Creating table template... ";
103 @header = ("Rank","User","Name");
104 @body = ('','$u','$users{$u}');
106 @footer = ('"Total"','','');
108 push @header, "Extra";
109 push @body, '$extra{$u}';
111 push @bodysums, $col;
112 push @footer, "sum($col)";
115 defined $known_tasks{$t} || die "Unknown task $t";
116 push @header, substr($t, 0, 4);
117 push @body, "(\$xx = \$total{\$u}{'$t'}) > 0 ? \$xx : 0";
119 push @footer, "sum($col)";
120 push @bodysums, $col;
122 foreach $s (sort { $a <=> $b } keys %{$known_tests{$t}}) {
124 push @body, "\$comment{\$u}{'$t'}{'$s'}";
126 push @footer, "sum($col)";
130 push @header, "Total";
131 push @body, join('+', map { $_ = "\$$_" } @bodysums);
133 push @footer, "sum($col)";
136 print STDERR "h: ", join(':',@header), "\n" if $debug;
137 print STDERR "b: ", join(':',@body), "\n" if $debug;
138 print STDERR "f: ", join(':',@footer), "\n" if $debug;
140 print STDERR "Filling in results... ";
142 foreach $u (keys %users) {
144 foreach my $c (@body) {
145 $c =~ s/\$(\d+)/\$\$row[$1]/g;
147 push @$row, (defined $x ? $x : '-');
149 print STDERR "row: ", join(':',@$row), "\n" if $debug;
154 print STDERR "Sorting... ";
155 $sortcol = @{$table[0]} - 1;
159 $p = $$b[$sortcol] <=> $$a[$sortcol];
160 ($an = $$a[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
161 ($bn = $$b[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
162 $p ? $p : ($an cmp $bn);
165 while ($i < @table) {
167 while ($i < @table && ${$table[$i]}[$sortcol] == ${$table[$j]}[$sortcol]) {
171 ${table[$j]}[0] = "$i.";
173 ${table[$j]}[0] = $j+1 . ".-" . $i . ".";
175 while ($j < $i) { ${table[$j++]}[0] = ""; };
180 print STDERR "Attaching headers and footers... ";
181 sub sum { my $col=shift @_; my $t=0; foreach my $z (0..@table-1) { $t += ${$table[$z]}[$col]; } $t; }
182 map { $_ = eval $_; } @footer;
183 push @table, \@footer;
184 unshift @table, \@header;
188 foreach $r (@table) { print join(':',@$r), "\n"; }
190 print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html40/strict.dtd">', "\n";
191 print "<HTML><HEAD><TITLE>Rank list</TITLE></HEAD><BODY>\n";
192 print "<H1>Rank list</H1>\n";
195 &printHtmlHeader(\@perm);
198 foreach $r (@table[1..($#table - 1)]) {
199 &printHtmlRow(@{$r}[@perm]);
203 &printHtmlRow(@{$table[$#table]}[@perm]);
207 print "<H2>Error codes</H2><UL>\n";
208 foreach $r (sort keys %error_codes) { print "<LI>$r: $error_codes{$r}\n"; }
211 print "</BODY></HTML>\n";
213 print "\\error{TeX output not supported yet!}\n";
215 foreach $r (@table) { print join("\t",@$r), "\n"; }
217 foreach $r (sort keys %error_codes) { print "$r: $error_codes{$r}\n"; }
222 print "<TR>", join('',map {
223 if ($hdr) { $_ = "<TH>$_"; }
224 else { $_ = "<TD align=" . (/^[0-9A-Z-]+$/ ? "right" : "left") . (length($_) > 14 ? " width=150" : "") . ">$_"; }
229 sub printHtmlHeader {
233 my $colspec = "<colgroup span=3>";
241 $hdr1 = "<th rowspan=2>Rank<th rowspan=2>User<th rowspan=2>Name";
242 for my $task (@tasks) {
244 my $nSub = scalar(keys %{$known_tests{$task}});
247 map { push @$perm, $p++ } (1..$nSub);
248 push @$perm, $p - $nSub - 1;
250 $colspec .= "<colgroup span='" . $nSub . "'>\n";
251 $colspec .= "<colgroup span='1'>\n";
252 $hdr1 .= "<th colspan='" . ($nSub + 1) . "' style='border-bottom:1px solid black;'>$task";
253 $hdr2 .= join("", map { "<th>$_" } sort {$a <=> $b} keys %{$known_tests{$task}});
254 $hdr2 .= "<th>Total";
257 $hdr1 .= "<th rowspan='2'>Total";
259 } else { ## no detail
261 $hdr1 = "<th>Rank<th>User<th>Name";
263 for my $task (@tasks) {
265 $hdr1 .= "<th>$task";
267 $hdr1 .= "<th>Total";
268 $colspec .= "<colgroup span='" . scalar (@tasks) . "'>";
273 print "<TABLE rules=groups frame=all border='1' cellpadding='2'>\n";
274 print "$colspec<colgroup span='1'>\n";
275 print "<tr>$hdr1</tr>\n";
276 print "<tr>$hdr2</tr>\n" if $detail;