4 $usage = "Usage: mo-score-mop [--tex] theoretical_tasks_nr praxis_tasks_nr task1 task2 ...";
5 while (($arg = $ARGV[0]) =~ /^--([a-z]+)$/) {
8 if (!eval "defined $var") { die $usage; }
11 @ARGV >=2 || die $usage;
14 @ARGV >= $praxis || die $usage;
15 $pos_delim=$tex ? '--' : '-';
17 print STDERR "Scanning contestants... ";
18 open (CT, "bin/mo-get-users --full |") || die "Cannot get list of contestants";
22 ($u eq "somebody") && next;
26 print STDERR 0+keys %users, "\n";
28 print STDERR "Scanning teoretical results... ";
29 if (open (EX, "teorie.txt")) {
32 (/^$/ || /^#/) && next;
33 @a = split /\ *\t\ */;
35 defined $users{$u} || die "Unknown user $u";
36 $names{$u} = shift @a;
37 $forms{$u} = shift @a;
38 $addresses{$u} = "{". (shift @a) ."}";
40 while (@a) { $tasks{$u}{$i} = shift @a;$i++; }
44 } else {die "none, cannot find file teorie.txt!\n";}
46 print STDERR "Scanning task results... ";
47 $need_tasks = join("|", @ARGV);
48 foreach $u (keys %users) {
49 opendir (D, "testing/$u") or next;
50 foreach $t (readdir(D)) {
52 $t =~ /$need_tasks/ || next;
55 for (my $t_num2=0;$t_num2<@ARGV;$t_num2++) {if ($t eq $ARGV[$t_num2]) {$t_num=$t_num2;}}
58 $tt = "testing/$u/$t/points";
60 print STDERR "$u/$t ";
61 open (X, $tt) || die "Unable to open $tt";
66 /^(\S+) (-?\d+)/ || die "Parse error: $_";
67 my ($t, $p) = ($1, $2);
69 $tests{$t} = $p if not exists $tests{$t} or $tests{$t} > $p;
71 foreach my $p (values %tests) {
72 $tasks{$u}{$t_num} += $p;
80 print STDERR "Creating table template... ";
81 @body = ('','$names{$u}','$forms{$u}','$addresses{$u}');
82 for ($a=0;$a<$theory+$praxis;$a++) {push @body,"\$tasks{\$u}{$a}";}
85 print STDERR "Filling in results... ";
87 foreach $u (keys %users) {
88 next unless defined $names{$u}; # don't show any user not defined in teorie.txt
92 foreach my $c (@body) {
93 $c =~ s/\$(\d+)/\$\$row[$1]/g;
95 push @$row, (defined $x ? $x : '-');
97 if ((defined $x) && ($x>0)) {$row_sum+=$x;}
101 push @$row, $row_sum;
106 print STDERR "Sorting... ";
107 $sortcol = @{$table[0]} - 1;
111 $p = $$b[$sortcol] <=> $$a[$sortcol];
112 ($an = $$a[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
113 ($bn = $$b[$namecol]) =~ s/(\S+)\s+(\S+)/$2 $1/;
114 $p ? $p : ($an cmp $bn);
117 while ($i < @table) {
119 while ($i < @table && ${$table[$i]}[$sortcol] == ${$table[$j]}[$sortcol]) {
123 ${table[$j]}[0] = "$i.";
125 ${table[$j]}[0] = $j+1 . '.' . $pos_delim . $i . ".";
128 while ($j < $i) { ${table[$j++]}[0] = $j_old+1 . '.' . $pos_delim . $i . "."; };
134 open HDR,"listina.hdr" or die "Cannot open file listina.hdr with TeX template!";
135 while (<HDR>) {print; }
138 foreach $r (@table) { print join('&',@$r), "\\cr\n";}
140 open FTR,"listina.ftr" or die "Cannot open file listina.ftr with TeX template!";
141 while (<FTR>) {print; }
144 foreach $r (@table) { print join("\t",@$r), "\n"; }