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

raeburn raeburn at source.lon-capa.org
Thu Oct 31 11:01:23 EDT 2019


raeburn		Thu Oct 31 15:01:23 2019 EDT

  Modified files:              
    /loncom/homework	structuretags.pm 
  Log:
  - Bug 6917. In Authoring Space, if randomizetry parameter in effect:
    (a) Check for randomizeontries paraemeter when displaying in Authoring Space.
    (b) Include "New Problem Variation After Every N Tries" header.
  
  
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.563 loncom/homework/structuretags.pm:1.564
--- loncom/homework/structuretags.pm:1.563	Sun Aug 11 12:27:11 2019
+++ loncom/homework/structuretags.pm	Thu Oct 31 15:01:22 2019
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.563 2019/08/11 12:27:11 raeburn Exp $
+# $Id: structuretags.pm,v 1.564 2019/10/31 15:01:22 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -669,13 +669,23 @@
 sub setup_rndseed {
     my ($safeeval,$target,$probpartlist)=@_;
     my ($symb)=&Apache::lonnet::whichuser();
-    my ($questiontype,$set_safespace,$rndseed);
+    my ($questiontype,$set_safespace,$rndseed,$numtries,$reqtries);
     if ($target eq 'analyze') {
         $questiontype = $env{'form.grade_questiontype'};
     }
     unless (defined($questiontype)) {
         $questiontype = $Apache::lonhomework::type;
     }
+    if ($Apache::lonhomework::type eq 'randomizetry') {
+        my $partfortries = $Apache::inputtags::part;
+        if (ref($probpartlist) eq 'ARRAY') {
+            if ((@{$probpartlist} == 1) && ($probpartlist->[0] ne $Apache::inputtags::part)) {
+                $partfortries = $probpartlist->[0];
+            }
+        }
+        $numtries = $Apache::lonhomework::history{"resource.$partfortries.tries"};
+        $reqtries = &Apache::lonnet::EXT("resource.$partfortries.randomizeontries");
+    }
     if (($env{'request.state'} eq "construct")
         || ($symb eq '')
         || ($Apache::lonhomework::type eq 'practice')
@@ -695,9 +705,13 @@
 	}
         if (($env{'request.state'} eq "construct") && 
             ($Apache::lonhomework::type eq 'randomizetry')) {
-            my $tries = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.tries"};
-            if ($tries) {
-                $rndseed += $tries;
+            if ($numtries) {
+                if (($reqtries =~ /^\d+$/) && ($reqtries > 1)) {
+                    my $inc = int($numtries/$reqtries);
+                    $rndseed += $inc;
+                } else {
+                    $rndseed += $numtries;
+                }
             }
             $env{'form.'.$Apache::inputtags::part.'.rndseed'}=$rndseed;
         }
@@ -735,13 +749,7 @@
         }
         unless (($target eq 'analyze') && (defined($rndseed))) {
             $rndseed=&Apache::lonnet::rndseed();
-            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"};
+            my $curr_try = $numtries;
             if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
                 $curr_try ++;
             }
@@ -749,7 +757,6 @@
                 $rndseed = $1;
             }
             if ($curr_try) {
-                my $reqtries = &Apache::lonnet::EXT("resource.$partfortries.randomizeontries");
                 if (($reqtries =~ /^\d+$/) && ($reqtries > 1)) {
                     my $inc = int(($curr_try-1)/$reqtries);
                     $rndseed += $inc;
@@ -1930,6 +1937,10 @@
                     $result.= '<button type="submit" name="resetdata" '.
                         'value="new_problem_variation">'.&mt('New Problem Variation').'</button>'.
                         &practice_problem_header().'<hr />';
+                } elsif ($Apache::lonhomework::type eq 'randomizetry') {
+                    my $reqtries = &Apache::lonnet::EXT("resource.$Apache::inputtags::part.randomizeontries");
+                    my $problemstatus = &get_problem_status($Apache::inputtags::part);
+                    $result.=&randomizetry_problem_header($problemstatus,$reqtries);
                 }
 	    }
 	    # if we are viewing someone else preserve that info




More information about the LON-CAPA-cvs mailing list