These utilities are however not compiled yet.
+++ /dev/null
-#!/bin/sh
-if [ -z "$1" ] ; then
- echo "Directory name expected"
- exit 1
-fi
-rm -rf solutions/mo*
-for m in `cd $1 ; echo *` ; do
- echo -n "$m:"
- for d in $1/$m/mo??/mo?? ; do
- u=`basename $d`
- if [ $u != mo00 -a -d $d/.submit ] ; then
- echo -n " $u"
- if [ -d solutions/$u ] ; then
- echo -n "<DUP!!!>"
- else
- cp -a $d/.submit solutions/$u
- fi
- fi
- done
- echo
-done
+++ /dev/null
-#!/bin/sh
-if [ -z "$1" ] ; then
- echo "Directory name expected"
- exit 1
-fi
-for m in `cd $1 ; echo *` ; do
- echo -n "$m:"
- for d in $1/$m/mo??/mo?? ; do
- u=`basename $d`
- if [ $u != mo00 -a `ls $d | wc -l` -gt 0 ] ; then
- echo -n " $u"
- if [ -d $d/.submit ] ; then
- echo -n '('
- ( cd $d/.submit ; echo -n * )
- echo -n ')'
- fi
- fi
- done
- echo
-done
+++ /dev/null
-#!/bin/sh
-if [ -z "$1" ] ; then
- D=back/`date '+%H%M'`
-else
- D=$1
-fi
-mkdir -p $D
-for m in `seq 27 74` ; do
- m="ceoi$m"
- echo -n "$m: "
- mkdir $p $D/$m
- pushd $D/$m >/dev/null
- ssh root@$m 'cd /mo/users ; tar czf - . --exclude=.kde' | tar xzf -
- popd >/dev/null
- du -s $D/$m | cut -f 1
-done
+++ /dev/null
-#!/bin/bash
-
-[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; }
-set -e
-. config
-
-H=`pwd`
-cd $MO_ROOT
-rm -rf users
-mkdir users
-cd users
-
-for a in `cd $H && bin/mo-get-users` ; do
- echo "Creating $a"
- mkdir $a $a/$a
- chown root.$a $a
- chmod 750 $a
- cp -a `find $H/template -mindepth 1 -maxdepth 1` $a/$a/
-
- if [ -n "$REMOTE_SUBMIT" ] ; then
- M=$a/$a/.mo
- mkdir $M
- cp $H/certs/$a-cert.pem $M/cert.pem
- cp $H/certs/$a-key.pem $M/key.pem
- chmod 600 $M/key.pem
- cp $H/certs/ca-cert.pem $M/
- fi
-
- chown $a.$a $a/$a -R
- chmod 700 $a/$a
-done
+++ /dev/null
-#!/bin/bash
-
-[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; }
-set -e
-. config
-
-H=`pwd`
-cd $MO_ROOT/eval
-
-echo "Creating $EVAL_USER"
-rm -rf eval
-mkdir eval
-cd eval
-cp -a $H/* .
-chmod +x bin/*
-if [ -d ~/.ssh ] ; then echo "Copying SSH configuration from ~/.ssh" ; cp -a ~/.ssh . ; fi
-cd ..
-chown -R $EVAL_USER.$EVAL_GROUP eval
-chmod 750 eval
+++ /dev/null
-#!/bin/bash
-
-[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; }
-set -e
-. config
-
-mode=$1
-
-case "$mode" in
- eval) uid=$EVAL_UID_MIN;;
- users) uid=$CT_UID_MIN;;
- *) echo "Usage: $0 [eval|users]!"; exit 1;;
-esac
-
->>etcshadow >>etcpasswd >>etcgroup
-expire=$((`date +%s` / 86400 - 1))
-
-case $mode in
- eval)
- echo -n Enter password for evaluation users:
- read passwd
- passwd=`echo $passwd | bin/md5crypt`
- gid=$uid
- tgid=$(($gid+1))
- rgid=$(($gid+2))
- echo $EVAL_USER:x:$uid:$gid:MO Evaluator:$MO_ROOT/eval/eval:/bin/bash >> etcpasswd
- echo $EVAL_USER:$passwd:$expire:0:99999:7::: >> etcshadow
- echo $EVAL_GROUP:x:$gid: >> etcgroup
- echo $TEST_GROUP:x:$tgid:$EVAL_USER >> etcgroup
-
- if [ -n "$REMOTE_SUBMIT" ] ; then
- uid=$(($uid + 1))
- echo $REMOTE_SUBMIT_USER:x:$uid:$rgid:MO Submitter:$MO_ROOT/eval/submit:/bin/bash >> etcpasswd
- echo $REMOTE_SUBMIT_USER:$passwd:$expire:0:99999:7::: >> etcshadow
- echo $REMOTE_SUBMIT_GROUP:x:$rgid: >> etcgroup
- fi
-
- tuid=$(($uid + 1))
- for tester in $TEST_USERS; do
- echo $tester:x:$tuid:$tgid:MO Tester `expr $tuid - $uid`:$MO_ROOT/eval/$tester:/bin/bash >> etcpasswd
- echo $tester:$passwd:$expire:0:99999:7::: >> etcshadow
- tuid=$(($tuid + 1))
- done
- ;;
-
- users)
-# if [ -f logins.tex ]; then echo "File logins.tex exists! Bailing out!"; exit 1; fi
- cat > logins.tex <<- EOF
- \\nopagenumbers
- \\voffset=-1.5cm\\vsize=280mm\\hoffset=-0.75cm\\advance\\hsize by 3cm
- \\raggedright\\parindent=0pt
- \\font\\ftt=cstt17
- \\font\\frm=csr17
- \\font\\fit=csti17
- \\ftt
- \\def\\user#1#2#3{\\vbox to 4.5cm{\\hsize=6cm\\vss\\vss{\\fit Practice Session}\\vss\\vss{\\frm #3}\\vss\\vss#1\\vss#2\\vss\\vss}}
- \\leavevmode
- EOF
-
- bin/mo-get-users --full | while read user name; do
- passwd=`apg -n1 -m6 -Mncl | cut -d" " -f1 | tr l1O0 '@*?-' `
- passwd_md5=`echo $passwd | bin/md5crypt`
- echo $user:x:$uid:$uid:$name:$MO_ROOT/users/$user/$user:/bin/bash >> etcpasswd
- echo $user:x:$uid: >> etcgroup
- echo $user:$passwd_md5:`expr \`date +%s\` / 86400 - 1`:0:99999:7::: >> etcshadow
- echo "\\user{$user}{$passwd}{$name}" >> logins.tex
- uid=$(($uid + 1))
- done
-
- cat >> logins.tex <<- EOF
- \\vfil
- \\bye
- EOF
- ;;
-esac
+++ /dev/null
-#!/bin/bash
-# Create contestant directories with their solutions and test logs
-
-[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; }
-set -e
-. config
-
-H=`pwd`
-cd $MO_ROOT
-rm -rf users2
-mkdir users2
-cd users2
-
-for a in `cd $H && bin/mo-get-users` ; do
- echo "Creating $a"
- mkdir $a $a/$a
- chown root.$a $a
- chmod 750 $a
- cp -a `find $H/template -type f -name ".*"` $a/$a/
- if [ -d $H/solutions/$a ] ; then cp -a $H/solutions/$a $a/$a/solutions ; fi
- if [ -d $H/testing/$a ] ; then cp -a $H/testing/$a $a/$a/testing ; fi
- chown $a.$a $a/$a -R
- chmod 700 $a/$a
-done
+++ /dev/null
-#!/bin/bash
-
-[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; }
-set -e
-. config
-
-echo "Populating $MO_ROOT/public"
-H=`pwd`
-cd $MO_ROOT/public
-rm -rf bin lib
-
-sed '/^\(TEST_USER\|MO_ROOT\)=/s/^/#/' <$H/config >config
-
-mkdir bin
-cp -a $H/public/[a-z]* bin/
-for a in `cat $H/public/COPY` ; do
- cp -a $H/$a bin/
-done
-
-if [ -n "$REMOTE_SUBMIT" ] ; then
- cp $H/submit/{contest,remote-submit,remote-status} bin/
- mkdir lib
- cp -a $H/submit/lib .
-fi
-
-mkdir -p problems
-
-if [ `id -u` == 0 ] ; then
- chown -R $EVAL_USER.$EVAL_GROUP .
- chmod 755 .
-fi
+++ /dev/null
-#!/bin/bash
-
-[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; }
-set -e
-. config
-[ -n "$REMOTE_SUBMIT" ] || { echo "Remote submit not enabled." ; exit 1 ; }
-
-echo "Creating submit directory"
-
-H=`pwd`
-cd $MO_ROOT/eval/submit
-mkdir -p certs
-cp $H/certs/server* certs/
-cp $H/certs/ca-cert.pem certs/
-
-rm -rf submit
-mkdir -p submit
-cp $H/submit/{submitd,config,show-submits} submit/
-
-mkdir -p solutions
-for a in `cd $H && bin/mo-get-users` ; do
- mkdir -p solutions/$a
-done
-
-rm -rf lib
-cp -a $H/submit/lib lib
-
-rm -rf tmp
-mkdir -p tmp
-
-mkdir -p log history
-
-chown -R $REMOTE_SUBMIT_USER.$REMOTE_SUBMIT_GROUP $MO_ROOT/eval/submit
+++ /dev/null
-#!/bin/bash
-
-[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; }
-set -e
-. config
-
-H=`pwd`
-cd $MO_ROOT/eval
-
-# mo-test home
-for u in $TEST_USERS ; do
- echo "Creating $u"
- rm -rf ./$u
- mkdir $u
- chown $u.$TEST_GROUP $u
- chmod 770 $u
- cp $H/bin/box eval/bin/box-$u
- chown $u.$EVAL_GROUP eval/bin/box-$u
- chmod 4550 eval/bin/box-$u
-done
+++ /dev/null
-#!/bin/bash
-
-[ -n "$1" ] || { echo "Usage: mo-ev-all <tasks>" ; exit 1 ; }
-
-while [ -n "$1" ] ; do
- for user in `bin/mo-get-users` ; do
- echo -e "\n### USER $user TASK $1 ###\n"
- bin/ev $user $1
- done
- shift
-done
+++ /dev/null
-#!/bin/bash
-
-[ -n "$1" ] || { echo "Usage: mo-ev-inc [--force] <tasks>" ; exit 1 ; }
-
-force=0
-if [ "$1" == --force ] ; then
- force=1
- shift
-fi
-for user in `bin/mo-get-users` ; do
- for task in "$@" ; do
- echo -n "$user/$task: "
- if [ -d solutions/$user/$task ] ; then
- N=`cd solutions/$user/$task && cat * | md5sum | head -c16`
- else
- N=none
- fi
- if [ -f testing/$user/$task/sum ] ; then
- O=`cat testing/$user/$task/sum`
- else
- O=none
- fi
- if [ $force == 1 -a $N != none ] ; then
- O=forced
- fi
- echo -n "($O $N) "
- if [ $O == $N ] ; then
- echo OK
- elif [ $N == none ] ; then
- rm -rf testing/$user/$task
- echo DELETED
- else
- echo CHANGED
- bin/ev $user $task
- echo $N >testing/$user/$task/sum
- fi
- done
-done
+++ /dev/null
-#!/bin/bash
-
-if [ "$1" = --help ] ; then
- echo "Usage: mo-get-users [--full]"
-fi
-[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; }
-set -e
-. config
-
-if [ -z "$CT_USER_LIST" ] ; then
- if [ "$1" = --full ] ; then
- FORM='$1,$5'
- else
- FORM='$1'
- fi
- awk -F: </etc/passwd "{ gsub(\",.*\",\"\",\$5); OFS=\"\t\"; if (\$3 >= $CT_UID_MIN && \$3 <= $CT_UID_MAX) print $FORM; }"
-else
- if [ "$1" = --full ] ; then
- cut -d ' ' -f 1,2 <$CT_USER_LIST
- else
- cut -d ' ' -f 1 <$CT_USER_LIST
- fi
-fi
+++ /dev/null
-#!/bin/bash
-
-[ -n "$1" ] || { echo "Usage: mo-grab <tasks>" ; exit 1 ; }
-[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; }
-set -e
-. config
-
-for user in `bin/mo-get-users` ; do
- echo -n "$user:"
- H=`eval echo ~$user`/.submit
- if [ -d $H ] ; then
- [ -d solutions/$user ] || mkdir -p solutions/$user
- for t in $@ ; do
- rm -rf solutions/$user/$t
- if [ -d $H/$t ] ; then
- echo -n " $t"
- cp -dr $H/$t solutions/$user/$t
- fi
- done
- echo
- else
- echo " ---"
- fi
-done
-chown -R $EVAL_USER solutions
-chmod -R a+r solutions
+++ /dev/null
-#!/bin/bash
-
-[ -n "$1" ] || { echo "Usage: mo-grab-remote <tasks>" ; exit 1 ; }
-[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; }
-set -e
-. config
-
-for user in `bin/mo-get-users` ; do
- echo -n "$user:"
- mkdir -p solutions/$user
- for t in $@ ; do
- rm -rf solutions/$user/$t
- D=$MO_ROOT/eval/submit/solutions/$user/$t
- if [ -d $D ] ; then
- echo -n " $t"
- cp -a $D solutions/$user/$t
- fi
- done
- echo
-done
+++ /dev/null
-#!/bin/bash
-
-[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; }
-set -e
-. config
-
-H=`pwd`
-
-# The eval directory
-cd $MO_ROOT
-rm -rf eval
-mkdir eval
-chgrp $EVAL_GROUP eval
-chmod 755 eval
-cd eval
-
-# mo-eval home
-( cd $H && bin/mo-create-eval )
-
-# testusers
-( cd eval && bin/mo-create-testusers )
-
-# mo-submit home
-if [ -n "$REMOTE_SUBMIT" ] ; then
- mkdir submit
- chmod 750 submit
- if [ -d ~/.ssh ] ; then echo "Copying SSH configuration from ~/.ssh" ; cp -a ~/.ssh submit/ ; fi
- ( cd $H && bin/mo-create-submit )
-fi
-
-# create public
-cd $MO_ROOT
-echo "Creating public"
-rm -rf public
-mkdir public
-
-# populate public
-( cd eval/eval ; bin/mo-create-public )
+++ /dev/null
-#!/usr/bin/perl
-
-# This script recalculates points according to grouping of testcases.
-# This is no longer necessary, because the score table and report generators
-# already know how to handle merging of groups, but we still keep it as an example.
-
-@ARGV == 1 or die "Usage: mo-merge <task>\n";
-my $task = $ARGV[0];
-foreach my $s (`ls -d testing/*/$task`) {
- chomp $s;
- if (! -s "$s/points.old") {
- if (-s "$s/points") {
- rename "$s/points", "$s/points.old" or die "Rename $s/points failed: $!";
- } else {
- print "$s: NO POINTS?\n";
- next;
- }
- }
- open X, "$s/points.old" or die;
- my %tests = ();
- my %cmts = ();
- while (<X>) {
- chomp;
- my ($test, $subtest, $pts, $cmt) = /^(\d+)([a-z]*)\s+(\d+)\s*(.*)/ or die;
- if (!exists($tests{$test}) || $tests{$test} > $pts) {
- $tests{$test} = $pts;
- $cmts{$test} = $cmt;
- }
- }
- close X;
- open X, ">$s/points" or die;
- foreach my $test (sort { $a <=> $b } keys %tests) {
- print X "$test $tests{$test} $cmts{$test}\n";
- }
- close X;
-}
+++ /dev/null
-#!/bin/bash
-[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; }
-set -e
-. config
-
-while IFS=" " read LOGIN FULL MACH ; do
- if [ -z "$1" -o "$1" == "$LOGIN" ] ; then
- echo "$LOGIN -> $MACH"
- D=/mo/users/$LOGIN/$LOGIN/
- rsync -av $D/.mo root@$MACH:$D/
- fi </dev/null
-done <userlist
+++ /dev/null
-#!/bin/bash
-set -e
-while IFS=" " read LOGIN FULL MACH ; do
- if [ -z "$1" -o "$1" == "$LOGIN" ] ; then
- echo "$LOGIN -> $MACH"
- D=/mo/users/$LOGIN/$LOGIN/
- rsync -av ~mo-eval/testing/$LOGIN root@$MACH:$D/results
- ssh root@$MACH "cd $D && chown -R $LOGIN.$LOGIN results"
- fi </dev/null
-done <userlist
+++ /dev/null
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-use POSIX;
-
-foreach my $user (`cd testing && ls`) {
- chomp $user;
- print "$user:";
- open REP, ">testing/$user/REPORT" or die;
- print REP "Evaluation report for CEOI 2007 Day 2\n\n";
- my $total = 0;
- foreach my $task (@ARGV) {
- print REP "### Task $task ###\n\n";
- if (open PTS, "testing/$user/$task/points") {
- my %merged_pts = ();
- my %split_comm = ();
- while (<PTS>) {
- chomp;
- my ($test, $pts, $comm) = /(\S+)\s+(\S+)\s+(.*)/;
- my $merged = $test;
- $merged =~ s/[^0-9]//;
- if (!defined($merged_pts{$merged}) || $merged_pts{$merged} > $pts) {
- $merged_pts{$merged} = $pts;
- }
- $split_comm{$merged}{$test} = $comm;
- }
- close PTS;
- my $tt = 0;
- foreach my $merged (sort { $a <=> $b } keys %merged_pts) {
- printf REP "Test %2s: %2d points", $merged, $merged_pts{$merged};
- $tt += $merged_pts{$merged};
- my @k = sort keys %{$split_comm{$merged}};
- if (@k == 1) {
- print REP " -- ", $split_comm{$merged}{$k[0]}, "\n";
- } else {
- print REP " -- ";
- my $cc = 0;
- foreach my $t (@k) {
- $cc++ and print REP ", ";
- print REP "$t: $split_comm{$merged}{$t}";
- }
- print REP "\n";
- }
- }
- print REP "\nTOTAL: $tt points\n\n";
- $total += $tt;
- print " $tt";
- } else {
- print REP "No solution submitted.\n\n";
- print " -";
- }
- }
- print REP "### TOTAL FOR DAY 2 ###\n\n";
- print REP "$total points\n";
- print REP "\n\n(generated on ", strftime("%Y-%m-%d %H:%M:%S", localtime), ")\n";
- close REP;
- print " -> $total\n";
-}
+++ /dev/null
-#!/usr/bin/perl
-
-$debug = 0;
-$detail = 0;
-$html = 0;
-$tex = 0;
-$extras = 0;
-$alt = 0;
-$merged = 0;
-$usage = "Usage: mo-score [--detail] [--alt] [--extras] [--html] [--tex] [--merged] [<directory>/]<task> ...";
-while (($arg = $ARGV[0]) =~ /^--([a-z]+)$/) {
- shift @ARGV;
- $var = "\$$1";
- if (!eval "defined $var") { die $usage; }
- eval "$var = 1;";
-}
-@ARGV || die $usage;
-
-print STDERR "Scanning contestants... ";
-open (CT, "bin/mo-get-users --full |") || die "Cannot get list of contestants";
-while (<CT>) {
- chomp;
- ($u,$f) = split /\t/;
- ($u eq "somebody") && next;
- $users{$u}=$f;
-}
-close CT;
-print STDERR 0+keys %users, "\n";
-
-print STDERR "Scanning exceptions... ";
-if ($extras && open (EX, "exceptions")) {
- while (<EX>) {
- chomp;
- (/^$/ || /^#/) && next;
- @a = split /\s+/;
- $u = shift @a;
- defined $users{$u} || die "Unknown user $u";
- while (@a) { $extra{$u} += shift @a; }
- }
- close EX;
- print STDERR "OK\n";
-} else { print STDERR "none\n"; }
-
-print STDERR "Scanning task results... ";
-%messages = ();
-%error_codes = ();
-foreach $u (keys %users) {
- foreach $task (@ARGV) {
- my ($dir, $t) = ("testing", $task);
- if ($task =~ m@^(.*)/([^/]*)$@) {
- $dir = $1;
- $t = $2;
- }
- $known_tasks{$t} = 1;
- $tt = "$dir/$u/$t/points" . ($alt ? ".alt" : "");
- -f $tt || next;
- print STDERR "$u/$t ";
- open (X, $tt) || die "Unable to open $tt";
- while (<X>) {
- chomp;
- /^(\S+) (-?\d+)\s*(.*)/ || die "Parse error: $_";
- $ttest = $1;
- $tpts = $2;
- $trem = $3;
- $trem =~ s/\[.*//;
- ($ttest_merged = $ttest) =~ s/[^0-9]//g;
- $ttest = $ttest_merged if $merged;
- $known_tests{$t}{$ttest} = 1;
- $cmt = $tpts;
- if ($tpts == 0 && $trem ne "OK") {
- if ($trem =~ /^Compile /) { $cmt = "CE"; }
- elsif ($trem =~ /^Time limit exceeded/) { $cmt = "TO"; }
- elsif ($trem =~ /^Exited with error /) { $cmt = "RE"; }
- elsif ($trem =~ /^Caught fatal signal /) { $cmt = "SG"; }
- elsif ($trem =~ /^([A-Za-z])\S*\s+([A-Za-z])/) {
- ($cmt = "$1$2") =~ tr/a-z/A-Z/;
- }
- if (!defined $messages{$trem}) {
- $messages{$trem} = $cmt;
- if (!defined $error_codes{$cmt}) {
- $error_codes{$cmt} = $trem;
- } else {
- $error_codes{$cmt} .= ", $trem";
- }
- }
- }
- if (!defined($results{$u}{$t}{$ttest}) || $results{$u}{$t}{$ttest} > $tpts) {
- $results{$u}{$t}{$ttest} = $tpts;
- $comment{$u}{$t}{$ttest} = $cmt;
- }
- if (!defined($results_merged{$u}{$t}{$ttest_merged}) || $results_merged{$u}{$t}{$ttest_merged} > $tpts) {
- $results_merged{$u}{$t}{$ttest_merged} = $tpts;
- }
- }
- close X;
- }
- foreach my $t (keys %known_tasks) {
- $total{$u}{$t} = 0;
- foreach my $pts (values %{$results_merged{$u}{$t}}) { $total{$u}{$t} += $pts; }
- }
-}
-print STDERR "OK\n";
-
-print STDERR "Creating table template... ";
-@header = ("Rank","User","Name");
-@body = ('','$u','$users{$u}');
-@bodysums = ();
-@footer = ('"Total"','','');
-if (keys %extra) {
- push @header, "Extra";
- push @body, '$extra{$u}';
- $col = 0+@footer;
- push @bodysums, $col;
- push @footer, "sum($col)";
-}
-@tasks = ();
-foreach $task (@ARGV) {
- my $t = ($task =~ m@/([^/]*)$@) ? $1 : $task;
- defined $known_tasks{$t} || die "Unknown task $t";
- push @tasks, $t;
- push @header, substr($t, 0, 4);
- push @body, "(\$xx = \$total{\$u}{'$t'}) > 0 ? \$xx : 0";
- $col = 0+@footer;
- push @footer, "sum($col)";
- push @bodysums, $col;
- if ($detail) {
- foreach $s (sort { $a <=> $b } keys %{$known_tests{$t}}) {
- push @header, "$s";
- push @body, "\$comment{\$u}{'$t'}{'$s'}";
- $col = 0+@footer;
- push @footer, "sum($col)";
- }
- }
-}
-push @header, "Total";
-push @body, join('+', map { $_ = "\$$_" } @bodysums);
-$col = 0+@footer;
-push @footer, "sum($col)";
-print STDERR "OK\n";
-
-print STDERR "h: ", join(':',@header), "\n" if $debug;
-print STDERR "b: ", join(':',@body), "\n" if $debug;
-print STDERR "f: ", join(':',@footer), "\n" if $debug;
-
-print STDERR "Filling in results... ";
-@table = ();
-foreach $u (keys %users) {
- $row = [];
- foreach my $c (@body) {
- $c =~ s/\$(\d+)/\$\$row[$1]/g;
- $x = eval $c;
- push @$row, (defined $x ? $x : '-');
- }
- print STDERR "row: ", join(':',@$row), "\n" if $debug;
- push @table, $row;
-}
-print STDERR "OK\n";
-
-print STDERR "Sorting... ";
-$sortcol = @{$table[0]} - 1;
-$namecol = 2;
-@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 . ".-" . $i . ".";
- $j++;
- while ($j < $i) { ${table[$j++]}[0] = ""; };
- }
-}
-print STDERR "OK\n";
-
-print STDERR "Attaching headers and footers... ";
-sub sum { my $col=shift @_; my $t=0; foreach my $z (0..@table-1) { $t += ${$table[$z]}[$col]; } $t; }
-map { $_ = eval $_; } @footer;
-push @table, \@footer;
-unshift @table, \@header;
-print STDERR "OK\n";
-
-if ($debug) {
- foreach $r (@table) { print join(':',@$r), "\n"; }
-} elsif ($html) {
- print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html40/strict.dtd">', "\n";
- print "<HTML><HEAD><TITLE>Rank list</TITLE></HEAD><BODY>\n";
- print "<H1>Rank list</H1>\n";
-
- my @perm;
- &printHtmlHeader(\@perm);
- print "<tbody>";
-
- foreach $r (@table[1..($#table - 1)]) {
- &printHtmlRow(@{$r}[@perm]);
- }
-
- print "<tbody>";
- &printHtmlRow(@{$table[$#table]}[@perm]);
-
- print "</TABLE>\n";
- if ($detail) {
- print "<H2>Error codes</H2><UL>\n";
- foreach $r (sort keys %error_codes) { print "<LI>$r: $error_codes{$r}\n"; }
- print "</UL>\n";
- }
- print "</BODY></HTML>\n";
-} elsif ($tex) {
- 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"; }
-}
-
-
-sub printHtmlRow {
- print "<TR>", join('',map {
- if ($hdr) { $_ = "<TH>$_"; }
- else { $_ = "<TD align=" . (/^[0-9A-Z-]+$/ ? "right" : "left") . (length($_) > 14 ? " width=150" : "") . ">$_"; }
- } @_), "\n";
-}
-
-
-sub printHtmlHeader {
-
- my ($perm) = @_;
-
- my $colspec = "<colgroup span=3>";
- my $hdr1;
- my $hdr2;
-
- @$perm = (0, 1, 2);
- my $p = 3;
-
- if ($detail) {
- $hdr1 = "<th rowspan=2>Rank<th rowspan=2>User<th rowspan=2>Name";
- $extras and $p++ and push @$perm, 3 and $hdr1.="<th rowspan=2>Extra" and $colspec.="<colgroup span=1>"; ##Extra hack
- for my $task (@tasks) {
-
- my $nSub = scalar(keys %{$known_tests{$task}});
-
- $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
-
- for my $task (@tasks) {
- push @$perm, $p++;
- $hdr1 .= "<th>$task";
- }
- $hdr1 .= "<th>Total";
- $colspec .= "<colgroup span='" . scalar (@tasks) . "'>";
- }
-
- 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;
-
-}
+++ /dev/null
-#!/bin/sh
-set -e
-[ -n "$1" ]
-sed <$1 's/^/ /' | a2ps -Ma4 -r --columns=1 --rows=1 --font-size=10 --borders=no -B -o /tmp/score.ps
-print /tmp/score.ps
--- /dev/null
+#!/bin/sh
+if [ -z "$1" ] ; then
+ echo "Directory name expected"
+ exit 1
+fi
+rm -rf solutions/mo*
+for m in `cd $1 ; echo *` ; do
+ echo -n "$m:"
+ for d in $1/$m/mo??/mo?? ; do
+ u=`basename $d`
+ if [ $u != mo00 -a -d $d/.submit ] ; then
+ echo -n " $u"
+ if [ -d solutions/$u ] ; then
+ echo -n "<DUP!!!>"
+ else
+ cp -a $d/.submit solutions/$u
+ fi
+ fi
+ done
+ echo
+done
--- /dev/null
+#!/bin/sh
+if [ -z "$1" ] ; then
+ echo "Directory name expected"
+ exit 1
+fi
+for m in `cd $1 ; echo *` ; do
+ echo -n "$m:"
+ for d in $1/$m/mo??/mo?? ; do
+ u=`basename $d`
+ if [ $u != mo00 -a `ls $d | wc -l` -gt 0 ] ; then
+ echo -n " $u"
+ if [ -d $d/.submit ] ; then
+ echo -n '('
+ ( cd $d/.submit ; echo -n * )
+ echo -n ')'
+ fi
+ fi
+ done
+ echo
+done
--- /dev/null
+#!/bin/sh
+if [ -z "$1" ] ; then
+ D=back/`date '+%H%M'`
+else
+ D=$1
+fi
+mkdir -p $D
+for m in `seq 27 74` ; do
+ m="ceoi$m"
+ echo -n "$m: "
+ mkdir $p $D/$m
+ pushd $D/$m >/dev/null
+ ssh root@$m 'cd /mo/users ; tar czf - . --exclude=.kde' | tar xzf -
+ popd >/dev/null
+ du -s $D/$m | cut -f 1
+done
--- /dev/null
+#!/bin/bash
+
+[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; }
+set -e
+. config
+
+H=`pwd`
+cd $MO_ROOT
+rm -rf users
+mkdir users
+cd users
+
+for a in `cd $H && bin/mo-get-users` ; do
+ echo "Creating $a"
+ mkdir $a $a/$a
+ chown root.$a $a
+ chmod 750 $a
+ cp -a `find $H/template -mindepth 1 -maxdepth 1` $a/$a/
+
+ if [ -n "$REMOTE_SUBMIT" ] ; then
+ M=$a/$a/.mo
+ mkdir $M
+ cp $H/certs/$a-cert.pem $M/cert.pem
+ cp $H/certs/$a-key.pem $M/key.pem
+ chmod 600 $M/key.pem
+ cp $H/certs/ca-cert.pem $M/
+ fi
+
+ chown $a.$a $a/$a -R
+ chmod 700 $a/$a
+done
--- /dev/null
+#!/bin/bash
+
+[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; }
+set -e
+. config
+
+H=`pwd`
+cd $MO_ROOT/eval
+
+echo "Creating $EVAL_USER"
+rm -rf eval
+mkdir eval
+cd eval
+cp -a $H/* .
+chmod +x bin/*
+if [ -d ~/.ssh ] ; then echo "Copying SSH configuration from ~/.ssh" ; cp -a ~/.ssh . ; fi
+cd ..
+chown -R $EVAL_USER.$EVAL_GROUP eval
+chmod 750 eval
--- /dev/null
+#!/bin/bash
+
+[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; }
+set -e
+. config
+
+mode=$1
+
+case "$mode" in
+ eval) uid=$EVAL_UID_MIN;;
+ users) uid=$CT_UID_MIN;;
+ *) echo "Usage: $0 [eval|users]!"; exit 1;;
+esac
+
+>>etcshadow >>etcpasswd >>etcgroup
+expire=$((`date +%s` / 86400 - 1))
+
+case $mode in
+ eval)
+ echo -n Enter password for evaluation users:
+ read passwd
+ passwd=`echo $passwd | bin/md5crypt`
+ gid=$uid
+ tgid=$(($gid+1))
+ rgid=$(($gid+2))
+ echo $EVAL_USER:x:$uid:$gid:MO Evaluator:$MO_ROOT/eval/eval:/bin/bash >> etcpasswd
+ echo $EVAL_USER:$passwd:$expire:0:99999:7::: >> etcshadow
+ echo $EVAL_GROUP:x:$gid: >> etcgroup
+ echo $TEST_GROUP:x:$tgid:$EVAL_USER >> etcgroup
+
+ if [ -n "$REMOTE_SUBMIT" ] ; then
+ uid=$(($uid + 1))
+ echo $REMOTE_SUBMIT_USER:x:$uid:$rgid:MO Submitter:$MO_ROOT/eval/submit:/bin/bash >> etcpasswd
+ echo $REMOTE_SUBMIT_USER:$passwd:$expire:0:99999:7::: >> etcshadow
+ echo $REMOTE_SUBMIT_GROUP:x:$rgid: >> etcgroup
+ fi
+
+ tuid=$(($uid + 1))
+ for tester in $TEST_USERS; do
+ echo $tester:x:$tuid:$tgid:MO Tester `expr $tuid - $uid`:$MO_ROOT/eval/$tester:/bin/bash >> etcpasswd
+ echo $tester:$passwd:$expire:0:99999:7::: >> etcshadow
+ tuid=$(($tuid + 1))
+ done
+ ;;
+
+ users)
+# if [ -f logins.tex ]; then echo "File logins.tex exists! Bailing out!"; exit 1; fi
+ cat > logins.tex <<- EOF
+ \\nopagenumbers
+ \\voffset=-1.5cm\\vsize=280mm\\hoffset=-0.75cm\\advance\\hsize by 3cm
+ \\raggedright\\parindent=0pt
+ \\font\\ftt=cstt17
+ \\font\\frm=csr17
+ \\font\\fit=csti17
+ \\ftt
+ \\def\\user#1#2#3{\\vbox to 4.5cm{\\hsize=6cm\\vss\\vss{\\fit Practice Session}\\vss\\vss{\\frm #3}\\vss\\vss#1\\vss#2\\vss\\vss}}
+ \\leavevmode
+ EOF
+
+ bin/mo-get-users --full | while read user name; do
+ passwd=`apg -n1 -m6 -Mncl | cut -d" " -f1 | tr l1O0 '@*?-' `
+ passwd_md5=`echo $passwd | bin/md5crypt`
+ echo $user:x:$uid:$uid:$name:$MO_ROOT/users/$user/$user:/bin/bash >> etcpasswd
+ echo $user:x:$uid: >> etcgroup
+ echo $user:$passwd_md5:`expr \`date +%s\` / 86400 - 1`:0:99999:7::: >> etcshadow
+ echo "\\user{$user}{$passwd}{$name}" >> logins.tex
+ uid=$(($uid + 1))
+ done
+
+ cat >> logins.tex <<- EOF
+ \\vfil
+ \\bye
+ EOF
+ ;;
+esac
--- /dev/null
+#!/bin/bash
+# Create contestant directories with their solutions and test logs
+
+[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; }
+set -e
+. config
+
+H=`pwd`
+cd $MO_ROOT
+rm -rf users2
+mkdir users2
+cd users2
+
+for a in `cd $H && bin/mo-get-users` ; do
+ echo "Creating $a"
+ mkdir $a $a/$a
+ chown root.$a $a
+ chmod 750 $a
+ cp -a `find $H/template -type f -name ".*"` $a/$a/
+ if [ -d $H/solutions/$a ] ; then cp -a $H/solutions/$a $a/$a/solutions ; fi
+ if [ -d $H/testing/$a ] ; then cp -a $H/testing/$a $a/$a/testing ; fi
+ chown $a.$a $a/$a -R
+ chmod 700 $a/$a
+done
--- /dev/null
+#!/bin/bash
+
+[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; }
+set -e
+. config
+
+echo "Populating $MO_ROOT/public"
+H=`pwd`
+cd $MO_ROOT/public
+rm -rf bin lib
+
+sed '/^\(TEST_USER\|MO_ROOT\)=/s/^/#/' <$H/config >config
+
+mkdir bin
+cp -a $H/public/[a-z]* bin/
+for a in `cat $H/public/COPY` ; do
+ cp -a $H/$a bin/
+done
+
+if [ -n "$REMOTE_SUBMIT" ] ; then
+ cp $H/submit/{contest,remote-submit,remote-status} bin/
+ mkdir lib
+ cp -a $H/submit/lib .
+fi
+
+mkdir -p problems
+
+if [ `id -u` == 0 ] ; then
+ chown -R $EVAL_USER.$EVAL_GROUP .
+ chmod 755 .
+fi
--- /dev/null
+#!/bin/bash
+
+[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; }
+set -e
+. config
+[ -n "$REMOTE_SUBMIT" ] || { echo "Remote submit not enabled." ; exit 1 ; }
+
+echo "Creating submit directory"
+
+H=`pwd`
+cd $MO_ROOT/eval/submit
+mkdir -p certs
+cp $H/certs/server* certs/
+cp $H/certs/ca-cert.pem certs/
+
+rm -rf submit
+mkdir -p submit
+cp $H/submit/{submitd,config,show-submits} submit/
+
+mkdir -p solutions
+for a in `cd $H && bin/mo-get-users` ; do
+ mkdir -p solutions/$a
+done
+
+rm -rf lib
+cp -a $H/submit/lib lib
+
+rm -rf tmp
+mkdir -p tmp
+
+mkdir -p log history
+
+chown -R $REMOTE_SUBMIT_USER.$REMOTE_SUBMIT_GROUP $MO_ROOT/eval/submit
--- /dev/null
+#!/bin/bash
+
+[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; }
+set -e
+. config
+
+H=`pwd`
+cd $MO_ROOT/eval
+
+# mo-test home
+for u in $TEST_USERS ; do
+ echo "Creating $u"
+ rm -rf ./$u
+ mkdir $u
+ chown $u.$TEST_GROUP $u
+ chmod 770 $u
+ cp $H/bin/box eval/bin/box-$u
+ chown $u.$EVAL_GROUP eval/bin/box-$u
+ chmod 4550 eval/bin/box-$u
+done
--- /dev/null
+#!/bin/bash
+
+[ -n "$1" ] || { echo "Usage: mo-ev-all <tasks>" ; exit 1 ; }
+
+while [ -n "$1" ] ; do
+ for user in `bin/mo-get-users` ; do
+ echo -e "\n### USER $user TASK $1 ###\n"
+ bin/ev $user $1
+ done
+ shift
+done
--- /dev/null
+#!/bin/bash
+
+[ -n "$1" ] || { echo "Usage: mo-ev-inc [--force] <tasks>" ; exit 1 ; }
+
+force=0
+if [ "$1" == --force ] ; then
+ force=1
+ shift
+fi
+for user in `bin/mo-get-users` ; do
+ for task in "$@" ; do
+ echo -n "$user/$task: "
+ if [ -d solutions/$user/$task ] ; then
+ N=`cd solutions/$user/$task && cat * | md5sum | head -c16`
+ else
+ N=none
+ fi
+ if [ -f testing/$user/$task/sum ] ; then
+ O=`cat testing/$user/$task/sum`
+ else
+ O=none
+ fi
+ if [ $force == 1 -a $N != none ] ; then
+ O=forced
+ fi
+ echo -n "($O $N) "
+ if [ $O == $N ] ; then
+ echo OK
+ elif [ $N == none ] ; then
+ rm -rf testing/$user/$task
+ echo DELETED
+ else
+ echo CHANGED
+ bin/ev $user $task
+ echo $N >testing/$user/$task/sum
+ fi
+ done
+done
--- /dev/null
+#!/bin/bash
+
+if [ "$1" = --help ] ; then
+ echo "Usage: mo-get-users [--full]"
+fi
+[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; }
+set -e
+. config
+
+if [ -z "$CT_USER_LIST" ] ; then
+ if [ "$1" = --full ] ; then
+ FORM='$1,$5'
+ else
+ FORM='$1'
+ fi
+ awk -F: </etc/passwd "{ gsub(\",.*\",\"\",\$5); OFS=\"\t\"; if (\$3 >= $CT_UID_MIN && \$3 <= $CT_UID_MAX) print $FORM; }"
+else
+ if [ "$1" = --full ] ; then
+ cut -d ' ' -f 1,2 <$CT_USER_LIST
+ else
+ cut -d ' ' -f 1 <$CT_USER_LIST
+ fi
+fi
--- /dev/null
+#!/bin/bash
+
+[ -n "$1" ] || { echo "Usage: mo-grab <tasks>" ; exit 1 ; }
+[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; }
+set -e
+. config
+
+for user in `bin/mo-get-users` ; do
+ echo -n "$user:"
+ H=`eval echo ~$user`/.submit
+ if [ -d $H ] ; then
+ [ -d solutions/$user ] || mkdir -p solutions/$user
+ for t in $@ ; do
+ rm -rf solutions/$user/$t
+ if [ -d $H/$t ] ; then
+ echo -n " $t"
+ cp -dr $H/$t solutions/$user/$t
+ fi
+ done
+ echo
+ else
+ echo " ---"
+ fi
+done
+chown -R $EVAL_USER solutions
+chmod -R a+r solutions
--- /dev/null
+#!/bin/bash
+
+[ -n "$1" ] || { echo "Usage: mo-grab-remote <tasks>" ; exit 1 ; }
+[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; }
+set -e
+. config
+
+for user in `bin/mo-get-users` ; do
+ echo -n "$user:"
+ mkdir -p solutions/$user
+ for t in $@ ; do
+ rm -rf solutions/$user/$t
+ D=$MO_ROOT/eval/submit/solutions/$user/$t
+ if [ -d $D ] ; then
+ echo -n " $t"
+ cp -a $D solutions/$user/$t
+ fi
+ done
+ echo
+done
--- /dev/null
+#!/bin/bash
+
+[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; }
+set -e
+. config
+
+H=`pwd`
+
+# The eval directory
+cd $MO_ROOT
+rm -rf eval
+mkdir eval
+chgrp $EVAL_GROUP eval
+chmod 755 eval
+cd eval
+
+# mo-eval home
+( cd $H && bin/mo-create-eval )
+
+# testusers
+( cd eval && bin/mo-create-testusers )
+
+# mo-submit home
+if [ -n "$REMOTE_SUBMIT" ] ; then
+ mkdir submit
+ chmod 750 submit
+ if [ -d ~/.ssh ] ; then echo "Copying SSH configuration from ~/.ssh" ; cp -a ~/.ssh submit/ ; fi
+ ( cd $H && bin/mo-create-submit )
+fi
+
+# create public
+cd $MO_ROOT
+echo "Creating public"
+rm -rf public
+mkdir public
+
+# populate public
+( cd eval/eval ; bin/mo-create-public )
--- /dev/null
+#!/usr/bin/perl
+
+# This script recalculates points according to grouping of testcases.
+# This is no longer necessary, because the score table and report generators
+# already know how to handle merging of groups, but we still keep it as an example.
+
+@ARGV == 1 or die "Usage: mo-merge <task>\n";
+my $task = $ARGV[0];
+foreach my $s (`ls -d testing/*/$task`) {
+ chomp $s;
+ if (! -s "$s/points.old") {
+ if (-s "$s/points") {
+ rename "$s/points", "$s/points.old" or die "Rename $s/points failed: $!";
+ } else {
+ print "$s: NO POINTS?\n";
+ next;
+ }
+ }
+ open X, "$s/points.old" or die;
+ my %tests = ();
+ my %cmts = ();
+ while (<X>) {
+ chomp;
+ my ($test, $subtest, $pts, $cmt) = /^(\d+)([a-z]*)\s+(\d+)\s*(.*)/ or die;
+ if (!exists($tests{$test}) || $tests{$test} > $pts) {
+ $tests{$test} = $pts;
+ $cmts{$test} = $cmt;
+ }
+ }
+ close X;
+ open X, ">$s/points" or die;
+ foreach my $test (sort { $a <=> $b } keys %tests) {
+ print X "$test $tests{$test} $cmts{$test}\n";
+ }
+ close X;
+}
--- /dev/null
+#!/bin/bash
+[ -f config ] || { echo "Missing config file, check cwd." ; exit 1 ; }
+set -e
+. config
+
+while IFS=" " read LOGIN FULL MACH ; do
+ if [ -z "$1" -o "$1" == "$LOGIN" ] ; then
+ echo "$LOGIN -> $MACH"
+ D=/mo/users/$LOGIN/$LOGIN/
+ rsync -av $D/.mo root@$MACH:$D/
+ fi </dev/null
+done <userlist
--- /dev/null
+#!/bin/bash
+set -e
+while IFS=" " read LOGIN FULL MACH ; do
+ if [ -z "$1" -o "$1" == "$LOGIN" ] ; then
+ echo "$LOGIN -> $MACH"
+ D=/mo/users/$LOGIN/$LOGIN/
+ rsync -av ~mo-eval/testing/$LOGIN root@$MACH:$D/results
+ ssh root@$MACH "cd $D && chown -R $LOGIN.$LOGIN results"
+ fi </dev/null
+done <userlist
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use POSIX;
+
+foreach my $user (`cd testing && ls`) {
+ chomp $user;
+ print "$user:";
+ open REP, ">testing/$user/REPORT" or die;
+ print REP "Evaluation report for CEOI 2007 Day 2\n\n";
+ my $total = 0;
+ foreach my $task (@ARGV) {
+ print REP "### Task $task ###\n\n";
+ if (open PTS, "testing/$user/$task/points") {
+ my %merged_pts = ();
+ my %split_comm = ();
+ while (<PTS>) {
+ chomp;
+ my ($test, $pts, $comm) = /(\S+)\s+(\S+)\s+(.*)/;
+ my $merged = $test;
+ $merged =~ s/[^0-9]//;
+ if (!defined($merged_pts{$merged}) || $merged_pts{$merged} > $pts) {
+ $merged_pts{$merged} = $pts;
+ }
+ $split_comm{$merged}{$test} = $comm;
+ }
+ close PTS;
+ my $tt = 0;
+ foreach my $merged (sort { $a <=> $b } keys %merged_pts) {
+ printf REP "Test %2s: %2d points", $merged, $merged_pts{$merged};
+ $tt += $merged_pts{$merged};
+ my @k = sort keys %{$split_comm{$merged}};
+ if (@k == 1) {
+ print REP " -- ", $split_comm{$merged}{$k[0]}, "\n";
+ } else {
+ print REP " -- ";
+ my $cc = 0;
+ foreach my $t (@k) {
+ $cc++ and print REP ", ";
+ print REP "$t: $split_comm{$merged}{$t}";
+ }
+ print REP "\n";
+ }
+ }
+ print REP "\nTOTAL: $tt points\n\n";
+ $total += $tt;
+ print " $tt";
+ } else {
+ print REP "No solution submitted.\n\n";
+ print " -";
+ }
+ }
+ print REP "### TOTAL FOR DAY 2 ###\n\n";
+ print REP "$total points\n";
+ print REP "\n\n(generated on ", strftime("%Y-%m-%d %H:%M:%S", localtime), ")\n";
+ close REP;
+ print " -> $total\n";
+}
--- /dev/null
+#!/usr/bin/perl
+
+$debug = 0;
+$detail = 0;
+$html = 0;
+$tex = 0;
+$extras = 0;
+$alt = 0;
+$merged = 0;
+$usage = "Usage: mo-score [--detail] [--alt] [--extras] [--html] [--tex] [--merged] [<directory>/]<task> ...";
+while (($arg = $ARGV[0]) =~ /^--([a-z]+)$/) {
+ shift @ARGV;
+ $var = "\$$1";
+ if (!eval "defined $var") { die $usage; }
+ eval "$var = 1;";
+}
+@ARGV || die $usage;
+
+print STDERR "Scanning contestants... ";
+open (CT, "bin/mo-get-users --full |") || die "Cannot get list of contestants";
+while (<CT>) {
+ chomp;
+ ($u,$f) = split /\t/;
+ ($u eq "somebody") && next;
+ $users{$u}=$f;
+}
+close CT;
+print STDERR 0+keys %users, "\n";
+
+print STDERR "Scanning exceptions... ";
+if ($extras && open (EX, "exceptions")) {
+ while (<EX>) {
+ chomp;
+ (/^$/ || /^#/) && next;
+ @a = split /\s+/;
+ $u = shift @a;
+ defined $users{$u} || die "Unknown user $u";
+ while (@a) { $extra{$u} += shift @a; }
+ }
+ close EX;
+ print STDERR "OK\n";
+} else { print STDERR "none\n"; }
+
+print STDERR "Scanning task results... ";
+%messages = ();
+%error_codes = ();
+foreach $u (keys %users) {
+ foreach $task (@ARGV) {
+ my ($dir, $t) = ("testing", $task);
+ if ($task =~ m@^(.*)/([^/]*)$@) {
+ $dir = $1;
+ $t = $2;
+ }
+ $known_tasks{$t} = 1;
+ $tt = "$dir/$u/$t/points" . ($alt ? ".alt" : "");
+ -f $tt || next;
+ print STDERR "$u/$t ";
+ open (X, $tt) || die "Unable to open $tt";
+ while (<X>) {
+ chomp;
+ /^(\S+) (-?\d+)\s*(.*)/ || die "Parse error: $_";
+ $ttest = $1;
+ $tpts = $2;
+ $trem = $3;
+ $trem =~ s/\[.*//;
+ ($ttest_merged = $ttest) =~ s/[^0-9]//g;
+ $ttest = $ttest_merged if $merged;
+ $known_tests{$t}{$ttest} = 1;
+ $cmt = $tpts;
+ if ($tpts == 0 && $trem ne "OK") {
+ if ($trem =~ /^Compile /) { $cmt = "CE"; }
+ elsif ($trem =~ /^Time limit exceeded/) { $cmt = "TO"; }
+ elsif ($trem =~ /^Exited with error /) { $cmt = "RE"; }
+ elsif ($trem =~ /^Caught fatal signal /) { $cmt = "SG"; }
+ elsif ($trem =~ /^([A-Za-z])\S*\s+([A-Za-z])/) {
+ ($cmt = "$1$2") =~ tr/a-z/A-Z/;
+ }
+ if (!defined $messages{$trem}) {
+ $messages{$trem} = $cmt;
+ if (!defined $error_codes{$cmt}) {
+ $error_codes{$cmt} = $trem;
+ } else {
+ $error_codes{$cmt} .= ", $trem";
+ }
+ }
+ }
+ if (!defined($results{$u}{$t}{$ttest}) || $results{$u}{$t}{$ttest} > $tpts) {
+ $results{$u}{$t}{$ttest} = $tpts;
+ $comment{$u}{$t}{$ttest} = $cmt;
+ }
+ if (!defined($results_merged{$u}{$t}{$ttest_merged}) || $results_merged{$u}{$t}{$ttest_merged} > $tpts) {
+ $results_merged{$u}{$t}{$ttest_merged} = $tpts;
+ }
+ }
+ close X;
+ }
+ foreach my $t (keys %known_tasks) {
+ $total{$u}{$t} = 0;
+ foreach my $pts (values %{$results_merged{$u}{$t}}) { $total{$u}{$t} += $pts; }
+ }
+}
+print STDERR "OK\n";
+
+print STDERR "Creating table template... ";
+@header = ("Rank","User","Name");
+@body = ('','$u','$users{$u}');
+@bodysums = ();
+@footer = ('"Total"','','');
+if (keys %extra) {
+ push @header, "Extra";
+ push @body, '$extra{$u}';
+ $col = 0+@footer;
+ push @bodysums, $col;
+ push @footer, "sum($col)";
+}
+@tasks = ();
+foreach $task (@ARGV) {
+ my $t = ($task =~ m@/([^/]*)$@) ? $1 : $task;
+ defined $known_tasks{$t} || die "Unknown task $t";
+ push @tasks, $t;
+ push @header, substr($t, 0, 4);
+ push @body, "(\$xx = \$total{\$u}{'$t'}) > 0 ? \$xx : 0";
+ $col = 0+@footer;
+ push @footer, "sum($col)";
+ push @bodysums, $col;
+ if ($detail) {
+ foreach $s (sort { $a <=> $b } keys %{$known_tests{$t}}) {
+ push @header, "$s";
+ push @body, "\$comment{\$u}{'$t'}{'$s'}";
+ $col = 0+@footer;
+ push @footer, "sum($col)";
+ }
+ }
+}
+push @header, "Total";
+push @body, join('+', map { $_ = "\$$_" } @bodysums);
+$col = 0+@footer;
+push @footer, "sum($col)";
+print STDERR "OK\n";
+
+print STDERR "h: ", join(':',@header), "\n" if $debug;
+print STDERR "b: ", join(':',@body), "\n" if $debug;
+print STDERR "f: ", join(':',@footer), "\n" if $debug;
+
+print STDERR "Filling in results... ";
+@table = ();
+foreach $u (keys %users) {
+ $row = [];
+ foreach my $c (@body) {
+ $c =~ s/\$(\d+)/\$\$row[$1]/g;
+ $x = eval $c;
+ push @$row, (defined $x ? $x : '-');
+ }
+ print STDERR "row: ", join(':',@$row), "\n" if $debug;
+ push @table, $row;
+}
+print STDERR "OK\n";
+
+print STDERR "Sorting... ";
+$sortcol = @{$table[0]} - 1;
+$namecol = 2;
+@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 . ".-" . $i . ".";
+ $j++;
+ while ($j < $i) { ${table[$j++]}[0] = ""; };
+ }
+}
+print STDERR "OK\n";
+
+print STDERR "Attaching headers and footers... ";
+sub sum { my $col=shift @_; my $t=0; foreach my $z (0..@table-1) { $t += ${$table[$z]}[$col]; } $t; }
+map { $_ = eval $_; } @footer;
+push @table, \@footer;
+unshift @table, \@header;
+print STDERR "OK\n";
+
+if ($debug) {
+ foreach $r (@table) { print join(':',@$r), "\n"; }
+} elsif ($html) {
+ print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html40/strict.dtd">', "\n";
+ print "<HTML><HEAD><TITLE>Rank list</TITLE></HEAD><BODY>\n";
+ print "<H1>Rank list</H1>\n";
+
+ my @perm;
+ &printHtmlHeader(\@perm);
+ print "<tbody>";
+
+ foreach $r (@table[1..($#table - 1)]) {
+ &printHtmlRow(@{$r}[@perm]);
+ }
+
+ print "<tbody>";
+ &printHtmlRow(@{$table[$#table]}[@perm]);
+
+ print "</TABLE>\n";
+ if ($detail) {
+ print "<H2>Error codes</H2><UL>\n";
+ foreach $r (sort keys %error_codes) { print "<LI>$r: $error_codes{$r}\n"; }
+ print "</UL>\n";
+ }
+ print "</BODY></HTML>\n";
+} elsif ($tex) {
+ 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"; }
+}
+
+
+sub printHtmlRow {
+ print "<TR>", join('',map {
+ if ($hdr) { $_ = "<TH>$_"; }
+ else { $_ = "<TD align=" . (/^[0-9A-Z-]+$/ ? "right" : "left") . (length($_) > 14 ? " width=150" : "") . ">$_"; }
+ } @_), "\n";
+}
+
+
+sub printHtmlHeader {
+
+ my ($perm) = @_;
+
+ my $colspec = "<colgroup span=3>";
+ my $hdr1;
+ my $hdr2;
+
+ @$perm = (0, 1, 2);
+ my $p = 3;
+
+ if ($detail) {
+ $hdr1 = "<th rowspan=2>Rank<th rowspan=2>User<th rowspan=2>Name";
+ $extras and $p++ and push @$perm, 3 and $hdr1.="<th rowspan=2>Extra" and $colspec.="<colgroup span=1>"; ##Extra hack
+ for my $task (@tasks) {
+
+ my $nSub = scalar(keys %{$known_tests{$task}});
+
+ $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
+
+ for my $task (@tasks) {
+ push @$perm, $p++;
+ $hdr1 .= "<th>$task";
+ }
+ $hdr1 .= "<th>Total";
+ $colspec .= "<colgroup span='" . scalar (@tasks) . "'>";
+ }
+
+ 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;
+
+}
--- /dev/null
+#!/bin/sh
+set -e
+[ -n "$1" ]
+sed <$1 's/^/ /' | a2ps -Ma4 -r --columns=1 --rows=1 --font-size=10 --borders=no -B -o /tmp/score.ps
+print /tmp/score.ps