--- loncom/homework/caparesponse/caparesponse.pm 2010/10/18 19:47:39 1.242 +++ loncom/homework/caparesponse/caparesponse.pm 2011/01/25 04:30:13 1.244 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # caparesponse definition # -# $Id: caparesponse.pm,v 1.242 2010/10/18 19:47:39 raeburn Exp $ +# $Id: caparesponse.pm,v 1.244 2011/01/25 04:30:13 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -451,6 +451,7 @@ sub check_submission { my ($result,@msgs) = &Apache::run::run("&caparesponse_check_list()",$safeeval); &Apache::lonxml::debug("checking $name $result with $response took ".&Time::HiRes::tv_interval($t0)); + &Apache::lonxml::debug('msgs are '.join(':',@msgs)); my ($awards)=split(/:/,$result); my @awards= split(/,/,$awards); @@ -1223,17 +1224,20 @@ sub end_stringresponse { $$args_ref{'type'} = 'ci'; } &add_in_tag_answer($parstack,$safeeval); - my (@final_awards,@final_msgs,@names); + my (@final_awards,@final_msgs,@names,%ansstring); foreach my $name (keys(%answer)) { &Apache::lonxml::debug(" doing $name with ".join(':',@{ $answer{$name}{'answers'} })); ${$safeeval->varglob('LONCAPA::CAPAresponse_answer')}=dclone($answer{$name}); my ($result, @msgs)=&Apache::run::run("&caparesponse_check_list()",$safeeval); if ($$args_ref{'type'} =~ /^c[si]$/) { + $ansstring{$name} = pop(@msgs); + } + if ($$args_ref{'type'} =~ /^c[si]$/) { my $control_chars_removed = pop(@msgs); my $error = pop(@msgs); if (($error ne '') || ($control_chars_removed ne '')) { - my ($symb,$courseid,$domain,$name) = + my ($symb,$courseid,$sdomain,$sname) = &Apache::lonnet::whichuser(); if ($control_chars_removed ne '') { my $showresponse = $response; @@ -1244,11 +1248,11 @@ sub end_stringresponse { my @lines = split(/[\r\n\f]+/,$showresponse); $showresponse = join('\\n',@lines); } - &Apache::lonnet::logthis("Stringresponse grading: control characters stripped from submission ".$showresponse." for $name:$domain in $courseid for part: $part response: $id and symb: $symb"); + &Apache::lonnet::logthis("Stringresponse grading: control characters stripped from submission ".$showresponse." for $sname:$sdomain in $courseid for part: $part response: $id and symb: $symb"); $Apache::lonhomework::results{"resource.$part.$id.submission"} = $response; } if ($error ne '') { - &Apache::lonnet::logthis("Stringresponse grading error: $error for $name:$domain in $courseid for part: $part response: $id and symb: $symb"); + &Apache::lonnet::logthis("Stringresponse grading error: $error for $sname:$sdomain in $courseid for part: $part response: $id and symb: $symb"); } } } @@ -1266,6 +1270,9 @@ sub end_stringresponse { &Apache::inputtags::finalizeawards(\@final_awards, \@final_msgs, \@names,1); + if (keys(%ansstring) > 0) { + $Apache::lonhomework::results{"resource.$part.$id.answerstring"} = &Apache::lonnet::hash2str(%ansstring); + } } if (($ad eq 'INCORRECT' || $ad eq 'APPROX_ANS' || $ad eq 'EXACT_ANS')) { @@ -1279,16 +1286,27 @@ sub end_stringresponse { $ad='ANONYMOUS_CREDIT'; } } - unless ($env{'request.state'} eq 'construct') { - if ($previous{'used'}) { - if ($ad ne $previous{'award'} && $previous{'award'} ne '') { - &stringresponse_gradechange($part,$id,\%previous, - 'cs',$response,$ad,$type); - } - } elsif ($previous{'usedci'}) { - if ($ad ne $previous{'awardci'} && $previous{'awardci'} ne '') { - &stringresponse_gradechange($part,$id,\%previous, - 'ci',$response,$ad,$type); + unless (($env{'request.state'} eq 'construct') || + ($Apache::lonhomework::type eq 'randomizetry')) { + if (($ad eq 'INCORRECT' || $ad eq 'APPROX_ANS' || $ad eq 'EXACT_ANS')) { + if ($previous{'used'}) { + if ($ad ne $previous{'award'}) { + if (($previous{'award'} eq 'INCORRECT' || + $previous{'award'} eq 'APPROX_ANS' || + $previous{'award'} eq 'EXACT_ANS')) { + &stringresponse_gradechange($part,$id,\%previous, + 'cs',$response,$ad,$type); + } + } + } elsif ($previous{'usedci'}) { + if ($ad ne $previous{'awardci'}) { + if (($previous{'awardci'} eq 'INCORRECT' || + $previous{'awardci'} eq 'APPROX_ANS' || + $previous{'awardci'} eq 'EXACT_ANS')) { + &stringresponse_gradechange($part,$id,\%previous, + 'ci',$response,$ad,$type); + } + } } } } @@ -1317,6 +1335,9 @@ sub end_stringresponse { if ($target eq 'answer') { $result.=&Apache::response::answer_part('stringresponse', $element); + if ($env{'form.grade_retrieveanswers'}) { + $env{'form.grade_answers.resource.'.$part.'.'.$id} = $element; + } } elsif ($target eq 'analyze') { push (@{ $Apache::lonhomework::analyze{"$part.$id.answer"}{$name}[$i] }, $element);