]> mj.ucw.cz Git - eval.git/blobdiff - mop/eval/mo-score.sh
mop: mo-score has gained a --table option for nice textual tables
[eval.git] / mop / eval / mo-score.sh
index 4dec3a11677f9106d694340be829cfb2a0c1f8fa..9d0a200ec13f29e72669b848d1bce8ffa5dc2dad 100755 (executable)
@@ -1,4 +1,5 @@
 #!/usr/bin/perl
+# A generator of score sheets. More ugly than it deserves.
 
 $debug = 0;
 $detail = 0;
@@ -7,7 +8,8 @@ $tex = 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";
@@ -16,6 +18,12 @@ while (($arg = $ARGV[0]) =~ /^--([a-z]+)$/) {
 }
 @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>) {
@@ -199,7 +207,7 @@ if ($debug) {
        my @perm;
        &printHtmlHeader(\@perm);
        print "<tbody>";
-       
+
        foreach $r (@table[1..($#table - 1)]) {
                &printHtmlRow(@{$r}[@perm]);
        }
@@ -218,11 +226,12 @@ if ($debug) {
        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>$_"; }
@@ -230,7 +239,6 @@ sub printHtmlRow {
        } @_), "\n";
 }
 
-
 sub printHtmlHeader {
 
   my ($perm) = @_;
@@ -252,18 +260,18 @@ sub printHtmlHeader {
        $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";
      }
-   
+
      $hdr1 .= "<th rowspan='2'>Total";
-     
+
    } 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
 
@@ -276,10 +284,10 @@ sub printHtmlHeader {
    }
 
    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;
-  
+
 }