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

albertel lon-capa-cvs@mail.lon-capa.org
Wed, 13 Dec 2006 22:48:12 -0000


This is a MIME encoded message

--albertel1166050092
Content-Type: text/plain

albertel		Wed Dec 13 17:48:12 2006 EDT

  Modified files:              
    /loncom/homework	lonhomework.pm 
    /loncom/homework/caparesponse	caparesponse.pm 
  Log:
  - anaylze now works for multiple answers each with multiple parts each with 1 or vecotr vbalues
  - string response also analyzable the same way
  
  
--albertel1166050092
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20061213174812.txt"

Index: loncom/homework/lonhomework.pm
diff -u loncom/homework/lonhomework.pm:1.262 loncom/homework/lonhomework.pm:1.263
--- loncom/homework/lonhomework.pm:1.262	Wed Nov 29 20:14:17 2006
+++ loncom/homework/lonhomework.pm	Wed Dec 13 17:48:07 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Homework handler
 #
-# $Id: lonhomework.pm,v 1.262 2006/11/30 01:14:17 banghart Exp $
+# $Id: lonhomework.pm,v 1.263 2006/12/13 22:48:07 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -753,13 +753,20 @@
 	    if ($analyze{$part.'.type'} eq 'numericalresponse'	||
 		$analyze{$part.'.type'} eq 'stringresponse'	||
 		$analyze{$part.'.type'} eq 'formularesponse'   ) {
-		my $concatanswer=join("\0",@{ $analyze{$part.'.answer'} });
-		if (($concatanswer eq '') || ($concatanswer=~/^\@/)) {
-		    @{$analyze{$part.'.answer'}}=('<font color="red">'.&mt('Error').'</font>');
+		foreach my $name (keys(%{ $analyze{$part.'.answer'} })) {
+		    my $i=0;
+		    foreach my $answer_part (@{ $analyze{$part.'.answer'}{$name} }) {
+			push( @{ $overall{$part.'.answer'}[$i] },
+			      $answer_part);
+			my $concatanswer= join("\0",@{ $answer_part });
+			if (($concatanswer eq '') || ($concatanswer=~/^\@/)) {
+			    $answer_part = ['<font color="red">'.&mt('Error').'</font>'];
+			}
+			$seedexample{join("\0",$part,$i,@{$answer_part})}=
+			    $thisseed;
+			$i++;
+		    }
 		}
-		push( @{ $overall{$part.'.answer'} },
-		      [@{ $analyze{$part.'.answer'} }]);
-                $seedexample{join("\0",@{ $analyze{$part.'.answer'}})}=$thisseed;
 	    }
 	}
     }
@@ -768,21 +775,27 @@
     $request->print('<hr />'.&mt('List of possible answers').': ');
     foreach my $part (sort(keys(%allparts))) {
 	if (defined(@{ $overall{$part.'.answer'} })) {
-	    my $num_cols=scalar(@{ $overall{$part.'.answer'}->[0] });
-	    $request->print('<table class="thinborder"><tr><th colspan="'.($num_cols+1).'">'.&mt('Part').' '.$part.'</th></tr>');
-	    my %frequency;
-	    foreach my $answer (sort {$a->[0] <=> $b->[0]} (@{ $overall{$part.'.answer'} })) {
-		$frequency{join("\0",@{ $answer })}++;
-	    }
-	    $request->print('<tr><th colspan="'.($num_cols).'">'.&mt('Answer').'</th><th>'.&mt('Frequency').'<br />('
-			    .&mt('click for example').')</th></tr>');
-	    foreach my $answer (sort {(split("\0",$a))[0] <=> (split("\0",$b))[0]} (keys(%frequency))) {
-		$request->print('<tr><td class="center">'.
-				join('</td><td class="center">',split("\0",$answer)).
-				'</td><td class="center"><a href="'.$request->uri.'?rndseed='.$seedexample{$answer}.'">'.$frequency{$answer}.
-				'</a></td></tr>');
+	    for (my $i=0;$i<scalar(@{ $overall{$part.'.answer'} });$i++) {
+		my $num_cols=scalar(@{ $overall{$part.'.answer'}[$i][0] });
+		$request->print('<table class="thinborder"><tr><th colspan="'.($num_cols+1).'">'.&mt('Part').' '.$part);
+		if (scalar(@{ $overall{$part.'.answer'} }) > 1) {
+		    $request->print(&mt(' Answer [_1]',$i+1));
+		}
+		$request->print('</th></tr>');
+		my %frequency;
+		foreach my $answer (sort {$a->[0] <=> $b->[0]} (@{ $overall{$part.'.answer'}[$i] })) {
+		    $frequency{join("\0",@{ $answer })}++;
+		}
+		$request->print('<tr><th colspan="'.($num_cols).'">'.&mt('Answer').'</th><th>'.&mt('Frequency').'<br />('
+				.&mt('click for example').')</th></tr>');
+		foreach my $answer (sort {(split("\0",$a))[0] <=> (split("\0",$b))[0]} (keys(%frequency))) {
+		    $request->print('<tr><td class="center">'.
+				    join('</td><td class="center">',split("\0",$answer)).
+				    '</td><td class="center"><a href="'.$request->uri.'?rndseed='.$seedexample{join("\0",$part,$i,$answer)}.'">'.$frequency{$answer}.
+				    '</a></td></tr>');
+		}
+		$request->print('</table>');
 	    }
-	    $request->print('</table>');
 	} else {
 	    $request->print('<p>'.&mt('Response').' '.$part.' '.
 			    &mt('is not analyzable at this time').'</p>');
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.199 loncom/homework/caparesponse/caparesponse.pm:1.200
--- loncom/homework/caparesponse/caparesponse.pm:1.199	Mon Dec 11 12:37:44 2006
+++ loncom/homework/caparesponse/caparesponse.pm	Wed Dec 13 17:48:10 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # caparesponse definition
 #
-# $Id: caparesponse.pm,v 1.199 2006/12/11 17:37:44 www Exp $
+# $Id: caparesponse.pm,v 1.200 2006/12/13 22:48:10 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);
-		    }
 		}
 	    }
 
@@ -1005,6 +1009,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 +1020,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';

--albertel1166050092--