--- loncom/homework/caparesponse/caparesponse.pm 2003/10/23 19:36:02 1.107.2.4 +++ 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.107.2.4 2003/10/23 19:36:02 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', @@ -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; @@ -176,10 +178,6 @@ sub end_numericalresponse { $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]; @@ -191,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); @@ -209,24 +205,22 @@ 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.')

';} @@ -293,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); @@ -316,6 +312,7 @@ sub end_numericalresponse { ($sighigh,$siglow)=&get_sigrange($Apache::inputtags::params{'sig'}); } if ($fmt && $$tagstack[-1] eq 'numericalresponse') { + $fmt=~s/e/E/g; $ans = sprintf('%.'.$fmt,$ans); if ($high) { $high=sprintf('%.'.$fmt,$high); @@ -368,7 +365,7 @@ sub end_numericalresponse { if ($target eq 'answer') { if ($ENV{'form.answer_output_mode'} eq 'tex') { $result.=&Apache::response::answer_part($$tagstack[-1], - "\\textbf{$string}"); + "$string"); } else { $result.=&Apache::response::answer_part($$tagstack[-1], "$string"); @@ -418,12 +415,13 @@ sub format_number { my ($number,$format,$target)=@_; my $ans; if ($format ne '') { + $format=~s/e/E/g; $ans = sprintf('%.'.$format,$number); } else { my $format = ''; #What is the number? (integer,decimal,floating point) if ($number=~/^(\d*\.?\d*)(E|e)(\d*)$/) { - $format = 'e'.$2; + $format = '3e'; } elsif ($number=~/^(\d*)\.(\d*)$/) { $format = '4f'; } elsif ($number=~/^(\d*)$/) { @@ -444,9 +442,22 @@ sub format_number { } sub make_numerical_bubbles { - my ($number_of_bubbles,$target,$answer,$format) =@_; - my @oldseed=&Math::Random::random_get_seed(); + my ($number_of_bubbles,$target,$answer,$format,$incorrect) =@_; my @bubble_values = (); + &Apache::lonxml::debug("incorrect is $incorrect"); + 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)); + 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(); @@ -460,7 +471,6 @@ sub make_numerical_bubbles { $format,$target); } - &Math::Random::random_set_seed(@oldseed); return @bubble_values; }