[LON-CAPA-cvs] cvs: loncom /homework/caparesponse caparesponse.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Thu, 14 Jul 2005 05:50:35 -0000
albertel Thu Jul 14 01:50:35 2005 EDT
Modified files:
/loncom/homework/caparesponse caparesponse.pm
Log:
- this computer answers correct is going to be the death of me, anyhoos
now supports vectors of answers BUG#4192
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.175 loncom/homework/caparesponse/caparesponse.pm:1.176
--- loncom/homework/caparesponse/caparesponse.pm:1.175 Wed Jul 13 22:52:22 2005
+++ loncom/homework/caparesponse/caparesponse.pm Thu Jul 14 01:50:33 2005
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# caparesponse definition
#
-# $Id: caparesponse.pm,v 1.175 2005/07/14 02:52:22 albertel Exp $
+# $Id: caparesponse.pm,v 1.176 2005/07/14 05:50:33 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -330,6 +330,7 @@
if ($target eq 'answer') {
$result.=&Apache::response::answer_header($tag);
}
+ my ($sigline,$tolline);
for(my $i=0;$i<=$#answers;$i++) {
my $ans=$answers[$i];
my $fmt=$formats[0];
@@ -352,23 +353,17 @@
# $low =&format_number($low,$fmt,$target,$safeeval);
#}
}
- my $response=$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";
- }
if ($target eq 'answer') {
- if ($high && $tag eq 'numericalresponse') { $ans.=' ['.$low.','.$high.']'; }
+ if ($high && $tag eq 'numericalresponse') {
+ $ans.=' ['.$low.','.$high.']';
+ $tolline .= "[$low, $high]";
+ }
if (defined($sighigh) && $tag eq 'numericalresponse') {
if ($env{'form.answer_output_mode'} eq 'tex') {
$ans.= " Sig $siglow - $sighigh";
} else {
$ans.= " Sig <i>$siglow - $sighigh</i>";
+ $sigline .= "[$siglow, $sighigh]";
}
}
$result.=&Apache::response::answer_part($tag,$ans);
@@ -382,34 +377,60 @@
push (@{ $Apache::lonhomework::analyze{"$part_id.format"} }, $fmt);
}
}
- my ($awards,$msgs)=&check_submission($response,$partid,$id,$tag,
- $parstack,$safeeval);
- my ($ad,$msg) =&Apache::inputtags::finalizeawards($awards,$msgs);
- if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') {
- my $error;
- if ($tag eq 'formularesponse') {
- $error=&mt('Computer\'s answer is incorrect ("[_1]").');
- } else {
- # answer failed check if it is sig figs that is failing
- my ($awards,$msgs)=&check_submission($response,$partid,$id,
- $tag,$parstack,
- $safeeval,1);
- ($ad,$msg)=&Apache::inputtags::finalizeawards($awards,
- $msgs);
+ }
+
+ my @fmt_ans;
+ for(my $i=0;$i<=$#answers;$i++) {
+ my $ans=$answers[$i];
+ my $fmt=$formats[0];
+ if (@formats && $#formats) {$fmt=$formats[$i];}
+ if ($fmt && $tag eq 'numericalresponse') {
+ $fmt=~s/e/E/g;
+ if ($unit=~/\$/) { $fmt="\$".$fmt; $unit=~s/\$//g; }
+ if ($unit=~/\,/) { $fmt="\,".$fmt; $unit=~s/\,//g; }
+ $ans = &format_number($ans,$fmt,$target,$safeeval);
+ }
+ 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";
+ }
+
+ my ($awards,$msgs)=&check_submission($response,$partid,$id,$tag,
+ $parstack,$safeeval);
+ my ($ad,$msg) =&Apache::inputtags::finalizeawards($awards,$msgs);
+ if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') {
+ my $error;
+ if ($tag eq 'formularesponse') {
+ $error=&mt('Computer\'s answer is incorrect ("[_1]").');
+ } else {
+ # answer failed check if it is sig figs that is failing
+ my ($awards,$msgs)=&check_submission($response,$partid,$id,
+ $tag,$parstack,
+ $safeeval,1);
+ ($ad,$msg)=&Apache::inputtags::finalizeawards($awards,
+ $msgs);
- if ($siglow ne '' && $sighigh ne '') {
- $error=&mt('Computer\'s answer is incorrect ("[_1]"). It is likely that the tolerance range ("[_2]" to "[_3]") or significant figures ("[_4]" to "[_5]") need to be adjusted.',$response,$low,$high,$siglow,$sighigh);
- } else {
- $error=&mt('Computer\'s answer is incorrect ("[_1]"). It is likely that the tolerance range ("[_2]" to "[_3]") needs to be adjusted.',$response,$low,$high);
- }
- }
- if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') {
- &Apache::lonxml::error($error);
+ 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 {
- &Apache::lonxml::warning($error);
+ $error=&mt('Computer\'s answer is incorrect ("[_1]"). It is likely that the tolerance range [_1] needs to be adjusted.',$response,$tolline);
}
}
+ 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
$tag eq 'numericalresponse') {
if ($target eq 'answer') {