[LON-CAPA-cvs] cvs: loncom /homework default_homework.lcpm lonmaxima.pm /homework/caparesponse caparesponse.pm

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 13 Jun 2006 14:58:14 -0000


albertel		Tue Jun 13 10:58:14 2006 EDT

  Modified files:              
    /loncom/homework	lonmaxima.pm default_homework.lcpm 
    /loncom/homework/caparesponse	caparesponse.pm 
  Log:
  - moving code from modules into main 
  
  
Index: loncom/homework/lonmaxima.pm
diff -u loncom/homework/lonmaxima.pm:1.4 loncom/homework/lonmaxima.pm:1.5
--- loncom/homework/lonmaxima.pm:1.4	Mon Jun 12 10:22:01 2006
+++ loncom/homework/lonmaxima.pm	Tue Jun 13 10:57:54 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Interface routines to MAXIMA CAS
 #
-# $Id: lonmaxima.pm,v 1.4 2006/06/12 14:22:01 bisitz Exp $
+# $Id: lonmaxima.pm,v 1.5 2006/06/13 14:57:54 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -76,13 +76,7 @@
 }
 
 sub maxima_check {
-    my ($response,$answer,$type,
-        $tol_type,$tol,
-        $sig_lbound,$sig_ubound,
-        $ans_fmt,$unit,$calc,$id_list,
-        $points,
-        $randomseed,
-        $reterror) = @_;
+    my ($response,$answer,$reterror) = @_;
     my $socket=&connect();
     my $reply=&compareterms($socket,$response,$answer);
     &disconnect($socket);
Index: loncom/homework/default_homework.lcpm
diff -u loncom/homework/default_homework.lcpm:1.106 loncom/homework/default_homework.lcpm:1.107
--- loncom/homework/default_homework.lcpm:1.106	Tue Dec 20 15:00:42 2005
+++ loncom/homework/default_homework.lcpm	Tue Jun 13 10:57:54 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run()
 #
-# $Id: default_homework.lcpm,v 1.106 2005/12/20 20:00:42 albertel Exp $
+# $Id: default_homework.lcpm,v 1.107 2006/06/13 14:57:54 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -117,10 +117,11 @@
 	if ( $answer eq ($answer *1.0)) { $type = 2;
 				      } else { $type = 3; }
     } else {
-	if ($type eq 'cs')    { $type = 4; }
+	if    ($type eq 'cs')    { $type = 4; }
 	elsif ($type eq 'ci')    { $type = 3 }
 	elsif ($type eq 'mc')    { $type = 5; }
 	elsif ($type eq 'fml')   { $type = 8; }
+        elsif ($type eq 'math')  { $type = 9; }
 	elsif ($type eq 'subj')  { $type = 7; }
 	elsif ($type eq 'float') { $type = 2; }
 	elsif ($type eq 'int')   { $type = 1; }
@@ -149,13 +150,17 @@
     ($sig_ubound,$sig_lbound)=&LONCAPA_INTERNAL_get_sigrange($sig);
 
     my $reterror="";
-    my $result = &caparesponse_capa_check_answer($response,$answer,$type,
+    my $result;
+    if ($type eq '9') {
+      $result = &maxima_check($response,$answer,\$reterror);
+    } else {
+       $result = &caparesponse_capa_check_answer($response,$answer,$type,
 						 $tol_type,$tol,
 						 $sig_lbound,$sig_ubound,
 						 $ans_fmt,$unit,$calc,$id_list,
 						 $points,$external::randomseed,
 						 \$reterror);
-
+    }
     if    ($result == '1') { $result='EXACT_ANS'; } 
     elsif ($result == '2') { $result='APPROX_ANS'; }
     elsif ($result == '3') { $result='SIG_FAIL'; }
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.189 loncom/homework/caparesponse/caparesponse.pm:1.190
--- loncom/homework/caparesponse/caparesponse.pm:1.189	Wed Mar  8 20:13:16 2006
+++ loncom/homework/caparesponse/caparesponse.pm	Tue Jun 13 10:58:14 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # caparesponse definition
 #
-# $Id: caparesponse.pm,v 1.189 2006/03/09 01:13:16 albertel Exp $
+# $Id: caparesponse.pm,v 1.190 2006/06/13 14:58:14 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -29,11 +29,13 @@
 package Apache::caparesponse;
 use strict;
 use capa;
+use Safe::Hole;
+use Apache::lonmaxima();
 use Apache::lonlocal;
 use Apache::lonnet;
 
 BEGIN {
-    &Apache::lonxml::register('Apache::caparesponse',('caparesponse','numericalresponse','stringresponse','formularesponse'));
+    &Apache::lonxml::register('Apache::caparesponse',('caparesponse','numericalresponse','stringresponse','formularesponse','mathresponse'));
 }
 
 my %answer;
@@ -248,6 +250,8 @@
     
     if ($tag eq 'formularesponse') {
 	$$args_ref{'type'}='fml';
+    } elsif ($tag eq 'mathresponse') {
+        $$args_ref{'type'}='math';
     } elsif ($tag eq 'numericalresponse') {
 	$$args_ref{'type'}='float';
     }
@@ -290,12 +294,15 @@
     my $partid = $Apache::inputtags::part;
     my $id = $Apache::inputtags::response[-1];
     my $tag;
+    my $safehole = new Safe::Hole;
     $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
+    $safehole->wrap(\&Apache::lonmaxima::maxima_check,$safeeval,'&maxima_check');
+
     if (scalar(@$tagstack)) { $tag=$$tagstack[-1]; }
     if ( $target eq 'grade' && &Apache::response::submitted() ) {
 	&Apache::response::setup_params($tag,$safeeval);
 	if ($Apache::lonhomework::type eq 'exam' && 
-	    $tag eq 'formularesponse') {
+	    (($tag eq 'formularesponse') || ($tag eq 'mathresponse'))) {
 	    $increment=&Apache::response::scored_response($partid,$id);
 	} else {
 	    my $response = &Apache::response::getresponse();
@@ -922,6 +929,23 @@
     return end_numericalresponse(@_);
 }
 
+sub start_mathresponse {
+    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+    my $result;
+    if ($target eq 'meta') {
+        &Apache::response::start_response($parstack,$safeeval);
+        $result=&Apache::response::meta_package_write('mathresponse');
+        &Apache::response::end_response();
+    } else {
+        $result.=&start_numericalresponse(@_);
+    }
+    return $result;
+}
+
+sub end_mathresponse {
+    return end_numericalresponse(@_);
+}
+
 1;
 __END__