Diff for /loncom/homework/functionplotresponse.pm between versions 1.36 and 1.37

version 1.36, 2010/11/12 22:23:40 version 1.37, 2010/11/13 03:22:58
Line 33  use Apache::lonlocal; Line 33  use Apache::lonlocal;
 use Apache::lonnet;  use Apache::lonnet;
     
 BEGIN {  BEGIN {
   &Apache::lonxml::register('Apache::functionplotresponse',('functionplotresponse','backgroundplot','spline','functionplotrule'));    &Apache::lonxml::register('Apache::functionplotresponse',('functionplotresponse','backgroundplot','spline',
                                                               'functionplotrule','functionplotruleset',
                                                               'functionplotelements'));
 }  }
   
 #  #
Line 660  sub populate_arrays { Line 662  sub populate_arrays {
 }  }
   
 #  #
 # Implentation of <functionplotresponse>  # Implementation of <functionplotresponse>
 #  #
   
 sub start_functionplotresponse {  sub start_functionplotresponse {
Line 678  sub start_functionplotresponse { Line 680  sub start_functionplotresponse {
   $Apache::functionplotresponse::counter=0;    $Apache::functionplotresponse::counter=0;
 # Remember rules  # Remember rules
   undef @Apache::functionplotresponse::functionplotrules;    undef @Apache::functionplotresponse::functionplotrules;
   # Remember failed rules
     if ($target eq 'grade') {
        undef @Apache::functionplotresponse::failedrules;
     }
   # Delete previous awards
     undef $Apache::functionplotresponse::awarddetail;
 # Part and ID  # Part and ID
   my $partid=$Apache::inputtags::part;    my $partid=$Apache::inputtags::part;
   my $id=&Apache::response::start_response($parstack,$safeeval);    my $id=&Apache::response::start_response($parstack,$safeeval);
Line 712  sub start_functionplotresponse { Line 720  sub start_functionplotresponse {
     $result.=&Apache::edit::start_table($token)      $result.=&Apache::edit::start_table($token)
        .'<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)         .&Apache::edit::deletelist($target,$token).'&nbsp;&nbsp;&nbsp;'
          .&Apache::edit::insertlist($target,$token)
        .'</span></td>'         .'</span></td>'
        ."<td>&nbsp;"         ."<td>&nbsp;"
        .&Apache::edit::end_row()         .&Apache::edit::end_row()
Line 745  sub start_functionplotresponse { Line 754  sub start_functionplotresponse {
   
   } elsif ($target eq 'meta') {    } elsif ($target eq 'meta') {
        $result=&Apache::response::meta_package_write('functionplotresponse');         $result=&Apache::response::meta_package_write('functionplotresponse');
   } elsif ($target eq 'web') {  
 # paste in the update routine to receive stuff back from the applet  
      $result.=&update_script($internalid);  
 # start the initscript for this applet  
      $result.=&start_init_script($internalid);  
 # put the axis commands inside  
      $result.=&axes_script($internalid,$xmin,$xmax,$ymin,$ymax,$xaxisvisible,$yaxisvisible,$gridvisible);  
      $result.=&axes_label($internalid,$xlabel,$ylabel);  
 # init script is left open  
   } elsif (($target eq 'answer') &&    } elsif (($target eq 'answer') &&
             ($env{'form.answer_output_mode'} ne 'tex') &&              ($env{'form.answer_output_mode'} ne 'tex') &&
             ($Apache::lonhomework::viewgrades == 'F')) {              ($Apache::lonhomework::viewgrades == 'F')) {
Line 912  sub functionplotrulecheck { Line 912  sub functionplotrulecheck {
         } else {          } else {
            $val=$Apache::functionplotresponse::func[$i];             $val=$Apache::functionplotresponse::func[$i];
         }          }
         &addlog("Actual value ".(defined($val)?$val:'undef').", expected $value, tolerance $tol");  
         unless (&compare_rel($relationship,$value,$val,$tol)) {           unless (&compare_rel($relationship,$value,$val,$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 for minimum and maximum lengths
Line 935  sub functionplotrulecheck { Line 935  sub functionplotrulecheck {
               return 1;                return 1;
            } else {             } else {
               &addlog("Rule $label failed.");                &addlog("Rule $label failed.");
                 my $hintlabel=$label;
                 $hintlabel=~s/^R//;
                 push(@Apache::functionplotresponse::failedrules,$hintlabel);
                 &addlog("Set hint condition $hintlabel");
               return 0;                 return 0; 
            }             }
         }          }
Line 943  sub functionplotrulecheck { Line 947  sub functionplotrulecheck {
    return 1;     return 1;
 }  }
   
 sub end_functionplotresponse {  sub start_functionplotruleset {
   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   &Apache::response::end_response;     if ($target eq 'edit') {
         return &Apache::edit::start_table($token).
   my $result;          '<tr><td><span class="LC_nobreak">'.&mt('Function Plot Rule Set').'</span></td>'
   my $id=$Apache::inputtags::response[-1];         .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
   my $partid=$Apache::inputtags::part;         .&Apache::edit::deletelist($target,$token).'&nbsp;&nbsp;&nbsp;'.
   my $internalid = $partid.'_'.$id;          &Apache::edit::insertlist($target,$token)
          .'</span></td>'
          ."<td>&nbsp;"
     if ($target eq 'edit') { $result=&Apache::edit::end_table(); }         .&Apache::edit::end_row()
     if ($target eq 'grade'         .&Apache::edit::start_spanning_row()
          && &Apache::response::submitted()         ."\n";
          && $Apache::lonhomework::type eq 'exam') {     }
   }
         &Apache::response::scored_response($partid,$id);  
   
     } elsif ($target eq 'grade'  sub end_functionplotruleset {
       my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
       my $id=$Apache::inputtags::response[-1];
       my $partid=$Apache::inputtags::part;
       my $internalid = $partid.'_'.$id;
   
       if ($target eq 'edit' ) {
           return &Apache::edit::end_table();
       }  elsif ($target eq 'grade'
          && &Apache::response::submitted()           && &Apache::response::submitted()
          && $Apache::lonhomework::type ne 'exam') {           && $Apache::lonhomework::type ne 'exam') {
         my ($response,%coords)=&get_answer_from_form_fields($internalid);  
         $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;  
         my %previous=&Apache::response::check_for_previous($response,$partid,$id);  
 #  #
 # Actually grade  # Actually grade
 #  #
         my $xmin=&Apache::lonxml::get_param('xmin',$parstack,$safeeval);          my $xmin=&Apache::lonxml::get_param('xmin',$parstack,$safeeval,-2);
         $xmin=(defined($xmin)?$xmin:-10);          $xmin=(defined($xmin)?$xmin:-10);
         my $xmax=&Apache::lonxml::get_param('xmax',$parstack,$safeeval);          my $xmax=&Apache::lonxml::get_param('xmax',$parstack,$safeeval,-2);
         $xmax=(defined($xmax)?$xmax:10);          $xmax=(defined($xmax)?$xmax:10);
         my $ymin=&Apache::lonxml::get_param('ymin',$parstack,$safeeval);          my $ymin=&Apache::lonxml::get_param('ymin',$parstack,$safeeval,-2);
         $ymin=(defined($ymin)?$ymin:-10);          $ymin=(defined($ymin)?$ymin:-10);
         my $ymax=&Apache::lonxml::get_param('ymax',$parstack,$safeeval);          my $ymax=&Apache::lonxml::get_param('ymax',$parstack,$safeeval,-2);
         $ymax=(defined($ymax)?$ymax:10);          $ymax=(defined($ymax)?$ymax:10);
   
         my $ad='';          my $ad='';
Line 1001  sub end_functionplotresponse { Line 1009  sub end_functionplotresponse {
 # If it's not wrong, it's correct   # If it's not wrong, it's correct 
            unless ($ad) { $ad='EXACT_ANS' };             unless ($ad) { $ad='EXACT_ANS' };
         }          }
           &addlog("Set hint conditions: ".join(",",@Apache::functionplotresponse::failedrules));
           &addlog("Assigned award detail: $ad");
   # Store for later to be assigned at end_functionplotresponse
           $Apache::functionplotresponse::awarddetail=$ad;
        }
   }
   
   
   sub end_functionplotresponse {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
     &Apache::response::end_response;
   
     my $result;
     my $id=$Apache::inputtags::response[-1];
     my $partid=$Apache::inputtags::part;
     my $internalid = $partid.'_'.$id;
   
       if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
       if ($target eq 'grade'
            && &Apache::response::submitted()
            && $Apache::lonhomework::type eq 'exam') {
   
           &Apache::response::scored_response($partid,$id);
   
       } elsif ($target eq 'grade'
            && &Apache::response::submitted()
            && $Apache::lonhomework::type ne 'exam') {
           my ($response,%coords)=&get_answer_from_form_fields($internalid);
           $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
           my %previous=&Apache::response::check_for_previous($response,$partid,$id);
   #
   # Assign grade
   #
           my $ad=$Apache::functionplotresponse::awarddetail;
 #  #
 # Store grading info  # Store grading info
 #  #
         $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;          $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;
         &Apache::response::handle_previous(\%previous,$ad);          &Apache::response::handle_previous(\%previous,$ad);
    } elsif ($target eq 'web') {     } elsif ($target eq 'web') {
           undef @Apache::functionplotresponse::failedrules;
      }
      return $result;
   }
   
   sub end_functionplotelements {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
     my $result='';
     my $id=$Apache::inputtags::response[-1];
     my $partid=$Apache::inputtags::part;
     my $internalid = $partid.'_'.$id;
     if ($target eq 'edit' ) {
        $result=&Apache::edit::end_table();
     } elsif ($target eq 'web') {
 # Now is the time to render all of the stored splines  # Now is the time to render all of the stored splines
      foreach my $label (keys(%Apache::functionplotresponse::splineorder)) {       foreach my $label (keys(%Apache::functionplotresponse::splineorder)) {
         $result.=&generate_spline($internalid,$label);          $result.=&generate_spline($internalid,$label);
Line 1034  sub end_functionplotresponse { Line 1089  sub end_functionplotresponse {
   }    }
   return $result;    return $result;
 }  }
   
   sub start_functionplotelements {
      my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
      my $result='';
      my $id=$Apache::inputtags::response[-1];
      my $partid=$Apache::inputtags::part;
      my $internalid = $partid.'_'.$id;
   
      if ($target eq 'edit') {
         return &Apache::edit::start_table($token).
           '<tr><td><span class="LC_nobreak">'.&mt('Function Plot Elements').'</span></td>'
          .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
          .&Apache::edit::deletelist($target,$token).'&nbsp;&nbsp;&nbsp;'.
           &Apache::edit::insertlist($target,$token)
          .'</span></td>'
          ."<td>&nbsp;"
          .&Apache::edit::end_row()
          .&Apache::edit::start_spanning_row()
          ."\n";
      } elsif ($target eq 'web') {
         my $xmin=&Apache::lonxml::get_param('xmin',$parstack,$safeeval,-2);
         $xmin=(defined($xmin)?$xmin:-10);
         my $xmax=&Apache::lonxml::get_param('xmax',$parstack,$safeeval,-2);
         $xmax=(defined($xmax)?$xmax:10);
         my $ymin=&Apache::lonxml::get_param('ymin',$parstack,$safeeval,-2);
         $ymin=(defined($ymin)?$ymin:-10);
         my $ymax=&Apache::lonxml::get_param('ymax',$parstack,$safeeval,-2);
         $ymax=(defined($ymax)?$ymax:10);
         if ($xmax<=$xmin) {
           $xmax=$xmin+20;
         }
         if ($ymax<=$ymin) {
            $ymax=$ymin+20;
         }
         my $xaxisvisible=(&Apache::lonxml::get_param('xaxisvisible',$parstack,$safeeval,-2)=~/on|true|yes|1/i?'true':'false');
         my $yaxisvisible=(&Apache::lonxml::get_param('yaxisvisible',$parstack,$safeeval,-2)=~/on|true|yes|1/i?'true':'false');
         my $gridvisible=(&Apache::lonxml::get_param('gridvisible',$parstack,$safeeval,-2)=~/on|true|yes|1/i?'true':'false');
         my $xlabel=&Apache::lonxml::get_param('xlabel',$parstack,$safeeval,-2);
         my $ylabel=&Apache::lonxml::get_param('ylabel',$parstack,$safeeval,-2);
   
   
   # paste in the update routine to receive stuff back from the applet
        $result.=&update_script($internalid);
   # start the initscript for this applet
        $result.=&start_init_script($internalid);
   # put the axis commands inside
        $result.=&axes_script($internalid,$xmin,$xmax,$ymin,$ymax,$xaxisvisible,$yaxisvisible,$gridvisible);
        $result.=&axes_label($internalid,$xlabel,$ylabel);
   # init script is left open
     }
     return $result;
   }
   
 1;  1;
   

Removed from v.1.36  
changed lines
  Added in v.1.37


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