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

www www at source.lon-capa.org
Sat Nov 19 21:53:27 EST 2011


www		Sun Nov 20 02:53:27 2011 EDT

  Modified files:              
    /loncom/homework	functionplotresponse.pm 
  Log:
  Length rule working
  Use absolute error
  
  
Index: loncom/homework/functionplotresponse.pm
diff -u loncom/homework/functionplotresponse.pm:1.78 loncom/homework/functionplotresponse.pm:1.79
--- loncom/homework/functionplotresponse.pm:1.78	Sun Nov 20 00:34:52 2011
+++ loncom/homework/functionplotresponse.pm	Sun Nov 20 02:53:27 2011
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # Functionplot responses
 #
-# $Id: functionplotresponse.pm,v 1.78 2011/11/20 00:34:52 www Exp $
+# $Id: functionplotresponse.pm,v 1.79 2011/11/20 02:53:27 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -768,9 +768,9 @@
    }
    $label=~s/\W//gs;
    unless ($label) {
-      $label='V'.$Apache::functionplotresponse::counter;
+      $label='R'.$Apache::functionplotresponse::counter;
    } else {
-      $label='V'.$label;
+      $label='R'.$label;
    }
    if ($Apache::functionplotresponse::splineorder{$label}) {
        &Apache::lonxml::error(&mt('Rule indices must be unique.'));
@@ -822,8 +822,8 @@
            $nottippoint,
            &Apache::lonxml::get_param('length',$parstack,$safeeval),
            &Apache::lonxml::get_param('angle',$parstack,$safeeval),
-           &Apache::lonxml::get_param('lengthpercenterror',$parstack,$safeeval),
-           &Apache::lonxml::get_param('anglepercenterror',$parstack,$safeeval),
+           &Apache::lonxml::get_param('lengtherror',$parstack,$safeeval),
+           &Apache::lonxml::get_param('angleerror',$parstack,$safeeval),
           )));
    } elsif ($target eq 'edit') {
         $result=&Apache::edit::tag_start($target,$token,'Function Plot Vector Rule').
@@ -847,9 +847,9 @@
                                      $token,'16').
              &Apache::edit::text_arg('Angle:','angle',
                                      $token,'16').
-             &Apache::edit::text_arg('Percent error length:','lengthpercenterror',
+             &Apache::edit::text_arg('Absolute error length:','lengtherror',
                                      $token,'8').
-             &Apache::edit::text_arg('Percent error angle:','anglepercenterror',
+             &Apache::edit::text_arg('Absolute error angle:','angleerror',
                                      $token,'8').
              &Apache::edit::end_row();
   } elsif ($target eq 'modified') {
@@ -864,7 +864,7 @@
                                                  $safeeval,'index','vector','attachpoint','notattachpoint',
                                                            'tailpoint','tippoint','nottailpoint','nottipoint',
                                                            'length','angle',
-                                                           'lengthpercenterror','anglepercenterror');
+                                                           'lengtherror','angleerror');
     if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
    }
    return $result;
@@ -892,9 +892,9 @@
    }
    $label=~s/\W//gs;
    unless ($label) {
-      $label='V'.$Apache::functionplotresponse::counter;
+      $label='R'.$Apache::functionplotresponse::counter;
    } else {
-      $label='V'.$label;
+      $label='R'.$label;
    }
    if ($Apache::functionplotresponse::splineorder{$label}) {
        &Apache::lonxml::error(&mt('Rule indices must be unique.'));
@@ -916,7 +916,7 @@
            &Apache::lonxml::get_param('angle',$parstack,$safeeval),
            &Apache::lonxml::get_param('lengthpercenterror',$parstack,$safeeval),
            &Apache::lonxml::get_param('lengthabserror',$parstack,$safeeval),
-           &Apache::lonxml::get_param('anglepercenterror',$parstack,$safeeval),
+           &Apache::lonxml::get_param('angleerror',$parstack,$safeeval),
           )));
    } elsif ($target eq 'edit') {
         $result=&Apache::edit::tag_start($target,$token,'Function Plot Vector Sum Rule').
@@ -932,7 +932,7 @@
                                      $token,'8').
              &Apache::edit::text_arg('Absolute error length:','lengthabserror',
                                      $token,'8').
-             &Apache::edit::text_arg('Percent error angle:','anglepercenterror',
+             &Apache::edit::text_arg('Error angle:','angleerror',
                                      $token,'8').
              &Apache::edit::end_row();
   } elsif ($target eq 'modified') {
@@ -940,7 +940,7 @@
     my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                                                  $safeeval,'index','object',
                                                            'length','angle',
-                                                           'lengthpercenterror','lengthabserror','anglepercenterror');
+                                                           'lengthpercenterror','lengthabserror','angleerror');
     if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
    }
    return $result;
@@ -1432,15 +1432,30 @@
    my ($label,$type,$id,$vector,
        $attachpoint,$notattachpoint,
        $tailpoint,$tippoint,$nottailpoint,$nottippoint,
-       $length,$angle,$lengthpercenterror,$anglepercenterror)=split(/\:/,$rule);
+       $length,$angle,$lengtherror,$angleerror)=split(/\:/,$rule);
    &addlog("Vector Rule $label for vector ".$vector);
-
+   if ($length ne '') {
+      &addlog("Checking for length $length with error $lengtherror");
+      $length=&Apache::run::run($length,$safeeval);
+      &addlog("Length evaluated to $length");
+      my $thislength=&plotvectorlength($id,$vector);
+      &addlog("Found length $thislength");
+      if (abs($thislength-$length)>$lengtherror) {
+         &setfailed($label);
+         return 0;
+      }
+   }
+   &addlog("Rule $label passed.");
+   return 1;
 }
 
 sub sumcheck {
    my ($rule,$xmin,$xmax,$ymin,$ymax,$safeeval)=@_;
-   my ($label,$type,$id,$object,$length,$angle,$lengthpercenterror,$lengthabserror,$anglepercenterror)=split(/\:/,$rule);
+   my ($label,$type,$id,$object,$length,$angle,$lengthpercenterror,$lengthabserror,$angleerror)=split(/\:/,$rule);
    &addlog("Vector Sum Rule $label for vectors attached to ".$object);
+
+   &addlog("Rule $label passed.");
+   return 1;
 }
 
 #
@@ -1542,10 +1557,7 @@
      unless (&compare_rel($relationship,$value,$integral,$tol)) {
         &addlog("Actual integral ".(defined($integral)?$integral:'undef').", expected $value, tolerance $tol");
         &addlog("Rule $label failed.");
-        my $hintlabel=$label;
-        $hintlabel=~s/^R//;
-        push(@Apache::functionplotresponse::failedrules,$hintlabel);
-        &addlog("Set hint condition $hintlabel");
+        &setfailed($label);
         return 0;
      } 
    } else {
@@ -1611,8 +1623,7 @@
 }
 
 sub setfailed {
-   my ($label)=@_;
-   my $hintlabel=$label;
+   my ($hintlabel)=@_;
    $hintlabel=~s/^R//;
    push(@Apache::functionplotresponse::failedrules,$hintlabel);
    &addlog("Set hint condition $hintlabel");




More information about the LON-CAPA-cvs mailing list