version 1.193, 2006/07/03 14:21:45
|
version 1.194, 2006/09/29 20:55:36
|
Line 33 use Safe::Hole;
|
Line 33 use Safe::Hole;
|
use Apache::lonmaxima(); |
use Apache::lonmaxima(); |
use Apache::lonlocal; |
use Apache::lonlocal; |
use Apache::lonnet; |
use Apache::lonnet; |
|
use Storable qw(dclone); |
|
|
BEGIN { |
BEGIN { |
&Apache::lonxml::register('Apache::caparesponse',('caparesponse','numericalresponse','stringresponse','formularesponse')); |
&Apache::lonxml::register('Apache::caparesponse',('numericalresponse','stringresponse','formularesponse')); |
} |
} |
|
|
my %answer; |
my %answer; |
Line 65 sub end_answer {
|
Line 66 sub end_answer {
|
sub start_answergroup { |
sub start_answergroup { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; |
my $result; |
my $result; |
my $id = $Apache::inputtags::response[-1]; |
|
my $dis = &Apache::lonxml::get_param('answerdisplay',$parstack,$safeeval); |
|
if (defined($dis)) { $Apache::inputtags::answertxt{$id}=$dis; } |
|
return $result; |
return $result; |
} |
} |
|
|
sub end_answergroup { |
sub end_answergroup { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; |
my $result; |
my $result; |
|
if ($target eq 'web') { |
|
if ( &Apache::response::show_answer() ) { |
|
my $partid = $Apache::inputtags::part; |
|
my $id = $Apache::inputtags::response[-1]; |
|
&set_answertext($Apache::lonhomework::history{"resource.$partid.$id.answername"}, |
|
$target,$token,$tagstack,$parstack,$parser, |
|
$safeeval,-2); |
|
} |
|
} |
return $result; |
return $result; |
} |
} |
|
|
Line 184 sub start_numericalresponse {
|
Line 191 sub start_numericalresponse {
|
if ($unit =~ /\S/) { $result.=" (in $unit) "; } |
if ($unit =~ /\S/) { $result.=" (in $unit) "; } |
} |
} |
if ( &Apache::response::show_answer() ) { |
if ( &Apache::response::show_answer() ) { |
my $answertxt; |
&set_answertext('INTERNAL',$target,$token,$tagstack,$parstack, |
my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack, |
$parser,$safeeval,-1); |
$safeeval); |
|
my (@formats)=&Apache::lonxml::get_param_var('format',$parstack, |
|
$safeeval); |
|
my $unit=&Apache::lonxml::get_param_var('unit',$parstack, |
|
$safeeval); |
|
for (my $i=0; $i <= $#answers; $i++) { |
|
my $answer=$answers[$i]; |
|
if ( scalar(@$tagstack) |
|
&& $tagstack->[-1] ne 'numericalresponse') { |
|
$answertxt.=$answer.','; |
|
} else { |
|
my $format; |
|
if ($#formats > 0) { |
|
$format=$formats[$i]; |
|
} else { |
|
$format=$formats[0]; |
|
} |
|
if ($unit=~/\$/) { $format="\$".$format; $unit=~s/\$//g; } |
|
if ($unit=~/\,/) { $format="\,".$format; $unit=~s/\,//g; } |
|
my $formatted=&format_number($answer,$format,$target, |
|
$safeeval); |
|
$answertxt.=$formatted.','; |
|
} |
|
} |
|
chop $answertxt; |
|
if ($target eq 'web') { |
|
$answertxt.=" $unit "; |
|
} |
|
$Apache::inputtags::answertxt{$id}=$answertxt; |
|
} |
} |
} |
} |
return $result; |
return $result; |
} |
} |
|
|
|
sub set_answertext { |
|
my ($name,$target,$token,$tagstack,$parstack,$parser,$safeeval, |
|
$response_level) = @_; |
|
my $answertxt; |
|
&add_in_tag_answer($parstack,$safeeval,$response_level); |
|
|
|
return if ($name eq '' || !ref($answer{$name})); |
|
|
|
my (@formats)=&Apache::lonxml::get_param_var('format',$parstack, |
|
$safeeval,$response_level); |
|
my $unit=&Apache::lonxml::get_param_var('unit',$parstack,$safeeval, |
|
$response_level); |
|
|
|
&Apache::lonxml::debug("answer looks to be $name"); |
|
for (my $i=0; $i < scalar(@{$answer{$name}{'answers'}}); $i++) { |
|
my $answer=$answer{$name}{'answers'}[$i]; |
|
if ( scalar(@$tagstack) |
|
&& $tagstack->[$response_level] ne 'numericalresponse') { |
|
$answertxt.=$answer.','; |
|
} else { |
|
my $format; |
|
if ($#formats > 0) { |
|
$format=$formats[$i]; |
|
} else { |
|
$format=$formats[0]; |
|
} |
|
if ($unit=~/\$/) { $format="\$".$format; $unit=~s/\$//g; } |
|
if ($unit=~/\,/) { $format="\,".$format; $unit=~s/\,//g; } |
|
my $formatted=&format_number($answer,$format,$target, |
|
$safeeval); |
|
$answertxt.=$formatted.','; |
|
} |
|
} |
|
|
|
chop($answertxt); |
|
if ($target eq 'web') { |
|
$answertxt.=" $unit "; |
|
} |
|
my $id = $Apache::inputtags::response[-1]; |
|
$Apache::inputtags::answertxt{$id}=$answertxt; |
|
} |
|
|
sub check_submission { |
sub check_submission { |
my ($response,$partid,$id,$tag,$parstack,$safeeval,$ignore_sig)=@_; |
my ($response,$partid,$id,$tag,$parstack,$safeeval,$ignore_sig)=@_; |
my $args_ref= \%{$safeeval->varglob('LONCAPA::CAPAresponse_args')}; |
my $args_ref= \%{$safeeval->varglob('LONCAPA::CAPAresponse_args')}; |
Line 257 sub check_submission {
|
Line 277 sub check_submission {
|
} elsif ($tag eq 'numericalresponse') { |
} elsif ($tag eq 'numericalresponse') { |
$$args_ref{'type'}='float'; |
$$args_ref{'type'}='float'; |
} |
} |
my @answer=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval); |
|
&Apache::lonxml::debug('answer is'.join(':',@answer)); |
&add_in_tag_answer($parstack,$safeeval); |
if (@answer && defined($answer[0])) { |
|
$answer{'INTERNAL'}= {'type' => 'ordered', |
#FIXME would be nice if we could save name so we know which answer |
'answers' => \@answer }; |
# graded the users submisson correct |
} |
|
#FIXME would be nice if we could save name so we know who graded him |
|
#correct |
|
my (%results,@final_awards,@final_msgs,@names); |
my (%results,@final_awards,@final_msgs,@names); |
foreach my $name (keys(%answer)) { |
foreach my $name (keys(%answer)) { |
&Apache::lonxml::debug(" doing $name with ".join(':',@{ $answer{$name}{'answers'} })); |
&Apache::lonxml::debug(" doing $name with ".join(':',@{ $answer{$name}{'answers'} })); |
@{$safeeval->varglob('LONCAPA::CAPAresponse_answer')}=@{ $answer{$name}{'answers'} }; |
|
|
${$safeeval->varglob('LONCAPA::CAPAresponse_answer')}=dclone($answer{$name}); |
my ($result,@msgs) = |
my ($result,@msgs) = |
&Apache::run::run("&caparesponse_check_list()",$safeeval); |
&Apache::run::run("&caparesponse_check_list()",$safeeval); |
&Apache::lonxml::debug('msgs are '.join(':',@msgs)); |
&Apache::lonxml::debug('msgs are '.join(':',@msgs)); |
Line 283 sub check_submission {
|
Line 301 sub check_submission {
|
my ($ad, $msg, $name) = &Apache::inputtags::finalizeawards(\@final_awards, |
my ($ad, $msg, $name) = &Apache::inputtags::finalizeawards(\@final_awards, |
\@final_msgs, |
\@final_msgs, |
\@names,1); |
\@names,1); |
return($ad,$msg); |
&Apache::lonxml::debug(" name of picked award is $name from ".join(', ',@names)); |
|
return($ad,$msg, $name); |
|
} |
|
|
|
sub add_in_tag_answer { |
|
my ($parstack,$safeeval,$response_level) = @_; |
|
my @answer=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval, |
|
$response_level); |
|
&Apache::lonxml::debug('answer is'.join(':',@answer)); |
|
if (@answer && defined($answer[0])) { |
|
$answer{'INTERNAL'}= {'type' => 'ordered', |
|
'answers' => \@answer }; |
|
} |
} |
} |
|
|
sub end_numericalresponse { |
sub end_numericalresponse { |
Line 319 sub end_numericalresponse {
|
Line 349 sub end_numericalresponse {
|
$response=$values->[$response]; |
$response=$values->[$response]; |
} |
} |
$Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response; |
$Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response; |
my ($ad,$msg)=&check_submission($response,$partid,$id, |
my ($ad,$msg,$name)=&check_submission($response,$partid,$id, |
$tag,$parstack,$safeeval); |
$tag,$parstack, |
|
$safeeval); |
|
|
&Apache::lonxml::debug('ad is'.$ad); |
&Apache::lonxml::debug('ad is'.$ad); |
if ($ad eq 'SIG_FAIL') { |
if ($ad eq 'SIG_FAIL') { |
Line 339 sub end_numericalresponse {
|
Line 370 sub end_numericalresponse {
|
&Apache::response::handle_previous(\%previous,$ad); |
&Apache::response::handle_previous(\%previous,$ad); |
$Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad; |
$Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad; |
$Apache::lonhomework::results{"resource.$partid.$id.awardmsg"}=$msg; |
$Apache::lonhomework::results{"resource.$partid.$id.awardmsg"}=$msg; |
|
$Apache::lonhomework::results{"resource.$partid.$id.answername"}=$name; |
$result=''; |
$result=''; |
} |
} |
} |
} |
} elsif ($target eq 'web' || $target eq 'tex') { |
} elsif ($target eq 'web' || $target eq 'tex') { |
my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack, |
|
$safeeval); |
|
my $award = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"}; |
my $award = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"}; |
my $status = $Apache::inputtags::status['-1']; |
my $status = $Apache::inputtags::status['-1']; |
if ($Apache::lonhomework::type eq 'exam') { |
if ($Apache::lonhomework::type eq 'exam') { |
|
# FIXME support multi dimensional numerical problems |
|
# in exam bubbles |
my ($bubble_values,$bubble_display)= |
my ($bubble_values,$bubble_display)= |
&make_numerical_bubbles($partid,$id,$target,$parstack, |
&make_numerical_bubbles($partid,$id,$target,$parstack, |
$safeeval); |
$safeeval); |
Line 418 sub end_numericalresponse {
|
Line 450 sub end_numericalresponse {
|
if (scalar(@$tagstack)) { |
if (scalar(@$tagstack)) { |
&Apache::response::setup_params($tag,$safeeval); |
&Apache::response::setup_params($tag,$safeeval); |
} |
} |
my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval); |
&add_in_tag_answer($parstack,$safeeval); |
my (@formats)=&Apache::lonxml::get_param_var('format',$parstack,$safeeval); |
my (@formats)=&Apache::lonxml::get_param_var('format',$parstack,$safeeval); |
|
|
my $unit=&Apache::lonxml::get_param_var('unit',$parstack,$safeeval); |
my $unit=&Apache::lonxml::get_param_var('unit',$parstack,$safeeval); |
my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval); |
|
|
|
if ($target eq 'answer') { |
if ($target eq 'answer') { |
$result.=&Apache::response::answer_header($tag); |
$result.=&Apache::response::answer_header($tag); |
Line 432 sub end_numericalresponse {
|
Line 464 sub end_numericalresponse {
|
$result.=&Apache::response::answer_part($tag,$correct); |
$result.=&Apache::response::answer_part($tag,$correct); |
} |
} |
} |
} |
my ($sigline,$tolline); |
foreach my $name (sort(keys(%answer))) { |
for(my $i=0;$i<=$#answers;$i++) { |
my @answers = @{ $answer{$name}{'answers'} }; |
my $ans=$answers[$i]; |
my ($sigline,$tolline); |
my $fmt=$formats[0]; |
for(my $i=0;$i<=$#answers;$i++) { |
if (@formats && $#formats) {$fmt=$formats[$i];} |
my $ans=$answers[$i]; |
my ($high,$low); |
my $fmt=$formats[0]; |
if ($Apache::inputtags::params{'tol'}) { |
if (@formats && $#formats) {$fmt=$formats[$i];} |
($high,$low)=&get_tolrange($ans,$Apache::inputtags::params{'tol'}); |
my ($high,$low); |
} |
if ($Apache::inputtags::params{'tol'}) { |
my ($sighigh,$siglow); |
($high,$low)=&get_tolrange($ans,$Apache::inputtags::params{'tol'}); |
if ($Apache::inputtags::params{'sig'}) { |
} |
($sighigh,$siglow)=&get_sigrange($Apache::inputtags::params{'sig'}); |
my ($sighigh,$siglow); |
} |
if ($Apache::inputtags::params{'sig'}) { |
if ($fmt && $tag eq 'numericalresponse') { |
($sighigh,$siglow)=&get_sigrange($Apache::inputtags::params{'sig'}); |
$fmt=~s/e/E/g; |
} |
if ($unit=~/\$/) { $fmt="\$".$fmt; $unit=~s/\$//g; } |
if ($fmt && $tag eq 'numericalresponse') { |
if ($unit=~/\,/) { $fmt="\,".$fmt; $unit=~s/\,//g; } |
$fmt=~s/e/E/g; |
$ans = &format_number($ans,$fmt,$target,$safeeval); |
if ($unit=~/\$/) { $fmt="\$".$fmt; $unit=~s/\$//g; } |
#if ($high) { |
if ($unit=~/\,/) { $fmt="\,".$fmt; $unit=~s/\,//g; } |
# $high=&format_number($high,$fmt,$target,$safeeval); |
$ans = &format_number($ans,$fmt,$target,$safeeval); |
# $low =&format_number($low,$fmt,$target,$safeeval); |
#if ($high) { |
#} |
# $high=&format_number($high,$fmt,$target,$safeeval); |
} |
# $low =&format_number($low,$fmt,$target,$safeeval); |
if ($target eq 'answer') { |
#} |
if ($high && $tag eq 'numericalresponse') { |
} |
$ans.=' ['.$low.','.$high.']'; |
if ($target eq 'answer') { |
$tolline .= "[$low, $high]"; |
if ($high && $tag eq 'numericalresponse') { |
} |
$ans.=' ['.$low.','.$high.']'; |
if (defined($sighigh) && $tag eq 'numericalresponse') { |
$tolline .= "[$low, $high]"; |
if ($env{'form.answer_output_mode'} eq 'tex') { |
} |
$ans.= " Sig $siglow - $sighigh"; |
if (defined($sighigh) && $tag eq 'numericalresponse') { |
} else { |
if ($env{'form.answer_output_mode'} eq 'tex') { |
$ans.= " Sig <i>$siglow - $sighigh</i>"; |
$ans.= " Sig $siglow - $sighigh"; |
$sigline .= "[$siglow, $sighigh]"; |
} else { |
|
$ans.= " Sig <i>$siglow - $sighigh</i>"; |
|
$sigline .= "[$siglow, $sighigh]"; |
|
} |
|
} |
|
$result.=&Apache::response::answer_part($tag,$ans); |
|
} elsif ($target eq 'analyze') { |
|
push (@{ $Apache::lonhomework::analyze{"$part_id.answer"} }, $ans); |
|
if ($high) { |
|
push (@{ $Apache::lonhomework::analyze{"$part_id.ans_high"} }, $high); |
|
push (@{ $Apache::lonhomework::analyze{"$part_id.ans_low"} }, $low); |
|
} |
|
if ($fmt) { |
|
push (@{ $Apache::lonhomework::analyze{"$part_id.format"} }, $fmt); |
} |
} |
} |
|
$result.=&Apache::response::answer_part($tag,$ans); |
|
} elsif ($target eq 'analyze') { |
|
push (@{ $Apache::lonhomework::analyze{"$part_id.answer"} }, $ans); |
|
if ($high) { |
|
push (@{ $Apache::lonhomework::analyze{"$part_id.ans_high"} }, $high); |
|
push (@{ $Apache::lonhomework::analyze{"$part_id.ans_low"} }, $low); |
|
} |
|
if ($fmt) { |
|
push (@{ $Apache::lonhomework::analyze{"$part_id.format"} }, $fmt); |
|
} |
} |
} |
} |
} |
|
|
|
my @fmt_ans; |
my @fmt_ans; |
for(my $i=0;$i<=$#answers;$i++) { |
for(my $i=0;$i<=$#answers;$i++) { |
my $ans=$answers[$i]; |
my $ans=$answers[$i]; |
my $fmt=$formats[0]; |
my $fmt=$formats[0]; |
if (@formats && $#formats) {$fmt=$formats[$i];} |
if (@formats && $#formats) {$fmt=$formats[$i];} |
if ($fmt && $tag eq 'numericalresponse') { |
if ($fmt && $tag eq 'numericalresponse') { |
$fmt=~s/e/E/g; |
$fmt=~s/e/E/g; |
if ($unit=~/\$/) { $fmt="\$".$fmt; $unit=~s/\$//g; } |
if ($unit=~/\$/) { $fmt="\$".$fmt; $unit=~s/\$//g; } |
if ($unit=~/\,/) { $fmt="\,".$fmt; $unit=~s/\,//g; } |
if ($unit=~/\,/) { $fmt="\,".$fmt; $unit=~s/\,//g; } |
$ans = &format_number($ans,$fmt,$target,$safeeval); |
$ans = &format_number($ans,$fmt,$target,$safeeval); |
if ($fmt=~/\$/ && $unit!~/\$/) { $ans=~s/\$//; } |
if ($fmt=~/\$/ && $unit!~/\$/) { $ans=~s/\$//; } |
|
} |
|
push(@fmt_ans,$ans); |
|
} |
|
my $response=join(', ',@fmt_ans); |
|
my $hideunit=&Apache::lonnet::EXT('resource.'.$partid.'_'. |
|
$id.'.turnoffunit'); |
|
if ($unit ne '' && |
|
! ($Apache::lonhomework::type eq 'exam' || |
|
lc($hideunit) eq "yes") ) { |
|
my $cleanunit=$unit; |
|
$cleanunit=~s/\$\,//g; |
|
$response.=" $cleanunit"; |
} |
} |
push(@fmt_ans,$ans); |
|
} |
my ($ad,$msg)=&check_submission($response,$partid,$id,$tag, |
my $response=join(', ',@fmt_ans); |
$parstack,$safeeval); |
my $hideunit=&Apache::lonnet::EXT('resource.'.$partid.'_'. |
if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') { |
$id.'.turnoffunit'); |
my $error; |
if ($unit ne '' && |
if ($tag eq 'formularesponse') { |
! ($Apache::lonhomework::type eq 'exam' || |
$error=&mt('Computer\'s answer is incorrect ("[_1]").[_2]',$response,$name); |
lc($hideunit) eq "yes") ) { |
|
my $cleanunit=$unit; |
|
$cleanunit=~s/\$\,//g; |
|
$response.=" $cleanunit"; |
|
} |
|
|
|
my ($ad,$msg)=&check_submission($response,$partid,$id,$tag, |
|
$parstack,$safeeval); |
|
if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') { |
|
my $error; |
|
if ($tag eq 'formularesponse') { |
|
$error=&mt('Computer\'s answer is incorrect ("[_1]").',$response); |
|
} else { |
|
# answer failed check if it is sig figs that is failing |
|
my ($ad,$msg)=&check_submission($response,$partid,$id, |
|
$tag,$parstack, |
|
$safeeval,1); |
|
if ($sigline ne '') { |
|
$error=&mt('Computer\'s answer is incorrect ("[_1]"). It is likely that the tolerance range [_2] or significant figures [_3] need to be adjusted.',$response,$tolline,$sigline); |
|
} else { |
} else { |
$error=&mt('Computer\'s answer is incorrect ("[_1]"). It is likely that the tolerance range [_2] needs to be adjusted.',$response,$tolline); |
# answer failed check if it is sig figs that is failing |
|
my ($ad,$msg)=&check_submission($response,$partid,$id, |
|
$tag,$parstack, |
|
$safeeval,1); |
|
if ($sigline ne '') { |
|
$error=&mt('Computer\'s answer is incorrect ("[_1]"). It is likely that the tolerance range [_2] or significant figures [_3] need to be adjusted.[_4]',$response,$tolline,$sigline,$name); |
|
} else { |
|
$error=&mt('Computer\'s answer is incorrect ("[_1]"). It is likely that the tolerance range [_2] needs to be adjusted.[_3]',$response,$tolline,$name); |
|
} |
|
} |
|
if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') { |
|
&Apache::lonxml::error($error); |
|
} else { |
|
&Apache::lonxml::warning($error); |
} |
} |
} |
} |
if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') { |
|
&Apache::lonxml::error($error); |
|
} else { |
|
&Apache::lonxml::warning($error); |
|
} |
|
} |
|
|
|
if (defined($unit) and ($unit ne '') and |
if (defined($unit) and ($unit ne '') and |
$tag eq 'numericalresponse') { |
$tag eq 'numericalresponse') { |
if ($target eq 'answer') { |
if ($target eq 'answer') { |
if ($env{'form.answer_output_mode'} eq 'tex') { |
if ($env{'form.answer_output_mode'} eq 'tex') { |
$result.=&Apache::response::answer_part($tag, |
$result.=&Apache::response::answer_part($tag, |
" Unit: $unit "); |
" Unit: $unit "); |
} else { |
} else { |
$result.=&Apache::response::answer_part($tag, |
$result.=&Apache::response::answer_part($tag, |
"Unit: <b>$unit</b>"); |
"Unit: <b>$unit</b>"); |
|
} |
|
} elsif ($target eq 'analyze') { |
|
push (@{ $Apache::lonhomework::analyze{"$part_id.unit"} }, $unit); |
} |
} |
} elsif ($target eq 'analyze') { |
|
push (@{ $Apache::lonhomework::analyze{"$part_id.unit"} }, $unit); |
|
} |
} |
} |
if ($tag eq 'formularesponse' && $target eq 'answer') { |
if ($tag eq 'formularesponse' && $target eq 'answer') { |
my $samples=&Apache::lonxml::get_param('samples',$parstack,$safeeval); |
my $samples=&Apache::lonxml::get_param('samples',$parstack,$safeeval); |
$result.=&Apache::response::answer_part($tag,$samples); |
$result.=&Apache::response::answer_part($tag,$samples); |
} |
} |
} |
if ($target eq 'answer') { |
if ($target eq 'answer') { |
$result.=&Apache::response::answer_footer($tag); |
$result.=&Apache::response::answer_footer($tag); |