[LON-CAPA-cvs] cvs: loncom /homework default_homework.lcpm inputtags.pm /homework/caparesponse caparesponse.pm /xml lonxml.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Thu, 21 Oct 2004 02:43:34 -0000
albertel Wed Oct 20 22:43:34 2004 EDT
Modified files:
/loncom/homework/caparesponse caparesponse.pm
/loncom/homework default_homework.lcpm inputtags.pm
/loncom/xml lonxml.pm
Log:
- BUG#1363, unit="$" now requires the answer to start with $
unit="," now requires proper commation
unit="$," requires both
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.155 loncom/homework/caparesponse/caparesponse.pm:1.156
--- loncom/homework/caparesponse/caparesponse.pm:1.155 Mon Oct 18 16:28:23 2004
+++ loncom/homework/caparesponse/caparesponse.pm Wed Oct 20 22:43:34 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# caparesponse definition
#
-# $Id: caparesponse.pm,v 1.155 2004/10/18 20:28:23 albertel Exp $
+# $Id: caparesponse.pm,v 1.156 2004/10/21 02:43:34 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -62,7 +62,7 @@
if ($token->[1] eq 'numericalresponse') {
$constructtag=&Apache::edit::get_new_args($token,$parstack,
$safeeval,'answer',
- 'incorrect','unit',
+ 'incorrect','unit',
'format');
} elsif ($token->[1] eq 'formularesponse') {
$constructtag=&Apache::edit::get_new_args($token,$parstack,
@@ -103,6 +103,8 @@
} 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.',';
@@ -134,6 +136,16 @@
if ($Apache::lonhomework::type eq 'exam' &&
$tag eq 'formularesponse') {
$increment=&Apache::response::scored_response($partid,$id);
+ } elsif ($Apache::lonhomework::type eq 'survey') {
+ if ( !defined($ENV{'form.submitted'})) { return ''; }
+ my $response = &Apache::response::getresponse();
+ if ( $response =~ /[^\s]/) {
+ my %previous=&Apache::response::check_for_previous($response,
+ $partid,$id);
+ $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
+ my $ad=$Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}='SUBMITTED';
+ &Apache::response::handle_previous(\%previous,$ad);
+ }
} else {
my $response = &Apache::response::getresponse();
if ( $response =~ /[^\s]/) {
@@ -326,6 +338,8 @@
}
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);
#if ($high) {
# $high=&format_number($high,$fmt,$target,$safeeval);
@@ -435,6 +449,9 @@
$format = 'd';
}
}
+ if (!$Apache::lonxml::default_homework_loaded) {
+ &Apache::lonxml::default_homework_load($safeeval);
+ }
$ans=&Apache::run::run("&prettyprint(q\0$number\0,q\0$format\0,q\0$target\0)",$safeeval);
return $ans;
}
Index: loncom/homework/default_homework.lcpm
diff -u loncom/homework/default_homework.lcpm:1.90 loncom/homework/default_homework.lcpm:1.91
--- loncom/homework/default_homework.lcpm:1.90 Mon Oct 11 12:31:34 2004
+++ loncom/homework/default_homework.lcpm Wed Oct 20 22:43:34 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run()
#
-# $Id: default_homework.lcpm,v 1.90 2004/10/11 16:31:34 albertel Exp $
+# $Id: default_homework.lcpm,v 1.91 2004/10/21 02:43:34 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -34,6 +34,32 @@
$deg2rad=$pi/180.0;
$"=' ';
+sub check_commas {
+ my ($response)=@_;
+ #print("$response ");
+ my @numbers=split(',',$response);
+ #print(" numbers ".join('-',@numbers)." ");
+ if (scalar(@numbers) > 1) {
+ #print(" numbers[0] ".$numbers[0]." ");
+ if (length($numbers[0]) > 3 || length($numbers[0]) == 0) { return -1; }
+ shift(@numbers);
+ #print(" numbers ".scalar(@numbers)." ");
+ while (scalar(@numbers) > 1) {
+ #print(" numbers ".join('-',@numbers)." ");
+ if (length($numbers[0]) != 3) { return -2; }
+ shift(@numbers);
+ }
+ my ($number)=split('\.',$numbers[0]);
+ #print(" number ".$number." ");
+ #print(" numbers[0] ".$numbers[0]." ");
+ if (length($number) != 3) { return -3; }
+ } else {
+ my ($number)=split('\.',$numbers[0]);
+ if (length($number) > 3) { return -4; }
+ }
+ return 1;
+}
+
sub caparesponse_check {
my ($answer,$response)=@_;
#not properly used yet: calc
@@ -69,12 +95,16 @@
$answer=~s/ +/ /g;
$response=~s/ +/ /g;
}
- if ($type eq 'float') { $response=~s/,//g; }
- if ($type eq 'float' && $ans_fmt=~/\$/) {
+ if ($type eq 'float' && $unit=~/\$/) {
if ($response!~/^\$/) { return "NO_UNIT: Missing \$ "; }
$response=~s/\$//g;
}
+ if ($type eq 'float' && $unit=~/\,/ && (&check_commas($response)<0)) {
+ return "COMMA_FAIL:";
+ }
$ans_fmt=~s/\W//g;
+ $unit=~s/[\$,]//g;
+ if ($type eq 'float') { $response=~s/,//g; }
if (length($response) > 500) { return "TOO_LONG: Answer too long"; }
Index: loncom/homework/inputtags.pm
diff -u loncom/homework/inputtags.pm:1.152 loncom/homework/inputtags.pm:1.153
--- loncom/homework/inputtags.pm:1.152 Tue Oct 19 11:24:32 2004
+++ loncom/homework/inputtags.pm Wed Oct 20 22:43:34 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# input definitons
#
-# $Id: inputtags.pm,v 1.152 2004/10/19 15:24:32 albertel Exp $
+# $Id: inputtags.pm,v 1.153 2004/10/21 02:43:34 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -317,7 +317,7 @@
'BAD_FORMULA', 'SIG_FAIL', 'INCORRECT',
'MISORDERED_RANK', 'INVALID_FILETYPE',
'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE',
- 'APPROX_ANS', 'EXACT_ANS') {
+ 'APPROX_ANS', 'EXACT_ANS','COMMA_FAIL') {
($result,$msg)=&checkstatus($possibleaward,$awardref,$msgref);
if (defined($result)) { return ($result,$msg); }
}
@@ -457,6 +457,10 @@
if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units')};
$bgcolor=$possiblecolors{'not_charged_try'};
$button=1;
+ } elsif ($award eq 'COMMA_FAIL') {
+ $message = &mt("Proper comma separation is required").'.';
+ $bgcolor=$possiblecolors{'not_charged_try'};
+ $button=1;
} elsif ($award eq 'BAD_FORMULA') {
$message = &mt("Unable to understand formula");
$bgcolor=$possiblecolors{'not_charged_try'};
Index: loncom/xml/lonxml.pm
diff -u loncom/xml/lonxml.pm:1.345 loncom/xml/lonxml.pm:1.346
--- loncom/xml/lonxml.pm:1.345 Mon Oct 18 15:49:58 2004
+++ loncom/xml/lonxml.pm Wed Oct 20 22:43:34 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# XML Parser Module
#
-# $Id: lonxml.pm,v 1.345 2004/10/18 19:49:58 albertel Exp $
+# $Id: lonxml.pm,v 1.346 2004/10/21 02:43:34 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1030,6 +1030,7 @@
my $val=$token->[2]->{$_};
$val =~ s/([\%\@\\\"\'])/\\$1/g;
$val =~ s/(\$[^{a-zA-Z_])/\\$1/g;
+ $val =~ s/(\$)$/\\$1/;
#if ($val =~ m/^[\%\@]/) { $val="\\".$val; }
$temp .= "my \$$_=\"$val\";";
}
@@ -1360,7 +1361,7 @@
my $request=$Apache::lonxml::request;
if (!$request) { $request=Apache->request; }
$request->print('<font size="-2"><pre>DEBUG:'.&HTML::Entities::encode($_[0],'<>&"')."</pre></font>\n");
-# &Apache::lonnet::logthis($_[0]);
+ #&Apache::lonnet::logthis($_[0]);
}
}