--- loncom/homework/inputtags.pm 2007/09/26 19:30:30 1.231 +++ loncom/homework/inputtags.pm 2007/10/03 02:10:45 1.232 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # input definitons # -# $Id: inputtags.pm,v 1.231 2007/09/26 19:30:30 albertel Exp $ +# $Id: inputtags.pm,v 1.232 2007/10/03 02:10:45 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -539,8 +539,17 @@ sub valid_award { $i=0; my %rev_awards = map { ($_,$i++) } @awards; +sub awarddetail_to_awarded { + my ($awarddetail) = @_; + if ($awarddetail eq 'EXACT_ANS' + || $awarddetail eq 'APPROX_ANS') { + return 1; + } + return 0; +} + sub finalizeawards { - my ($awardref,$msgref,$nameref,$reverse)=@_; + my ($awardref,$msgref,$nameref,$reverse,$final_scantron)=@_; my $result; if ($#$awardref == -1) { $result = "NO_RESPONSE"; } if ($result eq '' ) { @@ -551,10 +560,29 @@ sub finalizeawards { $blankcount++; } } - if ($blankcount == ($#$awardref + 1)) { $result = 'NO_RESPONSE'; } + if ($blankcount == ($#$awardref + 1)) { + return ('NO_RESPONSE'); + } } - if (defined($result)) { return ($result); } + if (!$final_scantron && defined($result)) { return ($result); } + # if in scantron mode, if the award for any response is + # assigned score, then the part gets an assigned score + if ($final_scantron + && grep {$_ eq 'ASSIGNED_SCORE'} (@$awardref)) { + return ('ASSIGNED_SCORE'); + } + + # if in scantron mode, if the award for any response is + # correct and there are non-correct responses, + # then the part gets an assigned score + if ($final_scantron + && (grep { $_ eq 'EXACT_ANS' || + $_ eq 'APPROX_ANS' } (@$awardref)) + && (grep { $_ ne 'EXACT_ANS' && + $_ ne 'APPROX_ANS' } (@$awardref))) { + return ('ASSIGNED_SCORE'); + } # these awards are ordered from most important error through best correct my $awards = (!$reverse) ? \%fwd_awards : \%rev_awards ; @@ -568,6 +596,7 @@ sub finalizeawards { } $j++; } + if (defined($which)) { if (ref($nameref)) { return ($$awardref[$which],$$msgref[$which],$$nameref[$which]); @@ -873,8 +902,13 @@ sub setgradedata { my $numawards=scalar(@Apache::inputtags::response); $Apache::lonhomework::results{"resource.$id.awarded"} = 0; foreach my $res (@Apache::inputtags::response) { - $Apache::lonhomework::results{"resource.$id.awarded"}+= - $Apache::lonhomework::results{"resource.$id.$res.awarded"}; + if (defined($Apache::lonhomework::results{"resource.$id.$res.awarded"})) { + $Apache::lonhomework::results{"resource.$id.awarded"}+= + $Apache::lonhomework::results{"resource.$id.$res.awarded"}; + } else { + $Apache::lonhomework::results{"resource.$id.awarded"}+= + &awarddetail_to_awarded($Apache::lonhomework::results{"resource.$id.$res.awarddetail"}); + } } if ($numawards > 0) { $Apache::lonhomework::results{"resource.$id.awarded"}/= @@ -1006,7 +1040,9 @@ sub grade { &Apache::lonxml::debug("got message $value from $response for $id"); push (@msgs,$value); } - my ($finalaward,$msg) = &finalizeawards(\@awards,\@msgs); + my ($finalaward,$msg) = + &finalizeawards(\@awards,\@msgs,undef,undef, + $Apache::lonhomework::scantronmode); my $previously_used; if ( $#Apache::inputtags::previous eq $#awards ) { my ($match) =