[LON-CAPA-cvs] cvs: loncom /homework functionplotresponse.pm /homework/templates functionplotback.problem functionplotone.problem functionplottwo.problem
www
www@source.lon-capa.org
Wed, 24 Nov 2010 02:53:18 -0000
This is a MIME encoded message
--www1290567198
Content-Type: text/plain
www Wed Nov 24 02:53:18 2010 EDT
Modified files:
/loncom/homework functionplotresponse.pm
/loncom/homework/templates functionplotback.problem
functionplotone.problem
functionplottwo.problem
Log:
Show answer functionality
--www1290567198
Content-Type: text/plain
Content-Disposition: attachment; filename="www-20101124025318.txt"
Index: loncom/homework/functionplotresponse.pm
diff -u loncom/homework/functionplotresponse.pm:1.46 loncom/homework/functionplotresponse.pm:1.47
--- loncom/homework/functionplotresponse.pm:1.46 Tue Nov 23 23:55:01 2010
+++ loncom/homework/functionplotresponse.pm Wed Nov 24 02:53:13 2010
@@ -1,7 +1,7 @@
# LearningOnline Network with CAPA
# option list style responses
#
-# $Id: functionplotresponse.pm,v 1.46 2010/11/23 23:55:01 www Exp $
+# $Id: functionplotresponse.pm,v 1.47 2010/11/24 02:53:13 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -330,7 +330,7 @@
}
sub plot_script {
- my ($id,$function,$fixed,$label,$color,$xmin,$xmax)=@_;
+ my ($id,$function,$fixed,$label,$color,$xmin,$xmax,$thickness)=@_;
$label=~s/\W//g;
if (($label) && ($label!~/^[A-Za-z]/)) {
$label='C'.$label;
@@ -354,7 +354,8 @@
if ($fixed) {
return "document.ggbApplet_$id.evalCommand('$label=Function[$function,$xmin,$xmax]');\n".
($visible?'':"document.ggbApplet_$id.setLabelVisible('$label', false);\n").
- ($color?"document.ggbApplet_$id.setColor('$label',$rc,$gc,$bc);\n":'');
+ ($color?"document.ggbApplet_$id.setColor('$label',$rc,$gc,$bc);\n":'').
+ ($thickness?"document.ggbApplet_$id.setLineThickness('$label',$thickness);\n":'');
} else {
return "document.ggbApplet_$id.evalCommand('y=$function');\n";
}
@@ -393,6 +394,8 @@
my $result='';
my $internalid = $Apache::inputtags::part.'_'.$Apache::inputtags::response[-1];
my $function=&Apache::lonxml::get_param('function',$parstack,$safeeval);
+ my $xinitial=&Apache::lonxml::get_param('xinitial',$parstack,$safeeval);
+ my $xfinal=&Apache::lonxml::get_param('xfinal',$parstack,$safeeval);
my $label=&Apache::lonxml::get_param('label',$parstack,$safeeval);
my $color=&Apache::lonxml::get_param('color',$parstack,$safeeval);
$color=~s/[^a-fA-F0-9]//gs;
@@ -402,11 +405,17 @@
unless ($function) { $function="0"; }
if ($target eq 'web') {
my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-3);
- $result.=&plot_script($internalid,$function,$fixed,$label,$color,$xmin,$xmax);
+ unless (defined($xinitial)) { $xinitial=$xmin; }
+ unless (defined($xfinal)) { $xfinal=$xmax; }
+ $result.=&plot_script($internalid,$function,$fixed,$label,$color,$xinitial,$xfinal);
} elsif ($target eq 'edit') {
$result=&Apache::edit::tag_start($target,$token,'Background Function Plot').
&Apache::edit::text_arg('Function:','function',
$token,'16').
+ &Apache::edit::text_arg('Initial x-value (optional):','xinitial',
+ $token,'8').
+ &Apache::edit::text_arg('Final x-value (optional):','xfinal',
+ $token,'8').
&Apache::edit::text_arg('Label on Plot:','label',
$token,'8').
&Apache::edit::text_arg('Color (hex code):','color',
@@ -416,7 +425,7 @@
&Apache::edit::end_row();
} elsif ($target eq 'modified') {
my $constructtag=&Apache::edit::get_new_args($token,$parstack,
- $safeeval,'function','label','color','fixed');
+ $safeeval,'function','label','xinitial','xfinal','color','fixed');
if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
}
return $result;
@@ -826,12 +835,15 @@
&Apache::edit::select_arg('y-axis visible:','yaxisvisible',
['yes','no'],$token).'<br />'.
&Apache::edit::select_arg('Grid visible:','gridvisible',
- ['yes','no'],$token).
+ ['yes','no'],$token).'<br />'.
+ &Apache::edit::text_arg('Background plot(s) for answer (function:xmin:xmax,function:xmin:xmax,...):',
+ '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') {
@@ -1162,8 +1174,24 @@
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 ($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);
+ }
+ }
+ }
+
+# 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);
}
Index: loncom/homework/templates/functionplotback.problem
diff -u loncom/homework/templates/functionplotback.problem:1.1 loncom/homework/templates/functionplotback.problem:1.2
--- loncom/homework/templates/functionplotback.problem:1.1 Sat Nov 13 22:30:32 2010
+++ loncom/homework/templates/functionplotback.problem Wed Nov 24 02:53:18 2010
@@ -4,14 +4,16 @@
$a=&random(0.5,0.9,0.1);
if (&random(0,1,1)) {
$function="$a*(x-($x))^2+($y)";
+ $answer="2*$a*(x-($x))";
$relation='gt';
} else {
$function="-$a*(x-($x))^2+($y)";
+ $answer="-2*$a*(x-($x))";
$relation='lt';
}</script>
<startouttext />
Provide a sketch of the derivative of the indicated function<br /> <endouttext />
-<functionplotresponse xaxisvisible="yes" xlabel="x" gridvisible="yes" ylabel="y(x)" id="11" xmax="10" yaxisvisible="yes" xmin="-10" ymin="-10" ymax="10">
+<functionplotresponse xaxisvisible="yes" xlabel="x" gridvisible="yes" ylabel="y(x)" id="11" xmax="10" yaxisvisible="yes" xmin="-10" ymin="-10" ymax="10" answerdisplay="$answer">
<functionplotelements>
<spline initx="-4" inity="0" index="A" order="3" scalex="8" />
<backgroundplot function="$function" fixed="yes" />
Index: loncom/homework/templates/functionplotone.problem
diff -u loncom/homework/templates/functionplotone.problem:1.3 loncom/homework/templates/functionplotone.problem:1.4
--- loncom/homework/templates/functionplotone.problem:1.3 Sat Nov 13 03:23:03 2010
+++ loncom/homework/templates/functionplotone.problem Wed Nov 24 02:53:18 2010
@@ -5,7 +5,7 @@
<startouttext />
At t=0 s, a car cruises at a constant positive velocity. Suddenly, a light switches to red. At t=$maxbraketime s, the driver is maximum on the brake. The car then stops in front of the red light for over $wait seconds. Eventually, it drives off, and then again cruises at a constant velocity. The car cannot accelerate with more than $maxacc m/s<sup>2</sup>.<br />
Provide a graph of its acceleration as a function of time.<br /> <endouttext />
-<functionplotresponse xaxisvisible="yes" xlabel="t [s]" gridvisible="yes" ylabel="a(t) [m/s^2]" id="11" xmax="30" yaxisvisible="yes" xmin="-4" ymin="-8" ymax="8">
+<functionplotresponse xaxisvisible="yes" xlabel="t [s]" gridvisible="yes" ylabel="a(t) [m/s^2]" id="11" xmax="30" yaxisvisible="yes" xmin="-4" ymin="-8" ymax="8" answerdisplay="0::$maxbraketime-4,-7*(exp(-0.5*(x-$maxbraketime)^2)-exp(-8)):$maxbraketime-4:$maxbraketime+4,0:$maxbraketime+4:$maxbraketime+5+$wait,($maxacc-0.3)*(exp(-(x-($maxbraketime+7+$wait))^2)-exp(-4)):$maxbraketime+5+$wait:$maxbraketime+9+$wait,0:$maxbraketime+9+$wait">
<functionplotelements>
<spline initx="-2" inity="0" index="A" order="8" scalex="28" />
</functionplotelements>
Index: loncom/homework/templates/functionplottwo.problem
diff -u loncom/homework/templates/functionplottwo.problem:1.3 loncom/homework/templates/functionplottwo.problem:1.4
--- loncom/homework/templates/functionplottwo.problem:1.3 Sat Nov 13 13:58:55 2010
+++ loncom/homework/templates/functionplottwo.problem Wed Nov 24 02:53:18 2010
@@ -3,7 +3,7 @@
<startouttext />
Make a sketch of the electrostatic potential (zero at infinity) of a negative point charge located at x=$x m.
<endouttext />
-<functionplotresponse xaxisvisible="yes" xlabel="x [m]" gridvisible="yes" ylabel="V(x) [V]" id="11" xmax="30" yaxisvisible="yes" xmin="-4" ymin="-10" ymax="10">
+<functionplotresponse xaxisvisible="yes" xlabel="x [m]" gridvisible="yes" ylabel="V(x) [V]" id="11" xmax="30" yaxisvisible="yes" xmin="-4" ymin="-10" ymax="10" answerdisplay="-4/abs(x-$x)">
<functionplotelements>
<spline initx="-2" inity="0" index="A" order="2" scalex="4" />
<spline index="B" order="2" initx="12" inity="0" scalex="4" />
--www1290567198--