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

albertel lon-capa-cvs@mail.lon-capa.org
Mon, 18 Dec 2006 23:31:33 -0000


albertel		Mon Dec 18 18:31:33 2006 EDT

  Modified files:              (Branch: version_2_3_X)
    /loncom/homework/caparesponse	caparesponse.pm 
  Log:
  - backport 1.200 1.201
  
  
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.198 loncom/homework/caparesponse/caparesponse.pm:1.198.2.1
--- loncom/homework/caparesponse/caparesponse.pm:1.198	Mon Dec  4 18:56:20 2006
+++ loncom/homework/caparesponse/caparesponse.pm	Mon Dec 18 18:31:32 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # caparesponse definition
 #
-# $Id: caparesponse.pm,v 1.198 2006/12/04 23:56:20 www Exp $
+# $Id: caparesponse.pm,v 1.198.2.1 2006/12/18 23:31:32 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -524,6 +524,11 @@
 	}
 	foreach my $name (sort(keys(%answer))) {
 	    my @answers = @{ $answer{$name}{'answers'} };
+	    if ($target eq 'analyze') {
+		foreach my $info ('answer','ans_high','ans_low','format') {
+		    $Apache::lonhomework::analyze{"$part_id.$info"}{$name}=[];
+		}
+	    }
 	    my ($sigline,$tolline);
 	    if ($name ne $tag_internal_answer_name 
 		|| scalar(keys(%answer)) > 1) {
@@ -543,13 +548,13 @@
 		} else {
 		    @vector = ($ans);
 		}
-		if ($target eq 'answer') {
-		    my @all_answer_info;
-		    foreach my $element (@vector) {
-			my ($high,$low);
-			if ($Apache::inputtags::params{'tol'}) {
-			    ($high,$low)=&get_tolrange($element,$Apache::inputtags::params{'tol'});
-			}
+		my @all_answer_info;
+		foreach my $element (@vector) {
+		    my ($high,$low);
+		    if ($Apache::inputtags::params{'tol'}) {
+			($high,$low)=&get_tolrange($element,$Apache::inputtags::params{'tol'});
+		    }
+		    if ($target eq 'answer') {
 			if ($fmt && $tag eq 'numericalresponse') {
 			    $fmt=~s/e/E/g;
 			    if ($unit=~/\$/) { $fmt="\$".$fmt; $unit=~s/\$//g; }
@@ -573,21 +578,20 @@
 			    }
 			}
 			push(@all_answer_info,$element);
+			
+		    } elsif ($target eq 'analyze') {
+			push (@{ $Apache::lonhomework::analyze{"$part_id.answer"}{$name}[$i] }, $element);
+			if ($high) {
+			    push (@{ $Apache::lonhomework::analyze{"$part_id.ans_high"}{$name}[$i] }, $high);
+			    push (@{ $Apache::lonhomework::analyze{"$part_id.ans_low"}{$name}[$i] }, $low);
+			}
+			if ($fmt) {
+			    push (@{ $Apache::lonhomework::analyze{"$part_id.format"}{$name}[$i] }, $fmt);
+			}
 		    }
+		}
+		if ($target eq 'answer') {
 		    $result.= &Apache::response::answer_part($tag,join(', ',@all_answer_info));
-		} elsif ($target eq 'analyze') {
-		    my ($high,$low);
-		    if ($Apache::inputtags::params{'tol'}) {
-			($high,$low)=&get_tolrange($ans,$Apache::inputtags::params{'tol'});
-		    }
-		    push (@{ $Apache::lonhomework::analyze{"$part_id.answer"} }, $ans);
-		    if ($high) {
-			push (@{ $Apache::lonhomework::analyze{"$part_id.ans_high"} }, $high);
-			push (@{ $Apache::lonhomework::analyze{"$part_id.ans_low"} }, $low);
-		    }
-		    if ($fmt) {
-			push (@{ $Apache::lonhomework::analyze{"$part_id.format"} }, $fmt);
-		    }
 		}
 	    }
 
@@ -772,7 +776,18 @@
 	&Apache::response::get_response_param($part.'_'.$id,'numbubbles',8);
 
     my ($format)=&Apache::lonxml::get_param_var('format',$parstack,$safeeval);
-    my ($answer)=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
+    my $name = (exists($answer{$tag_internal_answer_name}) 
+		? $tag_internal_answer_name
+		: (sort(keys(%answer)))[0]);
+
+    if ( scalar(@{$answer{$name}{'answers'}}) > 1) {
+	&Apache::lonxml::error("Only answers with 1 component are supported in exam mode");
+    }
+    if (scalar(@{$answer{$name}{'answers'}[0]}) > 1) {
+	&Apache::lonxml::error("Vector answers are unsupported in exam mode.");
+    }
+
+    my $answer = $answer{$name}{'answers'}[0][0];
     my (@incorrect)=&Apache::lonxml::get_param_var('incorrect',$parstack,
 						   $safeeval);
     if ($#incorrect eq 0) { @incorrect=(split(/,/,$incorrect[0])); }
@@ -1005,6 +1020,7 @@
 	    }
 	}
     } elsif ($target eq 'answer' || $target eq 'analyze') {
+	&add_in_tag_answer($parstack,$safeeval);
 	if ($target eq 'analyze') {
 	    push (@{ $Apache::lonhomework::analyze{"parts"} },"$part.$id");
 	    $Apache::lonhomework::analyze{"$part.$id.type"} = 'stringresponse';
@@ -1015,18 +1031,25 @@
 	if ($target eq 'answer') {
 	    $result.=&Apache::response::answer_header('stringresponse');
 	}
-#	foreach my $ans (@answers) {
-	    if ($target eq 'answer') {
-		$result.=&Apache::response::answer_part('stringresponse',$answer);
-		if ($type eq 're') {
+	foreach my $name (keys(%answer)) {
+	    my @answers = @{ $answer{$name}{'answers'} };
+	    for (my $i=0;$i<=$#answers;$i++) {
+		my $answer_part = $answers[$i];
+		foreach my $element (@{$answer_part}) {
+		    if ($target eq 'answer') {
+			$result.=&Apache::response::answer_part('stringresponse',
+								$element);
+		    } elsif ($target eq 'analyze') {
+			push (@{ $Apache::lonhomework::analyze{"$part.$id.answer"}{$name}[$i] },
+			      $element);
+		    }
+		}
+		if ($target eq 'answer' && $type eq 're') {
 		    $result.=&Apache::response::answer_part('stringresponse',
 							    $answerdisplay);
 		}
-	    } elsif ($target eq 'analyze') {
-		push (@{ $Apache::lonhomework::analyze{"$part.$id.answer"} },
-		      $answer);
 	    }
-#	}
+	}
 	my $string='Case Insensitive';
 	if ($type eq 'mc') {
 	    $string='Multiple Choice';