[LON-CAPA-cvs] cvs: loncom /homework default_homework.lcpm /homework/templates customunit.problem customunit.problem.meta /publisher packages.tab doc/loncapafiles loncapafiles.lpml

www www@source.lon-capa.org
Thu, 09 Jun 2011 15:44:00 -0000


www		Thu Jun  9 15:44:00 2011 EDT

  Added files:                 
    /loncom/homework/templates	customunit.problem 
                              	customunit.problem.meta 

  Modified files:              
    /doc/loncapafiles	loncapafiles.lpml 
    /loncom/homework	default_homework.lcpm 
    /loncom/publisher	packages.tab 
  Log:
  Bug #53: custom units now possible, new parameter "customunits"
  Format: unita=unitb,unitc=4*unitb,...
  
  
Index: doc/loncapafiles/loncapafiles.lpml
diff -u doc/loncapafiles/loncapafiles.lpml:1.754 doc/loncapafiles/loncapafiles.lpml:1.755
--- doc/loncapafiles/loncapafiles.lpml:1.754	Wed Jun  8 20:38:44 2011
+++ doc/loncapafiles/loncapafiles.lpml	Thu Jun  9 15:43:53 2011
@@ -2,7 +2,7 @@
  "http://lpml.sourceforge.net/DTD/lpml.dtd">
 <!-- loncapafiles.lpml -->
 
-<!-- $Id: loncapafiles.lpml,v 1.754 2011/06/08 20:38:44 www Exp $ -->
+<!-- $Id: loncapafiles.lpml,v 1.755 2011/06/09 15:43:53 www Exp $ -->
 
 <!--
 
@@ -1374,6 +1374,8 @@
 custompartial.problem.meta;
 CustomResponse.problem;
 CustomResponse.problem.meta;
+customunit.problem;
+customunit.problem.meta;
 Essay.problem;
 Essay.problem.meta;
 examupload.problem;
Index: loncom/homework/default_homework.lcpm
diff -u loncom/homework/default_homework.lcpm:1.158 loncom/homework/default_homework.lcpm:1.159
--- loncom/homework/default_homework.lcpm:1.158	Wed Jun  8 20:38:47 2011
+++ loncom/homework/default_homework.lcpm	Thu Jun  9 15:43:56 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.158 2011/06/08 20:38:47 www Exp $
+# $Id: default_homework.lcpm,v 1.159 2011/06/09 15:43:56 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -143,7 +143,6 @@
     my $sig_lbound=''; #done
     my $sig_ubound=''; #done
 
-
     #type's definitons come from capaParser.h
 
     #remove leading and trailing whitespace
@@ -152,10 +151,8 @@
     }
     if ($response=~ /^\s|\s$/) {
 	$response=~ s:^\s+|\s+$::g;
-	&LONCAPA_INTERNAL_DEBUG("Removed ws now :$response:");
     }
 
-    #&LONCAPA_INTERNAL_DEBUG(" type is $type ");
     if ($type eq 'cs' || $type eq 'ci') {
 	#for string answers make sure all places spaces occur, there is 
         #really only 1 space, in both the answer and the response
@@ -179,7 +176,6 @@
     if (length($response) > 500) { return ('TOO_LONG',undef); }
 
     if ($type eq '' ) {
-	&LONCAPA_INTERNAL_DEBUG("Didn't find a type :$type: defaulting");
 	if ( $answer eq ($answer *1.0)) { $type = 2;
 				      } else { $type = 3; }
     } else {
@@ -199,7 +195,6 @@
     #formula type setup the sample points
     if ($type eq '8') {
 	($id_list,$points)=split(/@/,$samples);
-	&LONCAPA_INTERNAL_DEBUG("Found :$id_list:$points: points in $samples");
     }
     if ($tol eq '') {
 	$tol=0.0;
@@ -258,8 +253,6 @@
     elsif ($result =='15') { $result='UNIT_IRRECONCIBLE'; }
     else  {$result = "ERROR: Unknown Result:$result:$@:";}
 
-    &LONCAPA_INTERNAL_DEBUG("RetError $reterror: Answer $answer: Response $response:  type-$type|$tol|$tol_type|$sig:$sig_lbound:$sig_ubound|$unit|");
-    &LONCAPA_INTERNAL_DEBUG(" $answer $response $result ");
     return ($result,$reterror);
 }
 
@@ -310,9 +303,8 @@
 	}
     }
 
-    &LONCAPA_INTERNAL_DEBUG("Initial final response :$responses->[0][-1]:");
     my $unit;
-    my ($allowalgebra)=(&parameter_setting('allowalgebra',&currentpart())=~/^(yes|1|on)$/i);
+    my ($allowalgebra)=($LONCAPA::CAPAresponse_args{'allowalgebra'}=~/^(yes|1|on)$/i);
     if ($type eq 'float' || $type eq '') {
 	#for numerical problems split off the unit
         my $part1;
@@ -325,10 +317,16 @@
         if (defined($part1) && defined($part2)) {
 	    $responses->[0][-1]=$part1;
 	    $unit=&capa_formula_fix($part2);
-            &LONCAPA_INTERNAL_DEBUG("Found unit :$unit:");
+            my $customunits=$LONCAPA::CAPAresponse_args{'customunits'};
+            foreach my $replacement (split(/\s*\,\s*/,$customunits)) {
+                my ($which,$what)=split(/\s*\=\s*/,$replacement);
+                if ((defined($which)) && (defined($what))) {
+                   $what=&capa_formula_fix($what);
+                   $unit=~s/$which/\($what\)/g;
+                }
+            }
 	}
     }
-    &LONCAPA_INTERNAL_DEBUG("Final final response :$responses->[0][-1]:$unit:");
     $unit=~s/\s//;
     my $error;
     foreach my $response (@$responses) {
@@ -414,14 +412,12 @@
                         }  
                     }
                 }
-                # See if we have preprocessor
-                &LONCAPA_INTERNAL_DEBUG("Ordered preprocessor $preprocess");
-                if ($preprocess=~/\S/) {
+                # See if we have preprocessor for string responses
+                if (($preprocess=~/\S/) && ($type eq 'cs' || $type eq 'ci'))  {
                     if (defined(&$preprocess)) {
                         no strict 'refs';
                         $response->[$j]=&$preprocess($response->[$j]);
                         use strict 'refs';
-                        &LONCAPA_INTERNAL_DEBUG("Ordered processed: $response->[$j]");
                     }
                 }
 
@@ -464,13 +460,11 @@
                             }
                         }
                         # See if we have preprocessor
-                        &LONCAPA_INTERNAL_DEBUG("Unordered preprocessor $preprocess");
-                        if ($preprocess=~/\S/) {
+                        if (($preprocess=~/\S/) && ($type eq 'cs' || $type eq 'ci')) {
                             if (defined(&$preprocess)) {
                                 no strict 'refs';
                                 $response->[$j]=&$preprocess($response->[$j]);
                                 use strict 'refs';
-                                &LONCAPA_INTERNAL_DEBUG("Unordered processed: $response->[$j]");
                             }
                         }
 
Index: loncom/publisher/packages.tab
diff -u loncom/publisher/packages.tab:1.65 loncom/publisher/packages.tab:1.66
--- loncom/publisher/packages.tab:1.65	Tue Jun  7 22:07:13 2011
+++ loncom/publisher/packages.tab	Thu Jun  9 15:44:00 2011
@@ -80,6 +80,8 @@
 numericalresponse&allowalgebra&type:string_yesno
 numericalresponse&allowalgebra&default:no
 numericalresponse&allowalgebra&display:Allow algebraic entry
+numericalresponse&customunits&type:string_any
+numericalresponse&customunits&display:Custom-defined Units
 formularesponse&tol&display:Numerical Tolerance
 formularesponse&tol&type:tolerance
 formularesponse&tol&default:0.00000000001

Index: loncom/homework/templates/customunit.problem
+++ loncom/homework/templates/customunit.problem
<problem>

<script type="loncapa/perl">
$pecks=&random(3,5,1);
$bushels=&random(2,6,1);
$total=4.4*(8*$bushels+2*$pecks);
</script>

<startouttext />
You go to the market and buy $pecks peck of apples and $bushels bushel of potatoes. How much produce did you buy? Note that these are dry goods.
<endouttext />

<numericalresponse answer="$total" unit="L" format="3s">
    <responseparam type="tolerance" default="5%" name="tol" description="Numerical Tolerance" />
    <responseparam name="customunits" type="string_any" description="Custom-defined Units" default="peck=2*gallon,bushel=8*gallon,gallon=4.4*L" />
    <textline readonly="no" />
</numericalresponse>

</problem>

Index: loncom/homework/templates/customunit.problem.meta
+++ loncom/homework/templates/customunit.problem.meta
<title>Numerical Response with Custom Units</title>
<category>Numerical Problems</category>