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

raeburn raeburn at source.lon-capa.org
Sun Jul 2 12:50:31 EDT 2017


raeburn		Sun Jul  2 16:50:31 2017 EDT

  Modified files:              
    /loncom/homework	grades.pm structuretags.pm 
  Log:
  - Support <randomlist> around parts in bubblesheet grading with CODEs.
  
  
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.740 loncom/homework/grades.pm:1.741
--- loncom/homework/grades.pm:1.740	Fri May 19 19:25:05 2017
+++ loncom/homework/grades.pm	Sun Jul  2 16:50:30 2017
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.740 2017/05/19 19:25:05 raeburn Exp $
+# $Id: grades.pm,v 1.741 2017/07/02 16:50:30 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -293,7 +293,7 @@
     }
 
     sub scantron_partids_tograde {
-        my ($resource,$cid,$uname,$udom,$check_for_randomlist,$bubbles_per_row) = @_;
+        my ($resource,$cid,$uname,$udom,$check_for_randomlist,$bubbles_per_row,$scancode) = @_;
         my (%analysis, at parts);
         if (ref($resource)) {
             my $symb = $resource->symb();
@@ -301,6 +301,13 @@
             if ($check_for_randomlist) {
                 $add_to_form = { 'check_parts_withrandomlist' => 1,};
             }
+            if ($scancode) {
+                if (ref($add_to_form) eq 'HASH') {
+                    $add_to_form->{'code_for_randomlist'} = $scancode;
+                } else {
+                    $add_to_form = { 'code_for_randomlist' => $scancode,};
+                }
+            }
             my $analyze = 
                 &get_analyze($symb,$uname,$udom,undef,$add_to_form,
                              undef,undef,undef,$bubbles_per_row);
@@ -8601,9 +8608,14 @@
             }
             if ((exists($grader_randomlists_by_symb{$ressymb})) ||
                 (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
+                my $currcode;
+                if (exists($grader_randomlists_by_symb{$ressymb})) {
+                    $currcode = $scancode;
+                }
                 my ($analysis,$parts) =
                     &scantron_partids_tograde($resource,$env{'request.course.id'},
-                                              $uname,$udom,undef,$bubbles_per_row);
+                                              $uname,$udom,undef,$bubbles_per_row,
+                                              $currcode);
                 $partids_by_symb{$ressymb} = $parts;
             } else {
                 $partids_by_symb{$ressymb} = $grader_partids_by_symb{$ressymb};
@@ -9258,10 +9270,14 @@
             my $ressymb = $resource->symb();
             if ((exists($grader_randomlists_by_symb{$ressymb})) ||
                 (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
+                my $currcode;
+                if (exists($grader_randomlists_by_symb{$ressymb})) {
+                    $currcode = $scancode;
+                }
                 (my $analysis,$parts) =
                     &scantron_partids_tograde($resource,$env{'request.course.id'},
                                               $username,$domain,undef,
-                                              $bubbles_per_row);
+                                              $bubbles_per_row,$currcode);
             } else {
                 $parts = $grader_partids_by_symb{$ressymb};
             }
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.554 loncom/homework/structuretags.pm:1.555
--- loncom/homework/structuretags.pm:1.554	Mon Feb  6 19:54:19 2017
+++ loncom/homework/structuretags.pm	Sun Jul  2 16:50:30 2017
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.554 2017/02/06 19:54:19 damieng Exp $
+# $Id: structuretags.pm,v 1.555 2017/07/02 16:50:30 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -678,10 +678,11 @@
     unless (defined($questiontype)) {
         $questiontype = $Apache::lonhomework::type;
     }
-    if ($env{'request.state'} eq "construct" 
-	|| $symb eq '' 
-	|| $Apache::lonhomework::type eq 'practice'
-	|| $Apache::lonhomework::history{'resource.CODE'}) {
+    if (($env{'request.state'} eq "construct")
+        || ($symb eq '')
+        || ($Apache::lonhomework::type eq 'practice')
+        || ($Apache::lonhomework::history{'resource.CODE'})
+        || (($env{'form.code_for_randomlist'}) && ($target eq 'analyze'))) {
 	&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 						['rndseed']);
 	$rndseed=$env{'form.rndseed'};
@@ -690,7 +691,9 @@
 	    if (!$rndseed) {
 		$rndseed=time;
 	    }
-	    $env{'form.rndseed'}=$rndseed;
+            unless ($env{'form.code_for_randomlist'}) {
+                $env{'form.rndseed'}=$rndseed;
+            }
 	}
         if (($env{'request.state'} eq "construct") && 
             ($Apache::lonhomework::type eq 'randomizetry')) {
@@ -718,7 +721,11 @@
 	       $rndseed=join(':',&Apache::lonnet::digest($rndseed));
             }
         }
-        if ($Apache::lonhomework::history{'resource.CODE'}) {
+        if (($env{'form.code_for_randomlist'}) && ($target eq 'analyze')) {
+            $env{'form.CODE'} = $env{'form.code_for_randomlist'};
+            $rndseed=&Apache::lonnet::rndseed();
+            undef($env{'form.CODE'});
+        } elsif ($Apache::lonhomework::history{'resource.CODE'}) {
 	   $rndseed=&Apache::lonnet::rndseed();
 	}
         $set_safespace = 1;
@@ -2592,7 +2599,12 @@
 	}
 	if (@randomlist) {
 	    my @idx_arr = (0 .. $#randomlist);
-	    &Apache::structuretags::shuffle(\@idx_arr);
+            if ($env{'form.code_for_randomlist'}) {
+                &Apache::structuretags::shuffle(\@idx_arr,$target);
+                undef($env{'form.code_for_randomlist'});
+            } else {
+                &Apache::structuretags::shuffle(\@idx_arr);
+            }
 	    my $bodytext = '';
 	    my $show=$#randomlist;
 	    my $showarg=&Apache::lonxml::get_param('show',$parstack,$safeeval);
@@ -2631,10 +2643,10 @@
 }
 
 sub shuffle {
-    my $a=shift;
+    my ($a,$target) = @_;
     my $i;
     if (ref($a) eq 'ARRAY' && @$a) {
-	&Apache::response::pushrandomnumber();
+	&Apache::response::pushrandomnumber(undef,$target);
 	for($i=@$a;--$i;) {
 	    my $j=int(&Math::Random::random_uniform() * ($i+1));
 	    next if $i == $j;




More information about the LON-CAPA-cvs mailing list