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

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 12 Aug 2005 21:33:44 -0000


This is a MIME encoded message

--albertel1123882424
Content-Type: text/plain

albertel		Fri Aug 12 17:33:44 2005 EDT

  Modified files:              
    /loncom/interface	lonprintout.pm 
    /loncom/homework	grades.pm 
  Log:
  - allow CODEs to have variable length and be both number and letters
  
  
--albertel1123882424
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20050812173344.txt"

Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.380 loncom/interface/lonprintout.pm:1.381
--- loncom/interface/lonprintout.pm:1.380	Tue Jul 26 06:50:32 2005
+++ loncom/interface/lonprintout.pm	Fri Aug 12 17:33:41 2005
@@ -1,7 +1,7 @@
 #  The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.380 2005/07/26 10:50:32 foxr Exp $
+# $Id: lonprintout.pm,v 1.381 2005/08/12 21:33:41 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1244,23 +1244,41 @@
 	 my $num_todo=$helper->{'VARS'}->{'NUMBER_TO_PRINT_TOTAL'};
 	 my $code_name=$helper->{'VARS'}->{'ANON_CODE_STORAGE_NAME'};
 	 my $old_name=$helper->{'VARS'}->{'REUSE_OLD_CODES'};
+	 
+	 my $code_option=$helper->{'VARS'}->{'CODE_OPTION'};
+	 open(FH,$Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
+	 my ($code_type,$code_length)=('letter',6);
+	 foreach my $line (<FH>) {
+	     my ($name,$type,$length) = (split(/:/,$line))[0,2,4];
+	     if ($name eq $code_option) {
+		 $code_length=$length;
+		 if ($type eq 'number') { $code_type = 'number'; }
+	     }
+	 }
 	 my %moreenv = ('textwidth' => &get_textwidth($helper,$LaTeXwidth));
 	 $moreenv{'problem_split'}    = $parmhash{'problem_stream_switch'};
 	 my $seed=time+($$<<16)+($$);
 	 my @allcodes;
 	 if ($old_name) {
-	     my %result=&Apache::lonnet::get('CODEs',[$old_name],$cdom,$cnum);
+	     my %result=&Apache::lonnet::get('CODEs',
+					     [$old_name,"type\0$old_name"],
+					     $cdom,$cnum);
+	     $code_type=$result{"type\0$old_name"};
 	     @allcodes=split(',',$result{$old_name});
 	     $num_todo=scalar(@allcodes);
 	 } else {
 	     my %allcodes;
 	     srand($seed);
 	     for (my $i=0;$i<$num_todo;$i++) {
-		 $moreenv{'CODE'}=&get_CODE(\%allcodes,$i,$seed,'6');
+		 $moreenv{'CODE'}=&get_CODE(\%allcodes,$i,$seed,$code_length,
+					    $code_type);
 	     }
 	     if ($code_name) {
 		 &Apache::lonnet::put('CODEs',
-				      {$code_name =>join(',',keys(%allcodes))},
+				      {
+					$code_name =>join(',',keys(%allcodes)),
+					"type\0$code_name" => $code_type
+				      },
 				      $cdom,$cnum);
 	     }
 	     @allcodes=keys(%allcodes);
@@ -1276,7 +1294,11 @@
 	 my $count=0;
 	 foreach my $code (sort(@allcodes)) {
 	     my $file_num=int($count/$number_per_page);
-	     $moreenv{'CODE'}=&num_to_letters($code);
+	     if ($code_type eq 'number') { 
+		 $moreenv{'CODE'}=$code;
+	     } else {
+		 $moreenv{'CODE'}=&num_to_letters($code);
+	     }
 	     my ($output,$fullname, $printed)=
 		 &print_resources($r,$helper,'anonymous',$type,\%moreenv,
 				  \@master_seq,$flag_latex_header_remove,
@@ -1479,14 +1501,18 @@
 }
 
 sub get_CODE {
-    my ($all_codes,$num,$seed,$size)=@_;
+    my ($all_codes,$num,$seed,$size,$type)=@_;
     my $max='1'.'0'x$size;
     my $newcode;
     while(1) {
 	$newcode=sprintf("%06d",int(rand($max)));
 	if (!exists($$all_codes{$newcode})) {
 	    $$all_codes{$newcode}=1;
-	    return &num_to_letters($newcode);
+	    if ($type eq 'number' ) {
+		return $newcode;
+	    } else {
+		return &num_to_letters($newcode);
+	    }
 	}
     }
 }
@@ -1939,8 +1965,22 @@
 	my $namechoice='<choice></choice>';
 	foreach my $name (sort {uc($a) cmp uc($b)} @names) {
 	    if ($name =~ /^error: 2 /) { next; }
+	    if ($name =~ /^type\0/) { next; }
 	    $namechoice.='<choice computer="'.$name.'">'.$name.'</choice>';
 	}
+	open(FH,$Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
+	my $codechoice='';
+	foreach my $line (<FH>) {
+	    my ($name,$description,$code_type,$code_length)=
+		(split(/:/,$line))[0,1,2,4];
+	    if ($code_length > 0 && 
+		$code_type =~/^(letter|number|-1)/) {
+		$codechoice.='<choice computer="'.$name.'">'.$description.'</choice>';
+	    }
+	}
+	if ($codechoice eq '') {
+	    $codechoice='<choice computer="default">Default</choice>';
+	}
         &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_ANON1);
   <state name="CHOOSE_ANON1" title="Select Students and Resources">
     <nextstate>PAGESIZE</nextstate>
@@ -1959,6 +1999,12 @@
     <message><b>Names to store the CODEs under for later:</b></message>
     <message></td><td></message>
     <string variable="ANON_CODE_STORAGE_NAME" maxlength="50" size="20" />
+    <message></td></tr><tr><td></message>
+    <message><b>Bubble sheet type:</b></message>
+    <message></td><td></message>
+    <dropdown variable="CODE_OPTION" multichoice="0" allowempty="0">
+    $codechoice
+    </dropdown>
     <message></td></tr></table></message>
     <message><hr width='33%' /></message>
     <message><b>Reprint a set of saved CODEs:</b></message>
@@ -2026,6 +2072,12 @@
     <message><b>Names to store the CODEs under for later:</b></message>
     <message></td><td></message>
     <string variable="ANON_CODE_STORAGE_NAME" maxlength="50" size="20" />
+    <message></td></tr><tr><td></message>
+    <message><b>Bubble sheet type:</b></message>
+    <message></td><td></message>
+    <dropdown variable="CODE_OPTION" multichoice="0" allowempty="0">
+    $codechoice
+    </dropdown>
     <message></td></tr></table></message>
     <message><hr width='33%' /></message>
     <message><b>Reprint a set of saved CODEs:</b></message>
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.277 loncom/homework/grades.pm:1.278
--- loncom/homework/grades.pm:1.277	Tue Aug  9 11:53:20 2005
+++ loncom/homework/grades.pm	Fri Aug 12 17:33:41 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.277 2005/08/09 15:53:20 albertel Exp $
+# $Id: grades.pm,v 1.278 2005/08/12 21:33:41 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2295,10 +2295,11 @@
 						'/userfiles/portfolio';
     foreach my $key (keys(%$record)) {
         my $new_portfiles;
+	
         if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
             my @v_portfiles;
             my @portfiles = split(/,/,$$record{$key});
-            # &Apache::lonnet::logthis("should be unmarking and remarking");
+            &Apache::lonnet::logthis("should be unmarking and remarking $key",@portfiles);
             foreach my $file (@portfiles) {
                 &Apache::lonnet::unmark_as_readonly($domain,$stuname,[$symb,$env{'request.course.id'}],$file);
                 my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*$)/);
@@ -3864,6 +3865,7 @@
     my $namechoice='<option></option>';
     foreach my $name (sort {uc($a) cmp uc($b)} @names) {
 	if ($name =~ /^error: 2 /) { next; }
+	if ($name =~ /^type\0/) { next; }
 	$namechoice.='<option value="'.$name.'">'.$name.'</option>';
     }
     $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
@@ -4139,8 +4141,11 @@
     my %record;
     my $questions=substr($line,$$scantron_config{'Qstart'}-1);
     my $data=substr($line,0,$$scantron_config{'Qstart'}-1);
-    if ($$scantron_config{'CODElocation'} ne 0) {
-	if ($$scantron_config{'CODElocation'} < 0) {
+    if (!($$scantron_config{'CODElocation'} eq 0 ||
+	  $$scantron_config{'CODElocation'} eq 'none')) {
+	if ($$scantron_config{'CODElocation'} < 0 ||
+	    $$scantron_config{'CODElocation'} eq 'letter' ||
+	    $$scantron_config{'CODElocation'} eq 'number') {
 	    $record{'scantron.CODE'}=substr($data,
 					    $$scantron_config{'CODEstart'}-1,
 					    $$scantron_config{'CODElength'});
@@ -4751,12 +4756,14 @@
 	if ($error eq 'incorrectCODE' 
 	    && $$scan_record{'scantron.CODE'}=~/\S/ ) {
 	    my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
-	    foreach my $testcode (@{$closest}) {
-		my $checked='';
-		if (!$i) { $checked=' checked="on" '; }
-		$r->print("<label><input type='radio' name='scantron_CODE_resolution' value='use_closest_$i' $checked /> Use the similar CODE <b><tt>".$testcode."</tt></b> instead.</label><input type='hidden' name='scantron_CODE_closest_$i' value='$testcode' />");
-		$r->print("\n<br />");
-		$i++;
+	    if ($closest > 0) {
+		foreach my $testcode (@{$closest}) {
+		    my $checked='';
+		    if (!$i) { $checked=' checked="on" '; }
+		    $r->print("<label><input type='radio' name='scantron_CODE_resolution' value='use_closest_$i' $checked /> Use the similar CODE <b><tt>".$testcode."</tt></b> instead.</label><input type='hidden' name='scantron_CODE_closest_$i' value='$testcode' />");
+		    $r->print("\n<br />");
+		    $i++;
+		}
 	    }
 	}
 	if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
@@ -4865,8 +4872,14 @@
     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 {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
+    my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
+				    $cdom,$cnum);
+    my %allcodes;
+    if ($result{"type\0$old_name"} eq 'number') {
+	%allcodes=map {($_,1)} split(',',$result{$old_name});
+    } else {
+	%allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
+    }
     return %allcodes;
 }
 

--albertel1123882424--