X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=mop%2Fscore%2Fmo-score-mop.sh;h=d7aca2e54e616006353aa4b88a68488e3752612d;hb=HEAD;hp=44944a589873c790ffa62b2e0979800a1c418100;hpb=0eff6ea5cee308543c087a5b1182ecafd18e1ed3;p=moe.git diff --git a/mop/score/mo-score-mop.sh b/mop/score/mo-score-mop.sh index 44944a5..d7aca2e 100755 --- a/mop/score/mo-score-mop.sh +++ b/mop/score/mo-score-mop.sh @@ -1,63 +1,27 @@ #!/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 () { 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, "teorie.txt")) { - while () { - 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 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"; @@ -76,76 +40,15 @@ foreach $u (keys %users) { close X; for my $g (keys %groups) { - $tasks{$u}{$t_num} += $groups{$g}; + $tasks{$u}{$t} += $groups{$g}; } } - 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;} - } - $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,"listina.hdr" or die "Cannot open file listina.hdr with TeX template!"; - while () {print; } - close HDR; - - foreach $r (@table) { print join('&',@$r), "\\cr\n";} - - open FTR,"listina.ftr" or die "Cannot open file listina.ftr with TeX template!"; - while () {print; } - close FTR; -} else { - foreach $r (@table) { print join("\t",@$r), "\n"; } -}