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

www lon-capa-cvs@mail.lon-capa.org
Mon, 11 Dec 2006 17:37:44 -0000


www		Mon Dec 11 12:37:44 2006 EDT

  Modified files:              
    /loncom/homework	lonmaxima.pm response.pm 
    /loncom/homework/caparesponse	caparesponse.pm 
  Log:
  Saving work for MAXIMA.
  
  
Index: loncom/homework/lonmaxima.pm
diff -u loncom/homework/lonmaxima.pm:1.5 loncom/homework/lonmaxima.pm:1.6
--- loncom/homework/lonmaxima.pm:1.5	Tue Jun 13 10:57:54 2006
+++ loncom/homework/lonmaxima.pm	Mon Dec 11 12:37:43 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Interface routines to MAXIMA CAS
 #
-# $Id: lonmaxima.pm,v 1.5 2006/06/13 14:57:54 albertel Exp $
+# $Id: lonmaxima.pm,v 1.6 2006/12/11 17:37:43 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -65,6 +65,27 @@
     return 0;
 }
 
+sub runscript {
+    my ($socket,$fullscript)=@_;
+    if (&blacklisted($fullscript)) { return 'Error: blacklisted'; }
+    return &maximareply($socket,$fullscript);
+}
+
+sub maxima_run {
+    my ($script,$submission,$arguments) = @_;
+    my $socket=&connect();
+    my $fullscript=$script;
+    my $reply=&runscript($socket,$fullscript);
+#    &Apache::lonnet::logthis('Script:'.$fullscript);
+#    &Apache::lonnet::logthis('Sub:'.$submission);
+#    &Apache::lonnet::logthis('Arg:'.$arguments);
+
+    &disconnect($socket);
+    if ($reply=~/^\s*true\s*$/) { return 'EXACT_ANS'; }
+    if ($reply=~/^\s*false\s*/) { return 'INCORRECT'; } 
+    return 'BAD_FORMULA';
+}
+
 sub compareterms {
     my ($socket,$terma,$termb)=@_;
     my $difference=$terma.'-'.$termb;
Index: loncom/homework/response.pm
diff -u loncom/homework/response.pm:1.152 loncom/homework/response.pm:1.153
--- loncom/homework/response.pm:1.152	Mon Dec  4 16:23:01 2006
+++ loncom/homework/response.pm	Mon Dec 11 12:37:43 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # various response type definitons response definition
 #
-# $Id: response.pm,v 1.152 2006/12/04 21:23:01 albertel Exp $
+# $Id: response.pm,v 1.153 2006/12/11 17:37:43 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -30,6 +30,7 @@
 use strict;
 use Apache::lonlocal;
 use Apache::lonnet;
+use Apache::lonmaxima();
 
 BEGIN {
     &Apache::lonxml::register('Apache::response',('responseparam','parameter','dataresponse','customresponse','mathresponse'));
@@ -474,21 +475,23 @@
 					   'cas',
 					   ['maxima'],
 					   $token);
-	$result.=&Apache::edit::text_arg('Algebra System:',
-					 'cas',$token);
 	$result.=&Apache::edit::text_arg('Argument Array:',
 					 'args',$token);
 	$result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
     } elsif ($target eq 'modified') {
 	my $constructtag;
 	$constructtag=&Apache::edit::get_new_args($token,$parstack,
-						  $safeeval,'answerdisplay');
+						  $safeeval,'answerdisplay','cas','args');
 	if ($constructtag) {
 	    $result = &Apache::edit::rebuild_tag($token);
 	    $result.=&Apache::edit::handle_insert();
 	}
     } elsif ($target eq 'answer' || $target eq 'grade') {
 	&Apache::response::reset_params();
+	my $args_ref= \%{$safeeval->varglob('LONCAPA::mathresponse_args')};
+	undef(%{ $args_ref });
+	$$args_ref{'cas'}=$token->[2]{'cas'};
+	$$args_ref{'args'}=$token->[2]{'args'};
     } elsif ($target eq 'meta') {
 	$result .= &Apache::response::meta_package_write('mathresponse');
     }
@@ -511,10 +514,11 @@
 	    $Apache::lonhomework::results{"resource.$part.$id.submission"}=
 		$response;
 	    my $error;
-	    ${$safeeval->varglob('LONCAPA::mathresponse_submission')}=
-		$response;
-	    
-	    my $award = &Apache::run::run('{ my $submission=$LONCAPA::mathresponse_submission;'.$Apache::response::custom_answer.'}',$safeeval);
+	    my $args_ref= \%{$safeeval->varglob('LONCAPA::mathresponse_args')};
+            my $award;
+            if ($$args_ref{'cas'} eq 'maxima') {
+		$award=&Apache::lonmaxima::maxima_run($Apache::response::custom_answer,$response,$$args_ref{'args'});
+	    }
 	    if (!&Apache::inputtags::valid_award($award)) {
 		$error = $award;
 		$award = 'ERROR';
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.198 loncom/homework/caparesponse/caparesponse.pm:1.199
--- loncom/homework/caparesponse/caparesponse.pm:1.198	Mon Dec  4 18:56:20 2006
+++ loncom/homework/caparesponse/caparesponse.pm	Mon Dec 11 12:37:44 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # caparesponse definition
 #
-# $Id: caparesponse.pm,v 1.198 2006/12/04 23:56:20 www Exp $
+# $Id: caparesponse.pm,v 1.199 2006/12/11 17:37:44 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -324,11 +324,11 @@
     }
     
     if ($tag eq 'formularesponse') {
-#	if ($$args_ref{'samples'}) {
+	if ($$args_ref{'samples'}) {
 	    $$args_ref{'type'}='fml';
-#	} else {
-#	    $$args_ref{'type'}='math';
-#	}
+	} else {
+	    $$args_ref{'type'}='math';
+	}
     } elsif ($tag eq 'numericalresponse') {
 	$$args_ref{'type'}='float';
     }