version 1.2, 2010/10/04 14:34:43
|
version 1.32, 2010/11/10 22:53:32
|
Line 33 use Apache::lonlocal;
|
Line 33 use Apache::lonlocal;
|
use Apache::lonnet; |
use Apache::lonnet; |
|
|
BEGIN { |
BEGIN { |
&Apache::lonxml::register('Apache::functionplotresponse',('functionplotresponse')); |
&Apache::lonxml::register('Apache::functionplotresponse',('functionplotresponse','backgroundplot','spline','functionplotrule')); |
} |
} |
|
|
|
# |
|
# There can be a number of applets on a page, each called ggbApplet_$id, |
|
# where $id is the "_"-concatenated part and responseid |
|
# |
|
|
sub geogebra_startcode { |
sub geogebra_startcode { |
|
my ($id)=@_; |
return (<<ENDSTARTCODE); |
return (<<ENDSTARTCODE); |
<applet name="ggbApplet" code="geogebra.GeoGebraApplet" archive="geogebra.jar" |
<applet name="ggbApplet_$id" code="geogebra.GeoGebraApplet" archive="geogebra.jar" |
codebase="/adm/geogebra/" width="714" height="447" MAYSCRIPT> |
codebase="/adm/geogebra/" width="714" height="447" MAYSCRIPT> |
<param name="java_arguments" value="-Xmx512m -Djnlp.packEnabled=true"/> |
<param name="java_arguments" value="-Xmx512m -Djnlp.packEnabled=true"/> |
ENDSTARTCODE |
ENDSTARTCODE |
Line 48 sub geogebra_endcode {
|
Line 54 sub geogebra_endcode {
|
return &Apache::lonhtmlcommon::java_not_enabled()."</applet>\n"; |
return &Apache::lonhtmlcommon::java_not_enabled()."</applet>\n"; |
} |
} |
|
|
|
# |
|
# This is the internal GeoGebra bytecode which defines the spline functions |
|
# |
sub geogebra_spline_program { |
sub geogebra_spline_program { |
return (<<ENDSPLINEPROGRAM); |
return (<<ENDSPLINEPROGRAM); |
<param name="ggbBase64" value="UEsDBBQACAAIADhQET0AAAAAAAAAAAAAAAASAAAAZ2VvZ2VicmFfbWFjcm8ueG1s7Z1bb+PGGYavk19BMDfexkvP+QCsEqzOuWi7gIveBG1By7RXrSwJsqyY+fWdGZLS2pQtzdqWSPoDApOSqCH5vSTnmdH7bj79en8zCVbJ4nY8m7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A1vzPovUEsHCEyILqxEAgAAlQQAAFBLAQIUABQACAAIADhQET1gj4YNdwsAAFgqAQASAAAAAAAAAAAAAAAAAAAAAABnZW9nZWJyYV9tYWNyby54bWxQSwECFAAUAAgACAA4UBE9TIgurEQCAACVBAAADAAAAAAAAAAAAAAAAAC3CwAAZ2VvZ2VicmEueG1sUEsFBgAAAAACAAIAegAAADUOAAAAAA=="/> |
ENDSPLINEPROGRAM |
ENDSPLINEPROGRAM |
} |
} |
|
|
|
# |
|
# The standard set of parameters inside <applet> |
|
# |
sub geogebra_default_parameters { |
sub geogebra_default_parameters { |
|
my ($id)=@_; |
return(<<ENDDEFAULTPARAMETERS); |
return(<<ENDDEFAULTPARAMETERS); |
<param name="image" value="/adm/lonIcons/lonanim.gif" /> |
<param name="image" value="/adm/lonIcons/lonanim.gif" /> |
<param name="boxborder" value="false" /> |
<param name="boxborder" value="false" /> |
Line 76 sub geogebra_default_parameters {
|
Line 89 sub geogebra_default_parameters {
|
<param name="enableShiftDragZoom" value="false" /> |
<param name="enableShiftDragZoom" value="false" /> |
<param name="allowRescaling" value="false" /> |
<param name="allowRescaling" value="false" /> |
<param name="enableLabelDrags" value="false" /> |
<param name="enableLabelDrags" value="false" /> |
<param name="ggbOnInitParam" value="applet1" /> |
<param name="ggbOnInitParam" value="applet_$id" /> |
ENDDEFAULTPARAMETERS |
ENDDEFAULTPARAMETERS |
} |
} |
|
|
|
# |
|
# This subroutine is called by LON-CAPA at </problem> |
|
# Each applet on the page will call function ggbOnInit when it is done loading |
|
# This function in turn will call the respective function registered by start_init_script |
|
# Which one of the registered functions is called is determined by ggbOnInitParam, which GeoGebra passes to ggbOnInit |
|
# |
|
|
|
sub init_script { |
|
if ($#Apache::functionplotresponse::callscripts>=0) { |
|
my $script=''; |
|
foreach my $id (@Apache::functionplotresponse::callscripts) { |
|
$script.="if (param=='applet_$id') { loaded_$id=true; }\n"; |
|
} |
|
$script.="if (".join(' && ',map { "loaded_$_" } (@Apache::functionplotresponse::callscripts)). |
|
") { setTimeout('ggbInitAll()',20) }"; |
|
my $calls=join("\n",map { "ggbInit_$_();" } (@Apache::functionplotresponse::callscripts)); |
|
return (<<ENDGGBINIT); |
|
<script type="text/javascript"> |
|
// <![CDATA[ |
|
// Function that each applet will call when loaded |
|
// It will pass "its" parameter |
|
// Set flags for when an applet is loaded, wait till all are loaded, and then some |
|
function ggbOnInit(param) { |
|
$script |
|
} |
|
function ggbInitAll() { |
|
$calls |
|
} |
|
// ]]> |
|
</script> |
|
ENDGGBINIT |
|
} |
|
} |
|
|
|
# |
|
# Each Geogebra applet is supposed to call this when parameters change |
|
# Changes the hidden fields on the web page |
|
# |
|
sub update_script { |
|
my ($id)=@_; |
|
return (<<ENDUPDATESCRIPT); |
|
<script type="text/javascript"> |
|
// <![CDATA[ |
|
function updatePointCoordinates_$id(coordinateName) { |
|
var x = document.ggbApplet_$id.getXcoord(coordinateName); |
|
var y = document.ggbApplet_$id.getYcoord(coordinateName); |
|
document.lonhomework.elements["HWVAL_$id\_" + coordinateName + "_x"].value = x; |
|
document.lonhomework.elements["HWVAL_$id\_" + coordinateName + "_y"].value = y; |
|
} |
|
// ]]> |
|
</script> |
|
ENDUPDATESCRIPT |
|
} |
|
|
|
# |
|
# Register the above update-handler for a variable |
|
# |
|
|
|
sub update_register { |
|
my ($id,$variable)=@_; |
|
return "document.ggbApplet_$id.registerObjectUpdateListener('$variable','updatePointCoordinates_$id');\n"; |
|
} |
|
|
|
# |
|
# Set a coordinate variable |
|
# |
|
sub set_coordinate { |
|
my ($id,$variable,$x,$y)=@_; |
|
return (<<ENDSETVARIABLE); |
|
document.ggbApplet_$id.evalCommand("$variable=($x,$y)"); |
|
ENDSETVARIABLE |
|
} |
|
|
|
# |
|
# Input field name for a coordinate variable |
|
# |
|
|
|
sub field_name { |
|
my ($id,$variable,$name)=@_; |
|
return "HWVAL_$id\_$variable\_$name"; |
|
} |
|
|
|
# |
|
# Generate an input field for a coordinate variable |
|
# |
|
|
|
sub generate_input_field { |
|
my ($id,$variable,$x,$y)=@_; |
|
$Apache::functionplotresponse::inputfields.= |
|
"<input type='hidden' name='".&field_name($id,$variable,'x')."' value='$x' />\n". |
|
"<input type='hidden' name='".&field_name($id,$variable,'y')."' value='$y' />\n"; |
|
} |
|
|
|
# |
|
# Initialize a new coordinate variable at set a listener on it |
|
# |
|
sub new_coordinate { |
|
my ($id,$variable,$x,$y)=@_; |
|
if (defined($Apache::functionplotresponse::previous{&field_name($id,$variable,'x')})) { |
|
$x=$Apache::functionplotresponse::previous{&field_name($id,$variable,'x')}; |
|
} |
|
if (defined($Apache::functionplotresponse::previous{&field_name($id,$variable,'y')})) { |
|
$y=$Apache::functionplotresponse::previous{&field_name($id,$variable,'y')}; |
|
} |
|
&generate_input_field($id,$variable,$x,$y); |
|
return &set_coordinate($id,$variable,$x,$y).&update_register($id,$variable); |
|
} |
|
|
|
# |
|
# This registers the init-function call for ggbOnInit, which LON-CAPA will place at </problem> |
|
# It then starts the right headers |
|
# |
|
sub start_init_script { |
|
my ($id)=@_; |
|
# Add id to the list of ggbInit_$id functions that need to be called |
|
push(@Apache::functionplotresponse::callscripts,$id); |
|
# ... and open this function |
|
return (<<ENDSTARTINIT); |
|
<script type="text/javascript"> |
|
// <![CDATA[ |
|
// variable that will eventually be passed back to the server |
|
var coordinateMap_$id = []; |
|
// flag for not loaded yet |
|
var loaded_$id=false; |
|
// Init-function for applet |
|
function ggbInit_$id() { |
|
ENDSTARTINIT |
|
} |
|
|
|
# |
|
# This sets the axes inside ggbInit_$id |
|
# |
|
|
|
sub axes_script { |
|
my ($id,$xmin,$xmax,$ymin,$ymax,$xvisible,$yvisible,$gvisible)=@_; |
|
return (<<ENDAXESSCRIPT); |
|
// changes (xmin, xmax, ymin, ymax) |
|
document.ggbApplet_$id.setCoordSystem($xmin,$xmax,$ymin,$ymax); |
|
|
|
// makes the (x,y) axis (in)visible |
|
document.ggbApplet_$id.setAxesVisible($xvisible,$yvisible); |
|
// makes the grid (in)visible |
|
document.ggbApplet_$id.setGridVisible($gvisible); |
|
ENDAXESSCRIPT |
|
} |
|
|
|
sub axes_label { |
|
my ($id,$xlabel,$ylabel)=@_; |
|
unless ($xlabel || $ylabel) { return ''; } |
|
my $return='document.ggbApplet_'.$id.'.evalCommand("topRight=Corner[3]");'; |
|
if ($xlabel) { |
|
$return.=(<<ENDXAXISLABELSCRIPT); |
|
document.ggbApplet_$id.evalCommand("Xlabel=(x(topRight)-AxisStepX[],AxisStepY[]/6)"); |
|
document.ggbApplet_$id.setVisible("Xlabel",false); |
|
document.ggbApplet_$id.evalCommand("Text[\\"$xlabel\\", Xlabel]"); |
|
ENDXAXISLABELSCRIPT |
|
} |
|
if ($ylabel) { |
|
$return.=(<<ENDYAXISLABELSCRIPT); |
|
document.ggbApplet_$id.evalCommand("Ylabel=(AxisStepX[]/6,y(topRight)-AxisStepY[]/3)"); |
|
document.ggbApplet_$id.setVisible("Ylabel",false); |
|
document.ggbApplet_$id.evalCommand("Text[\\"$ylabel\\", Ylabel]"); |
|
ENDYAXISLABELSCRIPT |
|
} |
|
return $return; |
|
} |
|
|
|
sub plot_script { |
|
my ($id,$function,$fixed)=@_; |
|
if ($fixed) { |
|
# Use stupid trick to nail this to a location |
|
# Oddly, it seems like only one plot cannot be nailed to a location |
|
# Non-nailed-down plots apparently get overwritten |
|
return (<<ENDPLOTSCRIPT); |
|
document.ggbApplet_$id.evalCommand("a=1"); |
|
document.ggbApplet_$id.setVisible("a",false); |
|
// This MUST be a DEPENDENT OBJECT in order to be locked down: |
|
document.ggbApplet_$id.evalCommand("y=a*($function)"); |
|
ENDPLOTSCRIPT |
|
} else { |
|
return "document.ggbApplet_$id.evalCommand('y=$function')"; |
|
} |
|
} |
|
|
|
# |
|
# Subroutine that generates code for spline $label based on stored information |
|
# |
|
|
|
sub generate_spline { |
|
my ($id,$label)=@_; |
|
my $result=''; |
|
my $order=$Apache::functionplotresponse::splineorder{$label}; |
|
my $x=$Apache::functionplotresponse::splineinitx{$label}; |
|
my $y=$Apache::functionplotresponse::splineinity{$label}; |
|
my $sx=$Apache::functionplotresponse::splinescalex{$label}; |
|
my $sy=$Apache::functionplotresponse::splinescaley{$label}; |
|
my @coords=(); |
|
foreach my $i (1..$order) { |
|
$result.=&new_coordinate($id,$label.'P'.$i,$x,$y); |
|
$x+=$sx/(2.*($order-1)); |
|
push(@coords,$label.'P'.$i); |
|
$result.=&new_coordinate($id,$label.'S'.$i,$x,$y+$sy); |
|
$x+=$sx/(2.*($order-1)); |
|
push(@coords,$label.'S'.$i); |
|
} |
|
$result.='document.ggbApplet_'.$id.'.evalCommand("Spline'.$order.'['.join(',',@coords).']");'."\n"; |
|
return $result; |
|
} |
|
# |
|
# <backgroundplot function="..." fixed="yes/no" /> |
|
# |
|
sub start_backgroundplot { |
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
|
my $result=''; |
|
my $internalid = $Apache::inputtags::part.'_'.$Apache::inputtags::response[-1]; |
|
my $function=&Apache::lonxml::get_param('function',$parstack,$safeeval); |
|
my $fixed=(&Apache::lonxml::get_param('fixed',$parstack,$safeeval)=~/on|true|yes|1/i?1:0); |
|
|
|
unless ($function) { $function="0"; } |
|
if ($target eq 'web') { |
|
$result.=&plot_script($internalid,$function,$fixed); |
|
} elsif ($target eq 'edit') { |
|
$result=&Apache::edit::tag_start($target,$token,'Background Function Plot'). |
|
&Apache::edit::text_arg('Function:','function', |
|
$token,'16'). |
|
&Apache::edit::select_arg('Fixed location:','fixed', |
|
['yes','no'],$token). |
|
&Apache::edit::end_row(); |
|
} elsif ($target eq 'modified') { |
|
my $constructtag=&Apache::edit::get_new_args($token,$parstack, |
|
$safeeval,'function','fixed'); |
|
if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); } |
|
} |
|
return $result; |
|
} |
|
|
|
sub end_backgroundplot { |
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
|
my $result=''; |
|
if ($target eq 'edit') { |
|
$result=&Apache::edit::end_table(); |
|
} |
|
return $result; |
|
} |
|
|
|
# |
|
# <functionplotrule ... /> |
|
# |
|
sub start_functionplotrule { |
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
|
my $result=''; |
|
my $label=&Apache::lonxml::get_param('index',$parstack,$safeeval); |
|
$Apache::functionplotresponse::counter++; |
|
if ($label=~/\W/) { |
|
&Apache::lonxml::warning(&mt('Rule indices should only contain alphanumeric characters.')); |
|
} |
|
$label=~s/\W//gs; |
|
unless ($label) { |
|
$label='R'.$Apache::functionplotresponse::counter; |
|
} else { |
|
$label='R'.$label; |
|
} |
|
if ($Apache::functionplotresponse::splineorder{$label}) { |
|
&Apache::lonxml::error(&mt('Rule indices must be unique.')); |
|
} |
|
|
|
|
|
if ($target eq 'grade') { |
|
# Simply remember - in order - for later |
|
my $beginninglabel=&Apache::lonxml::get_param('xinitiallabel',$parstack,$safeeval); |
|
my $endinglabel=&Apache::lonxml::get_param('xfinallabel',$parstack,$safeeval); |
|
if (($beginninglabel=~/\W/) || ($endinglabel=~/W/)) { |
|
&Apache::lonxml::warning(&mt('Rule labels must be alphanumeric.')); |
|
} |
|
$beginninglabel=~s/\W//gs; |
|
$endinglabel=~s/\W//gs; |
|
my $relationship=&Apache::lonxml::get_param('relationship',$parstack,$safeeval); |
|
$relationship=~s/\W//gs; |
|
$relationship=lc($relationship); |
|
unless ($relationship=~/^(eq|ge|gt|le|lt|ne)$/) { |
|
&Apache::lonxml::warning(&mt('Rule relationship not defined.')); |
|
$relationship='eq'; |
|
} |
|
my $derivative=&Apache::lonxml::get_param('derivative',$parstack,$safeeval); |
|
unless (($derivative==0) || ($derivative==1) || ($derivative==2)) { |
|
&Apache::lonxml::warning(&mt('Rule derivative not defined.')); |
|
$derivative=0; |
|
} |
|
push(@Apache::functionplotresponse::functionplotrules,join(':',( |
|
$label, |
|
$derivative, |
|
&Apache::lonxml::get_param('xinitial',$parstack,$safeeval), |
|
$beginninglabel, |
|
&Apache::lonxml::get_param('xfinal',$parstack,$safeeval), |
|
$endinglabel, |
|
$relationship, |
|
&Apache::lonxml::get_param('value',$parstack,$safeeval) |
|
))); |
|
} elsif ($target eq 'edit') { |
|
$result=&Apache::edit::tag_start($target,$token,'Function Plot Evaluation Rule'). |
|
&Apache::edit::text_arg('Index:','index', |
|
$token,'4').' '. |
|
&Apache::edit::select_arg(&mt('Function:'),'derivative', |
|
[['0','Function itself'], |
|
['1','First derivative'], |
|
['2','Second derivative']],$token).'<br />'. |
|
|
|
&Apache::edit::text_arg('(Initial) x-value:','xinitial', |
|
$token,'4'). |
|
&Apache::edit::select_or_text_arg('(Initial) x-value label:','xinitiallabel', |
|
[['start','Start of Plot']],$token,'8').'<br />'. |
|
|
|
&Apache::edit::text_arg('Optional final x-value for ranges:','xfinal', |
|
$token,'4'). |
|
&Apache::edit::select_or_text_arg('Optional final x-value label:','xfinallabel', |
|
[['end','End of Plot']],$token,'8').'<br />'. |
|
|
|
&Apache::edit::select_arg(&mt('Relationship:'),'relationship', |
|
[['eq','equal'], |
|
['ne','not equal'], |
|
['ge','greater than or equal'], |
|
['gt','greater than'], |
|
['lt','less than'], |
|
['le','less than or equal']],$token). |
|
$result.= &Apache::edit::select_or_text_arg('Value:','value', |
|
[['undef','not defined']],$token,'4'). |
|
&Apache::edit::text_arg('Percent error:','percenterror', |
|
$token,'4'). |
|
&Apache::edit::end_row(); |
|
} elsif ($target eq 'modified') { |
|
my $constructtag=&Apache::edit::get_new_args($token,$parstack, |
|
$safeeval,'index','derivative','xinitial','xinitiallabel','xfinal','xfinallabel','relationship', |
|
'value','percenterror'); |
|
if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); } |
|
} |
|
return $result; |
|
} |
|
|
|
sub end_functionplotrule { |
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
|
my $result=''; |
|
if ($target eq 'edit') { |
|
$result=&Apache::edit::end_table(); |
|
} |
|
return $result; |
|
} |
|
|
|
|
|
# |
|
# <spline index="..." order="1,2,3,4" initx="..." inity="..." scalex="..." scaley="..." /> |
|
# |
|
# Unfortunately, GeoGebra seems to want all splines after everything else, so we need to store them |
|
# |
|
sub start_spline { |
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
|
my $result=''; |
|
if ($target eq 'web') { |
|
my $label=&Apache::lonxml::get_param('index',$parstack,$safeeval); |
|
$Apache::functionplotresponse::counter++; |
|
if ($label=~/\W/) { |
|
&Apache::lonxml::warning(&mt('Spline indices should only contain alphanumeric characters.')); |
|
} |
|
$label=~s/\W//gs; |
|
unless ($label) { |
|
$label='S'.$Apache::functionplotresponse::counter; |
|
} else { |
|
$label='S'.$label; |
|
} |
|
if ($Apache::functionplotresponse::splineorder{$label}) { |
|
&Apache::lonxml::error(&mt('Spline indices must be unique.')); |
|
} |
|
|
|
my $order=&Apache::lonxml::get_param('order',$parstack,$safeeval); |
|
if ($order<2) { $order=2; } |
|
if ($order>8) { $order=8; } |
|
$Apache::functionplotresponse::splineorder{$label}=$order; |
|
|
|
my $x=&Apache::lonxml::get_param('initx',$parstack,$safeeval); |
|
unless ($x) { $x=0; } |
|
$Apache::functionplotresponse::splineinitx{$label}=$x; |
|
|
|
my $y=&Apache::lonxml::get_param('inity',$parstack,$safeeval); |
|
unless ($y) { $y=0; } |
|
$Apache::functionplotresponse::splineinity{$label}=$y; |
|
|
|
my $sx=&Apache::lonxml::get_param('scalex',$parstack,$safeeval); |
|
unless ($sx) { $sx=$order; } |
|
$Apache::functionplotresponse::splinescalex{$label}=$sx; |
|
|
|
my $sy=&Apache::lonxml::get_param('scaley',$parstack,$safeeval); |
|
unless ($sy) { $sy=2; } |
|
$Apache::functionplotresponse::splinescaley{$label}=$sy; |
|
} elsif ($target eq 'edit') { |
|
$result=&Apache::edit::tag_start($target,$token,'Spline'). |
|
&Apache::edit::text_arg('Index:','index', |
|
$token,'4').' '. |
|
&Apache::edit::select_arg('Order:','order', |
|
['2','3','4','5','6','7','8','9'],$token).' '. |
|
&Apache::edit::text_arg('Initial x-value:','initx', |
|
$token,'4').' '. |
|
&Apache::edit::text_arg('Initial y-value:','inity', |
|
$token,'4').' '. |
|
&Apache::edit::text_arg('Scale x:','scalex', |
|
$token,'4').' '. |
|
&Apache::edit::text_arg('Scale y:','scaley', |
|
$token,'4'). |
|
&Apache::edit::end_row(); |
|
} elsif ($target eq 'modified') { |
|
my $constructtag=&Apache::edit::get_new_args($token,$parstack, |
|
$safeeval,'index','order','initx','inity', |
|
'scalex','scaley'); |
|
if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); } |
|
} |
|
return $result; |
|
} |
|
|
|
sub end_spline { |
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
|
my $result=''; |
|
if ($target eq 'edit') { |
|
$result=&Apache::edit::end_table(); |
|
} |
|
return $result; |
|
} |
|
|
|
sub end_init_script { |
|
return (<<ENDENDINIT); |
|
} |
|
// ]]> |
|
</script> |
|
ENDENDINIT |
|
} |
|
|
|
# |
|
# Storing and restoring spline coordinates from part answers |
|
# |
|
sub decode_previous_answer { |
|
my ($answer)=@_; |
|
foreach my $coordinate (split(/\,/,$answer)) { |
|
my ($key,$value)=split(/\=/,$coordinate); |
|
$Apache::functionplotresponse::previous{$key}=$value; |
|
} |
|
} |
|
|
|
sub get_answer_from_form_fields { |
|
my ($id)=@_; |
|
my $answer=''; |
|
my %coords=(); |
|
foreach my $field (keys(%env)) { |
|
if ($field=~/^form\.HWVAL\_$id/) { |
|
$field=~/^form\.(.*)$/; |
|
$coords{$1}=$env{$field}; |
|
} |
|
} |
|
$answer=join(',',map { $_.'='.$coords{$_} } (sort(keys(%coords)))); |
|
return ($answer,%coords); |
|
} |
|
|
|
# |
|
# The following functions calculate the cubic-hermite splines server-side |
|
# |
|
|
|
sub cubic_hermite { |
|
my ($t,$p1,$s1,$p2,$s2)=@_; |
|
return (2.*$t*$t*$t-3.*$t*$t+1.)*$p1 + 5.*($t*$t*$t-2.*$t*$t+$t)*($s1-$p1)+ |
|
(-2.*$t*$t*$t+3.*$t*$t) *$p2 + 5.*($t*$t*$t-$t*$t) *($s2-$p2); |
|
} |
|
|
|
# |
|
# d/dt(...) |
|
# |
|
|
|
sub ddt_cubic_hermite { |
|
my ($t,$p1,$s1,$p2,$s2)=@_; |
|
return (6.*$t*$t-6.*$t) *$p1 + 5.*(3.*$t*$t-4.*$t+1.)*($s1-$p1)+ |
|
(-6.*$t*$t+6.*$t)*$p2 + 5.*(3.*$t*$t-2.*$t) *($s2-$p2); |
|
} |
|
|
|
# |
|
# d^2/dt^2(...) |
|
# |
|
|
|
sub d2dt2_cubic_hermite { |
|
my ($t,$p1,$s1,$p2,$s2)=@_; |
|
return (12.*$t-6.) *$p1 + 5.*(6.*$t-4.)*($s1-$p1)+ |
|
(-12.*$t+6.)*$p2 + 5.*(6.*$t-2.)*($s2-$p2); |
|
} |
|
|
|
# |
|
# Array index calculation |
|
# |
|
sub array_index { |
|
my ($xmin,$xmax,$x)=@_; |
|
return int(($x-$xmin)/($xmax-$xmin)*400.+0.5); |
|
} |
|
|
|
# |
|
# Populate the arrays |
|
# |
|
|
|
sub populate_arrays { |
|
my ($id,$xmin,$xmax)=@_; |
|
for (my $i=0; $i<=400; $i++) { |
|
$Apache::functionplotresponse::func[$i]=undef; |
|
$Apache::functionplotresponse::dfuncdx[$i]=undef; |
|
$Apache::functionplotresponse::d2funcd2x[$i]=undef; |
|
} |
|
unless ($xmax>$xmin) { return 'no_func'; } |
|
# Run over all splines in response |
|
foreach my $label (split(/\,/,$env{"form.HWVAL_AllSplines_$id"})) { |
|
my $xiold=-1; |
|
# Run over all points in spline |
|
for (my $i=1; $i<$env{"form.HWVAL_SplineOrder_".$id."_".$label}; $i++) { |
|
my $ni=$i+1; |
|
my @xparms=($env{'form.HWVAL_'.$id.'_'.$label.'P'.$i.'_x'}, |
|
$env{'form.HWVAL_'.$id.'_'.$label.'S'.$i.'_x'}, |
|
$env{'form.HWVAL_'.$id.'_'.$label.'P'.$ni.'_x'}, |
|
$env{'form.HWVAL_'.$id.'_'.$label.'S'.$ni.'_x'}); |
|
my @yparms=($env{'form.HWVAL_'.$id.'_'.$label.'P'.$i.'_y'}, |
|
$env{'form.HWVAL_'.$id.'_'.$label.'S'.$i.'_y'}, |
|
$env{'form.HWVAL_'.$id.'_'.$label.'P'.$ni.'_y'}, |
|
$env{'form.HWVAL_'.$id.'_'.$label.'S'.$ni.'_y'}); |
|
# Run in small steps over spline parameter |
|
for (my $t=0; $t<=1; $t+=0.0001) { |
|
my $xi=&array_index($xmin,$xmax,&cubic_hermite($t,@xparms)); |
|
if ($xi<$xiold) { return 'no_func'; } |
|
if (($xi>$xiold) && ($xi>=0) && ($xi<=400)) { |
|
if (defined($Apache::functionplotresponse::func[$xi])) { return 'no_func'; } |
|
$xiold=$xi; |
|
# Function value |
|
my $funcval=&cubic_hermite($t,@yparms); |
|
$Apache::functionplotresponse::func[$xi]=$funcval; |
|
if (defined($funcval)) { |
|
if ($xi<$Apache::functionplotresponse::functionplotrulelabels{'start'}) { |
|
$Apache::functionplotresponse::functionplotrulelabels{'start'}=$xi; |
|
} |
|
if ($xi>$Apache::functionplotresponse::functionplotrulelabels{'end'}) { |
|
$Apache::functionplotresponse::functionplotrulelabels{'end'}=$xi; |
|
} |
|
} |
|
# Chain rule |
|
# dy/dx=dy/dt/(dx/dt) |
|
my $dxdt=&ddt_cubic_hermite($t,@xparms); |
|
if ($dxdt) { |
|
$Apache::functionplotresponse::dfuncdx[$xi]=&ddt_cubic_hermite($t,@yparms)/$dxdt; |
|
} |
|
# Faa di Bruno |
|
# d^2y/dx^2=(d^2y/dt^2)/(dx/dt)^2+(dy/dt)/(d^2x/dt^2) |
|
my $d2xdt2=&d2dt2_cubic_hermite($t,@xparms); |
|
if (($dxdt) && ($d2xdt2)) { |
|
$Apache::functionplotresponse::d2funcdx2[$xi]= |
|
&d2dt2_cubic_hermite($t,@yparms)/($dxdt*$dxdt) |
|
+&ddt_cubic_hermite($t,@yparms)/$d2xdt2; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
# |
|
# Implentation of <functionplotresponse> |
|
# |
|
|
sub start_functionplotresponse { |
sub start_functionplotresponse { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result=''; |
my $result=''; |
my $id = &Apache::response::start_response($parstack,$safeeval); |
# To remember the splines - somehow, they need to come last |
if ($target eq 'web') { |
undef %Apache::functionplotresponse::splineorder; |
$result.=&geogebra_startcode(); |
undef %Apache::functionplotresponse::splineinitx; |
$result.=&geogebra_spline_program(); |
undef %Apache::functionplotresponse::splineinity; |
$result.=&geogebra_default_parameters(); |
undef %Apache::functionplotresponse::splinescalex; |
|
undef %Apache::functionplotresponse::splinescaley; |
|
# Remember input fields, etc |
|
undef %Apache::functionplotresponse::previous; |
|
$Apache::functionplotresponse::inputfields=''; |
|
$Apache::functionplotresponse::counter=0; |
|
# Remember rules |
|
undef @Apache::functionplotresponse::functionplotrules; |
|
# Part and ID |
|
my $partid=$Apache::inputtags::part; |
|
my $id=&Apache::response::start_response($parstack,$safeeval); |
|
# Internal ID to mark the applet and its coordinates |
|
my $internalid = $partid.'_'.$id; |
|
# Previous answer |
|
&decode_previous_answer($Apache::lonhomework::history{"resource.$partid.$id.submission"}); |
|
|
|
# Parameters of <functionplotresponse> |
|
my $xmin=&Apache::lonxml::get_param('xmin',$parstack,$safeeval); |
|
$xmin=(defined($xmin)?$xmin:-10); |
|
my $xmax=&Apache::lonxml::get_param('xmax',$parstack,$safeeval); |
|
$xmax=(defined($xmax)?$xmax:10); |
|
my $ymin=&Apache::lonxml::get_param('ymin',$parstack,$safeeval); |
|
$ymin=(defined($ymin)?$ymin:-10); |
|
my $ymax=&Apache::lonxml::get_param('ymax',$parstack,$safeeval); |
|
$ymax=(defined($ymax)?$ymax:10); |
|
if ($xmax<=$xmin) { |
|
&Apache::lonxml::warning('Maximum x-value needs to be larger than minimum value.'); |
|
$xmax=$xmin+20; |
|
} |
|
if ($ymax<=$ymin) { |
|
&Apache::lonxml::warning('Maximum y-value needs to be larger than minimum value.'); |
|
$ymax=$ymin+20; |
|
} |
|
my $xaxisvisible=(&Apache::lonxml::get_param('xaxisvisible',$parstack,$safeeval)=~/on|true|yes|1/i?'true':'false'); |
|
my $yaxisvisible=(&Apache::lonxml::get_param('yaxisvisible',$parstack,$safeeval)=~/on|true|yes|1/i?'true':'false'); |
|
my $gridvisible=(&Apache::lonxml::get_param('gridvisible',$parstack,$safeeval)=~/on|true|yes|1/i?'true':'false'); |
|
my $xlabel=&Apache::lonxml::get_param('xlabel',$parstack,$safeeval); |
|
my $ylabel=&Apache::lonxml::get_param('ylabel',$parstack,$safeeval); |
|
if ($target eq 'edit') { |
|
$result.=&Apache::edit::start_table($token) |
|
.'<tr><td><span class="LC_nobreak">'.&mt('Function Plot Question').'</span></td>' |
|
.'<td><span class="LC_nobreak">'.&mt('Delete?').' ' |
|
.&Apache::edit::deletelist($target,$token) |
|
.'</span></td>' |
|
."<td> " |
|
.&Apache::edit::end_row() |
|
.&Apache::edit::start_spanning_row() |
|
."\n"; |
|
$result.=&Apache::edit::text_arg('Label x-axis:','xlabel', |
|
$token,'6').' '. |
|
&Apache::edit::text_arg('Minimum x-value:','xmin', |
|
$token,'4').' '. |
|
&Apache::edit::text_arg('Maximum x-value:','xmax', |
|
$token,'4').' '. |
|
&Apache::edit::select_arg('x-axis visible:','xaxisvisible', |
|
['yes','no'],$token).'<br />'. |
|
&Apache::edit::text_arg('Label y-axis:','ylabel', |
|
$token,'6').' '. |
|
&Apache::edit::text_arg('Minimum y-value:','ymin', |
|
$token,'4').' '. |
|
&Apache::edit::text_arg('Maximum y-value:','ymax', |
|
$token,'4').' '. |
|
&Apache::edit::select_arg('y-axis visible:','yaxisvisible', |
|
['yes','no'],$token).'<br />'. |
|
&Apache::edit::select_arg('Grid visible:','gridvisible', |
|
['yes','no'],$token). |
|
&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'); |
|
if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); } |
|
|
|
} 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 |
} |
} |
return $result; |
return $result; |
} |
} |
|
|
|
sub compare_rel { |
|
my ($relationship,$value,$realval,$tol)=@_; |
|
# is the real value defined? |
|
unless (defined($realval)) { |
|
if ($relationship eq 'eq') { |
|
if ($value eq 'undef') { |
|
return 1; |
|
} else { |
|
return 0; |
|
} |
|
} elsif ($relationship eq 'ne') { |
|
if ($value eq 'undef') { |
|
return 0; |
|
} else { |
|
return 1; |
|
} |
|
} else { |
|
return 0; |
|
} |
|
} |
|
|
|
# it is defined. |
|
if ($relationship eq 'gt') { |
|
return ($realval>$value); |
|
} elsif ($relationship eq 'ge') { |
|
return ($realval>$value-$tol); |
|
} elsif ($relationship eq 'lt') { |
|
return ($realval<$value); |
|
} elsif ($relationship eq 'le') { |
|
return ($realval<$value+$tol); |
|
} elsif ($relationship eq 'ne') { |
|
return (abs($value-$realval)>$tol); |
|
} else { |
|
return (abs($value-$realval)<$tol); |
|
} |
|
return 0; |
|
} |
|
|
|
sub functionplotrulecheck { |
|
my ($rule,$xmin,$xmax,$tolfunc,$toldfdx,$told2fdx2)=@_; |
|
# &Apache::lonnet::logthis("Rule $rule TolFunc $tolfunc TolDfDx $toldfdx TolD2fDx2 $told2fdx2"); |
|
my ($label,$derivative,$xinitial,$xinitiallabel,$xfinal,$xfinallabel,$relationship,$value) |
|
=split(/\:/,$rule); |
|
|
|
my $li=0; |
|
my $lh=400; |
|
|
|
# Special case: the upper boundary was not defined |
|
# and needs to be set to the value where |
|
# the condition is not true anymore => set flag |
|
|
|
my $findupper=0; |
|
if (($xfinal eq '') |
|
&& (!defined($Apache::functionplotresponse::functionplotrulelabels{$xfinallabel})) |
|
&& ($xfinallabel)) { |
|
$findupper=1; |
|
} |
|
|
|
# if a hard value is set for the boundaries, it overrides the label |
|
if (($xinitial ne '') && ($xinitiallabel ne '') && ($xinitiallabel ne 'start')) { |
|
$li=&array_index($xmin,$xmax,$xinitial); |
|
$Apache::functionplotresponse::functionplotrulelabels{$xinitiallabel}=$li; |
|
} |
|
if (($xfinal ne '') && ($xfinallabel ne '') && ($xfinallabel ne 'end')) { |
|
$lh=&array_index($xmin,$xmax,$xfinal); |
|
$Apache::functionplotresponse::functionplotrulelabels{$xfinallabel}=$lh; |
|
} |
|
# if the label is defined, use it |
|
if (defined($Apache::functionplotresponse::functionplotrulelabels{$xinitiallabel})) { |
|
$li=$Apache::functionplotresponse::functionplotrulelabels{$xinitiallabel}; |
|
} else { |
|
$li=&array_index($xmin,$xmax,$xinitial); |
|
} |
|
unless ($findupper) { |
|
if (defined($Apache::functionplotresponse::functionplotrulelabels{$xfinallabel})) { |
|
$lh=$Apache::functionplotresponse::functionplotrulelabels{$xfinallabel}; |
|
} else { |
|
$lh=&array_index($xmin,$xmax,$xfinal); |
|
} |
|
} |
|
# Basic sanity checks |
|
if ($li<0) { $li=0; } |
|
if ($lh>400) { $lh=400; } |
|
if ($li>$lh) { |
|
$lh=$li; |
|
} |
|
|
|
# &Apache::lonnet::logthis("Init $xinitial=$li Final $xfinal=$lh Findupper: $findupper"); |
|
my $tol=$tolfunc; |
|
if ($derivative==2) { |
|
$tol=$told2fdx2; |
|
} elsif ($derivative==1) { |
|
$tol=$toldfdx; |
|
} |
|
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]; |
|
} else { |
|
$val=$Apache::functionplotresponse::func[$i]; |
|
} |
|
unless (&compare_rel($relationship,$value,$val,$tol)) { |
|
# &Apache::lonnet::logthis("Condition false $findupper at $i with $val"); |
|
if (($findupper) && ($i>$li)) { |
|
$Apache::functionplotresponse::functionplotrulelabels{$xfinallabel}=$i; |
|
# &Apache::lonnet::logthis("Setting $xfinallabel to $i"); |
|
return 1; |
|
} else { |
|
return 0; |
|
} |
|
} |
|
} |
|
return 1; |
|
} |
|
|
sub end_functionplotresponse { |
sub end_functionplotresponse { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
&Apache::response::end_response; |
&Apache::response::end_response; |
|
|
my $result; |
my $result; |
# if ($target eq 'edit') { $result=&Apache::edit::end_table(); } |
my $id=$Apache::inputtags::response[-1]; |
if ($target eq 'web') { |
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); |
|
# |
|
# Actually grade |
|
# |
|
my $xmin=&Apache::lonxml::get_param('xmin',$parstack,$safeeval); |
|
$xmin=(defined($xmin)?$xmin:-10); |
|
my $xmax=&Apache::lonxml::get_param('xmax',$parstack,$safeeval); |
|
$xmax=(defined($xmax)?$xmax:10); |
|
my $ymin=&Apache::lonxml::get_param('ymin',$parstack,$safeeval); |
|
$ymin=(defined($ymin)?$ymin:-10); |
|
my $ymax=&Apache::lonxml::get_param('ymax',$parstack,$safeeval); |
|
$ymax=(defined($ymax)?$ymax:10); |
|
|
|
my $percent=&Apache::lonxml::get_param('percenterror',$parstack,$safeeval); |
|
$percent=(defined($percent)?$percent:5); |
|
|
|
my $tolfunc=$percent*($ymax-$ymin)/100.; |
|
my $toldfdx=1; |
|
my $told2fdx2=1; |
|
if ($xmax>$xmin) { |
|
$toldfdx=$tolfunc/($xmax-$xmin); |
|
$told2fdx2=$toldfdx/($xmax-$xmin); |
|
} |
|
|
|
my $ad=''; |
|
undef %Apache::functionplotresponse::functionplotrulelabels; |
|
$Apache::functionplotresponse::functionplotrulelabels{'start'}=400; |
|
$Apache::functionplotresponse::functionplotrulelabels{'end'}=0; |
|
if (&populate_arrays($internalid,$xmin,$xmax) eq 'no_func') { |
|
$ad='NOT_FUNCTION'; |
|
} else { |
|
# 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,$tolfunc,$toldfdx,$told2fdx2)) { |
|
$ad='INCORRECT'; |
|
last; |
|
} |
|
} |
|
# If it's not wrong, it's correct |
|
unless ($ad) { $ad='EXACT_ANS' }; |
|
} |
|
|
|
# |
|
# Store grading info |
|
# |
|
$Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad; |
|
&Apache::response::handle_previous(\%previous,$ad); |
|
} 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); |
|
} |
|
# close the init script |
|
$result.=&end_init_script(); |
|
# register all splines in this response |
|
$result.='<input type="hidden" name="HWVAL_AllSplines_'.$internalid.'" value="'. |
|
join(',',keys(%Apache::functionplotresponse::splineorder)).'" />'."\n"; |
|
foreach my $label (keys(%Apache::functionplotresponse::splineorder)) { |
|
$result.='<input type="hidden" name="HWVAL_SplineOrder_'.$internalid.'_'.$label.'" value="'. |
|
$Apache::functionplotresponse::splineorder{$label}.'" />'."\n"; |
|
} |
|
# generate the input fields |
|
$result.=$Apache::functionplotresponse::inputfields; |
|
# actually start the <applet>-tag |
|
$result.=&geogebra_startcode($internalid); |
|
# load the spline bytecode |
|
$result.=&geogebra_spline_program(); |
|
# set default parameters |
|
$result.=&geogebra_default_parameters($internalid); |
|
# close the <applet>-tag |
$result.=&geogebra_endcode(); |
$result.=&geogebra_endcode(); |
} |
} |
return $result; |
return $result; |