Diff for /loncom/homework/caparesponse/caparesponse.pm between versions 1.168 and 1.176

version 1.168, 2005/05/23 21:18:25 version 1.176, 2005/07/14 05:50:33
Line 121  sub start_numericalresponse { Line 121  sub start_numericalresponse {
 }  }
   
 sub check_submission {  sub check_submission {
     my ($response,$partid,$id,$tag,$parstack,$safeeval)=@_;      my ($response,$partid,$id,$tag,$parstack,$safeeval,$ignore_sig)=@_;
     my $args_ref= \%{$safeeval->varglob('LONCAPA::CAPAresponse_args')};      my $args_ref= \%{$safeeval->varglob('LONCAPA::CAPAresponse_args')};
     $$args_ref{'response'}=$response;      $$args_ref{'response'}=$response;
     my $hideunit=&Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.turnoffunit');      my $hideunit=&Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.turnoffunit');
Line 142  sub check_submission { Line 142  sub check_submission {
     }      }
     #sig fig don't make much sense either      #sig fig don't make much sense either
     if (($Apache::lonhomework::type eq 'exam' ||      if (($Apache::lonhomework::type eq 'exam' ||
  &Apache::response::submitted('scantron')) &&   &Apache::response::submitted('scantron') ||
    $ignore_sig) &&
  $tag eq 'numericalresponse') {   $tag eq 'numericalresponse') {
  delete($$args_ref{'sig'});   delete($$args_ref{'sig'});
     }      }
Line 329  sub end_numericalresponse { Line 330  sub end_numericalresponse {
  if ($target eq 'answer') {   if ($target eq 'answer') {
     $result.=&Apache::response::answer_header($tag);      $result.=&Apache::response::answer_header($tag);
  }   }
    my ($sigline,$tolline);
  for(my $i=0;$i<=$#answers;$i++) {   for(my $i=0;$i<=$#answers;$i++) {
     my $ans=$answers[$i];      my $ans=$answers[$i];
     my $fmt=$formats[0];      my $fmt=$formats[0];
Line 351  sub end_numericalresponse { Line 353  sub end_numericalresponse {
  #    $low =&format_number($low,$fmt,$target,$safeeval);   #    $low =&format_number($low,$fmt,$target,$safeeval);
  #}   #}
     }      }
     my $response=$ans;  
     if ($target eq 'answer') {      if ($target eq 'answer') {
  if ($high && $tag eq 'numericalresponse') { $ans.=' ['.$low.','.$high.']'; }   if ($high && $tag eq 'numericalresponse') {
       $ans.=' ['.$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') {
  $ans.= " Sig $siglow - $sighigh";   $ans.= " Sig $siglow - $sighigh";
     } else {      } else {
  $ans.= " Sig <i>$siglow - $sighigh</i>";   $ans.= " Sig <i>$siglow - $sighigh</i>";
    $sigline .= "[$siglow, $sighigh]";
     }      }
  }   }
  $result.=&Apache::response::answer_part($tag,$ans);   $result.=&Apache::response::answer_part($tag,$ans);
Line 372  sub end_numericalresponse { Line 377  sub end_numericalresponse {
     push (@{ $Apache::lonhomework::analyze{"$part_id.format"} }, $fmt);      push (@{ $Apache::lonhomework::analyze{"$part_id.format"} }, $fmt);
  }   }
     }      }
     my ($awards,$msgs)=&check_submission($response,$partid,$id,$tag,   }
  $parstack,$safeeval);  
     my ($ad,$msg) =&Apache::inputtags::finalizeawards($awards,$msgs);   my @fmt_ans;
    for(my $i=0;$i<=$#answers;$i++) {
       my $ans=$answers[$i];
       my $fmt=$formats[0];
       if (@formats && $#formats) {$fmt=$formats[$i];}
       if ($fmt && $tag eq 'numericalresponse') {
    $fmt=~s/e/E/g;
    if ($unit=~/\$/) { $fmt="\$".$fmt; $unit=~s/\$//g; }
    if ($unit=~/\,/) { $fmt="\,".$fmt; $unit=~s/\,//g; }
    $ans = &format_number($ans,$fmt,$target,$safeeval);
       }
       push(@fmt_ans,$ans);
    }
    my $response=join(', ',@fmt_ans);
    my $hideunit=&Apache::lonnet::EXT('resource.'.$partid.'_'.
     $id.'.turnoffunit');
    if ($unit ne ''  && 
       ! ($Apache::lonhomework::type eq 'exam' ||
          lc($hideunit) eq "yes") )  {
       my $cleanunit=$unit;
       $cleanunit=~s/\$\,//g;
       $response.=" $cleanunit";
    }
   
    my ($awards,$msgs)=&check_submission($response,$partid,$id,$tag,
        $parstack,$safeeval);
    my ($ad,$msg) =&Apache::inputtags::finalizeawards($awards,$msgs);
    if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') {
       my $error;
       if ($tag eq 'formularesponse') {
    $error=&mt('Computer\'s answer is incorrect ("[_1]").');
       } else {
    # answer failed check if it is sig figs that is failing
    my ($awards,$msgs)=&check_submission($response,$partid,$id,
        $tag,$parstack,
        $safeeval,1);
    ($ad,$msg)=&Apache::inputtags::finalizeawards($awards,
         $msgs);
       
    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.',$response,$tolline,$sigline);
    } else {
       $error=&mt('Computer\'s answer is incorrect ("[_1]"). It is likely that the tolerance range [_1] needs to be adjusted.',$response,$tolline);
    }
       }
     if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') {      if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') {
  &Apache::lonxml::error(&mt('Computer\'s answer is incorrect ("[_1]"). It is likely that the tolerance range ("[_2]" to "[_3]") or significant figures ("[_4]" to "[_5]") needs to be adjusted',$response,$low,$high,$siglow,$sighigh));   &Apache::lonxml::error($error);
       } else {
    &Apache::lonxml::warning($error);
     }      }
  }   }
   
  if (defined($unit) and ($unit ne '') and   if (defined($unit) and ($unit ne '') and
     $tag eq 'numericalresponse') {      $tag eq 'numericalresponse') {
     if ($target eq 'answer') {      if ($target eq 'answer') {

Removed from v.1.168  
changed lines
  Added in v.1.176


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