[LON-CAPA-cvs] cvs: loncom /homework edit.pm functionplotresponse.pm hint.pm insertlist.xml /homework/templates functionplotone.problem functionplottwo.problem functionplottwo.problem.meta

www www@source.lon-capa.org
Sat, 13 Nov 2010 03:23:03 -0000


This is a MIME encoded message

--www1289618583
Content-Type: text/plain

www		Sat Nov 13 03:23:03 2010 EDT

  Modified files:              
    /loncom/homework	edit.pm functionplotresponse.pm hint.pm 
                    	insertlist.xml 
    /loncom/homework/templates	functionplotone.problem 
                              	functionplottwo.problem 
                              	functionplottwo.problem.meta 
  Log:
  Functionplotresponse hints working
  
  
--www1289618583
Content-Type: text/plain
Content-Disposition: attachment; filename="www-20101113032303.txt"

Index: loncom/homework/edit.pm
diff -u loncom/homework/edit.pm:1.132 loncom/homework/edit.pm:1.133
--- loncom/homework/edit.pm:1.132	Sun Nov  7 01:57:50 2010
+++ loncom/homework/edit.pm	Sat Nov 13 03:22:58 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # edit mode helpers
 #
-# $Id: edit.pm,v 1.132 2010/11/07 01:57:50 www Exp $
+# $Id: edit.pm,v 1.133 2010/11/13 03:22:58 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -400,8 +400,12 @@
 sub insert_functionplotresponse {
     return '
 <functionplotresponse>
+<functionplotelements>
 <spline />
+</functionplotelements>
+<functionplotruleset>
 <functionplotrule />
+</functionplotruleset>
 </functionplotresponse>';
 }
 
@@ -420,7 +424,19 @@
 <functionplotrule />';
 }
 
+sub insert_functionplotruleset {
+    return '
+<functionplotruleset>
+<functionplotrule />
+</functionplotruleset>';
+}
 
+sub insert_functionplotelements {
+    return '
+<functionplotelements>
+<spline />
+</functionplotelements>';
+}
 
 sub insert_numericalresponse {
     return '
Index: loncom/homework/functionplotresponse.pm
diff -u loncom/homework/functionplotresponse.pm:1.36 loncom/homework/functionplotresponse.pm:1.37
--- loncom/homework/functionplotresponse.pm:1.36	Fri Nov 12 22:23:40 2010
+++ loncom/homework/functionplotresponse.pm	Sat Nov 13 03:22:58 2010
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # option list style responses
 #
-# $Id: functionplotresponse.pm,v 1.36 2010/11/12 22:23:40 www Exp $
+# $Id: functionplotresponse.pm,v 1.37 2010/11/13 03:22:58 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -33,7 +33,9 @@
 use Apache::lonnet;
  
 BEGIN {
-  &Apache::lonxml::register('Apache::functionplotresponse',('functionplotresponse','backgroundplot','spline','functionplotrule'));
+  &Apache::lonxml::register('Apache::functionplotresponse',('functionplotresponse','backgroundplot','spline',
+                                                            'functionplotrule','functionplotruleset',
+                                                            'functionplotelements'));
 }
 
 #
@@ -660,7 +662,7 @@
 }
 
 #
-# Implentation of <functionplotresponse>
+# Implementation of <functionplotresponse>
 #
 
 sub start_functionplotresponse {
@@ -678,6 +680,12 @@
   $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 +720,8 @@
     $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)
+       .&Apache::edit::deletelist($target,$token).'&nbsp;&nbsp;&nbsp;'
+       .&Apache::edit::insertlist($target,$token)
        .'</span></td>'
        ."<td>&nbsp;"
        .&Apache::edit::end_row()
@@ -745,15 +754,6 @@
 
   } 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')) {
@@ -912,8 +912,8 @@
         } else {
            $val=$Apache::functionplotresponse::func[$i];
         }
-        &addlog("Actual value ".(defined($val)?$val:'undef').", expected $value, tolerance $tol");
         unless (&compare_rel($relationship,$value,$val,$tol)) { 
+           &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
@@ -935,6 +935,10 @@
               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; 
            }
         }
@@ -943,39 +947,43 @@
    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).
+        '<tr><td><span class="LC_nobreak">'.&mt('Function Plot Rule Set').'</span></td>'
+       .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
+       .&Apache::edit::deletelist($target,$token).'&nbsp;&nbsp;&nbsp;'.
+        &Apache::edit::insertlist($target,$token)
+       .'</span></td>'
+       ."<td>&nbsp;"
+       .&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='';
@@ -1001,13 +1009,60 @@
 # 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);
@@ -1035,6 +1090,58 @@
   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).
+        '<tr><td><span class="LC_nobreak">'.&mt('Function Plot Elements').'</span></td>'
+       .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
+       .&Apache::edit::deletelist($target,$token).'&nbsp;&nbsp;&nbsp;'.
+        &Apache::edit::insertlist($target,$token)
+       .'</span></td>'
+       ."<td>&nbsp;"
+       .&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;
 
 __END__
Index: loncom/homework/hint.pm
diff -u loncom/homework/hint.pm:1.76 loncom/homework/hint.pm:1.77
--- loncom/homework/hint.pm:1.76	Sun Jun 28 19:40:41 2009
+++ loncom/homework/hint.pm	Sat Nov 13 03:22:58 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # implements the tags that control the hints
 #
-# $Id: hint.pm,v 1.76 2009/06/28 19:40:41 www Exp $
+# $Id: hint.pm,v 1.77 2010/11/13 03:22:58 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -81,6 +81,10 @@
        }
     }
     @Apache::hint::which=();
+    if (($#Apache::functionplotresponse::failedrules>=0) && ($target eq 'web')) {
+        @Apache::hint::which=@Apache::functionplotresponse::failedrules;
+        undef @Apache::functionplotresponse::failedrules;
+    }
     return $result;
 }
 
Index: loncom/homework/insertlist.xml
diff -u loncom/homework/insertlist.xml:1.21 loncom/homework/insertlist.xml:1.22
--- loncom/homework/insertlist.xml:1.21	Sun Nov  7 01:57:50 2010
+++ loncom/homework/insertlist.xml	Sat Nov 13 03:22:58 2010
@@ -20,7 +20,7 @@
                 <description>Response: Function Plot</description>
                 <color>#77DD55</color>
                 <insert_sub>insert_functionplotresponse</insert_sub>
-                <allow>spline,backgroundplot,functionplotrule</allow>
+                <allow>functionplotelements,functionplotruleset,hintgroup</allow>
         </tag>
         <tag name="spline">
                 <description>Spline</description>
@@ -34,6 +34,19 @@
                 <insert_sub>insert_backgroundplot</insert_sub>
                 <allow></allow>
         </tag>
+        <tag name="functionplotruleset">
+                <description>Function Plot Rule Set</description>
+                <color>#99ff88</color>
+                <insert_sub>insert_functionplotruleset</insert_sub>
+                <allow>functionplotrule</allow>
+        <tag>
+        <tag name="functionplotelements">
+                <description>Function Plot Elements</description>
+                <color>#99ff88</color>
+                <insert_sub>insert_functionplotelements</insert_sub>
+                <allow>spline,backgroundplot</allow>
+        <tag>
+
         <tag name="functionplotrule">
                 <description>Function Plot Evaluation Rule</description>
                 <color>#99ff88</color>
Index: loncom/homework/templates/functionplotone.problem
diff -u loncom/homework/templates/functionplotone.problem:1.2 loncom/homework/templates/functionplotone.problem:1.3
--- loncom/homework/templates/functionplotone.problem:1.2	Fri Nov 12 02:16:24 2010
+++ loncom/homework/templates/functionplotone.problem	Sat Nov 13 03:23:03 2010
@@ -6,7 +6,10 @@
 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">
+<functionplotelements>
 <spline initx="-2" inity="0" index="A" order="8" scalex="28" />
+</functionplotelements>
+<functionplotruleset>
 <functionplotrule relationship="eq" xinitiallabel="start" xfinallabel="brake" value="0" derivativeorder="0" percenterror="1" minimumlength="1" />
 <functionplotrule relationship="eq" xinitial="0" value="0" derivativeorder="0" percenterror="1" />
 <functionplotrule relationship="lt" xinitiallabel="brake" xfinallabel="stop" value="-0.1" derivativeorder="0" />
@@ -15,5 +18,6 @@
 <functionplotrule relationship="gt" xinitiallabel="driveoff" xfinallabel="cruise" value="0.1" derivativeorder="0" />
 <functionplotrule relationship="le" xinitiallabel="driveoff" xfinallabel="cruise" value="$maxacc" derivativeorder="0" />
 <functionplotrule relationship="eq" xinitiallabel="cruise" xfinallabel="end" value="0" derivativeorder="0" percenterror="1" minimumlength="1" />
+</functionplotruleset>
 </functionplotresponse>
 </problem>
Index: loncom/homework/templates/functionplottwo.problem
diff -u loncom/homework/templates/functionplottwo.problem:1.1 loncom/homework/templates/functionplottwo.problem:1.2
--- loncom/homework/templates/functionplottwo.problem:1.1	Fri Nov 12 02:16:24 2010
+++ loncom/homework/templates/functionplottwo.problem	Sat Nov 13 03:23:03 2010
@@ -4,9 +4,12 @@
 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">
+<functionplotelements>
 <spline initx="-2" inity="0" index="A" order="2" scalex="4" />
 <spline index="B" order="2" initx="12" inity="0" scalex="4" />
-<functionplotrule relationship="eq" value="undef" derivative="0" xinitial="$x" />
+</functionplotelements>
+<functionplotruleset>
+<functionplotrule relationship="eq" value="undef" derivative="0" xinitial="$x" index="chargeposition" derivativeorder="0" />
 <functionplotrule relationship="lt" value="0" derivativeorder="0" xinitiallabel="start" xfinallabel="chargeleft" />
 <functionplotrule relationship="lt" value="0" derivativeorder="1" xinitiallabel="start" xfinallabel="chargeleft" />
 <functionplotrule relationship="le" value="0" derivativeorder="2" xinitiallabel="start" xfinallabel="chargeleft" />
@@ -14,5 +17,12 @@
 <functionplotrule relationship="lt" value="0" derivativeorder="0" xinitiallabel="chargeright" xfinallabel="end" />
 <functionplotrule relationship="gt" value="0" derivativeorder="1" xinitiallabel="chargeright" xfinallabel="end" />
 <functionplotrule relationship="le" value="0" derivativeorder="2" xinitiallabel="chargeright" xfinallabel="end" />
+</functionplotruleset>
+
+<hintgroup showoncorrect="no">
+<hintpart on="chargeposition">
+<startouttext />The charge is not in the correct position.<endouttext />
+</hintpart>
+</hintgroup>
 </functionplotresponse>
 </problem>
Index: loncom/homework/templates/functionplottwo.problem.meta
diff -u loncom/homework/templates/functionplottwo.problem.meta:1.1 loncom/homework/templates/functionplottwo.problem.meta:1.2
--- loncom/homework/templates/functionplottwo.problem.meta:1.1	Fri Nov 12 02:16:24 2010
+++ loncom/homework/templates/functionplottwo.problem.meta	Sat Nov 13 03:23:03 2010
@@ -1,2 +1,2 @@
-<title>Functionplotresponse with two Splines and Labels</title>
+<title>Functionplotresponse with two Splines and Hints</title>
 <category>Free Form Problems</category>

--www1289618583--