]> mj.ucw.cz Git - eval.git/blobdiff - mop/eval/mo-score.sh
Templater: Fix Pascal projects
[eval.git] / mop / eval / mo-score.sh
index 4dec3a11677f9106d694340be829cfb2a0c1f8fa..9326b9aa129c7d6cba5ddbb026aa0bc2a911d21d 100755 (executable)
@@ -1,4 +1,5 @@
 #!/usr/bin/perl
 #!/usr/bin/perl
+# A generator of score sheets. More ugly than it deserves.
 
 $debug = 0;
 $detail = 0;
 
 $debug = 0;
 $detail = 0;
@@ -7,7 +8,8 @@ $tex = 0;
 $extras = 0;
 $alt = 0;
 $merged = 0;
 $extras = 0;
 $alt = 0;
 $merged = 0;
-$usage = "Usage: mo-score [--detail] [--alt] [--extras] [--html] [--tex] [--merged] [<directory>/]<task> ...";
+$table = 0;
+$usage = "Usage: mo-score [--detail] [--alt] [--extras] [--html] [--tex] [--table] [--merged] [<directory>/]<task> ...";
 while (($arg = $ARGV[0]) =~ /^--([a-z]+)$/) {
        shift @ARGV;
        $var = "\$$1";
 while (($arg = $ARGV[0]) =~ /^--([a-z]+)$/) {
        shift @ARGV;
        $var = "\$$1";
@@ -16,6 +18,12 @@ while (($arg = $ARGV[0]) =~ /^--([a-z]+)$/) {
 }
 @ARGV || die $usage;
 
 }
 @ARGV || die $usage;
 
+$print_key = 1;
+if ($table) {
+       open STDOUT, "|column -t -s'\t'" or die;
+       $print_key = 0;
+}
+
 print STDERR "Scanning contestants... ";
 open (CT, "bin/mo-get-users --full |") || die "Cannot get list of contestants";
 while (<CT>) {
 print STDERR "Scanning contestants... ";
 open (CT, "bin/mo-get-users --full |") || die "Cannot get list of contestants";
 while (<CT>) {
@@ -74,6 +82,8 @@ foreach $u (keys %users) {
                                elsif ($trem =~ /^Caught fatal signal /) { $cmt = "SG"; }
                                elsif ($trem =~ /^([A-Za-z])\S*\s+([A-Za-z])/) {
                                        ($cmt = "$1$2") =~ tr/a-z/A-Z/;
                                elsif ($trem =~ /^Caught fatal signal /) { $cmt = "SG"; }
                                elsif ($trem =~ /^([A-Za-z])\S*\s+([A-Za-z])/) {
                                        ($cmt = "$1$2") =~ tr/a-z/A-Z/;
+                               } elsif ($trem =~ /^([A-Za-z]{2})/) {
+                                       ($cmt = $1) =~ tr/a-z/A-Z/;
                                }
                                if (!defined $messages{$trem}) {
                                        $messages{$trem} = $cmt;
                                }
                                if (!defined $messages{$trem}) {
                                        $messages{$trem} = $cmt;
@@ -177,7 +187,7 @@ while ($i < @table) {
        } else {
                ${table[$j]}[0] = $j+1 . ".-" . $i . ".";
                $j++;
        } else {
                ${table[$j]}[0] = $j+1 . ".-" . $i . ".";
                $j++;
-               while ($j < $i) { ${table[$j++]}[0] = ""; };
+               while ($j < $i) { ${table[$j++]}[0] = " "; };
        }
 }
 print STDERR "OK\n";
        }
 }
 print STDERR "OK\n";
@@ -199,7 +209,7 @@ if ($debug) {
        my @perm;
        &printHtmlHeader(\@perm);
        print "<tbody>";
        my @perm;
        &printHtmlHeader(\@perm);
        print "<tbody>";
-       
+
        foreach $r (@table[1..($#table - 1)]) {
                &printHtmlRow(@{$r}[@perm]);
        }
        foreach $r (@table[1..($#table - 1)]) {
                &printHtmlRow(@{$r}[@perm]);
        }
@@ -218,11 +228,12 @@ if ($debug) {
        print "\\error{TeX output not supported yet!}\n";
 } else {
        foreach $r (@table) { print join("\t",@$r), "\n"; }
        print "\\error{TeX output not supported yet!}\n";
 } else {
        foreach $r (@table) { print join("\t",@$r), "\n"; }
-       print "\n";
-       foreach $r (sort keys %error_codes) { print "$r: $error_codes{$r}\n"; }
+       if ($print_key) {
+               print "\n";
+               foreach $r (sort keys %error_codes) { print "$r: $error_codes{$r}\n"; }
+       }
 }
 
 }
 
-
 sub printHtmlRow {
        print "<TR>", join('',map {
                if ($hdr) { $_ = "<TH>$_"; }
 sub printHtmlRow {
        print "<TR>", join('',map {
                if ($hdr) { $_ = "<TH>$_"; }
@@ -230,7 +241,6 @@ sub printHtmlRow {
        } @_), "\n";
 }
 
        } @_), "\n";
 }
 
-
 sub printHtmlHeader {
 
   my ($perm) = @_;
 sub printHtmlHeader {
 
   my ($perm) = @_;
@@ -252,18 +262,18 @@ sub printHtmlHeader {
        $p++;
        map { push @$perm, $p++ } (1..$nSub);
        push @$perm, $p - $nSub - 1;
        $p++;
        map { push @$perm, $p++ } (1..$nSub);
        push @$perm, $p - $nSub - 1;
-       
+
        $colspec .= "<colgroup span='" . $nSub . "'>\n";
        $colspec .= "<colgroup span='1'>\n";
        $hdr1 .= "<th colspan='" . ($nSub + 1) . "' style='border-bottom:1px solid black;'>$task";
        $hdr2 .= join("", map { "<th>$_" } sort {$a <=> $b} keys %{$known_tests{$task}});
        $hdr2 .= "<th>Total";
      }
        $colspec .= "<colgroup span='" . $nSub . "'>\n";
        $colspec .= "<colgroup span='1'>\n";
        $hdr1 .= "<th colspan='" . ($nSub + 1) . "' style='border-bottom:1px solid black;'>$task";
        $hdr2 .= join("", map { "<th>$_" } sort {$a <=> $b} keys %{$known_tests{$task}});
        $hdr2 .= "<th>Total";
      }
-   
+
      $hdr1 .= "<th rowspan='2'>Total";
      $hdr1 .= "<th rowspan='2'>Total";
-     
+
    } else {  ## no detail
    } else {  ## no detail
-   
+
      $hdr1 = "<th>Rank<th>User<th>Name";
      $extras and $p++ and push @$perm, 3 and $hdr1.="<th>Extra" and $colspec.="<colgroup span=1>";                  ##Extra hack
 
      $hdr1 = "<th>Rank<th>User<th>Name";
      $extras and $p++ and push @$perm, 3 and $hdr1.="<th>Extra" and $colspec.="<colgroup span=1>";                  ##Extra hack
 
@@ -276,10 +286,12 @@ sub printHtmlHeader {
    }
 
    push @$perm, $p++;
    }
 
    push @$perm, $p++;
-   
+
    print "<TABLE rules=groups frame=all border='1' cellpadding='2'>\n";
    print "$colspec<colgroup span='1'>\n";
    print "<tr>$hdr1</tr>\n";
    print "<tr>$hdr2</tr>\n" if $detail;
    print "<TABLE rules=groups frame=all border='1' cellpadding='2'>\n";
    print "$colspec<colgroup span='1'>\n";
    print "<tr>$hdr1</tr>\n";
    print "<tr>$hdr2</tr>\n" if $detail;
-  
+
 }
 }
+
+close STDOUT;