[LON-CAPA-cvs] cvs: loncom /homework default_homework.lcpm /html/adm/help/tex Problem_LON-CAPA_Functions.tex Script_Functions.tex

www www@source.lon-capa.org
Sun, 22 May 2011 03:04:54 -0000


www		Sun May 22 03:04:54 2011 EDT

  Modified files:              
    /loncom/homework	default_homework.lcpm 
    /loncom/html/adm/help/tex	Problem_LON-CAPA_Functions.tex 
                             	Script_Functions.tex 
  Log:
  Function to generate wrong answer bubbles
  
  
Index: loncom/homework/default_homework.lcpm
diff -u loncom/homework/default_homework.lcpm:1.154 loncom/homework/default_homework.lcpm:1.155
--- loncom/homework/default_homework.lcpm:1.154	Sat May 21 14:50:36 2011
+++ loncom/homework/default_homework.lcpm	Sun May 22 03:04:51 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run()
 #
-# $Id: default_homework.lcpm,v 1.154 2011/05/21 14:50:36 www Exp $
+# $Id: default_homework.lcpm,v 1.155 2011/05/22 03:04:51 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1221,6 +1221,28 @@
     return &EXT('user.resource.resource.'.$partid.'.'.$which);
 }
 
+sub wrong_bubbles {
+    my ($correct,$lower,$upper,$step,@given)=@_;
+    my @array=();
+    my %hash=();
+    foreach my $new (@given) {
+        $hash{$new}=1;
+    }
+    my $num=int(&parameter_setting('numbubbles',&currentpart()));
+    unless ($num) { $num=8; }
+    if ($num>1) {
+        for (my $i=0;$i<=500;$i++) {
+            my $new=&random($lower,$upper,$step);
+            if ($hash{$new}) { next; }
+            if (abs($new-$correct)<$step) { next; }
+            $hash{$new}=1;
+            @array=keys(%hash);
+            if ($#array+2>=$num) { last; }
+        }
+    }
+    return @array;
+}
+
 sub array_moments {
     my @input=@_;
     my (@output,$N);
Index: loncom/html/adm/help/tex/Problem_LON-CAPA_Functions.tex
diff -u loncom/html/adm/help/tex/Problem_LON-CAPA_Functions.tex:1.21 loncom/html/adm/help/tex/Problem_LON-CAPA_Functions.tex:1.22
--- loncom/html/adm/help/tex/Problem_LON-CAPA_Functions.tex:1.21	Sat May 21 14:50:44 2011
+++ loncom/html/adm/help/tex/Problem_LON-CAPA_Functions.tex	Sun May 22 03:04:54 2011
@@ -149,6 +149,9 @@
 
 \&stored\_data(\$name,\$partid) & Returns the stored data \$name. Partid is optional.\\
 \hline
+\&wrong\_bubbles(\$correct,\$lower,\$upper,\$step,\@given) & Returns an array that can be used for wrong answers in numerical responses. The first argument is the correct answer, the next arguments are the lower and upper boundaries for the bubbles, as well as the step size. The next argument is an 
+optional array of wrong answers that should be included.\\
+\hline 
 
 \&currentpart() & 
 Returns the ID of the current part.\\
Index: loncom/html/adm/help/tex/Script_Functions.tex
diff -u loncom/html/adm/help/tex/Script_Functions.tex:1.12 loncom/html/adm/help/tex/Script_Functions.tex:1.13
--- loncom/html/adm/help/tex/Script_Functions.tex:1.12	Sat May 21 14:50:44 2011
+++ loncom/html/adm/help/tex/Script_Functions.tex	Sun May 22 03:04:54 2011
@@ -44,6 +44,7 @@
 \item caparesponse\_check\_list
 \item parameter\_setting(name,partid)
 \item stored\_data(name,partid)
+\item wrong\_bubbles(correct,lower,upper,step,\@given)
 \end{itemize}