[LON-CAPA-cvs] cvs: loncom /homework/caparesponse caparesponse.pm

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 08 Apr 2003 04:00:23 -0000


albertel		Tue Apr  8 00:00:23 2003 EDT

  Modified files:              
    /loncom/homework/caparesponse	caparesponse.pm 
  Log:
  - just format the numbers as we generate them
  
  
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.90 loncom/homework/caparesponse/caparesponse.pm:1.91
--- loncom/homework/caparesponse/caparesponse.pm:1.90	Mon Apr  7 23:54:22 2003
+++ loncom/homework/caparesponse/caparesponse.pm	Tue Apr  8 00:00:23 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # caparesponse definition
 #
-# $Id: caparesponse.pm,v 1.90 2003/04/08 03:54:22 albertel Exp $
+# $Id: caparesponse.pm,v 1.91 2003/04/08 04:00:23 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -187,7 +187,8 @@
 	    my $unit=&Apache::lonxml::get_param_var('unit',$parstack,
 						    $safeeval);
 	    my @bubble_values=&make_numerical_bubbles($number_of_bubbles,
-						      @answers);
+						      $target,$answers[0],
+						      $formats[0]);
 	    my @alphabet=('A'..'Z');
 	    my $id=$Apache::inputtags::response[-1];
 	    if ($target eq 'web') {
@@ -195,11 +196,10 @@
 		    if ($unit=~/\S/) {$result.=' (in '.$unit.')<br /><br />';}
 		    $result.= '<table border="1"><tr>';
 		    for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
-			my $ans=&format_number($bubble_values[$ind],
-					       $formats[0]);
 			$result.='<td><input type="radio" name="HWVAL_'.$id.
-			    '" value="'.$ans.'"><b>'.$alphabet[$ind].
-				'</b>: '.$ans.'</td>';
+			    '" value="'.$bubble_values[$ind].'"><b>'.
+				$alphabet[$ind].'</b>: '.
+				    $bubble_values[$ind].'</td>';
 		    }
 		    $result.='</tr></table>';
 		} elsif ($$tagstack[-1] eq 'formularesponse') {
@@ -224,9 +224,7 @@
 			}
 			$result.='}';
 			for (my $ind=$cou;$ind<$cou+$table_range[$j];$ind++) {
-			    my $ans=&format_number($bubble_values[$ind],
-						   $formats[0],$target);
-			    $result.='\hskip -3 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -2 mm & {\small '.$ans.'} ';
+			    $result.='\hskip -3 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -2 mm & {\small '.$bubble_values[$ind].'} ';
 			    if ($ind != $cou+$table_range[$j]-1) {$result.=' & ';}
 			}
 			$cou += $table_range[$j];
@@ -392,8 +390,8 @@
 }
 
 sub make_numerical_bubbles {
-    my ($number_of_bubbles,@answers) =@_;
-    my @bubbles_values = ();
+    my ($number_of_bubbles,$target,$answer,$format) =@_;
+    my @bubble_values = ();
     my @factors = (1.13,1.17,1.25,1.33,1.45); #default values of factors
     my @powers = (1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0); #default values for powers
     &Apache::response::setrandomnumber();
@@ -402,9 +400,12 @@
     $ind=&Math::Random::random_uniform_integer(1,0,$#factors);
     my $factor = $factors[$ind];
     for ($ind=0;$ind<$number_of_bubbles;$ind++) {
-	$bubbles_values[$ind] = $answers[0]*($factor**($power-$powers[$#powers-$ind]));
+	$bubble_values[$ind] = $answer*($factor**($power-$powers[$#powers-$ind]));
+	$bubble_values[$ind] = &format_number($bubble_values[$ind],
+					       $format,$target);
+
     }
-    return @bubbles_values;
+    return @bubble_values;
 }
 
 sub get_tolrange {