]> mj.ucw.cz Git - eval.git/blob - mop/eval/mo-report.sh
mo-score: Since STDOUT may be a pipe, we need to close it
[eval.git] / mop / eval / mo-report.sh
1 #!/usr/bin/perl
2 # A simple generator of evaluation reports
3 # (c) 2007 Martin Mares <mj@ucw.cz>
4
5 use strict;
6 use warnings;
7 use POSIX;
8
9 foreach my $user (`cd testing && ls`) {
10         chomp $user;
11         print "$user:";
12         open REP, ">testing/$user/REPORT" or die;
13         print REP "Evaluation report for CEOI 2007 Day 2\n\n";
14         my $total = 0;
15         foreach my $task (@ARGV) {
16                 print REP "### Task $task ###\n\n";
17                 if (open PTS, "testing/$user/$task/points") {
18                         my %merged_pts = ();
19                         my %split_comm = ();
20                         while (<PTS>) {
21                                 chomp;
22                                 my ($test, $pts, $comm) = /(\S+)\s+(\S+)\s+(.*)/;
23                                 my $merged = $test;
24                                 $merged =~ s/[^0-9]//;
25                                 if (!defined($merged_pts{$merged}) || $merged_pts{$merged} > $pts) {
26                                         $merged_pts{$merged} = $pts;
27                                 }
28                                 $split_comm{$merged}{$test} = $comm;
29                         }
30                         close PTS;
31                         my $tt = 0;
32                         foreach my $merged (sort { $a <=> $b } keys %merged_pts) {
33                                 printf REP "Test %2s: %2d points", $merged, $merged_pts{$merged};
34                                 $tt += $merged_pts{$merged};
35                                 my @k = sort keys %{$split_comm{$merged}};
36                                 if (@k == 1) {
37                                         print REP " -- ", $split_comm{$merged}{$k[0]}, "\n";
38                                 } else {
39                                         print REP " -- ";
40                                         my $cc = 0;
41                                         foreach my $t (@k) {
42                                                 $cc++ and print REP ", ";
43                                                 print REP "$t: $split_comm{$merged}{$t}";
44                                         }
45                                         print REP "\n";
46                                 }
47                         }
48                         print REP "\nTOTAL: $tt points\n\n";
49                         $total += $tt;
50                         print " $tt";
51                 } else {
52                         print REP "No solution submitted.\n\n";
53                         print " -";
54                 }
55         }
56         print REP "### TOTAL FOR DAY 2 ###\n\n";
57         print REP "$total points\n";
58         print REP "\n\n(generated on ", strftime("%Y-%m-%d %H:%M:%S", localtime), ")\n";
59         close REP;
60         print " -> $total\n";
61 }