--- loncom/homework/grades.pm 2008/05/23 22:14:25 1.521 +++ loncom/homework/grades.pm 2008/05/24 00:34:12 1.522 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.521 2008/05/23 22:14:25 www Exp $ +# $Id: grades.pm,v 1.522 2008/05/24 00:34:12 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -8325,15 +8325,18 @@ sub process_clicker_file { $result.=''.&mt('You need to specify a clicker ID for the correct answer').''; return $result.&show_grading_menu_form($symb); } - if (($env{'form.gradingmechanism'} eq 'given') && ($env{'form.givenanswer'}!~/\w/)) { + if (($env{'form.gradingmechanism'} eq 'given') && ($env{'form.givenanswer'}!~/\S/)) { $result.=''.&mt('You need to specify the correct answer').''; return $result.&show_grading_menu_form($symb); } + my $foundgiven=0; if ($env{'form.gradingmechanism'} eq 'given') { $env{'form.givenanswer'}=~s/^\s*//gs; $env{'form.givenanswer'}=~s/\s*$//gs; $env{'form.givenanswer'}=~s/[^a-zA-Z0-9\.\*\-]+/\,/g; $env{'form.givenanswer'}=uc($env{'form.givenanswer'}); + my @answers=split(/\,/,$env{'form.givenanswer'}); + $foundgiven=$#answers+1; } my %clicker_ids=&gather_clicker_ids(); my %correct_ids; @@ -8354,7 +8357,7 @@ sub process_clicker_file { if ($env{'form.gradingmechanism'} eq 'attendance') { $result.=&mt('Score based on attendance only'); } elsif ($env{'form.gradingmechanism'} eq 'given') { - $result.=&mt('Score based on [_1]',''.$env{'form.givenanswer'}.''); + $result.=&mt('Score based on [_1] ([_2] answers)',''.$env{'form.givenanswer'}.'',$foundgiven); } else { my $number=0; $result.='
'.&mt('Correctness determined by the following IDs').'';
@@ -8397,10 +8400,12 @@ sub process_clicker_file {
-
ENDHEADER
+ if ($env{'form.gradingmechanism'} eq 'given') {
+ $result.='';
+ }
my %responses;
my @questiontitles;
my $errormsg='';
@@ -8416,6 +8421,10 @@ ENDHEADER
&mt('Awarding [_1] percent for correct and [_2] percent for incorrect responses',
$env{'form.pcorrect'},$env{'form.pincorrect'}).
'
';
+ if (($env{'form.gradingmechanism'} eq 'given') && ($number!=$foundgiven)) {
+ $result.=''.&mt('Number of given answers does not agree with number of questions in file.').'';
+ return $result.&show_grading_menu_form($symb);
+ }
# Remember Question Titles
# FIXME: Possibly need delimiter other than ":"
for (my $i=0;$i<$number;$i++) {
@@ -8604,10 +8613,15 @@ ENDHEADER
if ($user) {
my @answer=split(/\,/,$env{$key});
my $sum=0;
+ my $realnumber=$number;
for (my $i=0;$i<$number;$i++) {
if ($answer[$i]) {
if ($gradingmechanism eq 'attendance') {
$sum+=$pcorrect;
+ } elsif ($answer[$i] eq '*') {
+ $sum+=$pcorrect;
+ } elsif ($answer[$i] eq '-') {
+ $realnumber--;
} else {
if ($answer[$i] eq $correct[$i]) {
$sum+=$pcorrect;
@@ -8617,7 +8631,7 @@ ENDHEADER
}
}
}
- my $ave=$sum/(100*$number);
+ my $ave=$sum/(100*$realnumber);
# Store
my ($username,$domain)=split(/\:/,$user);
my %grades=();