[LON-CAPA-cvs] cvs: loncom /homework essayresponse.pm inputtags.pm response.pm structuretags.pm /homework/caparesponse caparesponse.pm

albertel lon-capa-cvs@mail.lon-capa.org
Mon, 21 Apr 2003 20:59:02 -0000


This is a MIME encoded message

--albertel1050958742
Content-Type: text/plain

albertel		Mon Apr 21 16:59:02 2003 EDT

  Modified files:              
    /loncom/homework	structuretags.pm inputtags.pm essayresponse.pm 
                    	response.pm 
    /loncom/homework/caparesponse	caparesponse.pm 
  Log:
  - scantron grading of essay/formula/string works now
  - new global Apache::lonxml::scantronmode can be used to check if we are in scantron mode or not
  
  
  
--albertel1050958742
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20030421165902.txt"

Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.165 loncom/homework/structuretags.pm:1.166
--- loncom/homework/structuretags.pm:1.165	Thu Apr  3 17:25:49 2003
+++ loncom/homework/structuretags.pm	Mon Apr 21 16:59:02 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.165 2003/04/03 22:25:49 albertel Exp $
+# $Id: structuretags.pm,v 1.166 2003/04/21 20:59:02 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -271,6 +271,11 @@
     @Apache::structuretags::whileconds=();
     @Apache::structuretags::whilebody=();
     @Apache::structuretags::whileline=();
+    $Apache::lonhomework::scantronmode=0;
+
+    if (defined($ENV{'scantron.maxquest'})) {
+	$Apache::lonhomework::scantronmode=1;
+    }
 
     if ($target ne 'analyze') {
 	&initialize_storage();
Index: loncom/homework/inputtags.pm
diff -u loncom/homework/inputtags.pm:1.92 loncom/homework/inputtags.pm:1.93
--- loncom/homework/inputtags.pm:1.92	Sat Apr 19 05:00:54 2003
+++ loncom/homework/inputtags.pm	Mon Apr 21 16:59:02 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # input  definitons
 #
-# $Id: inputtags.pm,v 1.92 2003/04/19 09:00:54 albertel Exp $
+# $Id: inputtags.pm,v 1.93 2003/04/21 20:59:02 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -370,8 +370,14 @@
     $Apache::lonhomework::results{"resource.$id.afterduedate"}=$award;
     return '';
   } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} !~
-       /^correct/ ) {
+       /^correct/ || $Apache::lonhomework::scantronmode) {
     #handle assignment of tries and solved status
+    my $solvemsg;
+    if ($Apache::lonhomework::scantronmode) {
+	$solvemsg='correct_by_scantron';
+    } else {
+	$solvemsg='correct_by_student';
+    }
     if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
       $Apache::lonhomework::results{"resource.$id.afterduedate"}='';
     }
@@ -379,19 +385,23 @@
 	$Apache::lonhomework::results{"resource.$id.tries"} =
 	    $Apache::lonhomework::history{"resource.$id.tries"} + 1;
 	$Apache::lonhomework::results{"resource.$id.solved"} =
-	    'correct_by_student';
-	my $numawards=scalar(@Apache::inputtags::response);
+	    $solvemsg;
+	my $numawards=scalar(@Apache::inputtags::responselist);
+	&Apache::lonxml::debug("Whaaa!");
 	$Apache::lonhomework::results{"resource.$id.awarded"} = 0;
-	foreach my $res (@Apache::inputtags::response) {
+	foreach my $res (@Apache::inputtags::responselist) {
 	    $Apache::lonhomework::results{"resource.$id.awarded"}+=
 	       $Apache::lonhomework::results{"resource.$id.$res.awarded"};
 	}
-	$Apache::lonhomework::results{"resource.$id.awarded"}/=$numawards;
+	if ($numawards > 0) {
+	    $Apache::lonhomework::results{"resource.$id.awarded"}/=
+		$numawards;
+	}
     } elsif ( $award eq 'APPROX_ANS' || $award eq 'EXACT_ANS' ) {
       $Apache::lonhomework::results{"resource.$id.tries"} =
 	$Apache::lonhomework::history{"resource.$id.tries"} + 1;
       $Apache::lonhomework::results{"resource.$id.solved"} =
-	'correct_by_student';
+	$solvemsg;
       $Apache::lonhomework::results{"resource.$id.awarded"} = '1';
     } elsif ( $award eq 'INCORRECT' ) {
       $Apache::lonhomework::results{"resource.$id.tries"} =
Index: loncom/homework/essayresponse.pm
diff -u loncom/homework/essayresponse.pm:1.30 loncom/homework/essayresponse.pm:1.31
--- loncom/homework/essayresponse.pm:1.30	Sat Apr 19 05:00:54 2003
+++ loncom/homework/essayresponse.pm	Mon Apr 21 16:59:02 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # essay (ungraded) style responses
 #
-# $Id: essayresponse.pm,v 1.30 2003/04/19 09:00:54 albertel Exp $
+# $Id: essayresponse.pm,v 1.31 2003/04/21 20:59:02 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -100,17 +100,7 @@
 	}
 	if ( defined($ENV{'form.submitted'}) &&
 	     $ENV{'form.submitted'} eq 'scantron' ) {
-	    my $repetition=&Apache::response::repetition();
-	    $increment=$repetition;
-	    my $score=0;
-	    for (my $i=0;$i<$repetition;$i++) {
-		my $increase=&Apache::response::getresponse($i+1);
-		if ($increase ne '') { $score+=$increase+1; }
-	    }
-	    my $weight = &Apache::lonnet::EXT("resource.$part.weight");
-	    my $pcr=$score/$weight;
-	    $Apache::lonhomewok::results{"resource.$part.$id.awarded"}=$pcr;
-	    $Apache::lonhomewok::results{"resource.$part.$id.awarddetail"}='ASSIGNED_SCORE';
+	    $increment=&Apache::response::scored_response($part,$id);
 	} elsif ( defined($ENV{'form.submitted'}) ) {
 	    my $response      = $ENV{'form.HWVAL_'.$id};
             my $filename= $ENV{'form.HWFILE'.$part.'_'.$id.'.filename'};
Index: loncom/homework/response.pm
diff -u loncom/homework/response.pm:1.71 loncom/homework/response.pm:1.72
--- loncom/homework/response.pm:1.71	Fri Apr 18 03:12:13 2003
+++ loncom/homework/response.pm	Mon Apr 21 16:59:02 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # various response type definitons response definition
 #
-# $Id: response.pm,v 1.71 2003/04/18 07:12:13 albertel Exp $
+# $Id: response.pm,v 1.72 2003/04/21 20:59:02 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -436,6 +436,22 @@
     my $weight = &Apache::lonnet::EXT("resource.$id.weight");
     my $repetition = int $weight/9;
     if ($weight % 9 != 0) {$repetition++;} 
+    return $repetition;
+}
+
+sub scored_response {
+    my ($part,$id)=@_;
+    my $repetition=&repetition();
+    my $score=0;
+    for (my $i=0;$i<$repetition;$i++) {
+	my $increase=&Apache::response::getresponse($i+1);
+	if ($increase ne '') { $score+=$increase+1; }
+    }
+    my $weight = &Apache::lonnet::EXT("resource.$part.weight");
+    my $pcr=$score/$weight;
+    $Apache::lonhomework::results{"resource.$part.$id.awarded"}=$pcr;
+    $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=
+	'ASSIGNED_SCORE';
     return $repetition;
 }
 
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.94 loncom/homework/caparesponse/caparesponse.pm:1.95
--- loncom/homework/caparesponse/caparesponse.pm:1.94	Mon Apr 21 13:51:46 2003
+++ loncom/homework/caparesponse/caparesponse.pm	Mon Apr 21 16:59:02 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # caparesponse definition
 #
-# $Id: caparesponse.pm,v 1.94 2003/04/21 17:51:46 sakharuk Exp $
+# $Id: caparesponse.pm,v 1.95 2003/04/21 20:59:02 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -90,57 +90,63 @@
     if (!$Apache::lonxml::default_homework_loaded) {
 	&Apache::lonxml::default_homework_load($safeeval);
     }
-    if ( $target eq 'grade' && defined $ENV{'form.submitted'}) {
+    if ( $target eq 'grade' && defined($ENV{'form.submitted'})) {
 	&Apache::response::setup_params($$tagstack[-1]);
 	$safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
 	my $partid = $Apache::inputtags::part;
 	my $id = $Apache::inputtags::response['-1'];
-	my $response = &Apache::response::getresponse();
-	if ( $response =~ /[^\s]/) {
-	    my $ad;
-	    my %previous = &Apache::response::check_for_previous($response,$partid,$id);
-	    $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
-	    &Apache::lonxml::debug("submitted a $response<br>\n");
-	    &Apache::lonxml::debug($$parstack[-1] . "\n<br>");
-
-	    if ($ENV{'form.submitted'} eq 'scantron') {
-		my $number_of_bubbles = 8;#default values for number of bubbles
-		my (@formats)=&Apache::lonxml::get_param_var('format',
-							 $parstack,$safeeval);
-		my (@answers)=&Apache::lonxml::get_param_var('answer',
-							 $parstack,$safeeval);
-		my @values=&make_numerical_bubbles($number_of_bubbles,$target,
-						   $answers[0],$formats[0]);
-		$response=$values[$response];
-	    } else {
-		$response =~ s/\\/\\\\/g;
-		$response =~ s/\'/\\\'/g;
-	    }
-	    &Apache::lonxml::debug("current $response");
-	    my $expression="&caparesponse_check_list('".$response."','".
-		$$parstack[-1];
-	    #no way to enter units, with radio buttons
-	    if ($Apache::lonhomework::type eq 'exam') {
-		$expression.=';my $unit=undef;';
-	    }
-	    foreach my $key (keys(%Apache::inputtags::params)) {
-		$expression.= ';my $'. #'
-		    $key.'="'.$Apache::inputtags::params{$key}.'"';
-	    }
-	    if ($$tagstack[-1] eq 'formularesponse') {
-		$expression.=';my $type="fml";';
-	    } elsif ($$tagstack[-1] eq 'numericalresponse') {
-		$expression.=';my $type="float";';
+	if ($Apache::lonhomework::type eq 'exam' && 
+	    ($$tagstack[-1] eq 'formularesponse' ||
+	     $$tagstack[-1] eq 'stringresponse')) {
+	    $increment=&Apache::response::scored_response($partid,$id);
+	} else {
+	    my $response = &Apache::response::getresponse();
+	    if ( $response =~ /[^\s]/) {
+		my $ad;
+		my %previous = &Apache::response::check_for_previous($response,$partid,$id);
+		$Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
+		&Apache::lonxml::debug("submitted a $response<br>\n");
+		&Apache::lonxml::debug($$parstack[-1] . "\n<br>");
+		
+		if ($ENV{'form.submitted'} eq 'scantron') {
+		    my $number_of_bubbles = 8;#default values for number of bubbles
+		    my (@formats)=&Apache::lonxml::get_param_var('format',
+								 $parstack,$safeeval);
+		    my (@answers)=&Apache::lonxml::get_param_var('answer',
+								 $parstack,$safeeval);
+		    my @values=&make_numerical_bubbles($number_of_bubbles,$target,
+						       $answers[0],$formats[0]);
+		    $response=$values[$response];
+		} else {
+		    $response =~ s/\\/\\\\/g;
+		    $response =~ s/\'/\\\'/g;
+		}
+		&Apache::lonxml::debug("current $response");
+		my $expression="&caparesponse_check_list('".$response."','".
+		    $$parstack[-1];
+		#no way to enter units, with radio buttons
+		if ($Apache::lonhomework::type eq 'exam') {
+		    $expression.=';my $unit=undef;';
+		}
+		foreach my $key (keys(%Apache::inputtags::params)) {
+		    $expression.= ';my $'. #'
+			$key.'="'.$Apache::inputtags::params{$key}.'"';
+		}
+		if ($$tagstack[-1] eq 'formularesponse') {
+		    $expression.=';my $type="fml";';
+		} elsif ($$tagstack[-1] eq 'numericalresponse') {
+		    $expression.=';my $type="float";';
+		}
+		$expression.="');";
+		$result = &Apache::run::run($expression,$safeeval);
+		my ($awards) = split /:/ , $result;
+		($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards);
+		&Apache::lonxml::debug("$expression");
+		&Apache::lonxml::debug("\n<br>result:$result:$Apache::lonxml::curdepth<br>\n");
+		&Apache::response::handle_previous(\%previous,$ad);
+		$Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;
+		$result='';
 	    }
-	    $expression.="');";
-	    $result = &Apache::run::run($expression,$safeeval);
-	    my ($awards) = split /:/ , $result;
-	    ($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards);
-	    &Apache::lonxml::debug("$expression");
-	    &Apache::lonxml::debug("\n<br>result:$result:$Apache::lonxml::curdepth<br>\n");
-	    &Apache::response::handle_previous(\%previous,$ad);
-	    $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;
-	    $result='';
 	}
     } elsif ($target eq 'web' || $target eq 'tex') {
 	my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,

--albertel1050958742--