Diff for /loncom/homework/caparesponse/caparesponse.pm between versions 1.90 and 1.92

version 1.90, 2003/04/08 03:54:22 version 1.92, 2003/04/08 04:17:13
Line 101  sub end_numericalresponse { Line 101  sub end_numericalresponse {
     my %previous = &Apache::response::check_for_previous($response,$partid,$id);      my %previous = &Apache::response::check_for_previous($response,$partid,$id);
     $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;      $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
     &Apache::lonxml::debug("submitted a $response<br>\n");      &Apache::lonxml::debug("submitted a $response<br>\n");
     &Apache::lonxml::debug($$parstack[$#$parstack] . "\n<br>");      &Apache::lonxml::debug($$parstack[-1] . "\n<br>");
   
     if ($ENV{'form.submitted'} eq 'scantron') {      if ($ENV{'form.submitted'} eq 'scantron') {
  &Apache::response::setrandomnumber();   my $number_of_bubbles = 8;#default values for number of bubbles
  #FIXME the 8 here is based off of number of powers need a parameter   my (@formats)=&Apache::lonxml::get_param_var('format',
  my $ind=&Math::Random::random_uniform_integer(1,0,8);   $parstack,$safeeval);
  if ($ind eq $response) { $ad='CORRECT'; } else { $ad='INCORRECT'; }   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");      &Apache::lonxml::debug("current $response");
     my $expression="&caparesponse_check_list('".$response."','".      my $expression="&caparesponse_check_list('".$response."','".
  $$parstack[-1];   $$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)) {      foreach my $key (keys(%Apache::inputtags::params)) {
  $expression.= ';my $'. #'   $expression.= ';my $'. #'
     $key.'="'.$Apache::inputtags::params{$key}.'"';      $key.'="'.$Apache::inputtags::params{$key}.'"';
Line 143  sub end_numericalresponse { Line 152  sub end_numericalresponse {
  $safeeval);   $safeeval);
     my $unit=&Apache::lonxml::get_param_var('unit',$parstack,      my $unit=&Apache::lonxml::get_param_var('unit',$parstack,
     $safeeval);      $safeeval);
   
     if ($target eq 'web') {      if ($target eq 'web') {
  $result="<br />The correct answer is ";   $result="<br />The correct answer is ";
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
Line 187  sub end_numericalresponse { Line 195  sub end_numericalresponse {
     my $unit=&Apache::lonxml::get_param_var('unit',$parstack,      my $unit=&Apache::lonxml::get_param_var('unit',$parstack,
     $safeeval);      $safeeval);
     my @bubble_values=&make_numerical_bubbles($number_of_bubbles,      my @bubble_values=&make_numerical_bubbles($number_of_bubbles,
       @answers);        $target,$answers[0],
         $formats[0]);
     my @alphabet=('A'..'Z');      my @alphabet=('A'..'Z');
     my $id=$Apache::inputtags::response[-1];      my $id=$Apache::inputtags::response[-1];
     if ($target eq 'web') {      if ($target eq 'web') {
Line 195  sub end_numericalresponse { Line 204  sub end_numericalresponse {
     if ($unit=~/\S/) {$result.=' (in '.$unit.')<br /><br />';}      if ($unit=~/\S/) {$result.=' (in '.$unit.')<br /><br />';}
     $result.= '<table border="1"><tr>';      $result.= '<table border="1"><tr>';
     for (my $ind=0;$ind<$number_of_bubbles;$ind++) {      for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
  my $ans=&format_number($bubble_values[$ind],  
        $formats[0]);  
  $result.='<td><input type="radio" name="HWVAL_'.$id.   $result.='<td><input type="radio" name="HWVAL_'.$id.
     '" value="'.$ans.'"><b>'.$alphabet[$ind].      '" value="'.$bubble_values[$ind].'"><b>'.
  '</b>: '.$ans.'</td>';   $alphabet[$ind].'</b>: '.
       $bubble_values[$ind].'</td>';
     }      }
     $result.='</tr></table>';      $result.='</tr></table>';
  } elsif ($$tagstack[-1] eq 'formularesponse') {   } elsif ($$tagstack[-1] eq 'formularesponse') {
Line 224  sub end_numericalresponse { Line 232  sub end_numericalresponse {
  }   }
  $result.='}';   $result.='}';
  for (my $ind=$cou;$ind<$cou+$table_range[$j];$ind++) {   for (my $ind=$cou;$ind<$cou+$table_range[$j];$ind++) {
     my $ans=&format_number($bubble_values[$ind],      $result.='\hskip -3 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -2 mm & {\small '.$bubble_values[$ind].'} ';
    $formats[0],$target);  
     $result.='\hskip -3 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -2 mm & {\small '.$ans.'} ';  
     if ($ind != $cou+$table_range[$j]-1) {$result.=' & ';}      if ($ind != $cou+$table_range[$j]-1) {$result.=' & ';}
  }   }
  $cou += $table_range[$j];   $cou += $table_range[$j];
Line 392  sub format_number { Line 398  sub format_number {
 }  }
   
 sub make_numerical_bubbles {  sub make_numerical_bubbles {
     my ($number_of_bubbles,@answers) =@_;      my ($number_of_bubbles,$target,$answer,$format) =@_;
     my @bubbles_values = ();      my @bubble_values = ();
     my @factors = (1.13,1.17,1.25,1.33,1.45); #default values of factors      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      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();      &Apache::response::setrandomnumber();
Line 402  sub make_numerical_bubbles { Line 408  sub make_numerical_bubbles {
     $ind=&Math::Random::random_uniform_integer(1,0,$#factors);      $ind=&Math::Random::random_uniform_integer(1,0,$#factors);
     my $factor = $factors[$ind];      my $factor = $factors[$ind];
     for ($ind=0;$ind<$number_of_bubbles;$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 {  sub get_tolrange {

Removed from v.1.90  
changed lines
  Added in v.1.92


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>