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);
45 foreach $u (keys %users) {
46 opendir (D, "testing/$u") or next;
47 foreach $t (readdir(D)) {
49 $t =~ /$need_tasks/ || next;
51 $tt = "testing/$u/$t/points" . ($alt ? ".alt" : "");
53 print STDERR "$u/$t ";
54 open (X, $tt) || die "Unable to open $tt";
57 /^(\S+) (-?\d+)\s*(.*)/ || die "Parse error: $_";
61 $known_tests{$t}{$ttest} = 1;
62 $results{$u}{$t}{$ttest} = $tpts;
63 $remarks{$u}{$t}{$ttest} = $trem;
66 if ($trem =~ /^Compile /) { $cmt = "CE"; }
67 elsif ($trem =~ /^Time limit exceeded/) { $cmt = "TO"; }
68 elsif ($trem =~ /^Exited with error /) { $cmt = "RE"; }
69 elsif ($trem =~ /^Caught fatal signal /) { $cmt = "SG"; }
70 elsif ($trem =~ /^([A-Za-z])\S*\s+([A-Za-z])/) {
71 ($cmt = "$1$2") =~ tr/a-z/A-Z/;
73 elsif ($trem =~ /^Wrong answer/) { $cmt = "WA"; }
75 $comment{$u}{$t}{$ttest} = $cmt;
76 $total{$u}{$t} += $tpts;
84 print STDERR "Creating table template... ";
85 @header = ("Rank","User","Name");
86 @body = ('','$u','$users{$u}');
88 @footer = ('"Total"','','');
90 push @header, "Extra";
91 push @body, '$extra{$u}';
94 push @footer, "sum($col)";
97 defined $known_tasks{$t} || die "Unknown task $t";
98 push @header, substr($t, 0, 4);
99 push @body, "(\$xx = \$total{\$u}{'$t'}) > 0 ? \$xx : 0";
101 push @footer, "sum($col)";
102 push @bodysums, $col;
104 foreach $s (sort { $a <=> $b } keys %{$known_tests{$t}}) {
106 push @body, "\$comment{\$u}{'$t'}{'$s'}";
108 push @footer, "sum($col)";
112 push @header, "Total";
113 push @body, join('+', map { $_ = "\$$_" } @bodysums);
115 push @footer, "sum($col)";
118 print STDERR "h: ", join(':',@header), "\n" if $debug;
119 print STDERR "b: ", join(':',@body), "\n" if $debug;
120 print STDERR "f: ", join(':',@footer), "\n" if $debug;
122 print STDERR "Filling in results... ";
124 foreach $u (keys %users) {
126 foreach my $c (@body) {
127 $c =~ s/\$(\d+)/\$\$row[$1]/g;
129 push @$row, (defined $x ? $x : '-');
131 print STDERR "row: ", join(':',@$row), "\n" if $debug;
136 print STDERR "Sorting... ";
137 $sortcol = @{$table[0]} - 1;
141 $p = $$b[$sortcol] <=> $$a[$sortcol];
142 ($an = $$a[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
143 ($bn = $$b[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
144 $p ? $p : ($an cmp $bn);
147 while ($i < @table) {
149 while ($i < @table && ${$table[$i]}[$sortcol] == ${$table[$j]}[$sortcol]) {
153 ${table[$j]}[0] = "$i.";
155 ${table[$j]}[0] = $j+1 . ".-" . $i . ".";
157 while ($j < $i) { ${table[$j++]}[0] = ""; };
162 print STDERR "Attaching headers and footers... ";
163 sub sum { my $col=shift @_; my $t=0; foreach my $z (0..@table-1) { $t += ${$table[$z]}[$col]; } $t; }
164 map { $_ = eval $_; } @footer;
165 push @table, \@footer;
166 unshift @table, \@header;
170 foreach $r (@table) { print join(':',@$r), "\n"; }
172 print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html40/strict.dtd">', "\n";
173 print "<HTML><HEAD><TITLE>Rank list</TITLE></HEAD><BODY>\n";
174 print "<H1>Rank list</H1>\n";
177 foreach $r (@table) {
178 print "<TR>", join('',map {
179 if ($hdr) { $_ = "<TH>$_"; }
180 else { $_ = "<TD align=" . (/^[0-9A-Z-]+$/ ? "right" : "left") . (length($_) > 14 ? " width=150" : "") . ">$_"; }
185 print "</BODY></HTML>\n";
187 print "\\error{TeX output not supported yet!}\n";
189 foreach $r (@table) { print join("\t",@$r), "\n"; }