Commit e34ba6ba authored by Robert Ricci's avatar Robert Ricci

First version of script to compute grades

parent 69fc15c6
#!/usr/bin/perl -w
use strict;
use List::Util qw(reduce);
my %assignments = (
homework => { hw1 => 1, hw2 => 1, hw3 => 1, hw4 => 1, hw5 => 1, hw6 => 1},
participation => { participation => 1 },
papers => { papers1 => 1, papers2 => 1, papers3 => 1, papers4 => 1},
labs => { lab1 => 1, lab1prep => 1 }
);
my %weights = (
participation => 0.125,
homework => 0.250,
papers => 0.3125,
labs => 0.3125
);
my @students = `list-students`;
chomp @students;
sub get_grade_for($$);
sub sum_pairs(@);
my %scores;
foreach my $student (@students) {
print "##### $student\n";
$scores{$student} = {};
my @studentscores = ();
foreach my $type (keys %assignments) {
$scores{$student}{$type} = {};
foreach my $hw (keys %{$assignments{$type}}) {
my ($score, $possible) = get_grade_for($student,$hw);
my $weight = $assignments{$type}{$hw};
$scores{$student}{$type}{$hw} =
[$score * $weight, $possible *$weight];
}
my ($typetotal, $typepossible) =
sum_pairs(values $scores{$student}{$type});
my $pct = $typetotal / $typepossible;
print "\t$type:\t$typetotal / $typepossible ($pct)\n";
my $weight = $weights{$type};
push @studentscores, $pct * $weight;
}
my $studenttotal = reduce { $a + $b } @studentscores;
print "\tTOTAL:\t$studenttotal\n";
}
sub get_grade_for($$) {
my ($student, $hw) = @_;
my $branch = "$hw-graded-$student";
if (`git show -s --format=%s $branch` =~ /^\s*Total score: (\d+(\.\d+)?)\s*\/\s*(\d+)/) {
my ($score, $possible) = ($1,$3);
return ($score, $possible);
} else {
die "No score for student $student\n";
}
}
sub sum_pairs(@) {
my @pairs = @_;
my ($total, $possible) = (0,0);
for my $pair (@pairs) {
$total += $pair->[0];
$possible += $pair->[1];
}
return ($total, $possible);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment