Archived
1
0

Add average in cvs

This commit is contained in:
Mercier Pierre-Olivier 2013-11-13 03:07:56 +01:00
parent e2ba0a5e38
commit bedb084ffe

View File

@ -31,6 +31,7 @@ sub process
my %grades;
my @headers;
my @averages;
opendir(my $dh, "$basedir/$year/$project_id/grades/") or croak "can't opendir $basedir/$year/$project_id/grades/: $!";
for my $gfile (grep { ( ! /^\./ ) && -f "$basedir/$year/$project_id/grades/$_" } readdir($dh))
@ -52,6 +53,7 @@ sub process
if ($ugrades[$i] eq $grade->getAttribute("name"))
{
$ugrades[$i] = $grade->getAttribute("value");
$averages[$i] += $grade->getAttribute("value");
last;
}
}
@ -60,6 +62,7 @@ sub process
{
push @headers, $grade->getAttribute("name");
push @ugrades, $grade->getAttribute("value");
push @averages, $grade->getAttribute("value");
}
}
@ -70,13 +73,15 @@ sub process
# Print CSV
my $out = "login";
for my $header (@headers) {
foreach my $header (@headers) {
$out .= ",$header";
}
$out .= "\n";
for my $login (keys %grades)
my $nb = 0;
foreach my $login (keys %grades)
{
$nb += 1;
$out .= "$login";
my @ugrades = @{ $grades{$login} };
for my $header (@headers)
@ -92,6 +97,13 @@ sub process
$out .= "\n";
}
$out .= "Average";
foreach my $average (@averages)
{
$out .= ",".($average / $nb);
}
$out .= "\n";
return $out;
}