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

albertel lon-capa-cvs@mail.lon-capa.org
Sat, 13 Mar 2004 00:36:11 -0000


This is a MIME encoded message

--albertel1079138171
Content-Type: text/plain

albertel		Fri Mar 12 19:36:11 2004 EDT

  Modified files:              
    /loncom/homework	default_homework.lcpm hint.pm inputtags.pm 
    /loncom/homework/caparesponse	caparesponse.pm 
  Log:
  - BUG#32, mainly but alot of assocaited bugs
  - caparesponse messages are now printed,
     It now reports what it thought the unit was, how many sig figs it read (and how many were expected)
  
  
--albertel1079138171
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20040312193611.txt"

Index: loncom/homework/default_homework.lcpm
diff -u loncom/homework/default_homework.lcpm:1.71 loncom/homework/default_homework.lcpm:1.72
--- loncom/homework/default_homework.lcpm:1.71	Fri Mar 12 16:06:19 2004
+++ loncom/homework/default_homework.lcpm	Fri Mar 12 19:36:11 2004
@@ -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.71 2004/03/12 21:06:19 albertel Exp $
+# $Id: default_homework.lcpm,v 1.72 2004/03/13 00:36:11 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -55,6 +55,9 @@
   #type's definitons come from capaParser.h
   my $message='';
   #remove leading and trailing whitespace
+  if (!defined($response)) {
+      $response='';
+  }
   if ($response=~ /^\s|\s$/) {
     $response=~ s:^\s+|\s+$::g;
     $message .="Removed ws now :$response:\n";
Index: loncom/homework/hint.pm
diff -u loncom/homework/hint.pm:1.49 loncom/homework/hint.pm:1.50
--- loncom/homework/hint.pm:1.49	Fri Mar 12 16:06:19 2004
+++ loncom/homework/hint.pm	Fri Mar 12 19:36:11 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # implements the tags that control the hints
 #
-# $Id: hint.pm,v 1.49 2004/03/12 21:06:19 albertel Exp $
+# $Id: hint.pm,v 1.50 2004/03/13 00:36:11 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -177,9 +177,11 @@
 	@{$safeeval->varglob('CAPARESPONSE_CHECK_LIST_answer')}=@answer;
 		
 	($result,my @msgs) = &Apache::run::run($expression,$safeeval);
+	&Apache::lonxml::debug('msgs are'.join(':',@msgs));
 	&Apache::lonxml::debug("$expression:result:$result:$Apache::lonxml::curdepth");
-	my ($awards) = split /:/ , $result;
-	my ($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards);
+	my ($awards)=split(/:/,$result);
+	my (@awards) = split(/,/,$awards);
+	my ($ad, $msg) = &Apache::inputtags::finalizeawards(\@awards,\@msgs);
 	if ($ad eq 'EXACT_ANS' || $ad eq 'APPROX_ANS') { push (@Apache::hint::which,$name); }
 	$result='';
     } elsif ($target eq 'meta') {
Index: loncom/homework/inputtags.pm
diff -u loncom/homework/inputtags.pm:1.135 loncom/homework/inputtags.pm:1.136
--- loncom/homework/inputtags.pm:1.135	Fri Mar 12 16:14:54 2004
+++ loncom/homework/inputtags.pm	Fri Mar 12 19:36:11 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # input  definitons
 #
-# $Id: inputtags.pm,v 1.135 2004/03/12 21:14:54 albertel Exp $
+# $Id: inputtags.pm,v 1.136 2004/03/13 00:36:11 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -277,77 +277,48 @@
     return "";
 }
 
+sub checkstatus {
+    my ($value,$awardref,$msgref)=@_;
+    for (my $i=0;$i<=$#$awardref;$i++) {
+	if ($$awardref[$i] eq $value) {
+	    return ($$awardref[$i],$$msgref[$i]);
+	}
+    }
+    return(undef,undef);
+}
+
 sub finalizeawards {
-    my $result='';
+    my ($awardref,$msgref)=@_;
+    my $result=undef;
     my $award;
-    if ($#_ == '-1') { $result = "NO_RESPONSE"; }
+    my $msg;
+    if ($#$awardref == -1) { $result = "NO_RESPONSE"; }
     if ($result eq '' ) {
 	my $blankcount;
-	foreach $award (@_) {
+	foreach $award (@$awardref) {
 	    if ($award eq '') {
 		$result='MISSING_ANSWER';
 		$blankcount++;
 	    }
 	}
-	if ($blankcount == ($#_ + 1)) { $result = 'NO_RESPONSE'; }
-    }
-    if ($result eq '' ) {
-	foreach $award (@_) { if ($award eq 'MISSING_ANSWER') {$result='MISSING_ANSWER'; last;}}
-    }
-    if ($result eq '' ) {
-	foreach $award (@_) { if ($award eq 'ERROR') {$result='ERROR'; last;}}
-    }
-    if ($result eq '' ) {
-	foreach $award (@_) { if ($award eq 'NO_RESPONSE') {$result='NO_RESPONSE'; last;} }
-    }
-    if ($result eq '' ) {
-	foreach $award (@_) { if ($award eq 'TOO_LONG') {$result='TOO_LONG'; last;}}
-    }
-    if ($result eq '' ) {
-	foreach $award (@_) { 
-	    if ($award eq 'UNIT_FAIL' ||
-		$award eq 'NO_UNIT' ||
-		$award eq 'UNIT_NOTNEEDED') {
-		$result=$award; last;
-	    }
-	}
-    }
-    if ($result eq '' ) {
-	foreach $award (@_) { 
-	    if ($award eq 'WANTED_NUMERIC' || 
-		$award eq 'BAD_FORMULA') {$result=$award; last;}
-	}
-    }
-    if ($result eq '' ) {
-	foreach $award (@_) { if ($award eq 'SIG_FAIL') {$result=$award; last;} }
-    }
-    if ($result eq '' ) {
-	foreach $award (@_) { if ($award eq 'INCORRECT') {$result=$award; last;} }
-    }
-    if ($result eq '' ) {
-	foreach $award (@_) { if ($award eq 'MISORDERED_RANK') {$result=$award; last;} }
-    }
-    if ($result eq '' ) {
-	foreach $award (@_) { if ($award eq 'INVALID_FILETYPE') {$result=$award; last;} }
+	if ($blankcount == ($#$awardref + 1)) { $result = 'NO_RESPONSE'; }
     }
-    if ($result eq '' ) {
-	foreach $award (@_) { if ($award eq 'DRAFT') {$result=$award; last;} }
-    }
-    if ($result eq '' ) {
-	foreach $award (@_) { if ($award eq 'SUBMITTED') {$result=$award; last;} }
-    }
-    if ($result eq '' ) {
-	foreach $award (@_) { if ($award eq 'ASSIGNED_SCORE') {$result=$award; last;} }
+    if (defined($result)) { return ($result,$msg); }
+    foreach my $possibleaward ('MISSING_ANSWER', 'ERROR', 'NO_RESPONSE',
+			       'TOO_LONG', 'UNIT_FAIL', 'NO_UNIT',
+			       'UNIT_NOTNEEDED', 'WANTED_NUMERIC',
+			       'BAD_FORMULA', 'SIG_FAIL', 'INCORRECT', 
+			       'MISORDERED_RANK', 'INVALID_FILETYPE',
+			       'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE',
+			       'APPROX_ANS', 'EXACT_ANS') {
+	($result,$msg)=&checkstatus($possibleaward,$awardref,$msgref);
+	if (defined($result)) { return ($result,$msg); }
     }
-    if ($result eq '' ) {
-	foreach $award (@_) { if ($award eq 'APPROX_ANS') {$result=$award; last;} }
-    }
-    if ($result eq '' ) { $result='EXACT_ANS'; }
-    return $result
+    return ('ERROR',undef);
 }
 
 sub decideoutput {
-    my ($award,$solved,$previous,$target)=@_;
+    my ($award,$awardmsg,$solved,$previous,$target)=@_;
     my $message='';
     my $button=0;
     my $previousmsg;
@@ -439,16 +410,17 @@
 	$bgcolor=$possiblecolors{'not_charged_try'};
 	$button=1;
     } elsif ($award eq 'SIG_FAIL') {
-	$message = &mt("Significant figures are incorrect, submission was not graded.");# you provided %s significant figures";
+	$message = &mt("Significant figures are incorrect, you provided [_1] significant figures while [_2] to [_3] were expected. Submission not graded.",(split(/:/,$awardmsg)));
 	$bgcolor=$possiblecolors{'not_charged_try'};
 	$button=1;
     } elsif ($award eq 'UNIT_FAIL') {
-	$message = &mt("Units incorrect.");
-	if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');} #Computer reads units as %s";
+	$message = &mt('Units incorrect. Computer reads units as "[_1]"',
+		       $awardmsg);
+	if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');} 
 	$bgcolor=$possiblecolors{'not_charged_try'};
 	$button=1;
     } elsif ($award eq 'UNIT_NOTNEEDED') {
-	$message = &mt("Only a number required.");# Computer reads units of %s";
+	$message = &mt('Only a number required. Computer reads units of "[_1]"',$awardmsg);
 	$bgcolor=$possiblecolors{'not_charged_try'};
 	$button=1;
     } elsif ($award eq 'NO_UNIT') {
@@ -500,7 +472,7 @@
 }
 
 sub setgradedata {
-    my ($award,$id,$previously_used) = @_;
+    my ($award,$msg,$id,$previously_used) = @_;
     # if the student already has it correct, don't modify the status
     if (!$Apache::lonhomework::scantronmode &&
 	$Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
@@ -569,7 +541,9 @@
 		$Apache::lonhomework::results{"resource.$id.awarded"} = 0;
 	    }
 	}
-
+	if (defined($msg)) {
+	    $Apache::lonhomework::results{"resource.$id.awardmsg"} = $msg;
+	}
 	# did either of the overall awards chage? If so ignore the 
 	# previous check
 	if (($Apache::lonhomework::results{"resource.$id.awarded"} eq
@@ -608,14 +582,17 @@
     my $id = $Apache::inputtags::part;
     my $response='';
     if ( defined $ENV{'form.submitted'}) {
-	my @awards = ();
+	my (@awards,@msgs);
 	foreach $response (@Apache::inputtags::response) {
 	    &Apache::lonxml::debug("looking for response.$id.$response.awarddetail");
 	    my $value=$Apache::lonhomework::results{"resource.$id.$response.awarddetail"};
 	    &Apache::lonxml::debug("keeping $value from $response for $id");
 	    push (@awards,$value);
+	    $value=$Apache::lonhomework::results{"resource.$id.$response.awardmsg"};
+	    &Apache::lonxml::debug("got message $value from $response for $id");
+	    push (@msgs,$value);
 	}
-	my $finalaward = &finalizeawards(@awards);
+	my ($finalaward,$msg) = &finalizeawards(\@awards,\@msgs);
 	my $previously_used;
 	if ( $#Apache::inputtags::previous eq $#awards ) {
 	    my $match=0;
@@ -636,8 +613,8 @@
 		}
 	    }
 	}
-	&Apache::lonxml::debug("final award $finalaward, $previously_used");
-	&setgradedata($finalaward,$id,$previously_used);
+	&Apache::lonxml::debug("final award $finalaward, $previously_used, message $msg");
+	&setgradedata($finalaward,$msg,$id,$previously_used);
     }
     return '';
 }
@@ -659,11 +636,12 @@
 	my $award = $Apache::lonhomework::history{"resource.$id.award"};
 	my $solved = $Apache::lonhomework::history{"resource.$id.solved"};
 	my $previous = $Apache::lonhomework::history{"resource.$id.previous"};
-	&Apache::lonxml::debug("Found Award |$award|$solved|");
+	my $awardmsg = $Apache::lonhomework::history{"resource.$id.awardmsg"};
+	&Apache::lonxml::debug("Found Award |$award|$solved|$awardmsg");
 	if ( $award ne '' || $solved ne '') {
 	    &Apache::lonxml::debug('Getting message');
 	    ($showbutton,$bgcolor,$message,$previousmsg) =
-		&decideoutput($award,$solved,$previous,$target);
+		&decideoutput($award,$awardmsg,$solved,$previous,$target);
 	    if ($target eq 'tex') {
 		$message='\vskip 2 mm '.$message.' ';
 	    } else {
@@ -691,7 +669,7 @@
 		    $trystr = '\vskip 0 mm ';
 		}
 	    } else {
-		$trystr = "<td>".$tries_text." $tries";
+		$trystr = "<td><nobr>".$tries_text." $tries";
 		if($ENV{'request.state'} ne 'construct') {
 		    $trystr.="/$maxtries";
 		} else {
@@ -699,7 +677,7 @@
 			$trystr.="/".$Apache::inputtags::params{'maxtries'};
 		    }
 		}
-		$trystr.="</td>";
+		$trystr.="</nobr></td>";
 	    }
 	}
 	if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {$showbutton = 0;}
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.141 loncom/homework/caparesponse/caparesponse.pm:1.142
--- loncom/homework/caparesponse/caparesponse.pm:1.141	Fri Mar 12 16:06:19 2004
+++ loncom/homework/caparesponse/caparesponse.pm	Fri Mar 12 19:36:11 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # caparesponse definition
 #
-# $Id: caparesponse.pm,v 1.141 2004/03/12 21:06:19 albertel Exp $
+# $Id: caparesponse.pm,v 1.142 2004/03/13 00:36:11 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -161,12 +161,22 @@
 		
 		($result,my @msgs) = &Apache::run::run($expression,$safeeval);
 		&Apache::lonxml::debug('msgs are'.join(':',@msgs));
-		my ($awards) = split /:/ , $result;
-		($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards);
+		my ($awards)=split(/:/,$result);
+		my (@awards) = split(/,/,$awards);
+		($ad,my $msg) = &Apache::inputtags::finalizeawards(\@awards,\@msgs);
+		&Apache::lonxml::debug('ad is'.$ad);
+		if ($ad eq 'SIG_FAIL') {
+		    my ($sig_u,$sig_l)=
+			&get_sigrange($Apache::inputtags::params{'sig'});
+		    $msg=join(':',$msg,$sig_l,$sig_u);
+		    &Apache::lonxml::debug("sigs bad $sig_u $sig_l ".
+					   $Apache::inputtags::params{'sig'});
+		}
 		&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;
+		$Apache::lonhomework::results{"resource.$partid.$id.awardmsg"}=$msg;
 		$result='';
 	    }
 	}
@@ -598,7 +608,7 @@
 		
 		$Apache::lonhomework::results{"resource.$part.$id.submission"}=
 		    $response;
-		my $ad;
+		my ($ad,$msg);
 		if ($type eq 're' ) { 
 		    # if the RE wasn't in a var it likely got munged,
                     # thus grab it from the var directly
@@ -625,14 +635,17 @@
 		    $expression.="');";
 		    &Apache::lonxml::debug('answer is'.join(':',$answer));
 		    @{$safeeval->varglob('CAPARESPONSE_CHECK_LIST_answer')}=($answer);
-		    $result = &Apache::run::run($expression,$safeeval);
-		    my ($awards) = split /:/ , $result;
-		    ($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards);
+		    ($result, my @msgs) = &Apache::run::run($expression,$safeeval);
+		    &Apache::lonxml::debug('msgs are'.join(':',@msgs));
+		    my ($awards)=split(/:/,$result);
+		    my (@awards) = split(/,/,$awards);
+		    ($ad,$msg) = &Apache::inputtags::finalizeawards(\@awards,\@msgs);
 		    &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.$part.$id.awarddetail"}=$ad;
+		$Apache::lonhomework::results{"resource.$part.$id.awardmsg"}=$msg;
 	    }
 	}
     } elsif ($target eq 'web' || $target eq 'tex') {

--albertel1079138171--