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

ng lon-capa-cvs@mail.lon-capa.org
Fri, 19 Jul 2002 20:42:18 -0000


This is a MIME encoded message

--ng1027111338
Content-Type: text/plain

ng		Fri Jul 19 16:42:18 2002 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  modified some codes to speed up the display going from one student to the next.
  
  
  
--ng1027111338
Content-Type: text/plain
Content-Disposition: attachment; filename="ng-20020719164218.txt"

Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.39 loncom/homework/grades.pm:1.40
--- loncom/homework/grades.pm:1.39	Thu Jul 18 17:27:57 2002
+++ loncom/homework/grades.pm	Fri Jul 19 16:42:18 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.39 2002/07/18 21:27:57 ng Exp $
+# $Id: grades.pm,v 1.40 2002/07/19 20:42:18 ng Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -167,7 +167,8 @@
 &nbsp;<b>View Problem: </b><input type="radio" name="vProb" value="no" checked> no 
 <input type="radio" name="vProb" value="yes"> yes <br />
 &nbsp;<b>Submissions: </b>
-<input type="radio" name="lastSub" value="lastonly" checked /> last sub only
+<input type="radio" name="lastSub" value="hdgrade" checked /> handgrade only
+<input type="radio" name="lastSub" value="lastonly" /> last sub only
 <input type="radio" name="lastSub" value="last" /> last sub & parts info
 <input type="radio" name="lastSub" value="all" /> all details
 <input type="hidden" name="section" value="$getsec" />
@@ -486,14 +487,16 @@
   # Student info
   $request->print(($counter == 0 ? '' : '<br />'));
   my $fullname = ($ENV{'form.fullname'} ne '' ? $ENV{'form.fullname'} : &get_fullname($uname,$udom));
-  my $result.='<table border="0" width=100%><tr><td bgcolor="#777777">'.
+  my $result='<table border="0" width=100%><tr><td bgcolor="#777777">'.
       '<table border="0" width=100%><tr bgcolor="#ffffff"><td>';
+
   $result.='<table border="0"><tr bgcolor="#ffffff"><td><b>Fullname: </b>'.$fullname.
       '</td><td>&nbsp; &nbsp;<b>Username: </b>'.$uname.
 	      '</td><td>&nbsp; &nbsp;<b>Domain: </b>'.$udom.'</td></tr>';
   if ($ENV{'form.handgrade'} eq 'yes') {
 #      my $subonly = &get_last_submission($symb,$uname,$udom,$ENV{'request.course.id'});
-      my ($classlist) = &getclasslist('all','0');
+#      my ($classlist) = &getclasslist('all','0');
+      my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist('all','0');
       my @collaborators;
 #      foreach ( sort(@{ $$classlist{'all'} }) ) {
 #	  my ($uname,$udom) = split(/:/);
@@ -503,24 +506,22 @@
       if (scalar(@collaborators) != 0) {
 	  $result.='<tr bgcolor="#ffffff"><td colspan=3><b>Collaborators: </b>';
 	  foreach (@collaborators) {
-	      $result.=$_.' ('.&get_fullname($_,$udom).') &nbsp; &nbsp;';
+	      $result.=$_.' ('.$$fullname{$_.':'.$udom}.') &nbsp; &nbsp;';
+#	      $result.=$_.' ('.&get_fullname($_,$udom).') &nbsp; &nbsp;';
 	  }
 	  $result.='</td></tr>'."\n";
 	  $result.='<input type="hidden" name="collaborator'.$counter.
 	      '" value="'.(join ':',@collaborators).'" />'."\n";
       }
   }
-  $result.='</table>'."\n";
-  $request->print($result);
+  $request->print($result.'</table>'."\n");
 
   my ($partlist,$handgrade) = &response_type($url);
 
- # print student answer
-  if ($ENV{'form.lastSub'} eq 'lastonly') {
+  # print student answer
+  if ($ENV{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
       my ($string,$timestamp)=&get_last_submission ($symb,$uname,$udom,$ENV{'request.course.id'});
-      my $lastsubonly='<table border="0" width=100%><tr><td bgcolor="#777777">';
-      $lastsubonly.='<table border="0" width=100%><tr bgcolor="#ddffff">';
-      $lastsubonly.='<td><b>Last Submission Only</b>'.
+      my $lastsubonly.='</td></tr><tr><td bgcolor="#e6ffff"><b>Last Submission Only</b>'.
 	  ($$timestamp eq '' ? '' : '&nbsp; &nbsp; <b>Date Submitted:</b> '.$$timestamp).'</td></tr>';
       if ($$timestamp eq '') {
 	  $lastsubonly.='<tr><td bgcolor="#ffffe6">'.$$string[0].'</td></tr>';
@@ -532,12 +533,14 @@
 		      my ($ressub,$subval) = split(/:/,$_,2);
 		      $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part ID</b> '.
 			  $partid.' <b>Response ID</b> '.$respid.
-			  ' <b>Submission</b> '.&keywords_highlight($subval).'</td></tr>';
+			  ' <b>Submission</b> '.&keywords_highlight($subval).'</td></tr>'
+			  if ($ENV{'form.lastSub'} eq 'lastonly' || 
+			      ($ENV{'form.lastSub'} eq 'hdgrade' && $$handgrade{$part} =~ /:yes$/));
 		  }
 	      }
 	  }
       }
-      $lastsubonly.='</td></tr></table></td></tr></table>'."\n";
+      $lastsubonly.='</td></tr><tr><td bgcolor="#ffffff">'."\n";
       $request->print($lastsubonly);
   } else {
       $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
@@ -554,6 +557,10 @@
 
   my %seen = ();
   my @partlist;
+  my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
+#  while (my ($k,$v) = each (%record)){
+#      print "key=$k    ==>    value=$v<br>";
+#  }
   for (sort keys(%$handgrade)) {
       my ($partid,$respid) = split(/_/);
       next if ($seen{$partid} > 0);
@@ -563,12 +570,10 @@
       my $wgt    = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
       my $wgtmsg = ($wgt > 0 ? '(problem weight)' : '<font color="red">problem weight assigned by computer</font>');
       $wgt       = ($wgt > 0 ? $wgt : '1');
-      my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
-      my $score  = ($record{'resource.0.awarded'} eq '' ? '' : $record{'resource.0.awarded'}*$wgt);
+      my $score  = ($record{'resource.'.$partid.'.awarded'} eq '' ? '' : $record{'resource.'.$partid.'.awarded'}*$wgt);
 
       # display grading options
       $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />';
-
       $result.='<table border="0"><tr><td><b>Part </b>'.$partid.' <b>Points</b></td><td>';
 
       my $ctr = 0;
@@ -612,18 +617,17 @@
       my $endform.='<table border="0"><tr><td><input type="submit" name="gradeOpt" value="Save & Next" />';
       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";
+	  '<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="submit" name="gradeOpt" value="Next" />&nbsp';
-      $endform.='<input type="submit" name="gradeOpt" value="Previous" />&nbsp';
-      $endform.='(Next and Previous do not save the scores.)';
-      $endform.='</td><tr></table></form>';
+      $ntstu =~ s/<option>$nsel</<option selected="on">$nsel</;
+      $endform.=$ntstu.'student(s) &nbsp;&nbsp;'.
+	  '<input type="submit" name="gradeOpt" value="Next" />&nbsp'.
+	  '<input type="submit" name="gradeOpt" value="Previous" />&nbsp'.
+	  '(Next and Previous do not save the scores.)'.
+	  '</td><tr></table></form>';
       $request->print($endform);
   }
-
   return '';
 }
 
@@ -672,12 +676,12 @@
 
   my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
   my %keyhash = ();
-  $ENV{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
-  $ENV{'form.keywords'} =~ s/^\s+|\s+$//;
-  $keyhash{$symb.'_keywords'} = $ENV{'form.keywords'};
-  $keyhash{$symb.'_subject'} = $ENV{'form.msgsub'};
-  $keyhash{$loginuser.'_kwclr'} = $ENV{'form.kwclr'};
-  $keyhash{$loginuser.'_kwsize'} = $ENV{'form.kwsize'};
+  $ENV{'form.keywords'}           =~ s/,\s{0,}|\s+/ /g;
+  $ENV{'form.keywords'}           =~ s/^\s+|\s+$//;
+  $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'};
 
   my ($ctr,$idx) = (1,1);
@@ -706,9 +710,10 @@
 
   if ($ENV{'form.refresh'} eq 'on') {
       my $ctr = 0;
-      while ($ctr < $ntstu) {
+      $ENV{'form.NTSTU'}=$ngrade;
+      while ($ctr < $ngrade) {
 	  ($ENV{'form.student'},my $udom) = split(/:/,$ENV{'form.unamedom'.$ctr});
-	  &submission($request,$ctr,$ntstu-1);
+	  &submission($request,$ctr,$ngrade-1);
 	  $ctr++;
       }
       return '';
@@ -745,51 +750,50 @@
       }
   }
   my $firststu = $ENV{'form.unamedom0'};
-  my $laststu  = $ENV{'form.unamedom'.($ngrade-1)};
-
-  my ($classlist) = &getclasslist($ENV{'form.section'},'0');
-  my (@nextlist,@prevlist);
-  my ($nextflg,$ctr,$ctprev) = (0,0,0);
-  my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
-  foreach my $student ( sort(@{ $$classlist{$ENV{'form.section'}} }) ) {
-      my ($uname,$udom) = split(/:/,$student);
-      my (%status) = &student_gradeStatus($ENV{'form.url'},$udom,$uname,$partlist);
-      my $statusflg = '';
-      foreach (keys(%status)) {
-	  $statusflg = 1 if ($status{$_} ne 'nothing');
-      }
-      next if ($statusflg eq '' && $ENV{'form.submitonly'} eq 'yes');
+  my $laststu = $ENV{'form.unamedom'.($ngrade-1)};
+  $ctr = 2;
+  while ($laststu eq '') {
+      $laststu  = $ENV{'form.unamedom'.($ngrade-$ctr)};
+      $ctr++;
+      $laststu = $firststu if ($ctr > $ngrade);
+  }
+  my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist($ENV{'form.section'},'0');
 
+  my (@parsedlist,@nextlist);
+  my ($nextflg) = 0;
+  foreach ( sort(@{ $$classlist{$ENV{'form.section'}} }) ) {
       if ($nextflg == 1 && $button =~ /Next$/) {
-	  push @nextlist,$uname if ($ctr < $ntstu);
-	  $ctr++;
-	  last if ($ctr == $ntstu);
+	  push @parsedlist,$_;
       }
-      $nextflg = 1 if ($student eq $laststu);
+      $nextflg = 1 if ($_ eq $laststu);
       if ($button eq 'Previous') {
-	  last if ($student eq $firststu);
-	  push @prevlist,$uname;
-	  $ctprev++;
+	  last if ($_ eq $firststu);
+	  push @parsedlist,$_;
       }
   }
-
-  if ($button eq 'Previous') {
-      if ($ctprev <= $ntstu) {
-	  @nextlist = @prevlist;
-      } else {
-	  my $idx = 0;
-	  my $start = $ctprev - $ntstu;
-	  while ($idx < $ntstu) {
-	      $nextlist[$idx] = $prevlist[$start+$idx];
-	      $idx++;
+  $ctr = 0;
+  my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
+  @parsedlist = reverse @parsedlist if ($button eq 'Previous');
+  foreach my $student (@parsedlist) {
+      my ($uname,$udom) = split(/:/,$student);
+      if ($ENV{'form.submitonly'} eq 'yes') {
+	  my (%status) = &student_gradeStatus($ENV{'form.url'},$udom,$uname,$partlist) ;
+	  my $statusflg = '';
+	  foreach (keys(%status)) {
+	      $statusflg = 1 if ($status{$_} ne 'nothing');
 	  }
+	  next if ($statusflg eq '');
       }
+      push @nextlist,$student if ($ctr < $ntstu);
+      $ctr++;
   }
 
   $ctr = 0;
   my $total = scalar(@nextlist)-1;
-  foreach my $student (@nextlist) {
-      $ENV{'form.student'} = $student;
+  foreach (sort @nextlist) {
+      my ($uname,$udom) = split(/:/);
+      $ENV{'form.student'} = $uname;
+      $ENV{'form.fullname'} = $$fullname{$_};
       &submission($request,$ctr,$total);
       $ctr++;
   }
@@ -830,10 +834,10 @@
 
   if ( scalar(keys(%newrecord)) > 0 ) {
       $newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
-      while (my ($k,$v) = each %newrecord) {
-	 print "k=$k:v=$v:<br>\n";
-      }
-#     &Apache::lonnet::cstore(\%newrecord,$symb,$ENV{'request.course.id'},$domain,$stuname);
+#      while (my ($k,$v) = each %newrecord) {
+#	 print "k=$k:v=$v:<br>\n";
+#      }
+     &Apache::lonnet::cstore(\%newrecord,$symb,$ENV{'request.course.id'},$domain,$stuname);
   }
   return '';
 }
@@ -974,11 +978,11 @@
   $result.='&nbsp;<b>View/Grade an Individual Student\'s Submission</b></td></tr>'."\n";
   $result.='<tr bgcolor=#ffffe6><td>'."\n";
   $result.='<form action="/adm/grades" method="post">'."\n".
-     '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
+      '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
       '<input type="hidden" name="url" value="'.$url.'" />'."\n".
-       '<input type="hidden" name="response" value="'.$response.'" />'."\n".
-        '<input type="hidden" name="handgrade" value="'.$handgrade.'" />'."\n".
-	 '<input type="hidden" name="command" value="submission" />'."\n";
+      '<input type="hidden" name="response" value="'.$response.'" />'."\n".
+      '<input type="hidden" name="handgrade" value="'.$handgrade.'" />'."\n".
+      '<input type="hidden" name="command" value="submission" />'."\n";
 
   $result.='&nbsp;<b>Select section:</b> <select name="section">'."\n";
   foreach (sort (@$sections)) {
@@ -987,7 +991,7 @@
   $result.= '<option selected="on">all</select>'."\n";
   $result.='&nbsp;&nbsp;<b>Display students who has: </b>'.
       '<input type="radio" name="submitonly" value="yes" checked> submitted'.
-	  '<input type="radio" name="submitonly" value="all"> everybody <br />';
+      '<input type="radio" name="submitonly" value="all"> everybody <br />';
   $result.='&nbsp;(Section "no" implies the students were not assigned a section.)<br />' 
       if (grep /no/,@$sections);
 
@@ -1341,9 +1345,15 @@
     hwdWin.document.write("  opener.document.SCORE.kwclr.value = radioSelection(document.hlCenter.kwdclr);");
     hwdWin.document.write("  opener.document.SCORE.kwsize.value = radioSelection(document.hlCenter.kwdsize);");
     hwdWin.document.write("  opener.document.SCORE.kwstyle.value = radioSelection(document.hlCenter.kwdstyle);");
+//    hwdWin.document.write("     var kwords=opener.document.SCORE.keywords.value;");
+//    hwdWin.document.write("     alert(\\"keywords=\\"+opener.document.SCORE.keywords.value);");
+//    hwdWin.document.write("     return;");
+
     hwdWin.document.write("  if (flag==1){");
     hwdWin.document.write("     opener.document.SCORE.refresh.value = \\"on\\";");
-    hwdWin.document.write("     opener.document.SCORE.submit();");
+    hwdWin.document.write("     if (opener.document.SCORE.keywords.value!=\\"\\"){");
+    hwdWin.document.write("        opener.document.SCORE.submit();");
+    hwdWin.document.write("     }");
     hwdWin.document.write("   }");
     hwdWin.document.write("  self.close()");
     hwdWin.document.write("}");
@@ -1385,8 +1395,8 @@
   function highlightend() { 
     hwdWin.document.write("</table>");
     hwdWin.document.write("</td></tr></table>&nbsp;");
-    hwdWin.document.write("<input type=\\"button\\" value=\\"Refresh\\" onClick=\\"javascript:updateChoice(1)\\">&nbsp;&nbsp;");
-    hwdWin.document.write("<input type=\\"button\\" value=\\"Set Options\\" onClick=\\"javascript:updateChoice(0)\\">&nbsp;&nbsp;");
+    hwdWin.document.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:updateChoice(0)\\">&nbsp;&nbsp;");
+    hwdWin.document.write("<input type=\\"button\\" value=\\"Save & Refresh\\" onClick=\\"javascript:updateChoice(1)\\">&nbsp;&nbsp;");
     hwdWin.document.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
     hwdWin.document.write("</form>");
     hwdWin.document.write("</body></html>");

--ng1027111338--