'.&mt('Function Plot Question').' | '
.''.&mt('Delete?').' '
.&Apache::edit::deletelist($target,$token).' '
- .&Apache::edit::insertlist($target,$token)
+ .&Apache::edit::insertlist($target,$token).' '
+ .&Apache::loncommon::help_open_topic('Function_Plot_Response_Question','Function Plot Responses')
.' | '
." "
.&Apache::edit::end_row()
@@ -836,9 +895,8 @@ sub start_functionplotresponse {
['yes','no'],$token).' '.
&Apache::edit::select_arg('Grid visible:','gridvisible',
['yes','no'],$token).' '.
- &Apache::edit::text_arg('Background plot(s) for answer (function:xmin:xmax,function:xmin:xmax,...):',
- 'answerdisplay',$token,'50');
-
+ &Apache::edit::text_arg('Background plot(s) for answer (function(x):xmin:xmax,function(x):xmin:xmax,x1:y1:sx1:sy1:x2:y2:sx2:sy2,...):',
+ 'answerdisplay',$token,'50').
&Apache::edit::end_row().&Apache::edit::start_spanning_row();
} elsif ($target eq 'modified') {
my $constructtag=&Apache::edit::get_new_args($token,$parstack,
@@ -923,6 +981,7 @@ sub compare_rel {
sub addlog {
my ($text)=@_;
+ $text=~s/\'/\\\'/g;
$Apache::functionplotresponse::ruleslog.=$text.' ';
}
@@ -930,15 +989,59 @@ sub actualval {
my ($i,$xmin,$xmax)=@_;
return $xmin+$i/400.*($xmax-$xmin);
}
+
+sub fpr_val {
+ my ($arg)=@_;
+ return &actualval($Apache::functionplotresponse::functionplotrulelabels{$arg},
+ $Apache::functionplotresponse::fpr_xmin,
+ $Apache::functionplotresponse::fpr_xmax);
+}
+
+sub fpr_f {
+ my ($arg)=@_;
+ return $Apache::functionplotresponse::func[&array_index($Apache::functionplotresponse::fpr_xmin,
+ $Apache::functionplotresponse::fpr_xmax,
+ $arg)];
+}
+
+sub fpr_dfdx {
+ my ($arg)=@_;
+ return $Apache::functionplotresponse::dfuncdx[&array_index($Apache::functionplotresponse::fpr_xmin,
+ $Apache::functionplotresponse::fpr_xmax,
+ $arg)];
+}
+
+sub fpr_d2fdx2 {
+ my ($arg)=@_;
+ return $Apache::functionplotresponse::d2funcdx2[&array_index($Apache::functionplotresponse::fpr_xmin,
+ $Apache::functionplotresponse::fpr_xmax,
+ $arg)];
+}
sub functionplotrulecheck {
- my ($rule,$xmin,$xmax,$ymin,$ymax)=@_;
+ my ($rule,$xmin,$xmax,$ymin,$ymax,$safeeval)=@_;
my ($label,$derivative,$xinitial,$xinitiallabel,$xfinal,$xfinallabel,$minimumlength,$maximumlength,$relationship,$value,$percent)
=split(/\:/,$rule);
$percent=($percent>0?$percent:5);
&addlog("=================");
&addlog("Rule $label for ".($derivative<0?'integral':('function itself','first derivative','second derivative')[$derivative])." $relationship $value");
+#
+# Evaluate the value
+#
+ if ($value=~/\D/) {
+ $Apache::functionplotresponse::fpr_xmin=$xmin;
+ $Apache::functionplotresponse::fpr_xmax=$xmax;
+ $value=&Apache::run::run($value,$safeeval);
+ &addlog("Value evaluated to $value");
+ }
+
+#
+# Minimum and maximum lengths of the interval
+#
+ if ((defined($minimumlength)) || (defined($maximumlength))) {
+ &addlog("Minimumlength $minimumlength Maximumlength $maximumlength");
+ }
my $li=0;
my $lh=400;
@@ -1033,38 +1136,59 @@ sub functionplotrulecheck {
&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
- 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");
- return 0;
- }
- }
- if ($maximumlength) {
- if ($length>$maximumlength) {
- &addlog("Rule $label failed, actual length $length, maximum length $maximumlength");
- return 0;
- }
- }
+# Check lengths
+ unless (&checklength($i,$li,$minimumlength,$maximumlength,$xmin,$xmax,$label)) { return 0; }
+# Successfully found a new label, set it
$Apache::functionplotresponse::functionplotrulelabels{$xfinallabel}=$i;
&addlog("Rule $label passed, setting label $xfinallabel");
return 1;
} else {
&addlog("Rule $label failed.");
- my $hintlabel=$label;
- $hintlabel=~s/^R//;
- push(@Apache::functionplotresponse::failedrules,$hintlabel);
- &addlog("Set hint condition $hintlabel");
+ &setfailed($label);
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.");
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 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
if ($target eq 'edit') {
@@ -1072,7 +1196,8 @@ sub start_functionplotruleset {
' |
'.&mt('Function Plot Rule Set').' | '
.''.&mt('Delete?').' '
.&Apache::edit::deletelist($target,$token).' '.
- &Apache::edit::insertlist($target,$token)
+ &Apache::edit::insertlist($target,$token).' '
+ .&Apache::loncommon::help_open_topic('Function_Plot_Response_Rule_Set','Function Plot Rules')
.' | '
." "
.&Apache::edit::end_row()
@@ -1102,7 +1227,7 @@ sub end_functionplotruleset {
$Apache::functionplotresponse::ruleslog='';
$Apache::functionplotresponse::functionplotrulelabels{'start'}=400;
$Apache::functionplotresponse::functionplotrulelabels{'end'}=0;
- if (&populate_arrays($internalid,$xmin,$xmax) eq 'no_func') {
+ if (&populate_arrays($internalid,$xmin,$xmax,$ymin,$ymax) eq 'no_func') {
$ad='NOT_FUNCTION';
} else {
&addlog("Start of function ".&actualval($Apache::functionplotresponse::functionplotrulelabels{'start'},$xmin,$xmax)." (index ".
@@ -1112,7 +1237,7 @@ sub end_functionplotruleset {
# 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,$ymin,$ymax)) {
+ unless (&functionplotrulecheck($rule,$xmin,$xmax,$ymin,$ymax,$safeeval)) {
$ad='INCORRECT';
last;
}
@@ -1183,17 +1308,25 @@ sub end_functionplotelements {
my $answerdisplay=&Apache::lonxml::get_param('answerdisplay',$parstack,$safeeval,-2);
if ($answerdisplay=~/\S/s) {
foreach my $plot (split(/\s*\,\s*/,$answerdisplay)) {
- my ($func,$xl,$xh)=split(/\s*\:\s*/,$plot);
- if ((!defined($xl)) || ($xl eq '')) { $xl=$xmin; }
- if ((!defined($xh)) || ($xh eq '')) { $xh=$xmax; }
- $result.=&plot_script($internalid,$func,1,'','00aa00',$xl,$xh,6);
+ my @components=split(/\s*\:\s*/,$plot);
+ if ($#components<3) {
+# Just a simple plot
+ my ($func,$xl,$xh)=@components;
+ if ((!defined($xl)) || ($xl eq '')) { $xl=$xmin; }
+ if ((!defined($xh)) || ($xh eq '')) { $xh=$xmax; }
+ $result.=&plot_script($internalid,$func,1,'','00aa00',$xl,$xh,6);
+ } else {
+# This is a spline
+ $result.=&answer_spline_script($internalid,@components);
+ }
}
}
}
-
+ my $fixed=0;
+ if (($showanswer) || (&Apache::response::check_status()>=2)) { $fixed=1; }
# Now is the time to render all of the stored splines
foreach my $label (keys(%Apache::functionplotresponse::splineorder)) {
- $result.=&generate_spline($internalid,$label,$xmin,$xmax,$ymin,$ymax);
+ $result.=&generate_spline($internalid,$label,$xmin,$xmax,$ymin,$ymax,$fixed);
}
# close the init script
$result.=&end_init_script();
@@ -1249,7 +1382,8 @@ sub start_functionplotelements {
' |