3 use List::Util qw(min);
6 $usage = "Usage: mo-score-mop [--tex] theoretical_tasks_nr praxis_tasks_nr task1 task2 ...";
7 while (($arg = $ARGV[0]) =~ /^--([a-z]+)$/) {
10 if (!eval "defined $var") { die $usage; }
13 @ARGV >=2 || die $usage;
16 @ARGV >= $praxis || die $usage;
17 $pos_delim=$tex ? '--' : '-';
19 print STDERR "Scanning contestants... ";
20 open (CT, "bin/mo-get-users --full |") || die "Cannot get list of contestants";
24 ($u eq "somebody") && next;
28 print STDERR 0+keys %users, "\n";
30 print STDERR "Scanning teoretical results... ";
31 if (open (EX, "teorie.txt")) {
34 (/^$/ || /^#/) && next;
35 @a = split /\ *\t\ */;
37 defined $users{$u} || die "Unknown user $u";
38 $names{$u} = shift @a;
39 $forms{$u} = shift @a;
40 $addresses{$u} = "{". (shift @a) ."}";
42 while (@a) { $tasks{$u}{$i} = shift @a;$i++; }
46 } else {die "none, cannot find file teorie.txt!\n";}
48 print STDERR "Scanning task results... ";
49 $need_tasks = join("|", @ARGV);
50 foreach $u (keys %users) {
51 opendir (D, "testing/$u") or next;
52 foreach $t (readdir(D)) {
54 $t =~ /$need_tasks/ || next;
57 for (my $t_num2=0;$t_num2<@ARGV;$t_num2++) {if ($t eq $ARGV[$t_num2]) {$t_num=$t_num2;}}
60 $tt = "testing/$u/$t/points";
62 print STDERR "$u/$t ";
63 open (X, $tt) || die "Unable to open $tt";
67 my ($test, $pts) = /^(\S+) (-?\d+)/ or die "Parse error: $_";
70 if (defined $groups{$group}) {
71 $groups{$group} = min($groups{$group}, $pts);
73 $groups{$group} = $pts;
78 for my $g (keys %groups) {
79 $tasks{$u}{$t_num} += $groups{$g};
86 print STDERR "Creating table template... ";
87 @body = ('','$names{$u}','$forms{$u}','$addresses{$u}');
88 for ($a=0;$a<$theory+$praxis;$a++) {push @body,"\$tasks{\$u}{$a}";}
91 print STDERR "Filling in results... ";
93 foreach $u (keys %users) {
94 next unless defined $names{$u}; # don't show any user not defined in teorie.txt
98 foreach my $c (@body) {
99 $c =~ s/\$(\d+)/\$\$row[$1]/g;
101 push @$row, (defined $x ? $x : '-');
103 if ((defined $x) && ($x>0)) {$row_sum+=$x;}
107 push @$row, $row_sum;
112 print STDERR "Sorting... ";
113 $sortcol = @{$table[0]} - 1;
117 $p = $$b[$sortcol] <=> $$a[$sortcol];
118 ($an = $$a[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
119 ($bn = $$b[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
120 $p ? $p : ($an cmp $bn);
123 while ($i < @table) {
125 while ($i < @table && ${$table[$i]}[$sortcol] == ${$table[$j]}[$sortcol]) {
129 ${table[$j]}[0] = "$i.";
131 ${table[$j]}[0] = $j+1 . '.' . $pos_delim . $i . ".";
134 while ($j < $i) { ${table[$j++]}[0] = $j_old+1 . '.' . $pos_delim . $i . "."; };
140 open HDR,"listina.hdr" or die "Cannot open file listina.hdr with TeX template!";
141 while (<HDR>) {print; }
144 foreach $r (@table) { print join('&',@$r), "\\cr\n";}
146 open FTR,"listina.ftr" or die "Cannot open file listina.ftr with TeX template!";
147 while (<FTR>) {print; }
150 foreach $r (@table) { print join("\t",@$r), "\n"; }