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

ng lon-capa-cvs@mail.lon-capa.org
Fri, 18 Jul 2003 20:14:35 -0000


This is a MIME encoded message

--ng1058559275
Content-Type: text/plain

ng		Fri Jul 18 16:14:35 2003 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  clean up some more codes
  fix a couple of bugs
  
  
  
--ng1058559275
Content-Type: text/plain
Content-Disposition: attachment; filename="ng-20030718161435.txt"

Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.118 loncom/homework/grades.pm:1.119
--- loncom/homework/grades.pm:1.118	Thu Jul 17 18:08:25 2003
+++ loncom/homework/grades.pm	Fri Jul 18 16:14:35 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.118 2003/07/17 22:08:25 ng Exp $
+# $Id: grades.pm,v 1.119 2003/07/18 20:14:35 ng Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -140,7 +140,6 @@
 #--- Currently filters option response type only.
 sub cleanRecord {
     my ($answer,$response) = @_;
-    $answer =~ s|^<br />||;
     if ($response eq 'option') {
 	my (@IDs,@ans);
 	foreach (split(/\&/,&Apache::lonnet::unescape($answer))) {
@@ -471,8 +470,7 @@
     $request->print($result);
 
     my $checkhdgrade = ($ENV{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked' : '';
-    my $checklastsub = ($ENV{'form.handgrade'} eq 'no') ? 'checked' : '';
-    $checklastsub = 'checked' if ($checkhdgrade eq '' && $checklastsub eq '');
+    my $checklastsub = $checkhdgrade eq '' ? 'checked' : '';
     my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'."\n".
 	'&nbsp;<b>View Problem Text: </b><input type="radio" name="vProb" value="no" checked /> no '."\n".
 	'<input type="radio" name="vProb" value="yes" /> one student '."\n".
@@ -1033,16 +1031,6 @@
     hDoc.write("  self.close()");
     hDoc.write("}");
 
-/*    hDoc.write("function radioSelection(radioButton) {");
-    hDoc.write("    var selection=null;");
-    hDoc.write("    for (var i=0; i<radioButton.length; i++) {");
-    hDoc.write("        if (radioButton[i].checked) {");
-    hDoc.write("            selection=radioButton[i].value;");
-    hDoc.write("            return selection;");
-    hDoc.write("        }");
-    hDoc.write("    }");
-    hDoc.write("}"); */
-
     hDoc.write("<");
     hDoc.write("/script>");
 
@@ -1233,6 +1221,7 @@
 	$request->print('<form action="/adm/grades" method="post" name="SCORE">'."\n".
 			'<input type="hidden" name="command"    value="handgrade" />'."\n".
 			'<input type="hidden" name="saveState"  value="'.$ENV{'form.saveState'}.'" />'."\n".
+			'<input type="hidden" name="Status"     value="'.$ENV{'form.Status'}.'" />'."\n".
 			'<input type="hidden" name="probTitle"  value="'.$ENV{'form.probTitle'}.'" />'."\n".
 			'<input type="hidden" name="refresh"    value="off" />'."\n".
 			'<input type="hidden" name="symb"       value="'.$symb.'" />'."\n".
@@ -1377,8 +1366,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";
@@ -1416,9 +1404,11 @@
 				     '"><img src="/adm/lonIcons/unknown.gif" border=0"> File uploaded by student</a> '.
 				     '<font color="red" size="1">Like all files provided by users, '.
 				     'this file may contain virusses</font><br />':'').
-				     '<b>Submitted Answer: </b>'.($responsetype eq 'essay' ? '<blockquote>' : '').
+				     '<b>Submitted Answer: </b>'.($responsetype =~ /^(essay|option)$/ ? 
+								  '<blockquote>' : '').
 				     &cleanRecord(&keywords_highlight($subval),$responsetype).
-				     ($responsetype eq 'essay' ? '</blockquote><br />' : '<br /><br />').$similar."\n"
+				     ($responsetype =~ /^(essay|option)$/ ? '</blockquote><br />' : 
+				      '<br /><br />').$similar."\n"
 				     if ($ENV{'form.lastSub'} eq 'lastonly' || 
 					 ($ENV{'form.lastSub'} eq 'hdgrade' && 
 					  $$handgrade{$part} =~ /:yes$/));
@@ -1439,7 +1429,6 @@
     
     # return if view submission with no grading option
     if ($ENV{'form.showgrading'} eq '' || (!&canmodify($usec))) {
-#    if (!&canmodify($usec)) {
 	$request->print('</td></tr></table></td></tr></table></form>'."\n");
 	$request->print(&show_grading_menu_form($symb,$url)) 
 	    if (($ENV{'form.command'} eq 'submission') || 
@@ -1447,12 +1436,12 @@
 	return;
     }
 
+    $result='<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n".
+	'<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
+	'<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
+	.$udom.'" />'."\n";
     # essay grading options
     if ($ENV{'form.handgrade'} eq 'yes') {
-	$result='<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n".
-	    '<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
-	    '<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
-	    .$udom.'" />'."\n";
 	my ($lastname,$givenn) = split(/,/,$ENV{'form.fullname'});
 	my $msgfor = $givenn.' '.$lastname;
 	if (scalar(@col_fullnames) > 0) {
@@ -1468,8 +1457,8 @@
 	    '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
 	    '<br />&nbsp;(Message will be sent when you click on Save & Next below.)'."\n" 
 	    if ($ENV{'form.handgrade'} eq 'yes');
-	$request->print($result);
     }
+    $request->print($result);
 
     my %seen = ();
     my @partlist;
@@ -1496,26 +1485,21 @@
     if ($counter == $total) {
 	my $endform='<table border="0"><tr><td>'.
 	    '<input type="hidden" name="gradeOpt" value="" />'."\n";
-#	if ($ENV{'form.handgrade'} eq 'yes') {
-	    $endform.='<input type="button" value="Save & Next" '.
-		'onClick="javascript:checksubmit(this.form,\'Save & Next\','.
-		$total.','.scalar(@partlist).');" TARGET=_self> &nbsp;'."\n";
-	    my $ntstu ='<select name="NTSTU">'.
-		'<option>1</option><option>2</option>'.
-		'<option>3</option><option>5</option>'.
-		'<option>7</option><option>10</option></select>'."\n";
-	    my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1');
-	    $ntstu =~ s/<option>$nsel</<option selected="on">$nsel</;
-	    $endform.=$ntstu.'student(s) &nbsp;&nbsp;';
-#	} else {
-#	    $endform.='<input type="hidden" name="NTSTU" value="1" />'."\n";
-#	}
+	$endform.='<input type="button" value="Save & Next" '.
+	    'onClick="javascript:checksubmit(this.form,\'Save & Next\','.
+	    $total.','.scalar(@partlist).');" TARGET=_self> &nbsp;'."\n";
+	my $ntstu ='<select name="NTSTU">'.
+	    '<option>1</option><option>2</option>'.
+	    '<option>3</option><option>5</option>'.
+	    '<option>7</option><option>10</option></select>'."\n";
+	my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1');
+	$ntstu =~ s/<option>$nsel</<option selected="on">$nsel</;
+	$endform.=$ntstu.'student(s) &nbsp;&nbsp;';
 	$endform.='<input type="button" value="Next" '.
 	    'onClick="javascript:checksubmit(this.form,\'Next\');" TARGET=_self> &nbsp;'."\n".
 	    '<input type="button" value="Previous" '.
 	    'onClick="javascript:checksubmit(this.form,\'Previous\');" TARGET=_self> &nbsp;';
 	$endform.='(Next and Previous do not save the scores.)'."\n" ;
-#	    if ($ENV{'form.handgrade'} eq 'yes');
 	$endform.='</td><tr></table></form>';
 	$endform.=&show_grading_menu_form($symb,$url);
 	$request->print($endform);
@@ -1525,15 +1509,15 @@
 
 #--- Retrieve the last submission for all the parts
 sub get_last_submission {
-    my (%returnhash)=@_;
+    my ($returnhash)=@_;
     my (@string,$timestamp);
-    if ($returnhash{'version'}) {
+    if ($$returnhash{'version'}) {
 	my %lasthash=();
 	my ($version);
-	for ($version=1;$version<=$returnhash{'version'};$version++) {
-	    foreach (sort(split(/\:/,$returnhash{$version.':keys'}))) {
-		$lasthash{$_}=$returnhash{$version.':'.$_};
-		   $timestamp = scalar(localtime($returnhash{$version.':timestamp'}));
+	for ($version=1;$version<=$$returnhash{'version'};$version++) {
+	    foreach (sort(split(/\:/,$$returnhash{$version.':keys'}))) {
+		$lasthash{$_}=$$returnhash{$version.':'.$_};
+		   $timestamp = scalar(localtime($$returnhash{$version.':timestamp'}));
 	    }
 	}
 	foreach ((keys %lasthash)) {
@@ -1557,13 +1541,8 @@
     (my $styleoff = $styleon) =~ s/\</\<\//;
     my @keylist   = split(/[,\s+]/,$ENV{'form.keywords'});
     foreach (@keylist) {
-	$string =~ s/\b\Q$_\E(\b|\.)/\<font color\=$ENV{'form.kwclr'} $size\>$styleon$_$styleoff\<\/font\>/gi;
+	$string =~ s/\b\Q$_\E(\b|\.)/<font color\=$ENV{'form.kwclr'} $size\>$styleon$_$styleoff<\/font>/gi;
     }
-    # This is not really the right place to do this, but I cannot find a
-    # better one at this time.  So here we go - the m in the s:::mg causes
-    # ^ to match the beginning of a new line.  So we replace(???) the beginning
-    # of the line with <br /> to make things formatted a little better.
-    $string =~ s:^:<br />:mg;
     return $string;
 }
 
@@ -1609,7 +1588,8 @@
 	    if ($ENV{'form.collaborator'.$ctr}) {
 		my (@collaborators) = split(/:/,$ENV{'form.collaborator'.$ctr});
 		foreach (@collaborators) {
-		    my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$url,$symb,$_,$udom,$ctr,$ENV{'form.unamedom'.$ctr});
+		    my ($errorflag,$pts,$wgt) = 
+			&saveHandGrade($request,$url,$symb,$_,$udom,$ctr,$ENV{'form.unamedom'.$ctr});
 		    if ($errorflag eq 'not_allowed') {
 			$request->print("<font color=\"red\">Not allowed to modify grades for $_:$udom</font>");
 			next;
@@ -1626,48 +1606,50 @@
 	}
     }
 
-    # Keywords sorted in alphabatical order
-    my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
-    my %keyhash = ();
-    $ENV{'form.keywords'}           =~ s/,\s{0,}|\s+/ /g;
-    $ENV{'form.keywords'}           =~ s/^\s+|\s+$//;
-    my (@keywords) = sort(split(/\s+/,$ENV{'form.keywords'}));
-    $ENV{'form.keywords'} = join(' ',@keywords);
-    $keyhash{$symb.'_keywords'}     = $ENV{'form.keywords'};
-    $keyhash{$symb.'_subject'}      = $ENV{'form.msgsub'};
-    $keyhash{$loginuser.'_kwclr'}   = $ENV{'form.kwclr'};
-    $keyhash{$loginuser.'_kwsize'}  = $ENV{'form.kwsize'};
-    $keyhash{$loginuser.'_kwstyle'} = $ENV{'form.kwstyle'};
-
-    # message center - Order of message gets changed. Blank line is eliminated.
-    # New messages are saved in ENV for the next student.
-    # All messages are saved in nohist_handgrade.db
-    my ($ctr,$idx) = (1,1);
-    while ($ctr <= $ENV{'form.savemsgN'}) {
-	if ($ENV{'form.savemsg'.$ctr} ne '') {
-	    $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.savemsg'.$ctr};
-	    $idx++;
+    if ($ENV{'form.handgrade'} eq 'yes') {
+	# Keywords sorted in alphabatical order
+	my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
+	my %keyhash = ();
+	$ENV{'form.keywords'}           =~ s/,\s{0,}|\s+/ /g;
+	$ENV{'form.keywords'}           =~ s/^\s+|\s+$//;
+	my (@keywords) = sort(split(/\s+/,$ENV{'form.keywords'}));
+	$ENV{'form.keywords'} = join(' ',@keywords);
+	$keyhash{$symb.'_keywords'}     = $ENV{'form.keywords'};
+	$keyhash{$symb.'_subject'}      = $ENV{'form.msgsub'};
+	$keyhash{$loginuser.'_kwclr'}   = $ENV{'form.kwclr'};
+	$keyhash{$loginuser.'_kwsize'}  = $ENV{'form.kwsize'};
+	$keyhash{$loginuser.'_kwstyle'} = $ENV{'form.kwstyle'};
+
+	# message center - Order of message gets changed. Blank line is eliminated.
+	# New messages are saved in ENV for the next student.
+	# All messages are saved in nohist_handgrade.db
+	my ($ctr,$idx) = (1,1);
+	while ($ctr <= $ENV{'form.savemsgN'}) {
+	    if ($ENV{'form.savemsg'.$ctr} ne '') {
+		$keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.savemsg'.$ctr};
+		$idx++;
+	    }
+	    $ctr++;
 	}
-	$ctr++;
-    }
-    $ctr = 0;
-    while ($ctr < $ngrade) {
-	if ($ENV{'form.newmsg'.$ctr} ne '') {
-	    $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
-	    $ENV{'form.savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
-	    $idx++;
+	$ctr = 0;
+	while ($ctr < $ngrade) {
+	    if ($ENV{'form.newmsg'.$ctr} ne '') {
+		$keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
+		$ENV{'form.savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
+		$idx++;
+	    }
+	    $ctr++;
 	}
-	$ctr++;
+	$ENV{'form.savemsgN'} = --$idx;
+	$keyhash{$symb.'_savemsgN'} = $ENV{'form.savemsgN'};
+	my $putresult = &Apache::lonnet::put
+	    ('nohist_handgrade',\%keyhash,
+	     $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
+	     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
     }
-    $ENV{'form.savemsgN'} = --$idx;
-    $keyhash{$symb.'_savemsgN'} = $ENV{'form.savemsgN'};
-    my $putresult = &Apache::lonnet::put
-	('nohist_handgrade',\%keyhash,
-	 $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
-	 $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
-
     # Called by Save & Refresh from Highlight Attribute Window
-    my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'0');
+#    my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'0');
+    my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'1');
     if ($ENV{'form.refresh'} eq 'on') {
 	my ($ctr,$total) = (0,0);
 	while ($ctr < $ngrade) {
@@ -1689,7 +1671,7 @@
     # Get the next/previous one or group of students
     my $firststu = $ENV{'form.unamedom0'};
     my $laststu = $ENV{'form.unamedom'.($ngrade-1)};
-    $ctr = 2;
+    my $ctr = 2;
     while ($laststu eq '') {
 	$laststu  = $ENV{'form.unamedom'.($ngrade-$ctr)};
 	$ctr++;
@@ -1773,6 +1755,7 @@
 	    $wgt = $ENV{'form.WGT'.$newflg.'_'.$_} eq '' ? 1 : 
 		$ENV{'form.WGT'.$newflg.'_'.$_};
 	    my $partial= $pts/$wgt;
+	    next if ($partial eq $record{'resource.'.$_.'.awarded'}); #do not update score for part if not changed.
 	    $newrecord{'resource.'.$_.'.awarded'}  = $partial 
 		if ($record{'resource.'.$_.'.awarded'} ne $partial);
 	    my $reckey = 'resource.'.$_.'.solved';
@@ -2047,8 +2030,6 @@
 	'<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
     $result.='<input type="button" value="Reset" '.
 	'onClick="javascript:resetEntry('.$ctsparts.');" TARGET=_self>';
-#    $result.=' &nbsp; &nbsp;<input type="button" value="Submit Changes" name="subButton1'.
-#	'onClick="javascript:submit();" TARGET=_self />'."\n";
 
     #table listing all the students in a section/class
     #header of table
@@ -2824,45 +2805,11 @@
 		if ($record{'version'} eq '') {
 		    $studentTable.='<br />&nbsp;<font color="red">No recorded submission for this problem</font><br />';
 		} else {
-		    $studentTable.='<table border="0" width="100%"><tr><td bgcolor="#777777">'.
-			'<table border="0" width="100%"><tr bgcolor="#e6ffff">'.
-			'<td><b>Date/Time</b></td>'.
-			'<td><b>Submission</b></td>'.
-			'<td><b>Status&nbsp;</b></td></tr>';
 		    my %responseType = ();
 		    foreach my $partid (@{$parts}) {
 			$responseType{$partid} = $curRes->responseType($partid);
 		    }
-		    my ($version);
-		    my %mark;
-		    $mark{'correct_by_student'} = $checkIcon;
-		    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;
-			    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 />' : '';
-			    $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.')' : '';
-			}
-			$displaySub[2].=(exists $record{"$version:resource.regrader"}) ?
-			    $record{"$version:resource.regrader"} : '';
-			$studentTable.='<td>'.$displaySub[0].'&nbsp;</td><td>'.$displaySub[1].
-			    ($displaySub[2] eq '' ? '' : 'Manually graded by '.$displaySub[2]).'&nbsp;</td></tr>';
-		    }
-		    $studentTable.='</table></td></tr></table>';
+		    $studentTable.= &displaySubByDates(\%record,$parts,\%responseType,$checkIcon);
 		}
 	    } elsif ($ENV{'form.lastSub'} eq 'all') {
 		my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
@@ -2894,6 +2841,46 @@
     $request->print($studentTable);
 
     return '';
+}
+
+sub displaySubByDates {
+    my ($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>'.
+	'<td><b>Submission</b></td>'.
+	'<td><b>Status&nbsp;</b></td></tr>';
+    my ($version);
+    my %mark;
+    $mark{'correct_by_student'} = $checkIcon;
+    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;
+	    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 />' : '';
+	    $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.')' : '';
+	}
+	$displaySub[2].=(exists $$record{"$version:resource.regrader"}) ?
+	    $$record{"$version:resource.regrader"} : '';
+	$studentTable.='<td>'.$displaySub[0].'&nbsp;</td><td>'.$displaySub[1].
+	    ($displaySub[2] eq '' ? '' : 'Manually graded by '.$displaySub[2]).'&nbsp;</td></tr>';
+    }
+    $studentTable.='</table></td></tr></table>';
+    return $studentTable;
 }
 
 sub updateGradeByPage {

--ng1058559275--