[LON-CAPA-cvs] cvs: loncom /homework default_homework.lcpm /publisher packages.tab
www
www@source.lon-capa.org
Tue, 07 Jun 2011 22:07:14 -0000
www Tue Jun 7 22:07:14 2011 EDT
Modified files:
/loncom/homework default_homework.lcpm
/loncom/publisher packages.tab
Log:
Bug #6311: Allow for algebraic input in numerical response
Index: loncom/homework/default_homework.lcpm
diff -u loncom/homework/default_homework.lcpm:1.155 loncom/homework/default_homework.lcpm:1.156
--- loncom/homework/default_homework.lcpm:1.155 Sun May 22 03:04:51 2011
+++ loncom/homework/default_homework.lcpm Tue Jun 7 22:07:09 2011
@@ -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.155 2011/05/22 03:04:51 www Exp $
+# $Id: default_homework.lcpm,v 1.156 2011/06/07 22:07:09 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -309,12 +309,19 @@
&LONCAPA_INTERNAL_DEBUG("Initial final response :$responses->[0][-1]:");
my $unit;
+ my ($allowalgebra)=(¶meter_setting('allowalgebra',¤tpart())=~/^(yes|1|on)$/i);
if ($type eq 'float' || $type eq '') {
#for numerical problems split off the unit
-# if ( $responses->[0][-1]=~ /(.*[^\s])\s+([^\s]+)/ ) {
- if ( $responses->[0][-1]=~ /^([\d\.\,\s\$]*(?:(?:[xX\*]10[\^\*]*|[eE]*)[\+\-]*\d*)*(?:^|\S)\d+)([\$\s\w\^\*\/\(\)\+\-]*[^\d\.\s\,][\$\s\w\^\*\/\(\)\+\-]*)$/ ) {
- $responses->[0][-1]=$1;
- $unit=&capa_formula_fix($2);
+ my $part1;
+ my $part2;
+ if ($allowalgebra) {
+ ($part1,$part2)=($responses->[0][-1]=~ /^(.*[^\s])\s+([^\s]+)$/);
+ } else {
+ ($part1,$part2)=($responses->[0][-1]=~ /^([\d\.\,\s\$]*(?:(?:[xX\*]10[\^\*]*|[eE]*)[\+\-]*\d*)*(?:^|\S)\d+)([\$\s\w\^\*\/\(\)\+\-]*[^\d\.\s\,][\$\s\w\^\*\/\(\)\+\-]*)$/);
+ }
+ if ($part1 && $part2) {
+ $responses->[0][-1]=$part1;
+ $unit=&capa_formula_fix($part2);
&LONCAPA_INTERNAL_DEBUG("Found unit :$unit:");
}
}
@@ -344,6 +351,10 @@
if (($element==0) && ($unit!~/\w/) && ($answerunit=~/\w/)) {
$appendunit=$answerunit;
}
+# Do the math for the student if allowed
+ if ($allowalgebra) {
+ $element=&cas('maxima',$element);
+ }
if ($appendunit ne '') {
$element .= " $appendunit";
}
Index: loncom/publisher/packages.tab
diff -u loncom/publisher/packages.tab:1.64 loncom/publisher/packages.tab:1.65
--- loncom/publisher/packages.tab:1.64 Sun May 22 13:42:43 2011
+++ loncom/publisher/packages.tab Tue Jun 7 22:07:13 2011
@@ -77,6 +77,9 @@
numericalresponse&numbubbles&type:int_pos
numericalresponse&numbubbles&default:8
numericalresponse&numbubbles&display:Number of bubbles in exam mode
+numericalresponse&allowalgebra&type:string_yesno
+numericalresponse&allowalgebra&default:no
+numericalresponse&allowalgebra&display:Allow algebraic entry
formularesponse&tol&display:Numerical Tolerance
formularesponse&tol&type:tolerance
formularesponse&tol&default:0.00000000001