TU Wien:Funktionale Programmierung VU (Knoop)/Perlskript für Punkteübersicht

Aus VoWi
Zur Navigation springen Zur Suche springen

Perlskript für Punkteübersicht auf Übungsserver (g0) by patrikf @informatik-forum[1]

#!/usr/bin/perl
# vim:set sw=4 sts=4 et smartindent:

# Hier die Anzahl der Aufgaben setzen
my $numOfUe = 8;

use strict;
use File::Basename;

my @files = `ls *.out` or die;
my %scores;

my $maxScore = $numOfUe * 100;
my @limits = (0.5, 0.625, 0.75, 0.875); # in 0.1% = x/$maxScore
my @grades = ("nicht genuegend", "genuegend", "befriedigend", "gut", "sehr gut");

foreach my $file (@files) {
    chomp $file;

    my $name = basename $file;
    $name =~ /^Aufgabe(\d+).l?hs_(\d+).out$/ or next;

    my $aufg = $1;
    my $attempt = $2;

    my $pts;
    open IN, $file;
    while (<IN>) {
        chomp;
        /^Punkte gesamt: (\d+)$/ and $pts = $1;
    }
    close IN;

    unless (defined $scores{$aufg}) {
        $scores{$aufg} = [];
    }
    push @{$scores{$aufg}}, $pts;
}

my $total = 0;
my $optimist = 0;
my $possible = 0;

print "\n";
print "Aufgabe   |1.Abg|2.Abg| Avg\n";
print "----------+-----+-----+-----\n";

for my $i (sort {$a <=> $b} (keys %scores)) {
    my @scores = @{$scores{$i}};
    my $score;
    if ($#scores == 0) {
        my $first = $scores[0];
        $score = $first;
        printf "Aufgabe %-2d| %3d |     | %3d\n", $i, $first, $score;

        $optimist += 100;
    } elsif ($#scores == 1) {
        my $first = $scores[0];
        my $second = $scores[1];
        $score = ($first + $second)/2;
        printf "Aufgabe %-2d| %3d | %3d | %3d\n", $i, $first, $second, $score;

        $optimist += $score;
    } else {
        die;
    }
    $total += $score;
    $possible += 100;
}

sub grade {
    my $a = shift;
    my $b = shift;
    my $i = 0;
    $i++ while ($i <= $#limits && $a * $maxScore >= $b * $limits[$i]*$maxScore);
    return $grades[$i];
}

sub printGrade {
    my $label = shift;
    my $have = shift;
    my $outof = shift;
    printf "%-22s %4d /%4d  (%3d%%, entspr. %s)\n", $label, $have, $outof, $have*100/$outof, grade($have, $outof);
}

print "\n";
printGrade "Bisher", $total, $possible;
printGrade "Optimistisch*", $optimist, $possible;
printGrade "Endwertung**", $total, $maxScore; # lt. $numOfUe Abgaben
print "\n";
print "Alle Werte ohne Gewaehr!\n";
print "*  bei Korrektur aller Fehler\n";
printf "** Annahme: %3d Abgaben\n", $numOfUe;
print "\n";