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

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 20 Jun 2002 22:04:22 -0000


albertel		Thu Jun 20 18:04:22 2002 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  - Close BUG#526 (Heading wrong on manual grading)
  - Reset table colors to #000000
  - Close BUG#42 (CSV upload of scores)
  
  
  
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.28 loncom/homework/grades.pm:1.29
--- loncom/homework/grades.pm:1.28	Thu Jun 20 17:21:16 2002
+++ loncom/homework/grades.pm	Thu Jun 20 18:04:21 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.28 2002/06/20 21:21:16 ng Exp $
+# $Id: grades.pm,v 1.29 2002/06/20 22:04:21 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -112,9 +112,9 @@
 </form>
 <h2><font color="#339933">Show Student Submissions on Assessment</font></h2>
 
-<table border=0><tr><td bgcolor=#990404>
-<table border=0>
-<tr bgcolor=#e6ffff><td><b>Username</b></td><td><b>Name</b></td><td><b>Domain</b></td><td>&nbsp;</td></tr>
+<table border="0"><tr><td bgcolor="#000000">
+<table border="0">
+<tr bgcolor="#e6ffff"><td><b>Username</b></td><td><b>Name</b></td><td><b>Domain</b></td><td>&nbsp;</td></tr>
 ENDTABLEST
   my (%classlist) = &getclasslist($cdom,$cnum,'0');
   foreach my $student ( sort(@{ $classlist{'allids'} }) ) {
@@ -248,7 +248,7 @@
       $result.="</select></td>\n";
     }
   }
-  $result.='</tr>';
+  $result.='<td></td></tr>';
   return $result;
 }
 #FIXME need to look at the meatdata <stores> spec on what type of data to accept and provide an
@@ -343,22 +343,39 @@
  return ($symb,$url);
 }
 
+sub view_edit_entire_class_form {
+  my ($symb,$url)=@_;
+  my $result.='<form action="/adm/grades" method="post">'."\n".
+    '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
+      '<input type="hidden" name="url" value="'.$url.'" />'."\n".
+	'<input type="hidden" name="command" value="viewgrades" />'."\n".
+	  '<input type="submit" name="submit" value="View/Edit Entire Class" />'."\n".
+	    '</form>'."\n";
+  return $result;
+}
+
+sub show_grading_menu_form {
+  my ($symb,$url)=@_;
+  my $result.='<form action="/adm/grades" method="post">'."\n".
+    '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
+      '<input type="hidden" name="url" value="'.$url.'" />'."\n".
+	'<input type="hidden" name="command" value="gradingmenu" />'."\n".
+	  '<input type="submit" name="submit" value="Grading Menu" />'."\n".
+	    '</form>'."\n";
+  return $result;
+}
+
 sub gradingmenu {
   my ($request) = @_;
   my ($symb,$url)=&get_symb_and_url($request);
   if (!$symb) {return '';}
 
   my $result='<h2>&nbsp;<font color="#339933">Select a Grading Method</font></h2><br />';
-  $result.='<table width=100% border=0><tr><td bgcolor=#990404>'."\n";
+  $result.='<table width=100% border=0><tr><td bgcolor=#000000>'."\n";
   $result.='<table width=100% border=0><tr><td bgcolor=#e6ffff>'."\n";
   $result.='&nbsp;<b>Resource :</b> '.$url.'</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="url" value="'.$url.'" />'."\n".
-	'<input type="hidden" name="command" value="viewgrades" />'."\n".
-	  '<input type="submit" name="submit" value="View/Edit Entire Class" />'."\n".
-	    '</form>'."\n";
+  $result.=&view_edit_entire_class_form($symb,$url);
   $result.='<form action="/adm/grades" method="post">'."\n".
      '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
       '<input type="hidden" name="url" value="'.$url.'" />'."\n".
@@ -391,7 +408,7 @@
   my $cellclr = '"#ffffcc"';
 
   #get list of parts for this problem
-  my (@parts) = &getpartlist($url);
+  my (@parts) = sort(&getpartlist($url));
 
   $request->print ("<h2><font color=\"#339933\">Manual Grading</font></h2>");
 
@@ -401,10 +418,10 @@
       '<input type="hidden" name="url" value="'.$url.'" />'."\n".
 	'<input type="hidden" name="command" value="editgrades" />'."\n".
 	  '<input type="submit" name="submit" value="Submit Changes" />'."\n".
-	    '<table border=0><tr><td bgcolor="#990404">'."\n".
+	    '<table border=0><tr><td bgcolor="#000000">'."\n".
 	     '<table border=0>'."\n".
 	      '<tr bgcolor='.$headerclr.'><td><b>Username</b></td><td><b>Name</b></td><td><b>Domain</b></td>'."\n";
-  foreach my $part (sort(@parts)) {
+  foreach my $part (@parts) {
      my $display=&Apache::lonnet::metadata($url,$part.'.display');
      if  (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
      $result.='<td><b>'.$display.'</b></td>'."\n";
@@ -415,7 +432,7 @@
     $result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
   }
   $result.='</table></td></tr></table><input type="submit" name="submit" value="Submit Changes" /></form>';
-
+  $result.=&show_grading_menu_form($symb,$url);
   return $result;
 }
 
@@ -658,21 +675,44 @@
     }
   }
   $request->print('<h3>Assigning Grades</h3>');
-  &Apache::lonhomework::showhash(('1'=>\@keyfields));
-  &Apache::lonhomework::showhash(%fields);
   my $courseid=$ENV{'request.course.id'};
   my $cdom=$ENV{"course.$courseid.domain"};
   my $cnum=$ENV{"course.$courseid.num"};
   my (%classlist) = &getclasslist($cdom,$cnum,'1');
-  foreach my $student ( sort(@{ $classlist{'allids'} }) ) {
-    my %newhash;
-    foreach my $grade (@gradedata) {
-      my %entries=&Apache::loncommon::record_sep($grade);
-      foreach my $dest (keys(%fields)) {
-	
-      }
+  my @skipped;
+  my $countdone=0;
+  foreach my $grade (@gradedata) {
+    my %entries=&Apache::loncommon::record_sep($grade);
+    my $username=$entries{$fields{'username'}};
+    my $domain=$entries{$fields{'domain'}};
+    if (!exists($classlist{"$username:$domain"})) {
+      push(@skipped,"$username:$domain");
+      next;
     }
+    my %grades;
+    foreach my $dest (keys(%fields)) {
+      if ($dest eq 'username' || $dest eq 'domain') { next; }
+      if ($entries{$fields{$dest}} eq '') { next; }
+      my $store_key=$dest;
+      $store_key=~s/^stores/resource/;
+      $store_key=~s/_/\./g;
+      $grades{$store_key}=$entries{$fields{$dest}};
+    }
+    $grades{"resource.regrader"}="$ENV{'user.name'}:$ENV{'user.domain'}";
+    &Apache::lonnet::cstore(\%grades,$symb,$ENV{'request.course.id'},
+			    $domain,$username);
+    $request->print('.');
+    $request->rflush();
+    $countdone++;
+  }
+  $request->print("<br />Stored $countdone students\n");
+  if (@skipped) {
+    $request->print('<br /><font size="+1"><b>Skipped Students</b></font><br />');
+    foreach my $student (@skipped) { $request->print("<br />$student"); }
   }
+  $request->print(&view_edit_entire_class_form($symb,$url));
+  $request->print(&show_grading_menu_form($symb,$url));
+  return '';
 }
 
 sub send_header {
@@ -695,8 +735,6 @@
 sub handler {
   my $request=$_[0];
 
-  if ( $ENV{'user.name'} eq 'albertel' ) {$Apache::lonxml::debug=1;} else {$Apache::lonxml::debug=0;}
-  
   if ($ENV{'browser.mathml'}) {
     $request->content_type('text/xml');
   } else {
@@ -742,7 +780,7 @@
          }
      }
   } else {
-    &Apache::lonhomework::showhashsubset(\%ENV,'^form');
+    #&Apache::lonhomework::showhashsubset(\%ENV,'^form');
     $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
     if ($command eq 'submission') {
       &listStudents($request) if ($ENV{'form.student'} eq '');