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

albertel lon-capa-cvs@mail.lon-capa.org
Wed, 24 Sep 2003 23:51:14 -0000


albertel		Wed Sep 24 19:51:14 2003 EDT

  Modified files:              (Branch: version_1_0_2_scantron)
    /loncom/homework	grades.pm 
  Log:
  - backport 1.140 1.142
  
  
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.130.2.1 loncom/homework/grades.pm:1.130.2.1.2.1
--- loncom/homework/grades.pm:1.130.2.1	Sun Aug 17 14:36:46 2003
+++ loncom/homework/grades.pm	Wed Sep 24 19:51:14 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.130.2.1 2003/08/17 18:36:46 albertel Exp $
+# $Id: grades.pm,v 1.130.2.1.2.1 2003/09/24 23:51:14 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3184,7 +3184,7 @@
     my $result;
     $result.= <<SCANTRONFORM;
 <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantro_process">
-  <input type="hidden" name="command" value="scantron_process" />
+  <input type="hidden" name="command" value="scantron_validate" />
   $default_form_data
   <table width="100%" border="0">
     <tr>
@@ -3214,7 +3214,7 @@
       </td>
     </tr>
   </table>
-  <input type="submit" value="Submit" />
+  <input type="submit" value="Validate Scantron Records" />
 </form>
 $grading_menu_button
 SCANTRONFORM
@@ -3296,14 +3296,23 @@
 }
 
 sub scantron_add_delay {
+    my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
+    Apache->request->print('add_delay_error '.$_[2] );
+    push(@$delayqueue,
+	 {'line' => $scanline, 'emsg' => $errormessage,
+	  'ecode' => $errorcode }
+	 );
 }
 
 sub scantron_find_student {
     my ($scantron_record,$idmap)=@_;
     my $scanID=$$scantron_record{'scantron.ID'};
     foreach my $id (keys(%$idmap)) {
-	Apache->request->print('<pre>checking studnet -'.$id.'- againt -'.$scanID.'- </pre>');
-	if (lc($id) eq lc($scanID)) { Apache->request->print('success');return $$idmap{$id}; }
+	#Apache->request->print('<pre>checking studnet -'.$id.'- againt -'.$scanID.'- </pre>');
+	if (lc($id) eq lc($scanID)) {
+	    #Apache->request->print('success');
+	    return $$idmap{$id};
+	}
     }
     return undef;
 }
@@ -3316,6 +3325,18 @@
     return 0;
 }
 
+#FIXME I think I am doing this in the wrong order, I think it would be
+#better to make a several passes analyzing all of the lines in the
+#file for common errors wrong/invalid PID/username duplicated
+#PID/username, missing bubbles, double bubbles, missing/invalid CODE
+#and then get the instructor to fix all of these errors, then grade
+#the corrected one, I'll still need to catch error conditions, but
+#maybe most will taken care even before we start
+
+sub scantron_validate_file {
+    my ($r) = @_;
+}
+
 sub scantron_process_students {
     my ($r) = @_;
     my (undef,undef,$sequence)=split(/___/,$ENV{'form.selectpage'});
@@ -3331,7 +3352,7 @@
     my $navmap=Apache::lonnavmaps::navmap->new($ENV{'request.course.fn'}.'.db',$ENV{'request.course.fn'}.'_parms.db',1, 1);
     my $map=$navmap->getResourceByUrl($sequence);
     my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
-    $r->print("geto ".scalar(@resources)."<br />");
+#    $r->print("geto ".scalar(@resources)."<br />");
     my $result= <<SCANTRONFORM;
 <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
   <input type="hidden" name="command" value="scantron_configphase" />
@@ -3340,29 +3361,36 @@
     $r->print($result);
 
     my @delayqueue;
-    my $totalcorrect;
-    my $totalincorrect;
-
+    my %completedstudents;
+    
     my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,
 	           'Scantron Status','Scantron Progress',scalar(@scanlines));
+    &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
+					  'Processing first student');
+    my $start=&Time::HiRes::time();
     foreach my $line (@scanlines) {
-	my $studentcorrect;
-	my $studentincorrect;
+	$r->print('<pre>line is'.$line.'</pre>');
 
 	chomp($line);
 	my $scan_record=&scantron_parse_scanline($line,\%scantron_config);
 	my ($uname,$udom);
-	if ($uname=&scantron_find_student($scan_record,\%idmap)) {
+	unless ($uname=&scantron_find_student($scan_record,\%idmap)) {
 	    &scantron_add_delay(\@delayqueue,$line,
-				'Unable to find a student that matches');
+				'Unable to find a student that matches',1);
+	    next;
+	}
+	if (exists $completedstudents{$uname}) {
+	    &scantron_add_delay(\@delayqueue,$line,
+				'Student '.$uname.' has multiple sheets',2);
+	    next;
 	}
 	$r->print('<pre>doing studnet'.$uname.'</pre>');
 	($uname,$udom)=split(/:/,$uname);
 	&Apache::lonnet::delenv('form.counter');
 	&Apache::lonnet::appenv(%$scan_record);
 #    &Apache::lonhomework::showhash(%ENV);
-    $Apache::lonxml::debug=1;
-	&Apache::lonxml::debug("line is $line");
+#    $Apache::lonxml::debug=1;
+#	&Apache::lonxml::debug("line is $line");
 	
 	    my $i=0;
 	foreach my $resource (@resources) {
@@ -3374,31 +3402,31 @@
 				  'grade_domain'  =>$udom,
 				  'grade_courseid'=>$ENV{'request.course.id'},
 				  'grade_symb'    =>$resource->symb()));
-	    my %score=&Apache::lonnet::restore($resource->symb(),
-					       $ENV{'request.course.id'},
-					       $udom,$uname);
-	    foreach my $part ($resource->{PARTS}) {
-		if ($score{'resource.'.$part.'.solved'} =~ /^correct/) {
-		    $studentcorrect++;
-		    $totalcorrect++;
-		} else {
-		    $studentincorrect++;
-		    $totalincorrect++;
-		}
-	    }
-	    $r->print('<pre>'.
-		      $resource->symb().'-'.
-		      $resource->src().'-'.'</pre>result is'.$result);
-	    &Apache::lonhomework::showhash(%score);
+#	    my %score=&Apache::lonnet::restore($resource->symb(),
+#					       $ENV{'request.course.id'},
+#					       $udom,$uname);
+#	    foreach my $part ($resource->{PARTS}) {
+#		if ($score{'resource.'.$part.'.solved'} =~ /^correct/) {
+#		    $studentcorrect++;
+#		    $totalcorrect++;
+#		} else {
+#		    $studentincorrect++;
+#		    $totalincorrect++;
+#		}
+#	    }
+#	    $r->print('<pre>'.
+#		      $resource->symb().'-'.
+#		      $resource->src().'-'.'</pre>result is'.$result);
+#	    &Apache::lonhomework::showhash(%score);
 	#    if ($i eq 3) {last;}
 	}
+	$completedstudents{$uname}={'line'=>$line};
+    } continue {
 	&Apache::lonnet::delenv('form.counter');
 	&Apache::lonnet::delenv('scantron\.');
 	&Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
-             'last student Who got a '.$studentcorrect.' correct and '.
-	     $studentincorrect.' incorrect. The class has gotten '.
-             $totalcorrect.' correct and '.$totalincorrect.' incorrect');
-	last;
+						 'last student');
+	#last;
 	#FIXME
 	#get iterator for $sequence
 	#foreach question 'submit' the students answer to the server
@@ -3406,7 +3434,11 @@
 	#   generate data to pass back that includes grade recevied
 	#}
     }
-    $Apache::lonxml::debug=0;
+    &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
+    my $lasttime = &Time::HiRes::time()-$start;
+    $r->print("<p>took $lasttime</p>");
+
+    #$Apache::lonxml::debug=0;
     foreach my $delay (@delayqueue) {
 	#FIXME
 	#print out each delayed student with interface to select how
@@ -3689,6 +3721,8 @@
 	    }
 	} elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
 	    $request->print(&scantron_selectphase($request));
+	} elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
+	    $request->print(&scantron_validate_file($request));
 	} elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
 	    $request->print(&scantron_process_students($request));
 	} elsif ($command) {