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; }
18 print STDERR "Scanning contestants... ";
19 open (CT, "bin/mo-get-users --full |") || die "Cannot get list of contestants";
23 ($u eq "somebody") && next;
27 print STDERR 0+keys %users, "\n";
29 print STDERR "Scanning exceptions... ";
30 if ($extras && open (EX, "exceptions")) {
33 (/^$/ || /^#/) && next;
36 defined $users{$u} || die "Unknown user $u";
37 while (@a) { $extra{$u} += shift @a; }
41 } else { print STDERR "none\n"; }
43 print STDERR "Scanning task results... ";
44 $need_tasks = join("|", @ARGV);
47 foreach $u (keys %users) {
48 opendir (D, "testing/$u") or next;
49 foreach $t (readdir(D)) {
51 $t =~ /$need_tasks/ || next;
53 $tt = "testing/$u/$t/points" . ($alt ? ".alt" : "");
55 print STDERR "$u/$t ";
56 open (X, $tt) || die "Unable to open $tt";
59 /^(\S+) (-?\d+)\s*(.*)/ || die "Parse error: $_";
63 $known_tests{$t}{$ttest} = 1;
64 $results{$u}{$t}{$ttest} = $tpts;
65 $remarks{$u}{$t}{$ttest} = $trem;
68 if ($trem =~ /^Compile /) { $cmt = "CE"; }
69 elsif ($trem =~ /^Time limit exceeded/) { $cmt = "TO"; }
70 elsif ($trem =~ /^Exited with error /) { $cmt = "RE"; }
71 elsif ($trem =~ /^Caught fatal signal /) { $cmt = "SG"; }
72 elsif ($trem =~ /^([A-Za-z])\S*\s+([A-Za-z])/) {
73 ($cmt = "$1$2") =~ tr/a-z/A-Z/;
75 elsif ($trem =~ /^Wrong answer/) { $cmt = "WA"; }
76 if (!defined $messages{$trem}) {
77 $messages{$trem} = $cmt;
78 if (!defined $error_codes{$cmt}) {
79 $error_codes{$cmt} = $trem;
81 $error_codes{$cmt} .= ", $trem";
85 $comment{$u}{$t}{$ttest} = $cmt;
86 $total{$u}{$t} += $tpts;
94 print STDERR "Creating table template... ";
95 @header = ("Rank","User","Name");
96 @body = ('','$u','$users{$u}');
98 @footer = ('"Total"','','');
100 push @header, "Extra";
101 push @body, '$extra{$u}';
103 push @bodysums, $col;
104 push @footer, "sum($col)";
107 defined $known_tasks{$t} || die "Unknown task $t";
108 push @header, substr($t, 0, 4);
109 push @body, "(\$xx = \$total{\$u}{'$t'}) > 0 ? \$xx : 0";
111 push @footer, "sum($col)";
112 push @bodysums, $col;
114 foreach $s (sort { $a <=> $b } keys %{$known_tests{$t}}) {
116 push @body, "\$comment{\$u}{'$t'}{'$s'}";
118 push @footer, "sum($col)";
122 push @header, "Total";
123 push @body, join('+', map { $_ = "\$$_" } @bodysums);
125 push @footer, "sum($col)";
128 print STDERR "h: ", join(':',@header), "\n" if $debug;
129 print STDERR "b: ", join(':',@body), "\n" if $debug;
130 print STDERR "f: ", join(':',@footer), "\n" if $debug;
132 print STDERR "Filling in results... ";
134 foreach $u (keys %users) {
136 foreach my $c (@body) {
137 $c =~ s/\$(\d+)/\$\$row[$1]/g;
139 push @$row, (defined $x ? $x : '-');
141 print STDERR "row: ", join(':',@$row), "\n" if $debug;
146 print STDERR "Sorting... ";
147 $sortcol = @{$table[0]} - 1;
151 $p = $$b[$sortcol] <=> $$a[$sortcol];
152 ($an = $$a[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
153 ($bn = $$b[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
154 $p ? $p : ($an cmp $bn);
157 while ($i < @table) {
159 while ($i < @table && ${$table[$i]}[$sortcol] == ${$table[$j]}[$sortcol]) {
163 ${table[$j]}[0] = "$i.";
165 ${table[$j]}[0] = $j+1 . ".-" . $i . ".";
167 while ($j < $i) { ${table[$j++]}[0] = ""; };
172 print STDERR "Attaching headers and footers... ";
173 sub sum { my $col=shift @_; my $t=0; foreach my $z (0..@table-1) { $t += ${$table[$z]}[$col]; } $t; }
174 map { $_ = eval $_; } @footer;
175 push @table, \@footer;
176 unshift @table, \@header;
180 foreach $r (@table) { print join(':',@$r), "\n"; }
182 print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html40/strict.dtd">', "\n";
183 print "<HTML><HEAD><TITLE>Rank list</TITLE></HEAD><BODY>\n";
184 print "<H1>Rank list</H1>\n";
187 foreach $r (@table) {
188 print "<TR>", join('',map {
189 if ($hdr) { $_ = "<TH>$_"; }
190 else { $_ = "<TD align=" . (/^[0-9A-Z-]+$/ ? "right" : "left") . (length($_) > 14 ? " width=150" : "") . ">$_"; }
195 print "<H2>Error codes</H2><UL>\n";
196 foreach $r (sort keys %error_codes) { print "<LI>$r: $error_codes{$r}\n"; }
198 print "</BODY></HTML>\n";
200 print "\\error{TeX output not supported yet!}\n";
202 foreach $r (@table) { print join("\t",@$r), "\n"; }
204 foreach $r (sort keys %error_codes) { print "$r: $error_codes{$r}\n"; }