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

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 06 Nov 2003 15:22:33 -0000


This is a MIME encoded message

--albertel1068132153
Content-Type: text/plain

albertel		Thu Nov  6 10:22:33 2003 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  - fixes for BUG#2234, multiple responses in a single part display properly
  - some cleanup (removed nested ?: uses)
  
  
--albertel1068132153
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20031106102233.txt"

Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.146 loncom/homework/grades.pm:1.147
--- loncom/homework/grades.pm:1.146	Tue Nov  4 14:38:09 2003
+++ loncom/homework/grades.pm	Thu Nov  6 10:22:33 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.146 2003/11/04 19:38:09 albertel Exp $
+# $Id: grades.pm,v 1.147 2003/11/06 15:22:33 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -133,9 +133,9 @@
     $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url))) if ($symb eq '');
     my $allkeys = &Apache::lonnet::metadata($url,'keys');
     my %seen = ();
-    my (@partlist,%handgrade);
+    my (@partlist,%handgrade,%responseType);
     foreach (split(/,/,&Apache::lonnet::metadata($url,'packages'))) {
-	if (/^\w+response_\w+.*/) {
+	if (/^\w+response_.*/) {
 	    my ($responsetype,$part) = split(/_/,$_,2);
 	    my ($partid,$respid) = split(/_/,$part);
 	    if (&Apache::loncommon::check_if_partid_hidden($partid,$symb)) {
@@ -143,13 +143,15 @@
 	    }
 	    $responsetype =~ s/response$//; # make it compatible w/ navmaps - should move to that!!
 	    my ($value) = &Apache::lonnet::EXT('resource.'.$part.'.handgrade',$symb);
-	    $handgrade{$part} = $responsetype.':'.($value eq 'yes' ? 'yes' : 'no'); 
+	    $handgrade{$part} = ($value eq 'yes' ? 'yes' : 'no'); 
+	    if (!exists($responseType{$partid})) { $responseType{$partid}={}; }
+	    $responseType{$partid}->{$respid}=$responsetype;
 	    next if ($seen{$partid} > 0);
 	    $seen{$partid}++;
 	    push @partlist,$partid;
 	}
     }
-    return \@partlist,\%handgrade;
+    return \@partlist,\%handgrade,\%responseType;
 }
 
 #--- Show resource title
@@ -158,20 +160,21 @@
     my ($url,$probTitle) = @_;
     my $result ='<table border="0">'.
 	'<tr><td colspan=3><font size=+1><b>Current Resource: </b>'.$probTitle.'</font></td></tr>'."\n";
-    my ($partlist,$handgrade) = &response_type($url);
+    my ($partlist,$handgrade,$responseType) = &response_type($url);
     my %resptype = ();
     my $hdgrade='no';
-    for (sort keys(%$handgrade)) {
-	my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
-	my $partID = (split(/_/))[0];
-	$resptype{$partID} = $responsetype;
+    for my $part_resID (sort keys(%$handgrade)) {
+	my $handgrade=$$handgrade{$part_resID};
+	my ($partID,$resID) = split(/_/,$part_resID);
+	my $responsetype = $responseType->{$partID}->{$resID};
 	$hdgrade = $handgrade if ($handgrade eq 'yes');
-	$result.='<tr><td><b>Part </b>'.$partID.'</td>'.
+	$result.='<tr><td><b>Part </b>'.$partID.' <font color="#999999">'.
+	    $resID.'</font></td>'.
 	    '<td><b>Type: </b>'.$responsetype.'</td></tr>';
 #	    '<td><b>Handgrade: </b>'.$handgrade.'</td></tr>';
     }
     $result.='</table>'."\n";
-    return $result,\%resptype,$hdgrade,$partlist,$handgrade;
+    return $result,$responseType,$hdgrade,$partlist,$handgrade;
 }
 
 #--- Clean response type for display
@@ -1421,7 +1424,7 @@
 
     my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
 
-    my ($partlist,$handgrade) = &response_type($url,$symb);
+    my ($partlist,$handgrade,$responseType) = &response_type($url,$symb);
 
     # Display student info
     $request->print(($counter == 0 ? '' : '<br />'));
@@ -1504,7 +1507,7 @@
 		$$fullname{$ENV{'form.'.$uname.':'.$udom.':submitted_by'}}.'</a>';
 	    $request->print($submitby);
 	} else {
-	    my ($string,$timestamp)= &get_last_submission (\%record);
+	    my ($string,$timestamp)= &get_last_submission(\%record);
 	    my $lastsubonly=''.
 		($$timestamp eq '' ? '' : '<b>Date Submitted:</b> '.
 		 $$timestamp)."</td></tr>\n";
@@ -1512,8 +1515,8 @@
 		$lastsubonly.='<tr><td bgcolor="#ffffe6">'.$$string[0]; 
 	    } else {
 		for my $part (sort keys(%$handgrade)) {
-		    my ($responsetype,$foo) = split(/:/,$$handgrade{$part});
 		    my ($partid,$respid) = split(/_/,$part);
+		    my $responsetype = $responseType->{$partid}->{$respid};
 		    if (!exists($record{'resource.'.$partid.'.'.$respid.'.submission'})) {
 			$lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part '.
 			    $partid.'</b> <font color="#999999">( ID '.$respid.
@@ -2172,7 +2175,7 @@
 	my ($partid,$respid) = split (/_/,$_,2);
 	next if $seen{$partid};
 	$seen{$partid}++;
-	my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
+	my $handgrade=$$handgrade{$_};
 	my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
 	$weight{$partid} = $wgt eq '' ? '1' : $wgt;
 
@@ -2991,9 +2994,16 @@
 		} else {
 		    my %responseType = ();
 		    foreach my $partid (@{$parts}) {
-			$responseType{$partid} = $curRes->responseType($partid);
+			my @responseIds =$curRes->responseIds($partid);
+			my @responseType =$curRes->responseType($partid);
+			my %responseIds;
+			for (my $i=0;$i<=$#responseIds;$i++) {
+			    $responseIds{$responseIds[$i]}=$responseType[$i];
+			}
+			$responseType{$partid} = \%responseIds;
 		    }
 		    $studentTable.= &displaySubByDates(\$symbx,\%record,$parts,\%responseType,$checkIcon);
+
 		}
 	    } elsif ($ENV{'form.lastSub'} eq 'all') {
 		my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
@@ -3037,32 +3047,56 @@
     my ($version);
     my %mark;
     $mark{'correct_by_student'} = $checkIcon;
-    return '<br />&nbsp;<font color="red">Nothing submitted - no attempts</font><br />' 
-	if (!exists($$record{'1:timestamp'}));
+    if (!exists($$record{'1:timestamp'})) {
+	return '<br />&nbsp;<font color="red">Nothing submitted - no attempts</font><br />';
+    }
     for ($version=1;$version<=$$record{'version'};$version++) {
 	my $timestamp = scalar(localtime($$record{$version.':timestamp'}));
 	$studentTable.='<tr bgcolor="#ffffff" valign="top"><td>'.$timestamp.'</td>';
 	my @versionKeys = split(/\:/,$$record{$version.':keys'});
 	my @displaySub = ();
 	foreach my $partid (@{$parts}) {
-	    my @matchKey = grep /^resource\.$partid\..*?\.submission$/,@versionKeys;
+	    my @matchKey = sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys);
 #	    next if ($$record{"$version:resource.$partid.solved"} eq '');
-	    $displaySub[0].=(exists $$record{$version.':'.$matchKey[0]}) ? 
-		'<b>Part&nbsp;'.$partid.'&nbsp;'.
-		($$record{"$version:resource.$partid.tries"} eq '' ? 'Trial&nbsp;not&nbsp;counted' :
-		 'Trial&nbsp;'.$$record{"$version:resource.$partid.tries"}).'</b>&nbsp; '.
-		 &cleanRecord($$record{$version.':'.$matchKey[0]},$$responseType{$partid},$$symbx).'<br />' : '';
-	    $displaySub[1].=(exists $$record{"$version:resource.$partid.award"}) ?
-		'<b>Part&nbsp;'.$partid.'</b> &nbsp;'.
-		lc($$record{"$version:resource.$partid.award"}).' '.
-		$mark{$$record{"$version:resource.$partid.solved"}}.'<br />' : '';
-	    $displaySub[2].=(exists $$record{"$version:resource.$partid.regrader"}) ?
-		$$record{"$version:resource.$partid.regrader"}.' (<b>Part:</b> '.$partid.')' : '';
-	}
-	$displaySub[2].=(exists $$record{"$version:resource.regrader"}) ?
-	    $$record{"$version:resource.regrader"} : ''; # needed because old essay regrader has not parts info
-	$studentTable.='<td>'.$displaySub[0].'&nbsp;</td><td>'.$displaySub[1].
-	    ($displaySub[2] eq '' ? '' : 'Manually graded by '.$displaySub[2]).'&nbsp;</td></tr>';
+	    foreach my $matchKey (@matchKey) {
+		if (exists $$record{$version.':'.$matchKey}) {
+		    my ($responseId)=($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/);
+		    $displaySub[0].='<b>Part&nbsp;'.$partid.'&nbsp;';
+		    $displaySub[0].='<font color="#999999">(ID&nbsp;'.
+			$responseId.')</font>&nbsp;';
+		    if ($$record{"$version:resource.$partid.tries"} eq '') {
+			$displaySub[0].='Trial&nbsp;not&nbsp;counted';
+		    } else {
+			$displaySub[0].='Trial&nbsp;'.
+			    $$record{"$version:resource.$partid.tries"};
+		    }
+		    &Apache::lonnet::logthis("Part is $partid responseType is ".join(':',%$responseType));
+		    my $responseType=$responseType->{$partid}->{$responseId};
+		    $displaySub[0].='</b>&nbsp; '.
+			&cleanRecord($$record{$version.':'.$matchKey},$responseType,$$symbx).'<br />';
+		}
+	    }
+	    if (exists $$record{"$version:resource.$partid.award"}) {
+		$displaySub[1].='<b>Part&nbsp;'.$partid.'</b> &nbsp;'.
+		    lc($$record{"$version:resource.$partid.award"}).' '.
+		    $mark{$$record{"$version:resource.$partid.solved"}}.
+		    '<br />';
+	    }
+	    if (exists $$record{"$version:resource.$partid.regrader"}) {
+		$displaySub[2].=$$record{"$version:resource.$partid.regrader"}.
+		    ' (<b>Part:</b> '.$partid.')';
+	    }
+	}
+	# needed because old essay regrader has not parts info
+	if (exists $$record{"$version:resource.regrader"}) {
+	    $displaySub[2].=$$record{"$version:resource.regrader"};
+	}
+	$studentTable.='<td>'.$displaySub[0].'&nbsp;</td><td>'.$displaySub[1];
+	if ($displaySub[2]) {
+	    $studentTable.='Manually graded by '.$displaySub[2];
+	}
+	$studentTable.='&nbsp;</td></tr>';
+    
     }
     $studentTable.='</table></td></tr></table>';
     return $studentTable;

--albertel1068132153--