--- loncom/homework/caparesponse/caparesponse.pm 2003/10/15 19:40:43 1.116
+++ loncom/homework/caparesponse/caparesponse.pm 2003/10/24 17:41:45 1.120
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# caparesponse definition
#
-# $Id: caparesponse.pm,v 1.116 2003/10/15 19:40:43 albertel Exp $
+# $Id: caparesponse.pm,v 1.120 2003/10/24 17:41:45 sakharuk 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',
@@ -118,13 +121,12 @@ sub end_numericalresponse {
&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;
@@ -206,16 +208,19 @@ sub end_numericalresponse {
}
}
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.')
';}
@@ -282,6 +287,8 @@ sub end_numericalresponse {
if ($target eq 'analyze') {
push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
$Apache::lonhomework::analyze{"$part_id.type"} = $$tagstack[-1];
+ my (@incorrect)=&Apache::lonxml::get_param_var('incorrect',$parstack,$safeeval);
+ push (@{ $Apache::lonhomework::analyze{"$part_id.incorrect"} }, @incorrect);
}
&Apache::response::setup_params($$tagstack[-1]);
my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
@@ -376,7 +383,7 @@ sub end_numericalresponse {
$result.=&Apache::response::answer_footer($$tagstack[-1]);
}
}
- if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
+ if ($target eq 'grade' || $target eq 'web' ||
$target eq 'tex' || $target eq 'analyze') {
&Apache::lonxml::increment_counter($increment);
}
@@ -435,8 +442,24 @@ sub format_number {
}
sub make_numerical_bubbles {
- my ($number_of_bubbles,$target,$answer,$format) =@_;
+ my ($number_of_bubbles,$target,$answer,$format,$incorrect) =@_;
my @bubble_values = ();
+ &Apache::lonxml::debug("answer is $answer incorrect is $incorrect");
+ my @oldseed=&Math::Random::random_get_seed();
+ if (defined($incorrect) && ref($incorrect)) {
+ &Apache::lonxml::debug("inside ".(scalar(@$incorrect)+1 gt $number_of_bubbles));
+ if (scalar(@$incorrect)+1 >= $number_of_bubbles) {
+ &Apache::lonxml::debug("inside ".(scalar(@$incorrect)+1).":$number_of_bubbles");
+ &Apache::response::setrandomnumber();
+ my @rand_inc=&Math::Random::random_permutation(@$incorrect);
+ @bubble_values=@rand_inc[0..($number_of_bubbles-2)];
+ @bubble_values=sort {$a <=> $b} (@bubble_values,$answer);
+ &Apache::lonxml::debug("Answer was :$answer: returning :".$#bubble_values.": whih are :".join(':',@bubble_values));
+ &Math::Random::random_set_seed(@oldseed);
+ return @bubble_values;
+ }
+ #FIXME what to do when not enough incorrects specified?
+ }
my @factors = (1.13,1.17,1.25,1.33,1.45); #default values of factors
my @powers = (1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0); #default values for powers
&Apache::response::setrandomnumber();
@@ -450,6 +473,7 @@ sub make_numerical_bubbles {
$format,$target);
}
+ &Math::Random::random_set_seed(@oldseed);
return @bubble_values;
}