'.&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()
@@ -795,12 +878,14 @@ sub start_functionplotresponse {
&Apache::edit::select_arg('y-axis visible:','yaxisvisible',
['yes','no'],$token).' '.
&Apache::edit::select_arg('Grid visible:','gridvisible',
- ['yes','no'],$token).
+ ['yes','no'],$token).' '.
+ &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,
$safeeval,'xlabel','xmin','xmax','ylabel','ymin','ymax',
- 'xaxisvisible','yaxisvisible','gridvisible');
+ 'xaxisvisible','yaxisvisible','gridvisible','answerdisplay');
if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
} elsif ($target eq 'meta') {
@@ -895,7 +980,10 @@ sub functionplotrulecheck {
=split(/\:/,$rule);
$percent=($percent>0?$percent:5);
&addlog("=================");
- &addlog("Rule $label for ".('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 $lh=400;
@@ -952,14 +1040,37 @@ sub functionplotrulecheck {
$tol=4.*$tol/($xmax-$xmin);
} elsif ($derivative==1) {
$tol=2.*$tol/($xmax-$xmin);
+ } elsif ($derivative==-1) {
+ $tol=$tol*($xmax-$xmin)/2.;
}
}
- for (my $i=$li; $i<=$lh; $i++) {
+ my $integral=0;
+ my $binwidth=($xmax-$xmin)/400.;
+ if (($derivative<0) && (!$findupper)) {
+# definite integral, calculate over whole length
+ &addlog("Calculating definite integral");
+ for (my $i=$li; $i<=$lh; $i++) {
+ $integral+=$Apache::functionplotresponse::func[$i]*$binwidth;
+ }
+ 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");
+ return 0;
+ }
+ } else {
+ for (my $i=$li; $i<=$lh; $i++) {
my $val;
if ($derivative==2) {
$val=$Apache::functionplotresponse::d2funcdx2[$i];
} elsif ($derivative==1) {
$val=$Apache::functionplotresponse::dfuncdx[$i];
+ } elsif ($derivative==-1) {
+ $integral+=$Apache::functionplotresponse::func[$i]*$binwidth;
+ $val=$integral;
} else {
$val=$Apache::functionplotresponse::func[$i];
}
@@ -967,37 +1078,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') {
@@ -1005,7 +1138,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()
@@ -1107,10 +1241,34 @@ sub end_functionplotelements {
if ($target eq 'edit' ) {
$result=&Apache::edit::end_table();
} elsif ($target eq 'web') {
-# Now is the time to render all of the stored splines
my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-2);
+
+# Are we in show answer mode?
+ my $showanswer=&Apache::response::show_answer();
+ if ($showanswer) {
+# Render answerdisplay
+ my $answerdisplay=&Apache::lonxml::get_param('answerdisplay',$parstack,$safeeval,-2);
+ if ($answerdisplay=~/\S/s) {
+ foreach my $plot (split(/\s*\,\s*/,$answerdisplay)) {
+ 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();
@@ -1166,7 +1324,8 @@ sub start_functionplotelements {
' |
'.&mt('Function Plot Elements').' | '
.''.&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_Elements','Function Plot Elements')
.' | '
." "
.&Apache::edit::end_row()
@@ -1187,7 +1346,7 @@ sub start_functionplotelements {
$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);
+ $result.=&axes_label($internalid,$xmin,$xmax,$ymin,$ymax,$xlabel,$ylabel);
# init script is left open
}
return $result;
|