--- loncom/homework/caparesponse/caparesponse.pm 2003/04/08 03:54:22 1.90 +++ loncom/homework/caparesponse/caparesponse.pm 2003/04/18 07:12:13 1.93 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # caparesponse definition # -# $Id: caparesponse.pm,v 1.90 2003/04/08 03:54:22 albertel Exp $ +# $Id: caparesponse.pm,v 1.93 2003/04/18 07:12:13 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -101,19 +101,28 @@ sub end_numericalresponse { 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[$#$parstack] . "\n
"); + &Apache::lonxml::debug($$parstack[-1] . "\n
"); if ($ENV{'form.submitted'} eq 'scantron') { - &Apache::response::setrandomnumber(); - #FIXME the 8 here is based off of number of powers need a parameter - my $ind=&Math::Random::random_uniform_integer(1,0,8); - if ($ind eq $response) { $ad='CORRECT'; } else { $ad='INCORRECT'; } + 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; } - $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}.'"'; @@ -143,7 +152,6 @@ sub end_numericalresponse { $safeeval); my $unit=&Apache::lonxml::get_param_var('unit',$parstack, $safeeval); - if ($target eq 'web') { $result="
The correct answer is "; } elsif ($target eq 'tex') { @@ -187,7 +195,8 @@ sub end_numericalresponse { my $unit=&Apache::lonxml::get_param_var('unit',$parstack, $safeeval); my @bubble_values=&make_numerical_bubbles($number_of_bubbles, - @answers); + $target,$answers[0], + $formats[0]); my @alphabet=('A'..'Z'); my $id=$Apache::inputtags::response[-1]; if ($target eq 'web') { @@ -195,11 +204,10 @@ sub end_numericalresponse { if ($unit=~/\S/) {$result.=' (in '.$unit.')

';} $result.= ''; for (my $ind=0;$ind<$number_of_bubbles;$ind++) { - my $ans=&format_number($bubble_values[$ind], - $formats[0]); $result.=''; + '" value="'.$bubble_values[$ind].'">'. + $alphabet[$ind].': '. + $bubble_values[$ind].''; } $result.='
'.$alphabet[$ind]. - ': '.$ans.'
'; } elsif ($$tagstack[-1] eq 'formularesponse') { @@ -224,9 +232,7 @@ sub end_numericalresponse { } $result.='}'; for (my $ind=$cou;$ind<$cou+$table_range[$j];$ind++) { - my $ans=&format_number($bubble_values[$ind], - $formats[0],$target); - $result.='\hskip -3 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -2 mm & {\small '.$ans.'} '; + $result.='\hskip -3 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -2 mm & {\small '.$bubble_values[$ind].'} '; if ($ind != $cou+$table_range[$j]-1) {$result.=' & ';} } $cou += $table_range[$j]; @@ -236,13 +242,10 @@ sub end_numericalresponse { $result.='\end{enumerate}'; } else { $result.='\fbox{\fbox{\parbox{\textwidth-5mm}{\strut\\\\\strut\\\\\strut\\\\\strut\\\\}}}'; - my $id = $Apache::inputtags::part; - my $weight = &Apache::lonnet::EXT("resource.$id.weight"); - my $repetition = int $weight/9; - if ($weight % 9 != 0) {$repetition++;} + my $repetition = &Apache::response::repetition(); $result.='\begin{enumerate}'; for (my $i=0;$i<$repetition;$i++) { - $result.='\item[\textbf{'.$Apache::lonxml::counter.'}.]\textit{Leave blank on scoring form}\vskip 0 mm'; + $result.='\item[\textbf{'.($Apache::lonxml::counter+$i).'}.]\textit{Leave blank on scoring form}\vskip 0 mm'; } $increment=$repetition; $result.= '\end{enumerate}'; @@ -392,8 +395,8 @@ sub format_number { } sub make_numerical_bubbles { - my ($number_of_bubbles,@answers) =@_; - my @bubbles_values = (); + my ($number_of_bubbles,$target,$answer,$format) =@_; + my @bubble_values = (); 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(); @@ -402,9 +405,12 @@ sub make_numerical_bubbles { $ind=&Math::Random::random_uniform_integer(1,0,$#factors); my $factor = $factors[$ind]; for ($ind=0;$ind<$number_of_bubbles;$ind++) { - $bubbles_values[$ind] = $answers[0]*($factor**($power-$powers[$#powers-$ind])); + $bubble_values[$ind] = $answer*($factor**($power-$powers[$#powers-$ind])); + $bubble_values[$ind] = &format_number($bubble_values[$ind], + $format,$target); + } - return @bubbles_values; + return @bubble_values; } sub get_tolrange {