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

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 15 Mar 2007 02:52:18 -0000


albertel		Wed Mar 14 22:52:18 2007 EDT

  Modified files:              
    /loncom/homework	inputtags.pm response.pm 
  Log:
  - implement some of the suggestions from bug#2622 about prior tries display
    
  
  
Index: loncom/homework/inputtags.pm
diff -u loncom/homework/inputtags.pm:1.218 loncom/homework/inputtags.pm:1.219
--- loncom/homework/inputtags.pm:1.218	Mon Mar 12 20:21:28 2007
+++ loncom/homework/inputtags.pm	Wed Mar 14 22:52:16 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # input  definitons
 #
-# $Id: inputtags.pm,v 1.218 2007/03/13 00:21:28 albertel Exp $
+# $Id: inputtags.pm,v 1.219 2007/03/15 02:52:16 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -957,6 +957,42 @@
     }
 }
 
+sub find_which_previous {
+    my ($version) = @_;
+    my $part = $Apache::inputtags::part;
+    my (@previous_version);
+    foreach my $resp (@Apache::inputtags::response) {
+	my $key = "$version:resource.$part.$resp.submission";
+	my $submission = $Apache::lonhomework::history{$key};
+	my %previous = &Apache::response::check_for_previous($submission,
+							     $part,$resp,
+							     $version);
+	push(@previous_version,$previous{'version'});
+    }
+    return &previous_match(\@previous_version,
+			   scalar(@Apache::inputtags::response));
+}
+
+sub previous_match {
+    my ($previous_array,$count) = @_;
+    my $match = 0;
+    my @matches;
+    foreach my $versionar (@$previous_array) {
+	foreach my $version (@$versionar) {
+	    $matches[$version]++;
+	}
+    }
+    my $which=0;
+    foreach my $elem (@matches) {
+	if ($elem eq $count) {
+	    $match=1;
+	    last;
+	}
+	$which++;
+    }
+    return ($match,$which);
+}
+
 sub grade {
     my ($target) = @_;
     my $id = $Apache::inputtags::part;
@@ -975,14 +1011,10 @@
 	my ($finalaward,$msg) = &finalizeawards(\@awards,\@msgs);
 	my $previously_used;
 	if ( $#Apache::inputtags::previous eq $#awards ) {
-	    my $match=0;
-	    my @matches;
-	    foreach my $versionar (@Apache::inputtags::previous_version) {
-		foreach my $version (@$versionar) {
-		    $matches[$version]++;
-		}
-	    }
-	    foreach my $elem (@matches) {if ($elem eq ($#awards+1)) {$match=1;}}
+	    my ($match) =
+		&previous_match(\@Apache::inputtags::previous_version,
+				scalar(@Apache::inputtags::response));
+	    
 	    if ($match) {
 		$previously_used = 'PREVIOUSLY_LAST';
 		foreach my $value (@Apache::inputtags::previous) {
@@ -1121,11 +1153,17 @@
     my ($id,$target) = @_;
     my $output;
     my $status = $Apache::inputtags::status['-1'];
-    
+
+    my $count;
+    my %count_lookup;
+
     foreach my $i (1..$Apache::lonhomework::history{'version'}) {
 	my $prefix = $i.":resource.$id";
 
 	next if (!exists($Apache::lonhomework::history{"$prefix.award"}));
+	$count++;
+	$count_lookup{$i} = $count;
+	
 	my ($previousmsg,$latemessage,$message,$trystr);
 
 	($previousmsg,$latemessage,$message,$trystr) =
@@ -1134,11 +1172,21 @@
 	    undef($trystr);
 	}
 
-	if ($previousmsg eq '') { $previousmsg='<td></td>'; }
-	if ($trystr eq '') { $trystr = '<td></td>'; }
+	if ($previousmsg ne '') {
+	    my ($match,$which) = &find_which_previous($i);
+	    $message=$previousmsg;
+	    my $previous = $count_lookup{$which};
+	    $message =~ s{(</td>)}{ as submission $previous $1};
+	    
+	} elsif ($trystr ne '') { 
+	    ($trystr) = ($trystr =~ m{(\d+)/\d+});
+	    $message =~ s{(<td.*?>)}{$1 $trystr };
+	}
+
 
 	$output.='<tr>';
-	$output.=$message.$previousmsg.$trystr;
+	$output.='<td align ="center">'.$count.'</td>';
+	$output.=$message;
 
 	foreach my $resid (@Apache::inputtags::response) {
 	    my $prefix = $prefix.".$resid";
@@ -1154,11 +1202,15 @@
 		$output.='<td></td>';
 	    }
 	}
-	$output.='</tr>';
+	$output.='</tr>'."\n";
     }
     return if ($output eq '');
-
-    $output ='<table class="LC_prior_tries">'.$output.'</table>';
+    my $headers = 
+	'<tr>'.'<th>'.&mt('Submission #').'</th><th>'.&mt('Try').
+	'</th><th colspan="'.scalar(@Apache::inputtags::response).'">'.
+	&mt('Submitted Answer').'</th>';
+    $output ='<table class="LC_prior_tries">'.$headers.$output.'</table>';
+    $output .='<pre>'.join("\n",@Apache::inputtags::previous_version).'</pre>';
     #return $output;
     $output=~s/\\/\\\\/g;
     $output=~s/\'/\\\'/g;
Index: loncom/homework/response.pm
diff -u loncom/homework/response.pm:1.159 loncom/homework/response.pm:1.160
--- loncom/homework/response.pm:1.159	Fri Feb 23 20:44:14 2007
+++ loncom/homework/response.pm	Wed Mar 14 22:52:16 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # various response type definitons response definition
 #
-# $Id: response.pm,v 1.159 2007/02/24 01:44:14 albertel Exp $
+# $Id: response.pm,v 1.160 2007/03/15 02:52:16 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -265,11 +265,14 @@
 }
 
 sub check_for_previous {
-    my ($curresponse,$partid,$id) = @_;
+    my ($curresponse,$partid,$id,$last) = @_;
     my %previous;
     $previous{'used'} = 0;
     foreach my $key (sort(keys(%Apache::lonhomework::history))) {
 	if ($key =~ /resource\.$partid\.$id\.submission$/) {
+	    if ( $last && $key =~ /^(\d+):/ ) {
+		next if ($1 >= $last);
+	    }
 	    &Apache::lonxml::debug("Trying $key");
 	    my $pastresponse=$Apache::lonhomework::history{$key};
 	    if ($pastresponse eq $curresponse) {