7 $usage = "Usage: mo-score [--detail] [--html] [--tex] <task1> <task2> ...";
8 while (($arg = $ARGV[0]) =~ /^--([a-z]+)$/) {
11 if (!eval "defined $var") { die $usage; }
16 print STDERR "Scanning contestants... ";
17 open (CT, "bin/mo-get-users --full |") || die "Cannot get list of contestants";
24 print STDERR 0+keys %users, "\n";
26 print STDERR "Scanning task results... ";
27 foreach $u (keys %users) {
28 opendir (D, "testing/$u") or next;
29 foreach $t (readdir(D)) {
32 $tt = "testing/$u/$t/points";
34 print STDERR "$u/$t ";
35 open (X, $tt) || die "Unable to open $tt";
38 /^(\d+) (\d+)(.*)/ || die "Parse error: $_";
42 $known_tests{$t}{$ttest} = 1;
43 $results{$u}{$t}{$ttest} = $tpts;
44 $remarks{$u}{$t}{$ttest} = $trem;
48 if ($msg =~ /^Compile /) { $cmt = "CE"; }
49 elsif ($msg =~ /^Time limit exceeded/) { $cmt = "TO"; }
50 elsif ($msg =~ /^Exited with error /) { $cmt = "RE"; }
51 elsif ($msg =~ /^Caught fatal signal /) { $cmt = "SG"; }
53 $comment{$u}{$t}{$ttest} = $cmt;
54 $total{$u}{$t} += $tpts;
62 print STDERR "Creating table template... ";
63 @header = ("Rank","User","Name");
64 @body = ('','$u','$users{$u}');
66 @footer = ('"Total"','','');
68 defined $known_tasks{$t} || die "Unknown task $t";
70 push @body, "\$total{\$u}{'$t'}";
72 push @footer, "sum($col)";
75 foreach $s (sort { $a <=> $b } keys %{$known_tests{$t}}) {
77 push @body, "\$comment{\$u}{'$t'}{'$s'}";
79 push @footer, "sum($col)";
83 push @header, "Total";
84 push @body, join('+', map { $_ = "\$$_" } @bodysums);
86 push @footer, "sum($col)";
89 print STDERR "h: ", join(':',@header), "\n" if $debug;
90 print STDERR "b: ", join(':',@body), "\n" if $debug;
91 print STDERR "f: ", join(':',@footer), "\n" if $debug;
93 print STDERR "Filling in results... ";
95 foreach $u (keys %users) {
97 foreach my $c (@body) {
98 $c =~ s/\$(\d+)/\$\$row[$1]/g;
100 push @$row, (defined $x ? $x : '-');
102 print STDERR "row: ", join(':',@$row), "\n" if $debug;
107 print STDERR "Sorting... ";
108 $sortcol = @{$table[0]} - 1;
112 $p = $$b[$sortcol] <=> $$a[$sortcol];
113 ($an = $$a[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
114 ($bn = $$b[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
115 $p ? $p : ($an cmp $bn);
118 while ($i < @table) {
120 while ($i < @table && ${$table[$i]}[$sortcol] == ${$table[$j]}[$sortcol]) {
124 ${table[$j]}[0] = "$i.";
126 ${table[$j]}[0] = $j+1 . ".--" . $i . ".";
128 while ($j < $i) { ${table[$j++]}[0] = ""; };
133 print STDERR "Attaching headers and footers... ";
134 sub sum { my $col=shift @_; my $t=0; foreach my $z (0..@table-1) { $t += ${$table[$z]}[$col]; } $t; }
135 map { $_ = eval $_; } @footer;
136 push @table, \@footer;
137 unshift @table, \@header;
141 foreach $r (@table) { print join(':',@$r), "\n"; }
143 print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html40/strict.dtd">', "\n";
144 print "<HTML><HEAD><TITLE>Rank list</TITLE></HEAD><BODY>\n";
145 print "<H1>Rank list</H1>\n";
148 foreach $r (@table) {
149 print "<TR>", join('',map {
150 if ($hdr) { $_ = "<TH>$_"; }
151 else { $_ = "<TD align=" . (/^[0-9-]+$/ ? "right" : "left") . ">$_"; }
156 print "</BODY></HTML>\n";
158 print "\\error{TeX output not supported yet!}\n";
160 foreach $r (@table) { print join("\t",@$r), "\n"; }