--- loncom/homework/caparesponse/caparesponse.pm 2003/05/19 21:15:21 1.102
+++ loncom/homework/caparesponse/caparesponse.pm 2003/10/23 07:54:55 1.118
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# caparesponse definition
#
-# $Id: caparesponse.pm,v 1.102 2003/05/19 21:15:21 albertel Exp $
+# $Id: caparesponse.pm,v 1.118 2003/10/23 07:54:55 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -41,6 +41,8 @@ sub start_numericalresponse {
if ($target eq 'edit') {
$result.=&Apache::edit::tag_start($target,$token);
$result.=&Apache::edit::text_arg('Answer:','answer',$token);
+ $result.=&Apache::edit::text_arg('Incorrect Answers:','incorrect',
+ $token);
if ($token->[1] eq 'numericalresponse') {
$result.=&Apache::edit::text_arg('Unit:','unit',$token,5).
&Apache::loncommon::help_open_topic('Physical_Units');
@@ -61,7 +63,8 @@ sub start_numericalresponse {
if ($token->[1] eq 'numericalresponse') {
$constructtag=&Apache::edit::get_new_args($token,$parstack,
$safeeval,'answer',
- 'unit','format');
+ 'incorrect','unit',
+ 'format');
} elsif ($token->[1] eq 'stringresponse') {
$constructtag=&Apache::edit::get_new_args($token,$parstack,
$safeeval,'answer',
@@ -114,23 +117,22 @@ sub end_numericalresponse {
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
\n");
&Apache::lonxml::debug($$parstack[-1] . "\n
");
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]);
+ my $number_of_bubbles = &Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.numbubbles');
+ if (!$number_of_bubbles) { $number_of_bubbles=8; }
+ my (@formats)=&Apache::lonxml::get_param_var('format',$parstack,$safeeval);
+ my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
+ my (@incorrect)=&Apache::lonxml::get_param_var('incorrect',$parstack,$safeeval);
+ my @values=&make_numerical_bubbles($number_of_bubbles,$target,$answers[0],$formats[0],\@incorrect);
$response=$values[$response];
} else {
$response =~ s/\\/\\\\/g;
$response =~ s/\'/\\\'/g;
}
+ $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
&Apache::lonxml::debug("current $response");
my $expression="&caparesponse_check_list('".$response."','".
$$parstack[-1];
@@ -150,6 +152,10 @@ sub end_numericalresponse {
$expression.=';my $type="float";';
}
$expression.="');";
+ my @answer=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
+ &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);
@@ -165,20 +171,13 @@ sub end_numericalresponse {
$safeeval);
my $award = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
my $status = $Apache::inputtags::status['-1'];
- if ( ($award =~ /^correct/
- && lc($Apache::lonhomework::problemstatus) ne 'no')
- || $status eq "SHOW_ANSWER"
- || $ENV{'form.texaward'} eq 'SHOW_ANSWER') {
+ if ( &Apache::response::show_answer() ) {
my (@formats)=&Apache::lonxml::get_param_var('format',$parstack,
$safeeval);
my $unit=&Apache::lonxml::get_param_var('unit',$parstack,
$safeeval);
if ($target eq 'web') {
$result="
The correct answer is ";
- } elsif ($target eq 'tex') {
- if ($ENV{'form.texaward'} eq 'SHOW_ANSWER') {
- $result='\vskip 0 mm The correct answer is \\texttt{ ';
- }
}
for (my $i=0; $i <= $#answers; $i++) {
my $answer=$answers[$i];
@@ -190,15 +189,13 @@ sub end_numericalresponse {
}
my $formatted;
if ((defined($format)) && ($format ne '')) {
+ $format=~s/e/E/g;
&Apache::lonxml::debug("formatting with :$format: answer :$answer:");
$formatted=sprintf('%.'.$format,$answer).',';
} else {
&Apache::lonxml::debug("no format answer :$answer:");
$formatted="$answer,";
}
- if ($ENV{'form.texaward'} eq 'SHOW_ANSWER') {
- $result.=$formatted;
- }
if ($target eq 'tex') {
$formatted='';
#$formatted=&Apache::lonxml::latex_special_symbols($formatted);
@@ -208,33 +205,36 @@ sub end_numericalresponse {
chop $result;
if ($target eq 'web') {
$result.=" $unit.
";
- } elsif ($target eq 'tex') {
- if ($ENV{'form.texaward'} eq 'SHOW_ANSWER') {
- $result.=&Apache::lonxml::latex_special_symbols($unit);
- $result.="}. \\vskip 0 mm ";
- }
}
}
if ($Apache::lonhomework::type eq 'exam') {
- my $number_of_bubbles = 8; #default values for number of bubbles
+ my $partid=$Apache::inputtags::part;
+ my $id=$Apache::inputtags::response[-1];
+ my $number_of_bubbles = &Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.numbubbles');
+ if (!$number_of_bubbles) { $number_of_bubbles=8; }
my (@formats)=&Apache::lonxml::get_param_var('format',$parstack,
$safeeval);
my $unit=&Apache::lonxml::get_param_var('unit',$parstack,
$safeeval);
+ my (@incorrect)=&Apache::lonxml::get_param_var('incorrect',$parstack,$safeeval);
my @bubble_values=&make_numerical_bubbles($number_of_bubbles,
$target,$answers[0],
- $formats[0]);
+ $formats[0],\@incorrect);
my @alphabet=('A'..'Z');
- my $id=$Apache::inputtags::response[-1];
if ($target eq 'web') {
if ($$tagstack[-1] eq 'numericalresponse') {
if ($unit=~/\S/) {$result.=' (in '.$unit.')
';}
$result.= '
'. - $alphabet[$ind].': '. - $bubble_values[$ind].' | '; + '" value="'.$bubble_values[$ind].'" '.$checked + .' />'.$alphabet[$ind].': '. + $bubble_values[$ind].''; } $result.='