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

raeburn raeburn at source.lon-capa.org
Sat Feb 21 20:34:48 EST 2015


raeburn		Sun Feb 22 01:34:48 2015 EDT

  Modified files:              
    /loncom/homework	response.pm grades.pm structuretags.pm 
  Log:
  - Bug 6476
    - Store rawrndseed for parts with all responsetypes.
    - Eliminate storage of rndseed, since rawrndseed is the item needed to
      reconstruct the randomization for a problem in Authoring Space.
    - If questiontype is randomizetry rawrndseed and rndseed are the same,
      so use rawrndseed from the submission history, where it exists.
    - Support use of randomizetry for script blocks outside a part block in 
      problems with a single <part></part> tag.
    - Support use of randomizetry for script blocks inside part blocks.
  Note: randomizetry does not apply to randomization in script blocks 
  outside part blocks for problems with multiple parts, because the 
  number of tries is not uniquely defined. 
  
  
-------------- next part --------------
Index: loncom/homework/response.pm
diff -u loncom/homework/response.pm:1.239 loncom/homework/response.pm:1.240
--- loncom/homework/response.pm:1.239	Fri Feb 20 22:14:49 2015
+++ loncom/homework/response.pm	Sun Feb 22 01:34:48 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # various response type definitons response definition
 #
-# $Id: response.pm,v 1.239 2015/02/20 22:14:49 damieng Exp $
+# $Id: response.pm,v 1.240 2015/02/22 01:34:48 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -181,7 +181,6 @@
     } else {
 	($rndmod,$rndmod2)=&Apache::lonnet::digest("$id1,$id2");
     }
-    $Apache::lonhomework::results{'resource.'.$id1.'.rawrndseed'}=$rndseed;
     if ($rndseed =~/([,:])/) {
 	my $char=$1;
 	use integer;
@@ -198,7 +197,6 @@
 	}
     }
     &Apache::lonxml::debug("randseed $rndmod $rndseed");
-    $Apache::lonhomework::results{'resource.'.$id1.'.rndseed'}=$rndseed;
     &Apache::lonnet::setup_random_from_rndseed($rndseed);
     return '';
 }
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.731 loncom/homework/grades.pm:1.732
--- loncom/homework/grades.pm:1.731	Tue Feb 10 04:02:17 2015
+++ loncom/homework/grades.pm	Sun Feb 22 01:34:48 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.731 2015/02/10 04:02:17 raeburn Exp $
+# $Id: grades.pm,v 1.732 2015/02/22 01:34:48 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2231,7 +2231,11 @@
                 if ($hide eq 'rand') {
                     $type = 'randomizetry';
                     $trial = $record{"resource.$partid.tries"};
-                    $rndseed = $record{"resource.$partid.rndseed"};
+                    if (exists($record{"resource.$partid.rawrndseed"})) {
+                        $rndseed = $record{"resource.$partid.rawrndseed"};
+                    } else {
+                        $rndseed = $record{"resource.$partid.rndseed"};
+                    }
                 }
 	        if ($env{'form.checkPlag'}) {
     		    my ($oname,$odom,$ocrsid,$oessay,$osim)=
@@ -2543,7 +2547,7 @@
             }
             unless ($hide) {
                 if (@randomize) {
-                    foreach my $id (@hidden) {
+                    foreach my $id (@randomize) {
                         if ($key =~ /^\Q$id\E/) {
                             $hide = 'rand';
                             last;
@@ -4857,7 +4861,11 @@
                         my ($trial,$rndseed,$newvariation);
                         if ($type eq 'randomizetry') {
                             $trial = $$record{"$where.$partid.tries"};
-                            $rndseed = $$record{"$where.$partid.rndseed"};
+                            if (exists($$record{"$where.$partid.rawrndseed"})) {
+                                $rndseed = $$record{"$where.$partid.rawrndseed"};
+                            } else {
+                                $rndseed = $$record{"$where.$partid.rndseed"};
+                            }
                         }
 		        if ($$record{"$where.$partid.tries"} eq '') {
 			    $displaySub[0].=&mt('Trial not counted');
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.527 loncom/homework/structuretags.pm:1.528
--- loncom/homework/structuretags.pm:1.527	Mon Jan 19 15:35:53 2015
+++ loncom/homework/structuretags.pm	Sun Feb 22 01:34:48 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.527 2015/01/19 15:35:53 goltermann Exp $
+# $Id: structuretags.pm,v 1.528 2015/02/22 01:34:48 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -347,7 +347,7 @@
         $extra_head .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args);
     }
     my $is_task = ($env{'request.uri'} =~ /\.task$/);
-    my $needs_upload;
+    my ($needs_upload,$partlist);
     my ($symb)= &Apache::lonnet::whichuser();
     my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
     if ($is_task) {
@@ -365,6 +365,12 @@
                     unless ($is_page) {
                         $needs_upload = 1;
                     }
+                    if ((ref($tagstack) eq 'ARRAY') && ($tagstack->[-1] eq 'problem')) {
+                        my $res = $navmap->getBySymb($symb);
+                        if (ref($res)) {
+                            $partlist = $res->parts();
+                        }
+                    }
                 }
             }
         } else {
@@ -376,10 +382,17 @@
                     if (ref($mapres)) {
                         $is_page = $mapres->is_page();
                     }
-                    unless ($is_page) {
+                    if ($is_page) {
+                        if ((ref($tagstack) eq 'ARRAY') && ($tagstack->[-1] eq 'problem')) {
+                            my $res = $navmap->getBySymb($symb);
+                            if (ref($res)) {
+                                $partlist = $res->parts();
+                            }
+                        }
+                    } else {
                         my $res = $navmap->getBySymb($symb);
                         if (ref($res)) {
-                            my $partlist = $res->parts();
+                            $partlist = $res->parts();
                             if (ref($partlist) eq 'ARRAY') {
                                 foreach my $part (@{$partlist}) {
                                     my @types = $res->responseType($part);
@@ -515,7 +528,7 @@
 		"\t".'<input type="hidden" name="symb" value="'.$symb.'" />'."\n";
 	}
     }
-    return ($page_start,$form_tag_start);
+    return ($page_start,$form_tag_start,$partlist);
 }
 
 #use Time::HiRes();
@@ -546,7 +559,7 @@
 }
 
 sub setup_rndseed {
-    my ($safeeval,$target)=@_;
+    my ($safeeval,$target,$probpartlist)=@_;
     my ($symb)=&Apache::lonnet::whichuser();
     my ($questiontype,$set_safespace,$rndseed);
     if ($target eq 'analyze') {
@@ -607,7 +620,13 @@
         }
         unless (($target eq 'analyze') && (defined($rndseed))) {
             $rndseed=&Apache::lonnet::rndseed();
-            my $curr_try = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.tries"};
+            my $partfortries = $Apache::inputtags::part;
+            if (ref($probpartlist) eq 'ARRAY') {
+                if ((@{$probpartlist} == 1) && ($probpartlist->[0] ne $Apache::inputtags::part)) {
+                    $partfortries = $probpartlist->[0];
+                }
+            }
+            my $curr_try = $Apache::lonhomework::history{"resource.$partfortries.tries"};
             if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
                 $curr_try ++;
             }
@@ -615,7 +634,7 @@
                 $rndseed = $1;
             }
             if ($curr_try) {
-                my $reqtries = &Apache::lonnet::EXT("resource.$Apache::inputtags::part.randomizeontries");
+                my $reqtries = &Apache::lonnet::EXT("resource.$partfortries.randomizeontries");
                 if (($reqtries =~ /^\d+$/) && ($reqtries > 1)) {
                     my $inc = int(($curr_try-1)/$reqtries);
                     $rndseed += $inc;
@@ -625,6 +644,9 @@
             }
         }
         $set_safespace = 1;
+        if ($target eq 'grade') {
+            $Apache::lonhomework::rawrndseed = $rndseed;
+        }
     }
     if ($set_safespace) {
         if ($safeeval) {
@@ -1512,6 +1534,8 @@
     undef($Apache::inputtags::part);
     if ($type eq 'Task') {
         undef($Apache::inputtags::slot_name);
+    } elsif ($type eq 'problem') {
+        undef($Apache::lonhomework::rawrndseed);
     }
 #don't undef this, lonhomework.pm takes care of this, we use this to 
 #detect if we try to do 2 problems in one file
@@ -1613,7 +1637,7 @@
     my $resource_due;
 
     my $name= &get_resource_name($parstack,$safeeval);
-    my ($result,$form_tag_start,$slot_name,$slot);
+    my ($result,$form_tag_start,$slot_name,$slot,$probpartlist);
 
     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
         $target eq 'tex') {
@@ -1629,9 +1653,18 @@
 
     if ($target eq 'web' || $target eq 'webgrade' || $target eq 'tex'
 	|| $target eq 'edit') {
-	($result,$form_tag_start) =
+	($result,$form_tag_start,$probpartlist) =
 	    &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval,
 			$name);
+    } elsif (($target eq 'grade') && ($Apache::lonhomework::type eq 'randomizetry')) {
+        my ($symb)= &Apache::lonnet::whichuser();
+        my $navmap = Apache::lonnavmaps::navmap->new();
+        if (ref($navmap)) {
+            my $res = $navmap->getBySymb($symb);
+            if (ref($res)) {
+                $probpartlist = $res->parts();
+            }
+        }
     }
 
     if ($target eq 'tex' and $env{'request.symb'} =~ m/\.page_/) {$result='';}
@@ -1641,7 +1674,20 @@
 	$target eq 'tex') {
 
 	#handle rand seed in construction space
-	my $rndseed=&setup_rndseed($safeeval,$target);
+	my $rndseed=&setup_rndseed($safeeval,$target,$probpartlist);
+        if (($target eq 'grade') && &Apache::response::submitted()) {
+            if ($Apache::lonhomework::type eq 'randomizetry') {
+                $Apache::lonhomework::results{'resource.0.rawrndseed'}=$rndseed;
+            } else {
+                my @parts;
+                if (ref($probpartlist) eq 'ARRAY') {
+                    @parts = @{$probpartlist};
+                }
+                unless (@parts) {
+                    $Apache::lonhomework::results{'resource.0.rawrndseed'}=$Apache::lonhomework::rawrndseed;
+                }
+            }
+        }
 	my ($symb)=&Apache::lonnet::whichuser();
 
 	if ($env{'request.state'} ne "construct" && 
@@ -2698,6 +2744,14 @@
     my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part);
     my $newtype=&Apache::lonnet::EXT("resource.$id.type");
     if ($newtype) { $Apache::lonhomework::type=$newtype; }
+    if ($Apache::lonhomework::type eq 'randomizetry') {
+        my $rndseed=&setup_rndseed($safeeval,$target);
+        if (($target eq 'grade') && &Apache::response::submitted()) {
+            $Apache::lonhomework::results{"resource.$id.rawrndseed"}=$rndseed;
+        }
+    } elsif (($target eq 'grade') && &Apache::response::submitted()) {
+        $Apache::lonhomework::results{"resource.$id.rawrndseed"}=$Apache::lonhomework::rawrndseed;
+    }
     my $in_order_show=&ordered_show_check();
     my $expression='$external::part=\''.$Apache::inputtags::part.'\';';
     $expression.='$external::type=\''.$Apache::lonhomework::type.'\';';


More information about the LON-CAPA-cvs mailing list