Diff for /loncom/homework/functionplotresponse.pm between versions 1.48 and 1.52

version 1.48, 2010/11/24 15:30:45 version 1.52, 2011/01/26 20:20:50
Line 108  sub init_script { Line 108  sub init_script {
           $script.="if (param=='applet_$id') { loaded_$id=true; }\n";            $script.="if (param=='applet_$id') { loaded_$id=true; }\n";
       }        }
       $script.="if (".join(' && ',map { "loaded_$_" } (@Apache::functionplotresponse::callscripts)).        $script.="if (".join(' && ',map { "loaded_$_" } (@Apache::functionplotresponse::callscripts)).
                ") { setTimeout('ggbInitAll()',20) }";                 ") { setTimeout('ggbInitAll()',200) }";
       my $calls=join("\n",map { "ggbInit_$_();" } (@Apache::functionplotresponse::callscripts));         my $calls=join("\n",map { "ggbInit_$_();" } (@Apache::functionplotresponse::callscripts)); 
       return (<<ENDGGBINIT);        return (<<ENDGGBINIT);
 <script type="text/javascript">  <script type="text/javascript">
Line 184  sub set_slope_coordinate { Line 184  sub set_slope_coordinate {
    my $mult=($fixed?'a*':'');     my $mult=($fixed?'a*':'');
    return (<<ENDSETSVARIABLE);     return (<<ENDSETSVARIABLE);
 document.ggbApplet_$id.evalCommand("a=1");  document.ggbApplet_$id.evalCommand("a=1");
 document.ggbApplet_$id.evalCommand("$xvariable=Slider[0,$domain,$xinterval]");  document.ggbApplet_$id.evalCommand("$xvariable=Slider[$xinterval,$domain,$xinterval]");
 document.ggbApplet_$id.setVisible("$xvariable", false);  document.ggbApplet_$id.setVisible("$xvariable", false);
 document.ggbApplet_$id.evalCommand("$xvariable=$xrel");  document.ggbApplet_$id.evalCommand("$xvariable=$xrel");
 document.ggbApplet_$id.evalCommand("$yvariable=Slider[-$range,$range,$yinterval]");  document.ggbApplet_$id.evalCommand("$yvariable=Slider[-$range,$range,$yinterval]");
Line 816  sub start_functionplotresponse { Line 816  sub start_functionplotresponse {
        .'<tr><td><span class="LC_nobreak">'.&mt('Function Plot Question').'</span></td>'         .'<tr><td><span class="LC_nobreak">'.&mt('Function Plot Question').'</span></td>'
        .'<td><span class="LC_nobreak">'.&mt('Delete?').' '         .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
        .&Apache::edit::deletelist($target,$token).'&nbsp;&nbsp;&nbsp;'         .&Apache::edit::deletelist($target,$token).'&nbsp;&nbsp;&nbsp;'
        .&Apache::edit::insertlist($target,$token)         .&Apache::edit::insertlist($target,$token).'&nbsp;&nbsp;&nbsp;'
          .&Apache::loncommon::help_open_topic('Function_Plot_Response_Question','Function Plot Responses')
        .'</span></td>'         .'</span></td>'
        ."<td>&nbsp;"         ."<td>&nbsp;"
        .&Apache::edit::end_row()         .&Apache::edit::end_row()
Line 943  sub functionplotrulecheck { Line 944  sub functionplotrulecheck {
    $percent=($percent>0?$percent:5);     $percent=($percent>0?$percent:5);
    &addlog("=================");     &addlog("=================");
    &addlog("Rule $label for ".($derivative<0?'integral':('function itself','first derivative','second derivative')[$derivative])." $relationship $value");     &addlog("Rule $label for ".($derivative<0?'integral':('function itself','first derivative','second derivative')[$derivative])." $relationship $value");
      if ((defined($minimumlength)) || (defined($maximumlength))) {
         &addlog("Minimumlength $minimumlength Maximumlength $maximumlength");
      }
    my $li=0;     my $li=0;
    my $lh=400;     my $lh=400;
   
Line 1037  sub functionplotrulecheck { Line 1041  sub functionplotrulecheck {
            &addlog("Actual value ".(defined($val)?$val:'undef').", expected $value, tolerance $tol");             &addlog("Actual value ".(defined($val)?$val:'undef').", expected $value, tolerance $tol");
            &addlog("Condition not fulfilled at x=".&actualval($i,$xmin,$xmax)." (".$Apache::functionplotresponse::actualxval[$i]."; index $i)");             &addlog("Condition not fulfilled at x=".&actualval($i,$xmin,$xmax)." (".$Apache::functionplotresponse::actualxval[$i]."; index $i)");
            if (($findupper) && ($i>$li)) {             if (($findupper) && ($i>$li)) {
 # check for minimum and maximum lengths  # Check lengths
               my $length=&actualval($i,$xmin,$xmax)-&actualval($li,$xmin,$xmax);                unless (&checklength($i,$li,$minimumlength,$maximumlength,$xmin,$xmax,$label)) { return 0; }
               if ($minimumlength) {  # Successfully found a new label, set it
                  if ($length<$minimumlength) {  
                     &addlog("Rule $label failed, actual length $length, minimum length $minimumlength");  
                     return 0;  
                  }  
               }  
               if ($maximumlength) {  
                  if ($length>$maximumlength) {  
                     &addlog("Rule $label failed, actual length $length, maximum length $maximumlength");  
                     return 0;  
                  }  
               }  
               $Apache::functionplotresponse::functionplotrulelabels{$xfinallabel}=$i;                $Apache::functionplotresponse::functionplotrulelabels{$xfinallabel}=$i;
               &addlog("Rule $label passed, setting label $xfinallabel");                &addlog("Rule $label passed, setting label $xfinallabel");
               return 1;                return 1;
            } else {             } else {
               &addlog("Rule $label failed.");                &addlog("Rule $label failed.");
               my $hintlabel=$label;                &setfailed($label);
               $hintlabel=~s/^R//;  
               push(@Apache::functionplotresponse::failedrules,$hintlabel);  
               &addlog("Set hint condition $hintlabel");  
               return 0;                 return 0; 
            }             }
         }          }
      }       }
    }     }
   # Corner case where this makes sense: using start or stop as defined labels
      unless (&checklength($lh,$li,$minimumlength,$maximumlength,$xmin,$xmax,$label)) { return 0; }
    &addlog("Rule $label passed.");     &addlog("Rule $label passed.");
    return 1;     return 1;
 }  }
   
   #
   # check for minimum and maximum lengths
   #
   
   sub checklength {
       my ($i,$li,$minimumlength,$maximumlength,$xmin,$xmax,$label)=@_;
       unless (($minimumlength) || ($maximumlength)) { return 1; }
       my $length=&actualval($i,$xmin,$xmax)-&actualval($li,$xmin,$xmax);
       if ($minimumlength) {
          if ($length<$minimumlength) {
             &addlog("Rule $label failed, actual length $length, minimum length $minimumlength");
             &setfailed($label);
             return 0;
          }
       }
       if ($maximumlength) {
          if ($length>$maximumlength) {
             &addlog("Rule $label failed, actual length $length, maximum length $maximumlength");
             &setfailed($label);
             return 0;
          }
       }
       return 1;
   }
   
   sub setfailed {
      my ($label)=@_;
      my $hintlabel=$label;
      $hintlabel=~s/^R//;
      push(@Apache::functionplotresponse::failedrules,$hintlabel);
      &addlog("Set hint condition $hintlabel");
   }
   
 sub start_functionplotruleset {  sub start_functionplotruleset {
    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
    if ($target eq 'edit') {     if ($target eq 'edit') {
Line 1076  sub start_functionplotruleset { Line 1101  sub start_functionplotruleset {
         '<tr><td><span class="LC_nobreak">'.&mt('Function Plot Rule Set').'</span></td>'          '<tr><td><span class="LC_nobreak">'.&mt('Function Plot Rule Set').'</span></td>'
        .'<td><span class="LC_nobreak">'.&mt('Delete?').' '         .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
        .&Apache::edit::deletelist($target,$token).'&nbsp;&nbsp;&nbsp;'.         .&Apache::edit::deletelist($target,$token).'&nbsp;&nbsp;&nbsp;'.
         &Apache::edit::insertlist($target,$token)          &Apache::edit::insertlist($target,$token).'&nbsp;&nbsp;&nbsp;'
          .&Apache::loncommon::help_open_topic('Function_Plot_Response_Rule_Set','Function Plot Rules')
        .'</span></td>'         .'</span></td>'
        ."<td>&nbsp;"         ."<td>&nbsp;"
        .&Apache::edit::end_row()         .&Apache::edit::end_row()
Line 1254  sub start_functionplotelements { Line 1280  sub start_functionplotelements {
         '<tr><td><span class="LC_nobreak">'.&mt('Function Plot Elements').'</span></td>'          '<tr><td><span class="LC_nobreak">'.&mt('Function Plot Elements').'</span></td>'
        .'<td><span class="LC_nobreak">'.&mt('Delete?').' '         .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
        .&Apache::edit::deletelist($target,$token).'&nbsp;&nbsp;&nbsp;'.         .&Apache::edit::deletelist($target,$token).'&nbsp;&nbsp;&nbsp;'.
         &Apache::edit::insertlist($target,$token)          &Apache::edit::insertlist($target,$token).'&nbsp;&nbsp;&nbsp;'
          .&Apache::loncommon::help_open_topic('Function_Plot_Response_Elements','Function Plot Elements')
        .'</span></td>'         .'</span></td>'
        ."<td>&nbsp;"         ."<td>&nbsp;"
        .&Apache::edit::end_row()         .&Apache::edit::end_row()

Removed from v.1.48  
changed lines
  Added in v.1.52


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>