#
sub start_functionplotresponse {
@@ -678,6 +684,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 +724,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 +758,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')) {
@@ -784,8 +788,9 @@ sub start_functionplotresponse {
sub compare_rel {
my ($relationship,$value,$realval,$tol)=@_;
-# is the real value defined?
+# is the real value undefined?
unless (defined($realval)) {
+# the real value is not defined
if ($relationship eq 'eq') {
if ($value eq 'undef') {
return 1;
@@ -803,7 +808,13 @@ sub compare_rel {
}
}
-# it is defined.
+# is the expected value undefined?
+ if ($value eq 'undef') {
+# but by now we know that the real value is defined
+ return 0;
+ }
+
+# both are defined.
if ($relationship eq 'gt') {
return ($realval>$value);
} elsif ($relationship eq 'ge') {
@@ -879,7 +890,7 @@ sub functionplotrulecheck {
# Basic sanity checks
if ($li<0) { $li=0; }
if ($lh>400) { $lh=400; }
- if ($li>$lh) {
+ if (($li>$lh) || (!defined($lh))) {
$lh=$li;
}
@@ -906,8 +917,8 @@ sub functionplotrulecheck {
$val=$Apache::functionplotresponse::func[$i];
}
unless (&compare_rel($relationship,$value,$val,$tol)) {
- &addlog("Condition not fulfilled at x=".&actualval($i,$xmin,$xmax)." (".$Apache::functionplotresponse::actualxval[$i]."; index $i)");
&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);
@@ -928,6 +939,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;
}
}
@@ -936,38 +951,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='';
@@ -993,13 +1013,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);
@@ -1026,6 +1093,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;
|