Diff for /loncom/homework/caparesponse/caparesponse.pm between versions 1.221 and 1.236.12.1

version 1.221, 2008/02/01 23:00:56 version 1.236.12.1, 2010/08/20 03:44:18
Line 305  sub start_numericalresponse { Line 305  sub start_numericalresponse {
  my $hideunit=&Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.turnoffunit');   my $hideunit=&Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.turnoffunit');
  &Apache::lonxml::debug("Got unit $hideunit for $partid $id");   &Apache::lonxml::debug("Got unit $hideunit for $partid $id");
  #no way to enter units, with radio buttons   #no way to enter units, with radio buttons
  if (lc($hideunit) eq "yes") {          if ((lc($hideunit) eq "yes") && ($Apache::lonhomework::type ne 'exam')) {
     my $unit=&Apache::lonxml::get_param_var('unit',$parstack,      my $unit=&Apache::lonxml::get_param_var('unit',$parstack,
     $safeeval);      $safeeval);
     if ($unit =~ /\S/) { $result.=" (in $unit) "; }      if ($unit =~ /\S/) { $result.=" (in $unit) "; }
Line 427  sub check_submission { Line 427  sub check_submission {
  }   }
     } elsif ($tag eq 'numericalresponse') {      } elsif ($tag eq 'numericalresponse') {
  $$args_ref{'type'}='float';   $$args_ref{'type'}='float';
       } elsif ($tag eq 'stringresponse') {
           if ($$args_ref{'type'} eq '') {
               $$args_ref{'type'} = 'ci';
           }
     }      }
       
     &add_in_tag_answer($parstack,$safeeval);      &add_in_tag_answer($parstack,$safeeval);
   
     if (!%answer) {      if (!%answer) {
Line 510  sub end_numericalresponse { Line 514  sub end_numericalresponse {
  &Apache::lonxml::debug($$parstack[-1] . "\n<br>");   &Apache::lonxml::debug($$parstack[-1] . "\n<br>");
   
  if ( &Apache::response::submitted('scantron')) {   if ( &Apache::response::submitted('scantron')) {
     &add_in_tag_answer($parstack,$safeeval);      &add_in_tag_answer($parstack,$safeeval);
     my ($values,$display)=&make_numerical_bubbles($partid,$id,      my ($values,$display)=&make_numerical_bubbles($partid,$id,
   $target,$parstack,$safeeval);    $target,$parstack,$safeeval);
     $response=$values->[$response];      $response=$values->[$response];
  }   }
  $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;   $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
  my ($ad,$msg,$name)=&check_submission($response,$partid,$id,   my ($ad,$msg,$name)=&check_submission($response,$partid,$id,
       $tag,$parstack,        $tag,$parstack,
       $safeeval);        $safeeval);
Line 602  sub end_numericalresponse { Line 606  sub end_numericalresponse {
  }   }
     }      }
  }   }
           if (($target eq 'web') && ($tag eq 'formularesponse')
               && ($Apache::lonhomework::type ne 'exam') && ($Apache::inputtags::status['-1'] eq 'CAN_ANSWER')
       && (&Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.turnoffeditor') ne 'yes')) {
               $result.=&Apache::response::edit_mathresponse_button($id,"HWVAL_$id");
           }
               
  &Apache::response::setup_prior_tries_hash(\&format_prior_response_numerical);   &Apache::response::setup_prior_tries_hash(\&format_prior_response_numerical);
     } elsif ($target eq 'edit') {      } elsif ($target eq 'edit') {
  $result.='</td></tr>'.&Apache::edit::end_table;   $result.='</td></tr>'.&Apache::edit::end_table;
Line 678  sub end_numericalresponse { Line 688  sub end_numericalresponse {
     #}      #}
  }   }
  if ($high && $tag eq 'numericalresponse') {   if ($high && $tag eq 'numericalresponse') {
     $element.=' ['.$low.','.$high.']';      $element.='; ['.$low.'; '.$high.']';
     $tolline .= "[$low, $high]";      $tolline .= "[$low, $high]";
  }   }
  if (defined($sighigh) && $tag eq 'numericalresponse') {   if (defined($sighigh) && $tag eq 'numericalresponse') {
     if ($env{'form.answer_output_mode'} eq 'tex') {      if ($env{'form.answer_output_mode'} eq 'tex') {
  $element.= " Sig $siglow - $sighigh";   $element.= "; Sig $siglow - $sighigh";
     } else {      } else {
  $element.= " Sig <i>$siglow - $sighigh</i>";   $element.= " Sig <i>$siglow - $sighigh</i>";
  $sigline .= "[$siglow, $sighigh]";   $sigline .= "[$siglow, $sighigh]";
Line 703  sub end_numericalresponse { Line 713  sub end_numericalresponse {
     }      }
  }   }
  if ($target eq 'answer') {   if ($target eq 'answer') {
     $result.= &Apache::response::answer_part($tag,join(', ',@all_answer_info));      $result.= &Apache::response::answer_part($tag,join('; ',@all_answer_info));
  }   }
     }      }
   
Line 742  sub end_numericalresponse { Line 752  sub end_numericalresponse {
     if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') {      if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') {
  my $error;   my $error;
  if ($tag eq 'formularesponse') {   if ($tag eq 'formularesponse') {
     $error=&mt('Computer\'s answer is incorrect ("[_1]").',join(', ',@$response));      $error=&mt("Computer's answer is incorrect ([_1]).",'"'.join(', ',@$response).'"');
  } else {   } else {
     # answer failed check if it is sig figs that is failing      # answer failed check if it is sig figs that is failing
     my ($ad,$msg)=&check_submission($response,$partid,$id,      my ($ad,$msg)=&check_submission($response,$partid,$id,
     $tag,$parstack,      $tag,$parstack,
     $safeeval,1);      $safeeval,1);
       $error=&mt("Computer's answer is incorrect ([_1]).",'"'.join(', ',@$response).'"').' ';
     if ($sigline ne '') {      if ($sigline ne '') {
  $error=&mt('Computer\'s answer is incorrect ("[_1]"). It is likely that the tolerance range [_2] or significant figures [_3] need to be adjusted.',join(', ',@$response),$tolline,$sigline);   $error.=&mt('It is likely that the tolerance range [_1] or significant figures [_2] need to be adjusted.',$tolline,$sigline);
     } else {      } else {
  $error=&mt('Computer\'s answer is incorrect ("[_1]"). It is likely that the tolerance range [_2] needs to be adjusted.',join(', ',@$response),$tolline);   $error.=&mt('It is likely that the tolerance range [_1] needs to be adjusted.',$tolline);
     }      }
  }   }
  if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') {   if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') {
Line 988  sub make_numerical_bubbles { Line 999  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];
     my @bubble_display;      my @bubble_display;
       my $answerfactor=$answer;
       if ($answer==0) { 
          $answerfactor=&Math::Random::random_uniform_integer(1,1,100)/
                        &Math::Random::random_uniform_integer(1,1,10);
       }
     for ($ind=0;$ind<$number_of_bubbles;$ind++) {      for ($ind=0;$ind<$number_of_bubbles;$ind++) {
  $bubble_values[$ind] = $answer*($factor**($power-$powers[$#powers-$ind]));   $bubble_values[$ind] = $answerfactor*($factor**($power-$powers[$#powers-$ind]));
  $bubble_display[$ind] = &format_number($bubble_values[$ind],   $bubble_display[$ind] = &format_number($bubble_values[$ind],
        $format,$target,$safeeval);         $format,$target,$safeeval);
   
     }      }
     my $correct = $alphabet[$number_of_bubbles-$power];      my $correct = $alphabet[$number_of_bubbles-$power];
       if ($answer==0) {
          $correct='A';
          $bubble_values[0]=0;
          $bubble_display[0] = &format_number($bubble_values[0],
                                              $format,$target,$safeeval);
       }
     &Math::Random::random_set_seed(@oldseed);      &Math::Random::random_set_seed(@oldseed);
     return (\@bubble_values,\@bubble_display,$correct);      return (\@bubble_values,\@bubble_display,$correct);
 }  }
Line 1141  sub end_stringresponse { Line 1162  sub end_stringresponse {
     my @args = ('type');      my @args = ('type');
     my $args_ref = &setup_capa_args($safeeval,$parstack,      my $args_ref = &setup_capa_args($safeeval,$parstack,
     \@args,$response);      \@args,$response);
                       if ($$args_ref{'type'} eq '') {
                           $$args_ref{'type'} = 'ci';
                       }
     &add_in_tag_answer($parstack,$safeeval);      &add_in_tag_answer($parstack,$safeeval);
     my (@final_awards,@final_msgs,@names);      my (@final_awards,@final_msgs,@names);
     foreach my $name (keys(%answer)) {      foreach my $name (keys(%answer)) {

Removed from v.1.221  
changed lines
  Added in v.1.236.12.1


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