]> mj.ucw.cz Git - moe.git/blobdiff - mop/score/mo-score-mop.sh
Doc: Note that Isolate has moved
[moe.git] / mop / score / mo-score-mop.sh
index c20770652821d647c0b5eb7adfdda7c5c6d891c1..d7aca2e54e616006353aa4b88a68488e3752612d 100755 (executable)
 #!/usr/bin/perl
+use strict;
+use warnings;
+use List::Util qw(min);
 
-$tex = 0;
-$usage = "Usage: mo-score-mop [--tex] theoretical_tasks_nr praxis_tasks_nr task1 task2 ...";
-while (($arg = $ARGV[0]) =~ /^--([a-z]+)$/) {
-       shift @ARGV;
-       $var = "\$$1";
-       if (!eval "defined $var") { die $usage; }
-       eval "$var = 1;";
-}
-@ARGV >=2 || die $usage;
-$theory=shift @ARGV;
-$praxis=shift @ARGV;
-@ARGV >= $praxis || die $usage;
-$pos_delim=$tex ? '--' : '-';
+@ARGV or die "Usage: mo-score-mop task1 task2 ...";
 
 print STDERR "Scanning contestants... ";
 open (CT, "bin/mo-get-users --full |") || die "Cannot get list of contestants";
+my %users = ();
 while (<CT>) {
        chomp;
-       ($u,$f) = split /\t/;
-       ($u eq "somebody") && next;
-        $users{$u}=$f;
+       my ($u, $f) = split /\t/;
+       $u =~ /^mo/ or next;
+       $users{$u}=$f;
 }
 close CT;
 print STDERR 0+keys %users, "\n";
 
-print STDERR "Scanning teoretical results... ";
-if (open (EX, "mop/teorie.txt")) {
-       while (<EX>) {
-               chomp;
-               (/^$/ || /^#/) && next;
-               @a = split /\ *\t\ */;
-               $u = shift @a;
-               defined $users{$u} || die "Unknown user $u";
-               $names{$u} = shift @a;
-               $forms{$u} = shift @a;
-               $addresses{$u} = "{". (shift @a) ."}";
-               $i=0;
-               while (@a) { $tasks{$u}{$i} = shift @a;$i++; }
-       }
-       close EX;
-       print STDERR "OK\n";
-} else {die "none, cannot find file mop/teorie.txt!\n";}
-
 print STDERR "Scanning task results... ";
-$need_tasks = join("|", @ARGV);
-foreach $u (keys %users) {
-       opendir (D, "testing/$u") or next;
-       foreach $t (readdir(D)) {
-               $t =~ /^\./ && next;
-               $t =~ /$need_tasks/ || next;
-
-               $t_num=$praxis;
-               for (my $t_num2=0;$t_num2<@ARGV;$t_num2++) {if ($t eq $ARGV[$t_num2]) {$t_num=$t_num2;}}
-               $t_num+=$theory;
-
-               $tt = "testing/$u/$t/points";
+my %tasks = ();
+for my $u (keys %users) {
+       for my $t (@ARGV) {
+               my $tt = "testing/$u/$t/points";
                -f $tt || next;
                print STDERR "$u/$t ";
                open (X, $tt) || die "Unable to open $tt";
+               my %groups = ();
                while (<X>) {
                        chomp;
-                       /^\S+ (-?\d+)/ || die "Parse error: $_";
-                       $tasks{$u}{$t_num} += $1;
+                       my ($test, $pts) = /^(\S+) (-?\d+)/ or die "Parse error: $_";
+                       my $group = $test;
+                       $group =~ s{\D}{}g;
+                       if (defined $groups{$group}) {
+                               $groups{$group} = min($groups{$group}, $pts);
+                       } else {
+                               $groups{$group} = $pts;
+                       }
                }
                close X;
-       }
-       closedir D;
-}
-print STDERR "OK\n";
-
-print STDERR "Creating table template... ";
-@body = ('','$names{$u}','$forms{$u}','$addresses{$u}');
-for ($a=0;$a<$theory+$praxis;$a++) {push @body,"\$tasks{\$u}{$a}";}
-print STDERR "OK\n";
 
-print STDERR "Filling in results... ";
-@table = ();
-foreach $u (keys %users) {
-       next unless defined $names{$u}; # don't show any user not defined in teorie.txt
-       $row = [];
-       $row_index=0;
-       $row_sum=0;
-       foreach my $c (@body) {
-               $c =~ s/\$(\d+)/\$\$row[$1]/g;
-               $x = eval $c;
-               push @$row, (defined $x ? $x : '-');
-               if ($row_index>3) {
-                   if ((defined $x) && ($x>0)) {$row_sum+=$x;}
+               for my $g (keys %groups) {
+                       $tasks{$u}{$t} += $groups{$g};
                }
-               $row_index++;
        }
-       push @$row, $row_sum;
-       push @table, $row;
 }
 print STDERR "OK\n";
 
-print STDERR "Sorting... ";
-$sortcol = @{$table[0]} - 1;
-$namecol = 1;
-@table = sort {
-       my $p, $an, $bn;
-       $p = $$b[$sortcol] <=> $$a[$sortcol];
-       ($an = $$a[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
-       ($bn = $$b[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
-       $p ? $p : ($an cmp $bn);
-} @table;
-$i=0;
-while ($i < @table) {
-       $j = $i;
-       while ($i < @table && ${$table[$i]}[$sortcol] == ${$table[$j]}[$sortcol]) {
-               $i++;
-       }
-       if ($i == $j+1) {
-               ${table[$j]}[0] = "$i.";
-       } else {
-               ${table[$j]}[0] = $j+1 . '.' . $pos_delim . $i . ".";
-               $j_old=$j;
-               $j++;
-               while ($j < $i) { ${table[$j++]}[0] = $j_old+1 . '.' . $pos_delim . $i . "."; };
-       }
+print STDERR "Generating output... ";
+for my $u (sort keys %users) {
+       print join("\t", $u, $users{$u}, map { $tasks{$u}{$_} // '-' } @ARGV), "\n";
 }
 print STDERR "OK\n";
 
-if ($tex) {
-        open HDR,"mop/listina.hdr" or die "Cannot open file mop/listina.hdr with TeX template!";
-       while (<HDR>) {print; }
-       close HDR;
-       
-       foreach $r (@table) { print join('&',@$r), "\\cr\n";}
-
-        open FTR,"mop/listina.ftr" or die "Cannot open file mop/listina.ftr with TeX template!";
-       while (<FTR>) {print; }
-       close FTR;
-} else {
-       foreach $r (@table) { print join("\t",@$r), "\n"; }
-}