[LON-CAPA-cvs] cvs: loncom /homework grades.pm scantronformat.tab /interface lonprintout.pm

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 20 Apr 2004 06:11:49 -0000


This is a MIME encoded message

--albertel1082441509
Content-Type: text/plain

albertel		Tue Apr 20 02:11:49 2004 EDT

  Modified files:              
    /loncom/homework	grades.pm scantronformat.tab 
    /loncom/interface	lonprintout.pm 
  Log:
  - saving work in progress
  - fixed 'MSU with COde in sepearate location' entry to be correct
  - printing  Anonymous
      - removed useless checkbox
      - added ability to reuse a previously saved set of CODEs
  - Grading
      - most of CODE validation work done, still need to get correction information from user
  
      - saving of correction info should work but untested
      - corrected some random typos
  
  
  
--albertel1082441509
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20040420021149.txt"

Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.185 loncom/homework/grades.pm:1.186
--- loncom/homework/grades.pm:1.185	Wed Mar 31 00:23:59 2004
+++ loncom/homework/grades.pm	Tue Apr 20 02:11:49 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.185 2004/03/31 05:23:59 albertel Exp $
+# $Id: grades.pm,v 1.186 2004/04/20 06:11:49 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3445,6 +3445,30 @@
     return $result;
 }
 
+sub scantron_CODElist {
+    my $cdom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
+    my $cnum = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
+    my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
+    my $namechoice='<option></option>';
+    foreach my $name (@names) {
+	$namechoice.='<option value="'.$name.'">'.$name.'</option>';
+    }
+    $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
+    return $namechoice;
+}
+
+sub scantron_CODEunique {
+    my $result='<nobr>
+                 <input type="radio" name="scantron_CODEunique"
+                        value="Yes" checked="on" /> Yes
+                </nobr>
+                <nobr>
+                 <input type="radio" name="scantron_CODEunique"
+                        value="No" /> No
+                </nobr>';
+    return $result;
+}
+
 sub scantron_selectphase {
     my ($r) = @_;
     my ($symb,$url)=&get_symb_and_url($r);
@@ -3454,6 +3478,8 @@
     my $grading_menu_button=&show_grading_menu_form($symb,$url);
     my $file_selector=&scantron_uploads();
     my $format_selector=&scantron_scantab();
+    my $CODE_selector=&scantron_CODElist();
+    my $CODE_unique=&scantron_CODEunique();
     my $result;
     #FIXME allow instructor to be able to download the scantron file
     # and to upload it,
@@ -3480,6 +3506,12 @@
             <td> Format of data file: </td><td> $format_selector </td>
           </tr>
           <tr bgcolor="#ffffe6">
+            <td> Saved CODEs to validate against: </td><td> $CODE_selector</td>
+          </tr>
+          <tr bgcolor="#ffffe6">
+            <td> Each CODE is only to be used once:</td><td> $CODE_unique </td>
+          </tr>
+          <tr bgcolor="#ffffe6">
             <td>
 <!-- FIXME this is lazy, a single parse of the set should let me know what this is -->
               Last line to expect an answer on: </td><td>
@@ -3603,7 +3635,7 @@
     my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
     if ($field eq 'ID') {
 	if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
-	    return ($line,1,'New value to large');
+	    return ($line,1,'New value too large');
 	}
 	if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
 	    $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
@@ -3615,6 +3647,19 @@
 	    &scan_data($scan_data,"$whichline.user",
 		       $args->{'username'}.':'.$args->{'domain'});
 	}
+    } elsif ($field eq 'CODE') {
+	if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
+	    return ($line,1,'New CODE value too large');
+	}
+	if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
+	    $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',
+				       $args->{'CODE'});
+	}
+	substr($line,$$scantron_config{'CODEstart'}-1,
+	       $$scantron_config{'CODElength'})=$args->{'CODE'};
+	if ($args->{'CODE'}=~/^\s*$/) {
+	    &scan_data($scan_data,"$whichline.CODE",$args->{'CODE'});
+	}
     } elsif ($field eq 'answer') {
 	my $length=$scantron_config->{'Qlength'};
 	my $off=$scantron_config->{'Qoff'};
@@ -3748,6 +3793,11 @@
 				     'ID',{'newid'=>$newid,
 				    'username'=>$ENV{'form.scantron_username'},
 				    'domain'=>$ENV{'form.scantron_domain'}});
+    } elsif ($ENV{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
+	my $newCODE=$ENV{'form.scantron_CODE'};
+	($line,$err,$errmsg)=
+	    &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
+				     'CODE',{'CODE'=>$newCODE});
     } elsif ($ENV{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
 	foreach my $question (split(',',$ENV{'form.scantron_questions'})) {
 	    ($line,$err,$errmsg)=
@@ -3941,7 +3991,7 @@
 					 $line,'duplicateID',$username);
 		return(1);
 	    }
-	    #FIXME store away line we prviously saw the ID on to use above
+	    #FIXME store away line we previously saw the ID on to use above
 	    $found{'ids'}{$found}++;
 	    $found{'usernames'}{$username}++;
 	} else {
@@ -3988,7 +4038,7 @@
     $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
     $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
     if ($error =~ /ID$/) {
-	if ($error eq 'unknownID') {
+	if ($error eq 'incorrectID') {
 	    $r->print("The encoded ID is not in the classlist</p>\n");
 	} elsif ($error eq 'duplicateID') {
 	    $r->print("The encoded ID has also been used by a previous paper $arg</p>\n");
@@ -4006,9 +4056,23 @@
 				       'scantron_username','scantron_domain'));
 	$r->print(": <input type='text' name='scantron_username' value='' />");
 	$r->print("\n@".
-		 &Apache::loncommon::select_dom_form($ENV{'request.role..domain'},'scantron_domain'));
+		 &Apache::loncommon::select_dom_form($ENV{'request.role.domain'},'scantron_domain'));
 
 	$r->print('</li>');
+    } elsif ($error =~ /CODE$/) {
+	if ($error eq 'incorrectCODE') {
+	    $r->print("The encoded CODE is not in the list of possible CODEs</p>\n");
+	} elsif ($error eq 'duplicateCODE') {
+	    $r->print("The encoded CODE has also been used by a previous paper $arg, and CODEs were supposed to be unique</p>\n");
+	}
+	$r->print("<p>The ID on the form is  <tt>".
+		  $$scan_record{'scantron.ID'}."</tt><br />\n");
+	$r->print("The name on the paper is ".
+		  $$scan_record{'scantron.LastName'}.",".
+		  $$scan_record{'scantron.FirstName'}."</p>");
+	$r->print("<p>How should I handle this? <br /> \n");
+	$r->print("\n<ul><li> ");
+	$r->print('</li>');
     } elsif ($error eq 'doublebubble') {
 #FIXME Need to print out who this is along with the paper info
 	$r->print("<p>There have been multiple bubbles scanned for a some question(s)</p>\n");
@@ -4060,6 +4124,48 @@
 sub scantron_validate_CODE {
     my ($r,$currentphase) = @_;
     #FIXME doesn't do anything yet
+    my %scantron_config=&get_scantron_config($ENV{'form.scantron_format'});
+    if ($scantron_config{'CODElocation'} &&
+	$scantron_config{'CODEstart'} &&
+	$scantron_config{'CODElength'}) {
+	if (!$ENV{'form.scantron_CODElist'}) {
+	    &FIXME_blow_up()
+	}
+    } else {
+	&Apache::lonnet::logthis(" CODE stuf $scantron_config{'CODElocation'}:$scantron_config{'CODEstart'}:$scantron_config{'CODElength'}");
+	return (0,$currentphase+1);
+    }
+    
+    my %usedCODEs;
+
+    my $old_name=$ENV{'form.scantron_CODElist'};
+    my $cdom =$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
+    my $cnum =$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
+    my %result=&Apache::lonnet::get('CODEs',[$old_name],$cdom,$cnum);
+    my %allcodes=map {($_,1)} split(',',$result{$old_name});
+
+    my ($scanlines,$scan_data)=&scantron_getfile();
+    for (my $i=0;$i<=$scanlines->{'count'};$i++) {
+	my $line=&scantron_get_line($scanlines,$i);
+	if ($line=~/^[\s\cz]*$/) { next; }
+	my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
+						 $scan_data);
+	my $CODE=$$scan_record{'scantron.CODE'};
+	my $error=0;
+	if (!exists($allcodes{$CODE})) {
+	    &scantron_get_correction($r,$i,$scan_record,
+				     \%scantron_config,
+				     $line,'incorrectCODE',$CODE);
+	    return(1);
+	}
+	if (exists($usedCODEs{$CODE}) && $ENV{'form.scantron_CODEunique'}) {
+	    &scantron_get_correction($r,$i,$scan_record,
+				     \%scantron_config,
+				     $line,'duplicateCODE',$CODE);
+	    return(1);
+	}
+	$usedCODEs{$CODE}++;
+    }
     return (0,$currentphase+1);
 }
 
Index: loncom/homework/scantronformat.tab
diff -u loncom/homework/scantronformat.tab:1.6 loncom/homework/scantronformat.tab:1.7
--- loncom/homework/scantronformat.tab:1.6	Thu Jan 29 12:44:56 2004
+++ loncom/homework/scantronformat.tab	Tue Apr 20 02:11:49 2004
@@ -1,6 +1,6 @@
 #FIXME still need support for question style
 #name:description:code location:CODEstart:CODElength:IDstart:IDlength:Qstart:Qlength:Qoff:Qon:PaperID:PaperIDlength:FirstName:FirstNamelength:LastName:LastNamelength
 msunocode:MSU without any CODE:0:0:0:57:9:77:10: :1:5:5:51:1:41:10
+msucode:MSU with CODE in separate location:-1:69:6:57:9:77:10: :1:5:5:51:1:41:10
 #need updating:
-msucode:MSU with CODE in separate location:-1:69:6:57:9:77:10: :1
 msucodequest:MSU with CODE in first 6 questions:6:0:0:57:9:77:1012
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.291 loncom/interface/lonprintout.pm:1.292
--- loncom/interface/lonprintout.pm:1.291	Mon Apr 19 11:39:35 2004
+++ loncom/interface/lonprintout.pm	Tue Apr 20 02:11:49 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.291 2004/04/19 15:39:35 sakharuk Exp $
+# $Id: lonprintout.pm,v 1.292 2004/04/20 06:11:49 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1002,20 +1002,36 @@
 	 $result .= $print_array[0].'  \end{document}';
      } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_anon')     ||
 	      ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_anon')  ) { 
+	 my $cdom =$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
+	 my $cnum =$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
 	 my $num_todo=$helper->{'VARS'}->{'NUMBER_TO_PRINT_TOTAL'};
 	 my $code_name=$helper->{'VARS'}->{'ANON_CODE_STORAGE_NAME'};
-	 if ($helper->{'VARS'}->{'REMEBER_ANON_CODES'} != 1) {
-	     $code_name=undef;
-	 }
+	 my $old_name=$helper->{'VARS'}->{'REUSE_OLD_CODES'};
 	 my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};
 	 my ($type) = split(/_/,$helper->{'VARS'}->{'PRINT_TYPE'});
 	 my $flag_latex_header_remove = 'NO'; 
 	 my %moreenv = ('textwidth' => &get_textwidth($helper,$LaTeXwidth));
 	 my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$num_todo,'inline');
 	 my $seed=time+($$<<16)+($$);
-	 my %allcodes;
-	 for (my $i=0;$i<$num_todo;$i++) {
-	     $moreenv{'CODE'}=&get_CODE(\%allcodes,$i,$seed,'6');
+	 my @allcodes;
+	 if ($old_name) {
+	     my %result=&Apache::lonnet::get('CODEs',[$old_name],$cdom,$cnum);
+	     @allcodes=split(',',$result{$old_name});
+	 } else {
+	     my %allcodes;
+	     for (my $i=0;$i<$num_todo;$i++) {
+		 $moreenv{'CODE'}=&get_CODE(\%allcodes,$i,$seed,'6');
+	     }
+	     if ($code_name) {
+		 &Apache::lonnet::put('CODEs',
+				      {$code_name =>join(',',keys(%allcodes))},
+				      $cdom,$cnum);
+	     }
+	     @allcodes=keys(%allcodes);
+	 }
+	 my $i=0;
+	 foreach my $code (sort(@allcodes)) {
+	     $moreenv{'CODE'}=&num_to_letters($code);
 	     my ($output,$fullname)=
 		 &print_resources($r,$helper,'anonymous',$type,\%moreenv,
 				  \@master_seq,$flag_latex_header_remove);
@@ -1023,13 +1039,7 @@
 	     &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
 				       &mt('last assignment').' '.$fullname);
 	     $flag_latex_header_remove = 'YES';
-	 }
-	 if ($code_name) {
-	     my $cdom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
-	     my $cnum = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
-	     &Apache::lonnet::put('CODEs',
-				  { $code_name => join(',',keys(%allcodes)) },
-				  $cdom,$cnum);
+	     $i++;
 	 }
 	 &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
 	 $result .= $print_array[0].'  \end{document}';
@@ -1567,18 +1577,26 @@
     $resource_selector
   </state>
 CHOOSE_STUDENTS
+
+	my $cdom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
+	my $cnum = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
+        my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
+	my $namechoice='<choice></choice>';
+	foreach my $name (@names) {
+	    $namechoice.='<choice computer="'.$name.'">'.$name.'</choice>';
+	}
         &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_ANON1);
   <state name="CHOOSE_ANON1" title="Select Students and Resources">
     <nextstate>PAGESIZE</nextstate>
     <message><hr width='33%' /><b>Number of anonymous assignments to print?</b></message>
     <string variable="NUMBER_TO_PRINT_TOTAL" maxlength="5" size="5"></string>
-    <choices variable="REMEBER_ANON_CODES" allowempty="1" multichoice="1">
-      <choice computer="1">
-        Should the CODEs used on this printing be remebered for later?
-      </choice>
-    </choices>
-    <message><b>Names to store the CODEs under for later:</b></message>
+    <message><br /><b>Names to store the CODEs under for later:</b></message>
     <string variable="ANON_CODE_STORAGE_NAME" maxlength="50" size="20" />
+    <message><hr width='33%' /></message>
+    <message><b>Reprint a set of saved CODEs:</b></message>
+    <dropdown variable="REUSE_OLD_CODES">
+        $namechoice
+    </dropdown>
     <message><hr width='33%' /></message>
     $resource_selector
   </state>

--albertel1082441509--