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

ng lon-capa-cvs@mail.lon-capa.org
Tue, 22 Jul 2003 18:59:57 -0000


This is a MIME encoded message

--ng1058900397
Content-Type: text/plain

ng		Tue Jul 22 14:59:57 2003 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  restore number of tries column for grading by section/course
  Where is the can of raid? manual grading record - graded by grader has missing period ...
  Add highlight of keywords when displaying by page/sequence for essay response part.
  
  
--ng1058900397
Content-Type: text/plain
Content-Disposition: attachment; filename="ng-20030722145957.txt"

Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.121 loncom/homework/grades.pm:1.122
--- loncom/homework/grades.pm:1.121	Mon Jul 21 09:32:49 2003
+++ loncom/homework/grades.pm	Tue Jul 22 14:59:57 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.121 2003/07/21 13:32:49 ng Exp $
+# $Id: grades.pm,v 1.122 2003/07/22 18:59:57 ng Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -123,23 +123,25 @@
     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 ($resptype,$hdgrade)=('','no');
+    my %resptype = (); #,$hdgrade)=('','no');
+    my $hdgrade='no';
     for (sort keys(%$handgrade)) {
 	my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
-	$resptype = $responsetype;
+	my $partID = (split(/_/))[0];
+	$resptype{$partID} = $responsetype;
 	$hdgrade = $handgrade if ($handgrade eq 'yes');
-	$result.='<tr><td><b>Part </b>'.(split(/_/))[0].'</td>'.
+	$result.='<tr><td><b>Part </b>'.$partID.'</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,\%resptype,$hdgrade,$partlist,$handgrade;
 }
 
 #--- Clean response type for display
 #--- Currently filters option response type only.
 sub cleanRecord {
-    my ($answer,$response) = @_;
+    my ($answer,$response,$symb) = @_;
     if ($response eq 'option') {
 	my (@IDs,@ans);
 	foreach (split(/\&/,&Apache::lonnet::unescape($answer))) {
@@ -155,6 +157,21 @@
 	    (join '</td><td>'.$grayFont,@IDs).'</font></td></tr>'.
 	    '</table>';
     }
+    if ($response eq 'essay') {
+	if (! exists ($ENV{'form.'.$symb})) {
+	    my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade',
+						  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
+						  $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+
+	    my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
+	    $ENV{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
+	    $ENV{'form.kwclr'}    = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
+	    $ENV{'form.kwsize'}   = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
+	    $ENV{'form.kwstyle'}  = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
+	    $ENV{'form.'.$symb} = 1; # so that we don't have to read it from disk for multiple sub of the same prob.
+	}
+	return &keywords_highlight($answer);
+    }
     return $answer;
 }
 
@@ -431,7 +448,7 @@
     my $result='<h3><font color="#339933">&nbsp;'.$viewgrade.
 	' Submissions for a Student or a Group of Students</font></h3>';
 
-    my ($table,$resptype,$hdgrade,$partlist,$handgrade) = &showResourceInfo($url,$ENV{'form.probTitle'});
+    my ($table,undef,$hdgrade,$partlist,$handgrade) = &showResourceInfo($url,$ENV{'form.probTitle'});
     $result.=$table;
 
     $request->print(<<LISTJAVASCRIPT);
@@ -486,10 +503,10 @@
 
     $gradeTable.='<input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> last sub only'."\n".
 	'<input type="radio" name="lastSub" value="last" /> last sub & parts info'."\n".
+	'<input type="radio" name="lastSub" value="datesub" /> by dates and submissions'."\n".
 	'<input type="radio" name="lastSub" value="all" /> all details'."\n".
 	'<input type="hidden" name="section"     value="'.$getsec.'" />'."\n".
 	'<input type="hidden" name="submitonly"  value="'.$submitonly.'" />'."\n".
-	'<input type="hidden" name="response"    value="'.$ENV{'form.response'}.'" />'."\n".
 	'<input type="hidden" name="handgrade"   value="'.$ENV{'form.handgrade'}.'" /><br />'."\n".
 	'<input type="hidden" name="showgrading" value="'.$ENV{'form.showgrading'}.'" /><br />'."\n".
 	'<input type="hidden" name="saveState"   value="'.$ENV{'form.saveState'}.'" />'."\n".
@@ -806,14 +823,14 @@
 <script type="text/javascript" language="javascript">
 
 //===================== Show list of keywords ====================
-  function keywords(keyform) {
-    var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",keyform.value);
+  function keywords(formname) {
+    var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",formname.keywords.value);
     if (nret==null) return;
-    keyform.value = nret;
+    formname.keywords.value = nret;
 
-    document.SCORE.refresh.value = "on";
-    if (document.SCORE.keywords.value != "") {
-	document.SCORE.submit();
+    formname.refresh.value = "on";
+    if (formname.keywords.value != "") {
+	formname.submit();
     }
     return;
   }
@@ -1183,8 +1200,10 @@
 	return;
     }
 
-    $ENV{'form.lastSub'} = ($ENV{'form.lastSub'} eq '' ? 'all' : $ENV{'form.lastSub'});
+    $ENV{'form.lastSub'} = ($ENV{'form.lastSub'} eq '' ? 'datesub' : $ENV{'form.lastSub'});
     my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
+    my $checkIcon = '<img src="'.$request->dir_config('lonIconsURL').
+	'/check.gif" height="16" border="0" />';
 
     # header info
     if ($counter == 0) {
@@ -1197,8 +1216,6 @@
 			'<font size=+1>&nbsp;<b>Resource: </b>'.$ENV{'form.probTitle'}.'</font>'."\n");
 
 	if ($ENV{'form.handgrade'} eq 'no') {
-	    my $checkIcon = '<img src="'.$request->dir_config('lonIconsURL').
-		'/check.gif" height="16" border="0" />';
 	    my $checkMark='<br /><br />&nbsp;<b>Note:</b> Part(s) graded correct by the computer is marked with a '.
 		$checkIcon.' symbol.'."\n";
 	    $request->print($checkMark);
@@ -1246,7 +1263,6 @@
 			'<input type="hidden" name="lastSub"    value="'.$ENV{'form.lastSub'}.'" />'."\n".
 			'<input type="hidden" name="section"    value="'.$ENV{'form.section'}.'">'."\n".
 			'<input type="hidden" name="submitonly" value="'.$ENV{'form.submitonly'}.'">'."\n".
-			'<input type="hidden" name="response"   value="'.$ENV{'form.response'}.'">'."\n".
 			'<input type="hidden" name="handgrade"  value="'.$ENV{'form.handgrade'}.'">'."\n".
 			'<input type="hidden" name="keywords"   value="'.$ENV{'form.keywords'}.'" />'."\n".
 			'<input type="hidden" name="kwclr"      value="'.$ENV{'form.kwclr'}.'" />'."\n".
@@ -1274,7 +1290,7 @@
 #
 	    $request->print(<<KEYWORDS);
 &nbsp;<b>Keyword Options:</b>&nbsp;
-<a href="javascript:keywords(document.SCORE.keywords)"; TARGET=_self>List</a>&nbsp; &nbsp;
+<a href="javascript:keywords(document.SCORE)"; TARGET=_self>List</a>&nbsp; &nbsp;
 <a href="#" onMouseDown="javascript:getSel(); return false"
  CLASS="page">Paste Selection to List</a>&nbsp; &nbsp;
 <a href="javascript:kwhighlight()"; TARGET=_self>Highlight Attribute</a><br /><br />
@@ -1393,7 +1409,7 @@
 		    if (!exists($record{'resource.'.$partid.'.'.$respid.'.submission'})) {
 			$lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part '.
 			    $partid.'</b> <font color="#999999">( ID '.$respid.
-			    ' )</font>&nbsp; &nbsp;Nothing submitted<br /><br />';
+			    ' )</font>&nbsp; &nbsp;Nothing submitted - no attempts<br /><br />';
  		    } else {
 			foreach (@$string) {
 			    my ($partid,$respid) = /^resource\.(\w+)\.(\w+)\.submission/;
@@ -1420,7 +1436,8 @@
 				     'this file may contain virusses</font><br />':'').
 				     '<b>Submitted Answer: </b>'.($responsetype =~ /^(essay|option)$/ ? 
 								  '<blockquote>' : '').
-				     &cleanRecord(&keywords_highlight($subval),$responsetype).
+#				     &cleanRecord(&keywords_highlight($subval),$responsetype).
+				     &cleanRecord($subval,$responsetype,$symb).
 				     ($responsetype =~ /^(essay|option)$/ ? '</blockquote><br />' : 
 				      '<br /><br />').$similar."\n"
 				     if ($ENV{'form.lastSub'} eq 'lastonly' || 
@@ -1434,7 +1451,10 @@
 	    $lastsubonly.='</td></tr><tr bgcolor="#ffffff"><td>'."\n";
 	    $request->print($lastsubonly);
 	}
-    } else {
+    } elsif ($ENV{'form.lastSub'} eq 'datesub') {
+	my (undef,$responseType,undef,$parts) = &showResourceInfo($url);
+	$request->print(&displaySubByDates(\$symb,\%record,$parts,$responseType,$checkIcon));
+    } elsif ($ENV{'form.lastSub'} =~ /^(last|all)$/) {
 	$request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
 								 $ENV{'request.course.id'},
 								 $last,'.submission',
@@ -1794,7 +1814,7 @@
 	    }
 	    $newrecord{'resource.'.$_.'.submitted_by'} = $submitter 
 		if ($submitter && ($record{'resource.'.$_.'.submitted_by'} ne $submitter));
-	    $newrecord{'resource.'.$_.'regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
+	    $newrecord{'resource.'.$_.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
 	}
     }
 
@@ -2073,7 +2093,7 @@
     my (@parts) = sort(&getpartlist($url));
     foreach my $part (@parts) {
 	my $display=&Apache::lonnet::metadata($url,$part.'.display');
-	next if ($display =~ /Number of Attempts/);
+	$display =~ s/^Number of Attempts/Tries/; # makes the column narrower
 	if  (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
 	if ($display =~ /^Partial Credit Factor/) {
 	    my ($partid) = &split_part_type($part);
@@ -2145,13 +2165,13 @@
 		if ($status eq 'excused');
 	    $result.=$optsel;
 	    $result.="</select></td>\n";
-#	} else {
-#	    $result.='<input type="hidden" name="'.
-#		'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
-#		    "\n";
-#	    $result.='<td align="middle"><input type="text" name="'.
-#		'GD_'.$student.'_'.$part.'_'.$type.'" '.
-#		'value="'.$score.'" size="4" /></td>'."\n";
+	} else {
+	    $result.='<input type="hidden" name="'.
+		'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
+		    "\n";
+	    $result.='<td align="middle"><input type="text" name="'.
+		'GD_'.$student.'_'.$part.'_'.$type.'" '.
+		'value="'.$score.'" size="4" /></td>'."\n";
 	}
     }
     $result.='</tr>';
@@ -2275,7 +2295,7 @@
 		my $awarded   = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type};
 		if ($awarded ne '' && $awarded ne $old_aw) {
 		    $newrecord{'resource.'.$part.'.'.$type}= $awarded;
-		    $newrecord{'resource.'.$part.'regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
+		    $newrecord{'resource.'.$part.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
 		    $updateflag=1;
 		}
 		$line .= '<td align="center">'.$old_aw.'&nbsp;</td>'.
@@ -2404,7 +2424,7 @@
 	$javascript=&csvupload_javascript_forward_associate();
     }
 
-    my ($result,$resptype,$hdgrade,$partlist,$handgrade) = &showResourceInfo($url,$ENV{'form.probTitle'});
+    my ($result) = &showResourceInfo($url,$ENV{'form.probTitle'});
 
     $request->print(<<ENDPICK);
 <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
@@ -2616,7 +2636,7 @@
 #
 #-------------------------------------------------------------------
 #
-#-------------- Next few routines handles grading by page/sequence
+#-------------- Next few routines handle grading by page/sequence
 #
 #--- Select a page/sequence and a student to grade
 sub pickStudentPage {
@@ -2675,7 +2695,7 @@
 
     $result.='&nbsp;<b>Submission Details: </b>'.
 	'<input type="radio" name="lastSub" value="none" /> none'."\n".
-	'<input type="radio" name="lastSub" value="datesub" checked /> dates and submissions'."\n".
+	'<input type="radio" name="lastSub" value="datesub" checked /> by dates and submissions'."\n".
 	'<input type="radio" name="lastSub" value="all" /> all details'."\n";
 
     $result.='<input type="hidden" name="section"     value="'.$getsec.'" />'."\n".
@@ -2836,7 +2856,7 @@
 		    foreach my $partid (@{$parts}) {
 			$responseType{$partid} = $curRes->responseType($partid);
 		    }
-		    $studentTable.= &displaySubByDates(\%record,$parts,\%responseType,$checkIcon);
+		    $studentTable.= &displaySubByDates(\$symbx,\%record,$parts,\%responseType,$checkIcon);
 		}
 	    } elsif ($ENV{'form.lastSub'} eq 'all') {
 		my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
@@ -2871,7 +2891,7 @@
 }
 
 sub displaySubByDates {
-    my ($record,$parts,$responseType,$checkIcon) = @_;
+    my ($symbx,$record,$parts,$responseType,$checkIcon) = @_;
     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>'.
@@ -2880,6 +2900,8 @@
     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'}));
     for ($version=1;$version<=$$record{'version'};$version++) {
 	my $timestamp = scalar(localtime($$record{$version.':timestamp'}));
 	$studentTable.='<tr bgcolor="#ffffff" valign="top"><td>'.$timestamp.'</td>';
@@ -2887,17 +2909,16 @@
 	my @displaySub = ();
 	foreach my $partid (@{$parts}) {
 	    my @matchKey = grep /^resource\.$partid\..*?\.submission$/,@versionKeys;
-	    next if ($$record{"$version:resource.$partid.solved"} eq '');
+#	    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}).'<br />' : '';
+		 &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 />' : '';
-#	    $$record{"$version:resource.$partid.solved"}.'<br />' : '';
 	    $displaySub[2].=(exists $$record{"$version:resource.$partid.regrader"}) ?
 		$$record{"$version:resource.$partid.regrader"}.' (<b>Part:</b> '.$partid.')' : '';
 	}
@@ -3412,7 +3433,7 @@
 GRADINGMENUJS
     &commonJSfunctions($request);
     my $result='<h3>&nbsp;<font color="#339933">Manual Grading/View Submission</font></h3>';
-    my ($table,$resptype,$hdgrade) = &showResourceInfo($url,$probTitle);
+    my ($table,undef,$hdgrade) = &showResourceInfo($url,$probTitle);
     $result.=$table;
     my (undef,$sections) = &getclasslist('all','0');
     my $savedState = &savedState();
@@ -3424,7 +3445,6 @@
     $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
 	'<input type="hidden" name="symb"        value="'.$symb.'" />'."\n".
 	'<input type="hidden" name="url"         value="'.$url.'" />'."\n".
-	'<input type="hidden" name="response"    value="'.$resptype.'" />'."\n".
 	'<input type="hidden" name="handgrade"   value="'.$hdgrade.'" />'."\n".
 	'<input type="hidden" name="probTitle"   value="'.$probTitle.'" />'."\n".
 	'<input type="hidden" name="command"     value="" />'."\n".

--ng1058900397--