[LON-CAPA-cvs] cvs: loncom /homework hint.pm lonmaxima.pm response.pm

www lon-capa-cvs@mail.lon-capa.org
Mon, 18 Dec 2006 21:12:51 -0000


This is a MIME encoded message

--www1166476371
Content-Type: text/plain

www		Mon Dec 18 16:12:51 2006 EDT

  Modified files:              
    /loncom/homework	hint.pm lonmaxima.pm response.pm 
  Log:
  <mathhint> functionality
  
  
--www1166476371
Content-Type: text/plain
Content-Disposition: attachment; filename="www-20061218161251.txt"

Index: loncom/homework/hint.pm
diff -u loncom/homework/hint.pm:1.62 loncom/homework/hint.pm:1.63
--- loncom/homework/hint.pm:1.62	Tue Mar  7 17:42:47 2006
+++ loncom/homework/hint.pm	Mon Dec 18 16:12:51 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # implements the tags that control the hints
 #
-# $Id: hint.pm,v 1.62 2006/03/07 22:42:47 albertel Exp $
+# $Id: hint.pm,v 1.63 2006/12/18 21:12:51 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -31,10 +31,12 @@
 use strict;
 use Apache::lonnet;
 use capa;
+use Apache::lonmaxima();
+use Apache::response();
 use Apache::lonlocal;
 
 BEGIN {
-    &Apache::lonxml::register('Apache::hinttags',('hintgroup','hintpart','numericalhint','stringhint','formulahint','optionhint','radiobuttonhint'));
+    &Apache::lonxml::register('Apache::hinttags',('hintgroup','hintpart','numericalhint','stringhint','formulahint','optionhint','radiobuttonhint','mathhint'));
 }
 
 
@@ -215,6 +217,71 @@
     return &end_numericalhint(@_);
 }
 
+sub start_mathhint {
+    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+    #do everything in end, so intervening <responseparams> and <answer> work
+    &Apache::response::start_hintresponse($parstack,$safeeval);
+    &Apache::lonxml::register('Apache::response',('answer'));
+    my $result;
+    if ($target eq 'edit') {
+        $result.=&Apache::edit::tag_start($target,$token);
+        $result.=&Apache::edit::text_arg('Name:','name',$token);
+        $result.=&Apache::edit::select_arg('Algebra System:',
+                                           'cas',
+                                           ['maxima'],
+                                           $token);
+        $result.=&Apache::edit::text_arg('Argument Array:',
+                                         'args',$token);
+        $result.=&Apache::edit::end_row();
+        $result.=&Apache::edit::start_spanning_row();
+    } elsif ($target eq 'modified') {
+        my $constructtag;
+        $constructtag=&Apache::edit::get_new_args($token,$parstack,
+                                                  $safeeval,'name','cas',
+                                                  'args');
+        $result  = &Apache::edit::rebuild_tag($token);
+        $result .= &Apache::edit::handle_insert();
+    } elsif ($target eq 'web') {
+        &Apache::response::reset_params();
+    }
+    return $result;
+}
+
+sub end_mathhint {
+    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+    my $result;
+    if ($target eq 'web') {
+        if (!$Apache::lonxml::default_homework_loaded) {
+            &Apache::lonxml::default_homework_load($safeeval);
+        }
+	my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
+        &Apache::response::setup_params('mathhint',$safeeval);
+        my $partid=$Apache::inputtags::part;
+        my $submitid=$Apache::inputtags::response[-1];
+        my $response = $Apache::lonhomework::history{
+                            "resource.$partid.$submitid.submission"};
+	
+	my $cas = &Apache::lonxml::get_param('cas',$parstack,$safeeval);
+	my $award;
+	if ($cas eq 'maxima') {
+	    my $args = [&Apache::lonxml::get_param_var('args',$parstack,$safeeval)];
+	    $award=&Apache::lonmaxima::maxima_run($Apache::response::custom_answer[-1],$response,$args);
+	}
+        if ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS') {
+            push (@Apache::hint::which,$name);
+        }
+        $result='';
+    } elsif ($target eq 'meta') {
+        $result=&Apache::response::meta_package_write($token->[1]);
+    } elsif ($target eq 'edit') {
+        $result.=&Apache::edit::end_row().&Apache::edit::end_table();
+    }
+    pop(@Apache::response::custom_answer);
+    pop(@Apache::response::custom_answer_type);
+    &Apache::response::end_hintresponse();
+    return $result;
+}
+
 sub start_stringhint {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
     #do everything in end, so intervening <responseparams> work
Index: loncom/homework/lonmaxima.pm
diff -u loncom/homework/lonmaxima.pm:1.9 loncom/homework/lonmaxima.pm:1.10
--- loncom/homework/lonmaxima.pm:1.9	Fri Dec 15 17:11:43 2006
+++ loncom/homework/lonmaxima.pm	Mon Dec 18 16:12:51 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Interface routines to MAXIMA CAS
 #
-# $Id: lonmaxima.pm,v 1.9 2006/12/15 22:11:43 www Exp $
+# $Id: lonmaxima.pm,v 1.10 2006/12/18 21:12:51 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -95,7 +95,7 @@
     }
     my $argument_index=1;
     foreach my $argument_component (@{$argument}) {
-	$fullscript.="LONCAPALIST[$argument_index]:$argument_component;\n";
+	$fullscript.="LONCAPALIST[$argument_index]:".&maxima_cas_formula_fix($argument_component).";\n";
 	$argument_index++;
     }
     $fullscript.=$script;
Index: loncom/homework/response.pm
diff -u loncom/homework/response.pm:1.156 loncom/homework/response.pm:1.157
--- loncom/homework/response.pm:1.156	Fri Dec 15 17:11:43 2006
+++ loncom/homework/response.pm	Mon Dec 18 16:12:51 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # various response type definitons response definition
 #
-# $Id: response.pm,v 1.156 2006/12/15 22:11:43 www Exp $
+# $Id: response.pm,v 1.157 2006/12/18 21:12:51 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -368,7 +368,8 @@
     my $id = &Apache::response::start_response($parstack,$safeeval);
     push(@Apache::lonxml::namespace,'customresponse');
     my $result;
-    undef($Apache::response::custom_answer);
+    @Apache::response::custom_answer=();
+    @Apache::response::custom_answer_type=();
     &Apache::lonxml::register('Apache::response',('answer'));
     if ($target eq 'web') {
   	if (  &Apache::response::show_answer() ) {
@@ -420,7 +421,7 @@
 	    ${$safeeval->varglob('LONCAPA::customresponse_submission')}=
 		$response;
 	    
-	    my $award = &Apache::run::run('{ my $submission=$LONCAPA::customresponse_submission;'.$Apache::response::custom_answer.'}',$safeeval);
+	    my $award = &Apache::run::run('{ my $submission=$LONCAPA::customresponse_submission;'.$Apache::response::custom_answer[-1].'}',$safeeval);
 	    if (!&Apache::inputtags::valid_award($award)) {
 		$error = $award;
 		$award = 'ERROR';
@@ -448,6 +449,8 @@
 	&Apache::lonxml::increment_counter(&Apache::response::repetition());
     }
     pop(@Apache::lonxml::namespace);
+    pop(@Apache::response::custom_answer);
+    pop(@Apache::response::custom_answer_type);
     &Apache::lonxml::deregister('Apache::response',('answer'));
     &Apache::response::end_response();
     return $result;
@@ -459,7 +462,8 @@
     my $id = &Apache::response::start_response($parstack,$safeeval);
     push(@Apache::lonxml::namespace,'mathresponse');
     my $result;
-    undef($Apache::response::custom_answer);
+    @Apache::response::custom_answer=();
+    @Apache::response::custom_answer_type=();
     &Apache::lonxml::register('Apache::response',('answer'));
     if ($target eq 'web') {
   	if (  &Apache::response::show_answer() ) {
@@ -514,7 +518,7 @@
 	    my $cas = &Apache::lonxml::get_param('cas',$parstack,$safeeval);
             if ($cas eq 'maxima') {
                 my $args = [&Apache::lonxml::get_param_var('args',$parstack,$safeeval)];
-                $award=&Apache::lonmaxima::maxima_run($Apache::response::custom_answer,$response,$args);
+                $award=&Apache::lonmaxima::maxima_run($Apache::response::custom_answer[-1],$response,$args);
             }
 	    if (!&Apache::inputtags::valid_award($award)) {
 		$error = $award;
@@ -530,6 +534,8 @@
 	}
     }
     pop(@Apache::lonxml::namespace);
+    pop(@Apache::response::custom_answer);
+    pop(@Apache::response::custom_answer_type);
     &Apache::lonxml::deregister('Apache::response',('answer'));
     &Apache::response::end_response();
     return $result;
@@ -561,11 +567,11 @@
 sub start_answer {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
     my $result;
-    $Apache::response::custom_answer=
-	&Apache::lonxml::get_all_text_unbalanced("/answer",$parser);
-    $Apache::response::custom_answer_type=
-	lc(&Apache::lonxml::get_param('type',$parstack,$safeeval));
-    $Apache::response::custom_answer_type =~ s/\s+//g;
+    push(@Apache::response::custom_answer,
+	&Apache::lonxml::get_all_text_unbalanced("/answer",$parser));
+    push(@Apache::response::custom_answer_type,
+	lc(&Apache::lonxml::get_param('type',$parstack,$safeeval)));
+    $Apache::response::custom_answer_type[-1] =~ s/\s+//g;
     if ($target eq "edit" ) {
 	$result=&Apache::edit::tag_start($target,$token,'Answer algorithm');
 	$result.=&Apache::edit::editfield($token->[1],

--www1166476371--