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

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


albertel		Tue Apr  8 00:17:13 2003 EDT

  Modified files:              
    /loncom/homework/caparesponse	caparesponse.pm 
  Log:
  - can get numerical response questions correct in bubble mode both online and scantron
  - Hallelujah! Praise Jesus!
  
  
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.91 loncom/homework/caparesponse/caparesponse.pm:1.92
--- loncom/homework/caparesponse/caparesponse.pm:1.91	Tue Apr  8 00:00:23 2003
+++ loncom/homework/caparesponse/caparesponse.pm	Tue Apr  8 00:17:13 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # caparesponse definition
 #
-# $Id: caparesponse.pm,v 1.91 2003/04/08 04:00:23 albertel Exp $
+# $Id: caparesponse.pm,v 1.92 2003/04/08 04:17:13 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -101,19 +101,28 @@
 	    my %previous = &Apache::response::check_for_previous($response,$partid,$id);
 	    $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
 	    &Apache::lonxml::debug("submitted a $response<br>\n");
-	    &Apache::lonxml::debug($$parstack[$#$parstack] . "\n<br>");
+	    &Apache::lonxml::debug($$parstack[-1] . "\n<br>");
 
 	    if ($ENV{'form.submitted'} eq 'scantron') {
-		&Apache::response::setrandomnumber();
-		#FIXME the 8 here is based off of number of powers need a parameter
-		my $ind=&Math::Random::random_uniform_integer(1,0,8);
-		if ($ind eq $response) { $ad='CORRECT'; } else { $ad='INCORRECT'; }
+		my $number_of_bubbles = 8;#default values for number of bubbles
+		my (@formats)=&Apache::lonxml::get_param_var('format',
+							 $parstack,$safeeval);
+		my (@answers)=&Apache::lonxml::get_param_var('answer',
+							 $parstack,$safeeval);
+		my @values=&make_numerical_bubbles($number_of_bubbles,$target,
+						   $answers[0],$formats[0]);
+		$response=$values[$response];
+	    } else {
+		$response =~ s/\\/\\\\/g;
+		$response =~ s/\'/\\\'/g;
 	    }
-	    $response =~ s/\\/\\\\/g;
-	    $response =~ s/\'/\\\'/g;
 	    &Apache::lonxml::debug("current $response");
 	    my $expression="&caparesponse_check_list('".$response."','".
 		$$parstack[-1];
+	    #no way to enter units, with radio buttons
+	    if ($Apache::lonhomework::type eq 'exam') {
+		$expression.=';my $unit=undef;';
+	    }
 	    foreach my $key (keys(%Apache::inputtags::params)) {
 		$expression.= ';my $'. #'
 		    $key.'="'.$Apache::inputtags::params{$key}.'"';
@@ -143,7 +152,6 @@
 							 $safeeval);
 	    my $unit=&Apache::lonxml::get_param_var('unit',$parstack,
 						    $safeeval);
-
 	    if ($target eq 'web') {
 		$result="<br />The correct answer is ";
 	    } elsif ($target eq 'tex') {