version 1.252, 2012/03/05 11:50:39
|
version 1.263, 2021/10/05 02:41:32
|
Line 1
|
Line 1
|
# The LearningOnline Network with CAPA |
# The LearningOnline Network with CAPA |
# caparesponse definition |
# caparesponse definition |
# |
# |
# caparesponse.pm,v 1.249.8.2 2012/02/04 20:40:15 foxr |
# $Id$ |
# |
# |
# Copyright Michigan State University Board of Trustees |
# Copyright Michigan State University Board of Trustees |
# |
# |
Line 401 sub setup_capa_response {
|
Line 401 sub setup_capa_response {
|
if (ref($response)) { |
if (ref($response)) { |
$$args_ref{'response'}=dclone($response); |
$$args_ref{'response'}=dclone($response); |
} else { |
} else { |
$$args_ref{'response'}=dclone([$response]); |
$$args_ref{'response'}=dclone(["$response"]); |
} |
} |
} |
} |
|
|
Line 456 sub check_submission {
|
Line 456 sub check_submission {
|
my ($result,@msgs) = |
my ($result,@msgs) = |
&Apache::run::run("&caparesponse_check_list()",$safeeval); |
&Apache::run::run("&caparesponse_check_list()",$safeeval); |
&Apache::lonxml::debug("checking $name $result with $response took ".&Time::HiRes::tv_interval($t0)); |
&Apache::lonxml::debug("checking $name $result with $response took ".&Time::HiRes::tv_interval($t0)); |
|
|
&Apache::lonxml::debug('msgs are '.join(':',@msgs)); |
&Apache::lonxml::debug('msgs are '.join(':',@msgs)); |
my ($awards)=split(/:/,$result); |
my ($awards)=split(/:/,$result); |
my @awards= split(/,/,$awards); |
my @awards= split(/,/,$awards); |
Line 643 sub end_numericalresponse {
|
Line 642 sub end_numericalresponse {
|
} |
} |
} |
} |
} |
} |
if (($target eq 'web') && ($tag eq 'formularesponse') |
|
&& ($Apache::lonhomework::type ne 'exam') && ($Apache::inputtags::status['-1'] eq 'CAN_ANSWER') |
|
&& (&Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.turnoffeditor') ne 'yes')) { |
|
$result.=&Apache::response::edit_mathresponse_button($id,"HWVAL_$id"); |
|
} |
|
|
|
&Apache::response::setup_prior_tries_hash(\&format_prior_response_numerical); |
&Apache::response::setup_prior_tries_hash(\&format_prior_response_numerical); |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result.='</td></tr>'.&Apache::edit::end_table; |
$result.='</td></tr>'.&Apache::edit::end_table; |
Line 670 sub end_numericalresponse {
|
Line 664 sub end_numericalresponse {
|
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 ($needsdollar,$needscomma); |
|
if ($unit =~ /\$/) { |
|
$needsdollar = 1; |
|
} |
|
if ($unit =~ /\,/) { |
|
$needscomma = 1; |
|
} |
|
|
if ($target eq 'answer') { |
if ($target eq 'answer') { |
$result.=&Apache::response::answer_header($tag,undef, |
$result.=&Apache::response::answer_header($tag,undef, |
scalar(keys(%answer))); |
scalar(keys(%answer))); |
Line 759 sub end_numericalresponse {
|
Line 760 sub end_numericalresponse {
|
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];} |
foreach my $element (@$ans) { |
my @answers; |
|
if (ref($ans) eq 'ARRAY') { |
|
@answers = (@{$ans}); |
|
} |
|
foreach my $element (@answers) { |
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; } |
$element = &format_number($element,$fmt,$target, |
$element = &format_number($element,$fmt,$target, |
$safeeval); |
$safeeval); |
if ($fmt=~/\$/ && $unit!~/\$/) { $element=~s/\$//; } |
if ($fmt=~/\$/ && !$needsdollar) { $element=~s/\$//; } |
} |
} |
} |
} |
push(@fmt_ans,join(',',@$ans)); |
push(@fmt_ans,join(',',@answers)); |
} |
} |
my $response=\@fmt_ans; |
my $response=\@fmt_ans; |
|
|
Line 779 sub end_numericalresponse {
|
Line 784 sub end_numericalresponse {
|
! ($Apache::lonhomework::type eq 'exam' || |
! ($Apache::lonhomework::type eq 'exam' || |
lc($hideunit) eq "yes") ) { |
lc($hideunit) eq "yes") ) { |
my $cleanunit=$unit; |
my $cleanunit=$unit; |
$cleanunit=~s/\$\,//g; |
$cleanunit=~s/[\$,]//g; |
foreach my $ans (@fmt_ans) { |
foreach my $ans (@fmt_ans) { |
$ans.=" $cleanunit"; |
$ans.=" $cleanunit"; |
} |
} |
Line 796 sub end_numericalresponse {
|
Line 801 sub end_numericalresponse {
|
$tag,$parstack, |
$tag,$parstack, |
$safeeval,1); |
$safeeval,1); |
$error=&mt("Computer's answer is incorrect ([_1]).",'"'.join(', ',@$response).'"').' '; |
$error=&mt("Computer's answer is incorrect ([_1]).",'"'.join(', ',@$response).'"').' '; |
if ($sigline ne '') { |
if (($ad eq 'NO_UNIT') && $needsdollar) { |
|
$error.=&mt('The unit attribute includes [_1] but the answer format does not.','$').' '. |
|
&mt('Either remove the [_1] from the unit or prepend [_1] to the answer format.','$'); |
|
} elsif (($ad eq 'COMMA_FAIL') && $needscomma) { |
|
$error.=&mt('The unit attribute includes [_1] but the answer format does not.',',').' '. |
|
&mt('Either remove the [_1] from the unit or prepend [_1] to the answer format.',','); |
|
} elsif ($ad eq 'UNIT_INVALID_STUDENT') { |
|
$error.=&mt('Unable to interpret units. Computer reads units as "[_1]".',$msg).' '. |
|
&mt('The unit attribute in the numericalresponse item needs to be a supported physical unit.'); |
|
} elsif ($sigline ne '') { |
$error.=&mt('It is likely that the tolerance range [_1] or significant figures [_2] need to be adjusted.',$tolline,$sigline); |
$error.=&mt('It is likely that the tolerance range [_1] or significant figures [_2] need to be adjusted.',$tolline,$sigline); |
} else { |
} else { |
$error.=&mt('It is likely that the tolerance range [_1] needs to be adjusted.',$tolline); |
$error.=&mt('It is likely that the tolerance range [_1] needs to be adjusted.',$tolline); |
Line 897 sub get_table_sizes {
|
Line 911 sub get_table_sizes {
|
my $cell_width=0; |
my $cell_width=0; |
foreach my $member (@$rbubble_values) { |
foreach my $member (@$rbubble_values) { |
my $cell_width_real=0; |
my $cell_width_real=0; |
if ($member=~/(\+|-)?(\d*)\.?(\d*)\s*\$?\\times\s*10\^{(\+|-)?(\d+)}\$?/) { |
if ($member=~/(\+|-)?(\d*)\.?(\d*)\s*\$?\\times\s*10\^\{(\+|-)?(\d+)}\$?/) { |
$cell_width_real=(length($2)+length($3)+length($5)+7)*$scale; |
$cell_width_real=(length($2)+length($3)+length($5)+7)*$scale; |
} elsif ($member=~/(\d*)\.?(\d*)(E|e)(\+|-)?(\d*)/) { |
} elsif ($member=~/(\d*)\.?(\d*)(E|e)(\+|-)?(\d*)/) { |
$cell_width_real=(length($1)+length($2)+length($5)+9)*$scale; |
$cell_width_real=(length($1)+length($2)+length($5)+9)*$scale; |
Line 1051 sub make_numerical_bubbles {
|
Line 1065 sub make_numerical_bubbles {
|
&Math::Random::random_uniform_integer(1,1,10); |
&Math::Random::random_uniform_integer(1,1,10); |
} |
} |
for ($ind=0;$ind<$number_of_bubbles;$ind++) { |
for ($ind=0;$ind<$number_of_bubbles;$ind++) { |
$bubble_values[$ind] = $answerfactor*($factor**($power-$powers[$#powers-$ind])); |
my $exponent = $power-$powers[$#powers-$ind]; |
|
$bubble_values[$ind] = $answerfactor*($factor**$exponent); |
|
|
|
# If bubble is for correct answer (i.e., exponent = 0), and value |
|
# of $answerfactor * factor**$exponent is an integer with more than |
|
# 15 digits, assign $answerfactor itself as bubble value. |
|
# This prevents a "use fewer digits" issue on 64bit servers |
|
# when correct answer is >= 1e+16, and when correct bubble is A. |
|
|
|
if ($exponent == 0) { |
|
if ($bubble_values[$ind] =~ /^-?(\d+)$/) { |
|
if (length($1) > 15) { |
|
$bubble_values[$ind] = $answerfactor; |
|
} |
|
} |
|
} |
|
|
$bubble_display[$ind] = &format_number($bubble_values[$ind], |
$bubble_display[$ind] = &format_number($bubble_values[$ind], |
$format,$target,$safeeval); |
$format,$target,$safeeval); |
} |
} |