File:  [LON-CAPA] / loncom / homework / default_homework.lcpm
Revision 1.9: download - view: text, annotated - select for diffs
Mon Oct 30 20:36:18 2000 UTC (23 years, 6 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- parses $result
- sends $units along

    1: # file name (temp): default_homework 
    2: # used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run()
    3: # 
    4: #
    5: $RANDOMINIT=0;
    6: 
    7: sub caparesponse_check {
    8:   my $answer='';
    9:   my $type='';
   10:   my $tol_type='';
   11:   my $tolerance='';
   12:   my $sig_lbound='';
   13:   my $sig_ubound='';
   14:   my $ans_fmt='';
   15:   my $units='';
   16:   my $calc='';
   17:   my ($response,$expr)=@_;
   18:   
   19:   ($answer,$type,$tol_type,$tolerance,$sig_lbound,$sig_ubound,$ans_fmt,
   20:    $units,$calc) = eval $expr.'return $answer,$type,$tol_type,$tolerance,$sig_lbound,$sig_ubound,$ans_fmt,$units,$calc';
   21: 
   22:   #type's definitons come from capaParser.h
   23:   if ($type eq '' ) {
   24:     if ( $answer eq ($answer *1.0)) { $type = 2;
   25:     } else { $type = 3; }
   26:   } else {
   27:          if ($type eq 'cs')    { $type = 4;
   28:     } elsif ($type eq 'ci')    { $type = 3;
   29:     } elsif ($type eq 'mc')    { $type = 5;
   30:     } elsif ($type eq 'fml')   { $type = 8;
   31:     } elsif ($type eq 'subj')  { $type = 7;
   32:     } else { return "ERROR: Unknown type of answer: $type" }
   33:   }
   34: 
   35:   
   36:   my $result = &caparesponse_capa_check_answer($response,$answer,$type,
   37: 					       $tol_type,$tolerance,
   38: 					       $sig_lbound,$sig_ubound,
   39: 					       $ans_fmt, $units,$calc);
   40: 
   41:   if    ($result == '1') { $result='EXACT_ANS'; } 
   42:   elsif ($result == '2') { $result='APPROX_ANS'; }
   43:   elsif ($result == '3') { $result='SIG_FAIL'; }
   44:   elsif ($result == '4') { $result='UNIT_FAIL'; }
   45:   elsif ($result == '5') { $result='NO_UNIT'; }
   46:   elsif ($result == '6') { $result='UNIT_OK'; }
   47:   elsif ($result == '7') { $result='INCORRECT'; }
   48:   elsif ($result == '8') { $result='UNIT_NOTNEEDED'; }
   49:   elsif ($result == '9') { $result='ANS_CNT_NOT_MATCH'; }
   50:   elsif ($result =='10') { $result='SUB_RECORDED'; }
   51:   elsif ($result =='11') { $result='BAD_FORMULA'; }
   52:   elsif ($result =='12') { $result='WANTED_NUMERIC'; }
   53:   else  {$result = "ERROR: Unknown Result: $result";}
   54: 
   55:   return ":$result:$response:$answer:";
   56: }
   57: 
   58: sub tex {
   59:   if ( $external::target eq "tex" ) {
   60:     #$SCRIPT_RESULT.=@_[0];
   61:     return @_[0];
   62:   } else {
   63:     #$SCRIPT_RESULT.=@_[1];
   64:     return @_[1];
   65:   }
   66: }
   67: 
   68: sub web {
   69:   if ( $external::target eq "tex" ) {
   70:     #$SCRIPT_RESULT.=@_[1];
   71:     return @_[1];
   72:   } else {
   73:     if ( $external::target eq "web") {
   74:       #$SCRIPT_RESULT.=@_[0];
   75:       return @_[0];
   76:     } else {
   77:       #$SCRIPT_RESULT.=@_[2];
   78:       return @_[2];
   79:     }
   80:   }
   81: }
   82: 
   83: sub problem {
   84:   $SCRIPT_RESULT.='1';
   85:   return '';
   86: }
   87: 
   88: sub hinton {
   89:   return 0;
   90: }
   91: 
   92: sub random {
   93:   my ($start,$end,$step)=@_;
   94:   if ( ! $RANDOMINIT ) { srand($external::randomseed); $RANDOMINIT=1; }
   95:   my $num=1+int(($end-$start)/$step);
   96:   my $result=$start + int(rand() * $num)*$step;
   97:   return $result;
   98: }
   99: 
  100: sub tan  { sin($_[0]) / cos($_[0]) }
  101: sub acos { atan2(sqrt(1 - $_[0] * $_[0]), $_[0] ); }
  102: sub asin { atan2($_[0], sqrt(1- $_[0] * $_[0]) );  }
  103: 
  104: sub html {
  105:   if ( $external::target eq "web" ) {
  106:     #$SCRIPT_RESULT.=@_[0];
  107:     return @_[0];
  108:   }
  109: }
  110: 
  111: 
  112: sub pow   {return $_[0] ** $_[1]; }
  113: sub ceil  {return (($_[0]-int($_[0]))== 0.0) ? $_[0] : (int($_[0])+ 1); }
  114: sub floor {return int($_[0]);  }
  115: 
  116: sub format {
  117:   my ($value,$fmt)=@_;
  118:   $SCRIPT_RESULT.=sprintf('%.'.$fmt,$value);
  119: }
  120: 
  121: sub map {
  122:   my $num = $#_/2;
  123:   my $i;
  124:   my @used;
  125:   my @permutation;
  126:   for ($i=0; $i < $num;) {
  127:     $rand = &random(1,$num,1);
  128:     if ( $used[$rand] == '0' ) {
  129:       $i++;
  130:       $used[$rand]='1';
  131:       $permutation[$i]=$rand;
  132:     }
  133:   }
  134:   for ( $i=1 ; $i<$num+1 ; $i++ ) {
  135:     ${$_[$permutation[$i]]}=$_[$i+$num]
  136:   }
  137: }
  138: 
  139: sub choose {
  140:   my $num = $_[0];
  141:   return $_[$num];
  142: }
  143: #$external::randomseed=time;
  144: #$a=2;
  145: #$b=2;
  146: #$c=2;
  147: #&map(1,\$a,\$b,\$c,3,4,5);
  148: #print $a."\n".$b."\n";

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