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 $ttest =~ s/[^0-9]//g;
64 $known_tests{$t}{$ttest} = 1;
65 $results{$u}{$t}{$ttest} = $tpts;
66 $remarks{$u}{$t}{$ttest} = $trem;
69 if ($trem =~ /^Compile /) { $cmt = "CE"; }
70 elsif ($trem =~ /^Time limit exceeded/) { $cmt = "TO"; }
71 elsif ($trem =~ /^Exited with error /) { $cmt = "RE"; }
72 elsif ($trem =~ /^Caught fatal signal /) { $cmt = "SG"; }
73 elsif ($trem =~ /^([A-Za-z])\S*\s+([A-Za-z])/) {
74 ($cmt = "$1$2") =~ tr/a-z/A-Z/;
76 elsif ($trem =~ /^Wrong answer/) { $cmt = "WA"; }
77 if (!defined $messages{$trem}) {
78 $messages{$trem} = $cmt;
79 if (!defined $error_codes{$cmt}) {
80 $error_codes{$cmt} = $trem;
82 $error_codes{$cmt} .= ", $trem";
86 $comment{$u}{$t}{$ttest} = $cmt;
87 $total{$u}{$t} += $tpts;
95 print STDERR "Creating table template... ";
96 @header = ("Rank","User","Name");
97 @body = ('','$u','$users{$u}');
99 @footer = ('"Total"','','');
101 push @header, "Extra";
102 push @body, '$extra{$u}';
104 push @bodysums, $col;
105 push @footer, "sum($col)";
108 defined $known_tasks{$t} || die "Unknown task $t";
109 push @header, substr($t, 0, 4);
110 push @body, "(\$xx = \$total{\$u}{'$t'}) > 0 ? \$xx : 0";
112 push @footer, "sum($col)";
113 push @bodysums, $col;
115 foreach $s (sort { $a <=> $b } keys %{$known_tests{$t}}) {
117 push @body, "\$comment{\$u}{'$t'}{'$s'}";
119 push @footer, "sum($col)";
123 push @header, "Total";
124 push @body, join('+', map { $_ = "\$$_" } @bodysums);
126 push @footer, "sum($col)";
129 print STDERR "h: ", join(':',@header), "\n" if $debug;
130 print STDERR "b: ", join(':',@body), "\n" if $debug;
131 print STDERR "f: ", join(':',@footer), "\n" if $debug;
133 print STDERR "Filling in results... ";
135 foreach $u (keys %users) {
137 foreach my $c (@body) {
138 $c =~ s/\$(\d+)/\$\$row[$1]/g;
140 push @$row, (defined $x ? $x : '-');
142 print STDERR "row: ", join(':',@$row), "\n" if $debug;
147 print STDERR "Sorting... ";
148 $sortcol = @{$table[0]} - 1;
152 $p = $$b[$sortcol] <=> $$a[$sortcol];
153 ($an = $$a[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
154 ($bn = $$b[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
155 $p ? $p : ($an cmp $bn);
158 while ($i < @table) {
160 while ($i < @table && ${$table[$i]}[$sortcol] == ${$table[$j]}[$sortcol]) {
164 ${table[$j]}[0] = "$i.";
166 ${table[$j]}[0] = $j+1 . ".-" . $i . ".";
168 while ($j < $i) { ${table[$j++]}[0] = ""; };
173 print STDERR "Attaching headers and footers... ";
174 sub sum { my $col=shift @_; my $t=0; foreach my $z (0..@table-1) { $t += ${$table[$z]}[$col]; } $t; }
175 map { $_ = eval $_; } @footer;
176 push @table, \@footer;
177 unshift @table, \@header;
181 foreach $r (@table) { print join(':',@$r), "\n"; }
183 print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html40/strict.dtd">', "\n";
184 print "<HTML><HEAD><TITLE>Rank list</TITLE></HEAD><BODY>\n";
185 print "<H1>Rank list</H1>\n";
188 foreach $r (@table) {
189 print "<TR>", join('',map {
190 if ($hdr) { $_ = "<TH>$_"; }
191 else { $_ = "<TD align=" . (/^[0-9A-Z-]+$/ ? "right" : "left") . (length($_) > 14 ? " width=150" : "") . ">$_"; }
197 print "<H2>Error codes</H2><UL>\n";
198 foreach $r (sort keys %error_codes) { print "<LI>$r: $error_codes{$r}\n"; }
201 print "</BODY></HTML>\n";
203 print "\\error{TeX output not supported yet!}\n";
205 foreach $r (@table) { print join("\t",@$r), "\n"; }
207 foreach $r (sort keys %error_codes) { print "$r: $error_codes{$r}\n"; }