--- loncom/homework/functionplotresponse.pm 2010/11/12 22:23:40 1.36 +++ loncom/homework/functionplotresponse.pm 2010/11/13 03:22:58 1.37 @@ -1,7 +1,7 @@ # LearningOnline Network with CAPA # option list style responses # -# $Id: functionplotresponse.pm,v 1.36 2010/11/12 22:23:40 www Exp $ +# $Id: functionplotresponse.pm,v 1.37 2010/11/13 03:22:58 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -33,7 +33,9 @@ use Apache::lonlocal; use Apache::lonnet; BEGIN { - &Apache::lonxml::register('Apache::functionplotresponse',('functionplotresponse','backgroundplot','spline','functionplotrule')); + &Apache::lonxml::register('Apache::functionplotresponse',('functionplotresponse','backgroundplot','spline', + 'functionplotrule','functionplotruleset', + 'functionplotelements')); } # @@ -660,7 +662,7 @@ sub populate_arrays { } # -# Implentation of +# Implementation of # sub start_functionplotresponse { @@ -678,6 +680,12 @@ sub start_functionplotresponse { $Apache::functionplotresponse::counter=0; # Remember rules 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 my $partid=$Apache::inputtags::part; my $id=&Apache::response::start_response($parstack,$safeeval); @@ -712,7 +720,8 @@ sub start_functionplotresponse { $result.=&Apache::edit::start_table($token) .''.&mt('Function Plot Question').'' .''.&mt('Delete?').' ' - .&Apache::edit::deletelist($target,$token) + .&Apache::edit::deletelist($target,$token).'   ' + .&Apache::edit::insertlist($target,$token) .'' ." " .&Apache::edit::end_row() @@ -745,15 +754,6 @@ sub start_functionplotresponse { } elsif ($target eq 'meta') { $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') && ($env{'form.answer_output_mode'} ne 'tex') && ($Apache::lonhomework::viewgrades == 'F')) { @@ -912,8 +912,8 @@ sub functionplotrulecheck { } else { $val=$Apache::functionplotresponse::func[$i]; } - &addlog("Actual value ".(defined($val)?$val:'undef').", expected $value, tolerance $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)"); if (($findupper) && ($i>$li)) { # check for minimum and maximum lengths @@ -935,6 +935,10 @@ sub functionplotrulecheck { return 1; } else { &addlog("Rule $label failed."); + my $hintlabel=$label; + $hintlabel=~s/^R//; + push(@Apache::functionplotresponse::failedrules,$hintlabel); + &addlog("Set hint condition $hintlabel"); return 0; } } @@ -943,39 +947,43 @@ sub functionplotrulecheck { return 1; } -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); +sub start_functionplotruleset { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + if ($target eq 'edit') { + return &Apache::edit::start_table($token). + ''.&mt('Function Plot Rule Set').'' + .''.&mt('Delete?').' ' + .&Apache::edit::deletelist($target,$token).'   '. + &Apache::edit::insertlist($target,$token) + .'' + ." " + .&Apache::edit::end_row() + .&Apache::edit::start_spanning_row() + ."\n"; + } +} - } 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::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 # - my $xmin=&Apache::lonxml::get_param('xmin',$parstack,$safeeval); + my $xmin=&Apache::lonxml::get_param('xmin',$parstack,$safeeval,-2); $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); - my $ymin=&Apache::lonxml::get_param('ymin',$parstack,$safeeval); + my $ymin=&Apache::lonxml::get_param('ymin',$parstack,$safeeval,-2); $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); my $ad=''; @@ -1001,13 +1009,60 @@ sub end_functionplotresponse { # If it's not wrong, it's correct 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 # $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad; &Apache::response::handle_previous(\%previous,$ad); } 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 foreach my $label (keys(%Apache::functionplotresponse::splineorder)) { $result.=&generate_spline($internalid,$label); @@ -1034,6 +1089,58 @@ sub end_functionplotresponse { } 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). + ''.&mt('Function Plot Elements').'' + .''.&mt('Delete?').' ' + .&Apache::edit::deletelist($target,$token).'   '. + &Apache::edit::insertlist($target,$token) + .'' + ." " + .&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;