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

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 29 Apr 2004 07:21:16 -0000


albertel		Thu Apr 29 03:21:16 2004 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  - now able to restart on a data file, by removing all saved corrections
  - no allows one to force through a duplicate CODE even when CODEs are suppose to be unique
  
  
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.191 loncom/homework/grades.pm:1.192
--- loncom/homework/grades.pm:1.191	Thu Apr 29 00:47:47 2004
+++ loncom/homework/grades.pm	Thu Apr 29 03:21:16 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.191 2004/04/29 04:47:47 albertel Exp $
+# $Id: grades.pm,v 1.192 2004/04/29 07:21:16 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3517,8 +3517,8 @@
           <tr bgcolor="#ffffe6">
 	    <td> Options: </td>
             <td>
-                <input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> Redo skipped records <br />
-                <input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> Ignore Original Corrections
+                <input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> Do only skipped records <br />
+                <input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> Remove any exisiting corrections
 	    </td>
           </tr>
           <tr bgcolor="#ffffe6">
@@ -3685,9 +3685,11 @@
 		       $args->{'username'}.':'.$args->{'domain'});
 	}
     } elsif ($field eq 'CODE') {
-	if ($args->{'CODE'} eq 'use_unfound') {
-	    &scan_data($scan_data,"$whichline.useCODE",'1');
-	} else {
+	if ($args->{'CODE_ignore_dup'}) {
+	    &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
+	}
+	&scan_data($scan_data,"$whichline.useCODE",'1');
+	if ($args->{'CODE'} ne 'use_unfound') {
 	    if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
 		return ($line,1,'New CODE value too large');
 	    }
@@ -3696,9 +3698,6 @@
 	    }
 	    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'};
@@ -3742,6 +3741,9 @@
 	    if (&scan_data($scan_data,"$whichline.useCODE")) {
 		$record{'scantron.useCODE'}=1;
 	    }
+	    if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
+		$record{'scantron.CODE_ignore_dup'}=1;
+	    }
 	} else {
 	    #FIXME interpret first N questions
 	}
@@ -3841,6 +3843,7 @@
     } elsif ($ENV{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
 	my $resolution=$ENV{'form.scantron_CODE_resolution'};
 	my $newCODE;
+	my %args;
 	if      ($resolution eq 'use_unfound') {
 	    $newCODE='use_unfound';
 	} elsif ($resolution eq 'use_found') {
@@ -3848,9 +3851,13 @@
 	} elsif ($resolution eq 'use_typed') {
 	    $newCODE=$ENV{'form.scantron_CODE_newvalue'};
 	}
+	if ($ENV{'form.scantron_corrections'} eq 'duplicateCODE') {
+	    $args{'CODE_ignore_dup'}=1;
+	}
+	$args{'CODE'}=$newCODE;
 	($line,$err,$errmsg)=
 	    &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
-				     'CODE',{'CODE'=>$newCODE});
+				     'CODE',\%args);
     } elsif ($ENV{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
 	foreach my $question (split(',',$ENV{'form.scantron_questions'})) {
 	    ($line,$err,$errmsg)=
@@ -3875,7 +3882,14 @@
     my ($symb,$url)=&get_symb_and_url($r);
     if (!$symb) {return '';}
     my $default_form_data=&defaultFormData($symb,$url);
-
+    if ($ENV{'form.scantron_options_ignore'} eq 'ignore_corrections') {
+	my $result=&scantron_remove('corrected');
+	&Apache::lonnet::logthis("result was $result");
+	if ($result ne 'ok' && $result ne 'not_found' ) {
+	    $r->print("An error occured ($result) when trying to Remove the existing corrections.");
+	}
+	$ENV{'form.scantron_options_ignore'}='done';
+    }
     if ($ENV{'form.scantron_corrections'}) {
 	&scantron_process_corrections($r);
     }
@@ -3891,8 +3905,8 @@
   <input type="hidden" name="scantron_maxbubble" value="$max_bubble'" />
   <input type="hidden" name="scantron_CODElist" value="$ENV{'form.scantron_CODElist'}" />
   <input type="hidden" name="scantron_CODEunique" value="$ENV{'form.scantron_CODEunique'}" />
-  <input type="hidden" name="scantron_options_redo" value="$ENV{'form.scantron_optiond_redo'}" />
-  <input type="hidden" name="scantron_options_ignore" value="$ENV{'form.scantron_optiond_ignore'}" />
+  <input type="hidden" name="scantron_options_redo" value="$ENV{'form.scantron_options_redo'}" />
+  <input type="hidden" name="scantron_options_ignore" value="$ENV{'form.scantron_options_ignore'}" />
   $default_form_data
 SCANTRONFORM
     $r->print($result);
@@ -3939,6 +3953,37 @@
     return '';
 }
 
+sub scantron_remove {
+    my ($which)=@_;
+    my $cname=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
+    my $cdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
+    my $file='scantron_';
+    if ($which eq 'corrected') {
+	$file.='corrected_';
+    } else {
+	return 'refused';
+    }
+    $file.=$ENV{'form.scantron_selectfile'};
+    &Apache::lonnet::logthis("removeing $file");
+    my $result=&Apache::lonnet::removeuserfile($cname,$cdom,$file);
+    my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
+    &Apache::lonnet::logthis('got keys '.join(':',@keys));
+    &Apache::lonnet::logthis("cdom $cdom cname $cname");
+    my @todelete;
+    my $filename=$ENV{'form.scantron_selectfile'};
+    &Apache::lonnet::logthis('filename '.$filename);
+    foreach my $key (@keys) {
+	if ($key=~/^\Q$filename\E_/) {
+	    push(@todelete,$key);
+	}
+    }
+    &Apache::lonnet::logthis('todelete '.join(':',@todelete));
+    if (@todelete) {
+	&Apache::lonnet::del('nohist_scantrondata',\@todelete,$cdom,$cname);
+    }
+    return $result;
+}
+
 sub scantron_getfile {
     #FIXME really would prefer a scantron directory but tokenwrapper
     # doesn't allow access to subdirs of userfiles
@@ -4240,7 +4285,8 @@
 				     $line,'incorrectCODE',$CODE);
 	    return(1);
 	}
-	if (exists($usedCODEs{$CODE}) && $ENV{'form.scantron_CODEunique'}) {
+	if (exists($usedCODEs{$CODE}) && $ENV{'form.scantron_CODEunique'}
+	    && !$$scan_record{'scantron.CODE_ignore_dup'}) {
 	    &scantron_get_correction($r,$i,$scan_record,
 				     \%scantron_config,
 				     $line,'duplicateCODE',$CODE);