[LON-CAPA-cvs] cvs: loncom /homework/caparesponse caparesponse.pm
raeburn
raeburn at source.lon-capa.org
Thu Sep 13 13:00:05 EDT 2018
raeburn Thu Sep 13 17:00:05 2018 EDT
Modified files:
/loncom/homework/caparesponse caparesponse.pm
Log:
- Better error messages about "Computer's answer" where unit includes
$ or , (in numericalresponse), and format lacks that character.
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.258 loncom/homework/caparesponse/caparesponse.pm:1.259
--- loncom/homework/caparesponse/caparesponse.pm:1.258 Tue Aug 9 23:43:45 2016
+++ loncom/homework/caparesponse/caparesponse.pm Thu Sep 13 17:00:05 2018
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# caparesponse definition
#
-# $Id: caparesponse.pm,v 1.258 2016/08/09 23:43:45 raeburn Exp $
+# $Id: caparesponse.pm,v 1.259 2018/09/13 17:00:05 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -664,7 +664,14 @@
my (@formats)=&Apache::lonxml::get_param_var('format',$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') {
$result.=&Apache::response::answer_header($tag,undef,
scalar(keys(%answer)));
@@ -760,7 +767,7 @@
if ($unit=~/\,/) { $fmt="\,".$fmt; $unit=~s/\,//g; }
$element = &format_number($element,$fmt,$target,
$safeeval);
- if ($fmt=~/\$/ && $unit!~/\$/) { $element=~s/\$//; }
+ if ($fmt=~/\$/ && !$needsdollar) { $element=~s/\$//; }
}
}
push(@fmt_ans,join(',',@$ans));
@@ -773,7 +780,7 @@
! ($Apache::lonhomework::type eq 'exam' ||
lc($hideunit) eq "yes") ) {
my $cleanunit=$unit;
- $cleanunit=~s/\$\,//g;
+ $cleanunit=~s/[\$,]//g;
foreach my $ans (@fmt_ans) {
$ans.=" $cleanunit";
}
@@ -790,7 +797,13 @@
$tag,$parstack,
$safeeval,1);
$error=&mt("Computer's answer is incorrect ([_1]).",'"'.join(', ',@$response).'"').' ';
- if ($ad eq 'UNIT_INVALID_STUDENT') {
+ 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 '') {
More information about the LON-CAPA-cvs
mailing list