[LON-CAPA-cvs] cvs: loncom /homework functionplotresponse.pm /homework/templates functionplotone.problem functionplotone.problem.meta doc/loncapafiles loncapafiles.lpml

www www@source.lon-capa.org
Thu, 11 Nov 2010 03:53:33 -0000


www		Thu Nov 11 03:53:33 2010 EDT

  Added files:                 
    /loncom/homework/templates	functionplotone.problem 
                              	functionplotone.problem.meta 

  Modified files:              
    /doc/loncapafiles	loncapafiles.lpml 
    /loncom/homework	functionplotresponse.pm 
  Log:
  * Implement tolerance on rule-level
  * Template
  
  
Index: doc/loncapafiles/loncapafiles.lpml
diff -u doc/loncapafiles/loncapafiles.lpml:1.709 doc/loncapafiles/loncapafiles.lpml:1.710
--- doc/loncapafiles/loncapafiles.lpml:1.709	Wed Sep 29 02:48:41 2010
+++ doc/loncapafiles/loncapafiles.lpml	Thu Nov 11 03:51:36 2010
@@ -2,7 +2,7 @@
  "http://lpml.sourceforge.net/DTD/lpml.dtd">
 <!-- loncapafiles.lpml -->
 
-<!-- $Id: loncapafiles.lpml,v 1.709 2010/09/29 02:48:41 raeburn Exp $ -->
+<!-- $Id: loncapafiles.lpml,v 1.710 2010/11/11 03:51:36 www Exp $ -->
 
 <!--
 
@@ -1311,6 +1311,8 @@
 Essay.problem.meta;
 examupload.problem;
 examupload.problem.meta;
+functionplotone.problem;
+functionplotone.problem.meta;
 HintFormula.problem;
 HintFormula.problem.meta;
 HintMathResponse.problem;
Index: loncom/homework/functionplotresponse.pm
diff -u loncom/homework/functionplotresponse.pm:1.32 loncom/homework/functionplotresponse.pm:1.33
--- loncom/homework/functionplotresponse.pm:1.32	Wed Nov 10 22:53:32 2010
+++ loncom/homework/functionplotresponse.pm	Thu Nov 11 03:52:35 2010
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # option list style responses
 #
-# $Id: functionplotresponse.pm,v 1.32 2010/11/10 22:53:32 www Exp $
+# $Id: functionplotresponse.pm,v 1.33 2010/11/11 03:52:35 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -389,7 +389,8 @@
            &Apache::lonxml::get_param('xfinal',$parstack,$safeeval),
            $endinglabel,
            $relationship,
-           &Apache::lonxml::get_param('value',$parstack,$safeeval)
+           &Apache::lonxml::get_param('value',$parstack,$safeeval),
+           &Apache::lonxml::get_param('percenterror',$parstack,$safeeval)
           )));
    } elsif ($target eq 'edit') {
         $result=&Apache::edit::tag_start($target,$token,'Function Plot Evaluation Rule').
@@ -791,10 +792,13 @@
 }
 
 sub functionplotrulecheck {
-   my ($rule,$xmin,$xmax,$tolfunc,$toldfdx,$told2fdx2)=@_;
-#   &Apache::lonnet::logthis("Rule $rule TolFunc $tolfunc TolDfDx $toldfdx TolD2fDx2 $told2fdx2");
-   my ($label,$derivative,$xinitial,$xinitiallabel,$xfinal,$xfinallabel,$relationship,$value)
+   my ($rule,$xmin,$xmax,$ymin,$ymax)=@_;
+
+#   &Apache::lonnet::logthis("Rule $rule $xmin $xmax $ymin $ymax");
+
+   my ($label,$derivative,$xinitial,$xinitiallabel,$xfinal,$xfinallabel,$relationship,$value,$percent)
       =split(/\:/,$rule);
+   $percent=($percent>0?$percent:5);
 
    my $li=0;
    my $lh=400;
@@ -827,7 +831,7 @@
    }
    unless ($findupper) {
       if (defined($Apache::functionplotresponse::functionplotrulelabels{$xfinallabel})) {
-         $lh=$Apache::functionplotresponse::functionplotrulelabels{$xfinallabel};
+         $lh=$Apache::functionplotresponse::functionplotrulelabels{$xfinallabel}-1;
       } else {
          $lh=&array_index($xmin,$xmax,$xfinal);
       }
@@ -840,11 +844,13 @@
    }
 
 #   &Apache::lonnet::logthis("Init $xinitial=$li Final $xfinal=$lh Findupper: $findupper");
-   my $tol=$tolfunc;
-   if ($derivative==2) {
-      $tol=$told2fdx2;
-   } elsif ($derivative==1) {
-      $tol=$toldfdx;
+   my $tol=$percent*($ymax-$ymin)/100;
+   if ($xmax>$xmin) {
+      if ($derivative==2) {
+         $tol=4.*$tol/($xmax-$xmin);
+      } elsif ($derivative==1) {
+         $tol=2.*$tol/($xmax-$xmin);
+      }
    }
    for (my $i=$li; $i<=$lh; $i++) {
         my $val;
@@ -856,7 +862,7 @@
            $val=$Apache::functionplotresponse::func[$i];
         }
         unless (&compare_rel($relationship,$value,$val,$tol)) { 
-#           &Apache::lonnet::logthis("Condition false $findupper at $i with $val");
+#           &Apache::lonnet::logthis("Condition false $findupper at $i with $val tol:$tol from $value");
            if (($findupper) && ($i>$li)) {
               $Apache::functionplotresponse::functionplotrulelabels{$xfinallabel}=$i;
 #              &Apache::lonnet::logthis("Setting $xfinallabel to $i");
@@ -903,17 +909,6 @@
         my $ymax=&Apache::lonxml::get_param('ymax',$parstack,$safeeval);
         $ymax=(defined($ymax)?$ymax:10);
 
-        my $percent=&Apache::lonxml::get_param('percenterror',$parstack,$safeeval);
-        $percent=(defined($percent)?$percent:5);
-
-        my $tolfunc=$percent*($ymax-$ymin)/100.;
-        my $toldfdx=1;
-        my $told2fdx2=1;
-        if ($xmax>$xmin) {
-           $toldfdx=$tolfunc/($xmax-$xmin);
-           $told2fdx2=$toldfdx/($xmax-$xmin);
-        }
-
         my $ad='';
         undef  %Apache::functionplotresponse::functionplotrulelabels;
         $Apache::functionplotresponse::functionplotrulelabels{'start'}=400;
@@ -923,7 +918,7 @@
         } else {
 # We have a function that we can actually grade, go through the spline rules.
            foreach my $rule (@Apache::functionplotresponse::functionplotrules) {
-              unless (&functionplotrulecheck($rule,$xmin,$xmax,$tolfunc,$toldfdx,$told2fdx2)) {
+              unless (&functionplotrulecheck($rule,$xmin,$xmax,$ymin,$ymax)) {
                  $ad='INCORRECT';
                  last;
               }

Index: loncom/homework/templates/functionplotone.problem
+++ loncom/homework/templates/functionplotone.problem
<problem>
<script type="loncapa/perl">$maxacc=&random(3,5,1);
$maxbraketime=&random(6,10,2);</script>
<startouttext />
At t=0 s, a car cruises at a constant positive velocity. Suddenly, a light switches to red. At t=$maxbraketime s, the driver is maximum on the brake. The car then stops in front of the red light for a while. Eventually, it drives off, and then again cruises at a constant velocity. Provide a graph of its acceleration as a function of time. The car cannot accelerate with more than $maxacc m/s<sup>2</sup>.<br />
<endouttext />
<functionplotresponse xaxisvisible="yes" xlabel="t [s]" gridvisible="yes" ylabel="a(t) [m/s^2]" id="11" xmax="30" yaxisvisible="yes" xmin="-4" ymin="-8" ymax="8">
<spline initx="-2" inity="0" index="A" order="8" scalex="28" />
<functionplotrule relationship="eq" xinitiallabel="start" xfinallabel="brake" value="0" derivative="0" percenterror="1" />
<functionplotrule relationship="eq" xinitial="0" value="0" derivative="0" percenterror="1" />
<functionplotrule relationship="lt" xinitiallabel="brake" xfinallabel="stop" value="0.1" derivative="0" />
<functionplotrule relationship="eq" xinitial="$maxbraketime" value="0" derivative="1" percenterror="40" />
<functionplotrule relationship="eq" xinitiallabel="stop" xfinallabel="driveoff" value="0" derivative="0" percenterror="1" />
<functionplotrule relationship="gt" xinitiallabel="driveoff" xfinallabel="cruise" value="0.1" derivative="0" />
<functionplotrule relationship="le" xinitiallabel="driveoff" xfinallabel="cruise" value="$maxacc" derivative="0" />
<functionplotrule relationship="eq" xinitiallabel="cruise" xfinallabel="end" value="0" derivative="0" percenterror="1" />
</functionplotresponse>
</problem>

Index: loncom/homework/templates/functionplotone.problem.meta
+++ loncom/homework/templates/functionplotone.problem.meta
<title>Functionplotresponse with Labels</title>
<category>Free Form Problems</category>