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

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 07 Nov 2003 08:56:52 -0000


This is a MIME encoded message

--albertel1068195412
Content-Type: text/plain

albertel		Fri Nov  7 03:56:52 2003 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  - BUG#1946, BUG#1206
  - for rank/match/option/radiobutton response types when viewing the submissions or attempting to grade, the responses are shown in foil order, and the correct elements are bolded, the incorrect elements are itailcized, also the same text as used in the 'Correct Answers' display is used to make it easier to compare submissions and see what a student is doing wrong.
  
  
  
--albertel1068195412
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20031107035652.txt"

Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.147 loncom/homework/grades.pm:1.148
--- loncom/homework/grades.pm:1.147	Thu Nov  6 10:22:33 2003
+++ loncom/homework/grades.pm	Fri Nov  7 03:56:52 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.147 2003/11/06 15:22:33 albertel Exp $
+# $Id: grades.pm,v 1.148 2003/11/07 08:56:52 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -177,26 +177,88 @@
     return $result,$responseType,$hdgrade,$partlist,$handgrade;
 }
 
+
+sub get_order {
+    my ($partid,$respid,$symb,$uname,$udom)=@_;
+    my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
+    $url=&Apache::lonnet::clutter($url);
+    my $subresult=&Apache::lonnet::ssi($url,
+				       ('grade_target' => 'analyze'),
+				       ('grade_domain' => $udom),
+				       ('grade_symb' => $symb),
+				       ('grade_courseid' => 
+					        $ENV{'request.course.id'}),
+				       ('grade_username' => $uname));
+    (my $debug,$subresult)=split(/_HASH_REF__/,$subresult,2);
+    Apache->request->print($debug);
+    my %analyze=&Apache::lonnet::str2hash($subresult);
+    return ($analyze{"$partid.$respid.shown"});
+}
 #--- Clean response type for display
-#--- Currently filters option response type only.
+#--- Currently filters option/rank/radiobutton/match/essay response types only.
 sub cleanRecord {
-    my ($answer,$response,$symb) = @_;
-    if ($response eq 'option') {
-	my (@IDs,@ans);
-	foreach (split(/\&/,&Apache::lonnet::unescape($answer))) {
-	    my ($optionID,$ans) = split(/=/);
-	    push @IDs,$optionID.'</font>';
-	    push @ans,$ans;
+    my ($answer,$response,$symb,$partid,$respid,$record,$order,$version) = @_;
+    my $grayFont = '<font color="#999999">';
+    if ($response =~ /^(option|rank)$/) {
+	my %answer=&Apache::lonnet::str2hash($answer);
+	my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
+	my ($toprow,$bottomrow);
+	foreach my $foil (@$order) {
+	    if ($grading{$foil} == 1) {
+		$toprow.='<td><b>'.$answer{$foil}.'&nbsp;</b></td>';
+	    } else {
+		$toprow.='<td><i>'.$answer{$foil}.'&nbsp;</i></td>';
+	    }
+	    $bottomrow.='<td>'.$grayFont.$foil.'</font>&nbsp;</td>';
 	}
-	my $grayFont = '<font color="#999999">';
 	return '<blockquote><table border="1">'.
-	    '<tr valign="top"><td>Answer</td><td>'.
-	    (join '</td><td>',@ans).'</td></tr>'.
-	    '<tr valign="top"><td>'.$grayFont.'Option ID</font></td><td>'.$grayFont.
-	    (join '</td><td>'.$grayFont,@IDs).'</font></td></tr>'.
-	    '</table></blockquote>';
-    }
-    if ($response eq 'essay') {
+	    '<tr valign="top"><td>Answer</td>'.$toprow.'</tr>'.
+	    '<tr valign="top"><td>'.$grayFont.'Option ID</font></td>'.
+	    $grayFont.$bottomrow.'</tr>'.'</table></blockquote>';
+    } elsif ($response eq 'match') {
+	my %answer=&Apache::lonnet::str2hash($answer);
+	my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
+	my @items=&Apache::lonnet::str2array($record->{$version."resource.$partid.$respid.submissionitems"});
+	my ($toprow,$middlerow,$bottomrow);
+	foreach my $foil (@$order) {
+	    my $item=shift(@items);
+	    if ($grading{$foil} == 1) {
+		$toprow.='<td><b>'.$item.'&nbsp;</b></td>';
+		$middlerow.='<td><b>'.$grayFont.$answer{$foil}.'&nbsp;</font></b></td>';
+	    } else {
+		$toprow.='<td><i>'.$item.'&nbsp;</i></td>';
+		$middlerow.='<td><i>'.$grayFont.$answer{$foil}.'&nbsp;</font></i></td>';
+	    }
+	    $bottomrow.='<td>'.$grayFont.$foil.'</font>&nbsp;</td>';
+	}
+	return '<blockquote><table border="1">'.
+	    '<tr valign="top"><td>Answer</td>'.$toprow.'</tr>'.
+	    '<tr valign="top"><td>'.$grayFont.'Item ID</font></td>'.
+	    $middlerow.'</tr>'.
+	    '<tr valign="top"><td>'.$grayFont.'Option ID</font></td>'.
+	    $bottomrow.'</tr>'.'</table></blockquote>';
+    } elsif ($response eq 'radiobutton') {
+	my %answer=&Apache::lonnet::str2hash($answer);
+	my ($toprow,$bottomrow);
+	my $correct=($order->[0])+1;
+	for (my $i=1;$i<=$#$order;$i++) {
+	    my $foil=$order->[$i];
+	    if (exists($answer{$foil})) {
+		if ($i == $correct) {
+		    $toprow.='<td><b>true</b></td>';
+		} else {
+		    $toprow.='<td><i>true</i></td>';
+		}
+	    } else {
+		$toprow.='<td>false</td>';
+	    }
+	    $bottomrow.='<td>'.$grayFont.$foil.'</font>&nbsp;</td>';
+	}
+	return '<blockquote><table border="1">'.
+	    '<tr valign="top"><td>Answer</td>'.$toprow.'</tr>'.
+	    '<tr valign="top"><td>'.$grayFont.'Option ID</font></td>'.
+	    $grayFont.$bottomrow.'</tr>'.'</table></blockquote>';
+    } elsif ($response eq 'essay') {
 	if (! exists ($ENV{'form.'.$symb})) {
 	    my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade',
 						  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
@@ -1524,7 +1586,7 @@
 			    '<font color="red">Nothing submitted - no attempts</font><br /><br />';
  		    } else {
 			foreach (@$string) {
-			    my ($partid,$respid) = /^resource\.(\w+)\.(\w+)\.submission/;
+			    my ($partid,$respid) = /^resource\.([^\.]*)\.([^\.]*)\.submission/;
 			    if ($part eq ($partid.'_'.$respid)) {
 				my ($ressub,$subval) = split(/:/,$_,2);
                             # Similarity check
@@ -1544,6 +1606,7 @@
 					    &keywords_highlight($oessay).'</i></blockquote><hr />';
 				    }
 				}
+				my $order=&get_order($partid,$respid,$symb,$uname,$udom);
 				$lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part '.
 				    $partid.'</b> <font color="#999999">( ID '.$respid.
 				    ' )</font>&nbsp; &nbsp;'.
@@ -1554,7 +1617,7 @@
 				     '<font color="red" size="1">Like all files provided by users, '.
 				     'this file may contain virusses</font><br />':'').
 				     '<b>Submitted Answer: </b>'.
-				     &cleanRecord($subval,$responsetype,$symb).
+				     &cleanRecord($subval,$responsetype,$symb,$partid,$respid,\%record,$order).
 				     '<br /><br />'.$similar."\n"
 				     if ($ENV{'form.lastSub'} eq 'lastonly' || 
 					 ($ENV{'form.lastSub'} eq 'hdgrade' && 
@@ -1569,7 +1632,7 @@
 	}
     } elsif ($ENV{'form.lastSub'} eq 'datesub') {
 	my (undef,$responseType,undef,$parts) = &showResourceInfo($url);
-	$request->print(&displaySubByDates(\$symb,\%record,$parts,$responseType,$checkIcon));
+	$request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
     } elsif ($ENV{'form.lastSub'} =~ /^(last|all)$/) {
 	$request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
 								 $ENV{'request.course.id'},
@@ -3002,7 +3065,7 @@
 			}
 			$responseType{$partid} = \%responseIds;
 		    }
-		    $studentTable.= &displaySubByDates(\$symbx,\%record,$parts,\%responseType,$checkIcon);
+		    $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
 
 		}
 	    } elsif ($ENV{'form.lastSub'} eq 'all') {
@@ -3038,7 +3101,7 @@
 }
 
 sub displaySubByDates {
-    my ($symbx,$record,$parts,$responseType,$checkIcon) = @_;
+    my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
     my $studentTable='<table border="0" width="100%"><tr><td bgcolor="#777777">'.
 	'<table border="0" width="100%"><tr bgcolor="#e6ffff">'.
 	'<td><b>Date/Time</b></td>'.
@@ -3046,6 +3109,7 @@
 	'<td><b>Status&nbsp;</b></td></tr>';
     my ($version);
     my %mark;
+    my %orders;
     $mark{'correct_by_student'} = $checkIcon;
     if (!exists($$record{'1:timestamp'})) {
 	return '<br />&nbsp;<font color="red">Nothing submitted - no attempts</font><br />';
@@ -3070,10 +3134,14 @@
 			$displaySub[0].='Trial&nbsp;'.
 			    $$record{"$version:resource.$partid.tries"};
 		    }
-		    &Apache::lonnet::logthis("Part is $partid responseType is ".join(':',%$responseType));
 		    my $responseType=$responseType->{$partid}->{$responseId};
+		    if (!exists($orders{$partid})) { $orders{$partid}={}; }
+		    if (!exists($orders{$partid}->{$responseId})) {
+			$orders{$partid}->{$responseId}=
+			    &get_order($partid,$responseId,$symb,$uname,$udom);
+		    }
 		    $displaySub[0].='</b>&nbsp; '.
-			&cleanRecord($$record{$version.':'.$matchKey},$responseType,$$symbx).'<br />';
+			&cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:").'<br />';
 		}
 	    }
 	    if (exists $$record{"$version:resource.$partid.award"}) {

--albertel1068195412--