Annotation of loncom/homework/default_homework.lcpm, revision 1.10
1.1 harris41 1: # file name (temp): default_homework
2: # used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run()
3: #
4: #
1.3 albertel 5: $RANDOMINIT=0;
6:
1.7 albertel 7: sub caparesponse_check {
1.10 ! albertel 8: my $answer=''; #done
! 9: my $type=''; #done
! 10: my $tol_type=''; # gets it's value from whether tol has a % or not done
! 11: my $tol=''; #done
1.7 albertel 12: my $sig_lbound='';
13: my $sig_ubound='';
14: my $ans_fmt='';
1.9 albertel 15: my $units='';
1.7 albertel 16: my $calc='';
17: my ($response,$expr)=@_;
18:
1.10 ! albertel 19: ($answer,$type,$tol,$sig_lbound,$sig_ubound,$ans_fmt,
! 20: $units,$calc) = eval $expr.'return $answer,$type,$tol,$sig_lbound,$sig_ubound,$ans_fmt,$units,$calc';
1.8 albertel 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;
1.9 albertel 31: } elsif ($type eq 'subj') { $type = 7;
32: } else { return "ERROR: Unknown type of answer: $type" }
1.8 albertel 33: }
34:
1.10 ! albertel 35: if ($tol eq '') {
! 36: $tol=0.0;
! 37: $tol_type=1; #TOL_ABSOLUTE
! 38: } else {
! 39: if ($tol =~ /%$/) {
! 40: $tol=chop($tol);
! 41: $tol_type=2; #TOL_PERCENTAGE
! 42: } else {
! 43: $tol_type=1; #TOL_ABSOLUTE
! 44: }
! 45: }
1.7 albertel 46: my $result = &caparesponse_capa_check_answer($response,$answer,$type,
1.10 ! albertel 47: $tol_type,$tol,
1.7 albertel 48: $sig_lbound,$sig_ubound,
1.9 albertel 49: $ans_fmt, $units,$calc);
50:
51: if ($result == '1') { $result='EXACT_ANS'; }
52: elsif ($result == '2') { $result='APPROX_ANS'; }
53: elsif ($result == '3') { $result='SIG_FAIL'; }
54: elsif ($result == '4') { $result='UNIT_FAIL'; }
55: elsif ($result == '5') { $result='NO_UNIT'; }
56: elsif ($result == '6') { $result='UNIT_OK'; }
57: elsif ($result == '7') { $result='INCORRECT'; }
58: elsif ($result == '8') { $result='UNIT_NOTNEEDED'; }
59: elsif ($result == '9') { $result='ANS_CNT_NOT_MATCH'; }
60: elsif ($result =='10') { $result='SUB_RECORDED'; }
61: elsif ($result =='11') { $result='BAD_FORMULA'; }
62: elsif ($result =='12') { $result='WANTED_NUMERIC'; }
63: else {$result = "ERROR: Unknown Result: $result";}
64:
1.10 ! albertel 65: return "$result:$tol:$tol_type";
1.7 albertel 66: }
67:
1.4 albertel 68: sub tex {
69: if ( $external::target eq "tex" ) {
70: #$SCRIPT_RESULT.=@_[0];
71: return @_[0];
72: } else {
73: #$SCRIPT_RESULT.=@_[1];
74: return @_[1];
75: }
76: }
77:
78: sub web {
79: if ( $external::target eq "tex" ) {
80: #$SCRIPT_RESULT.=@_[1];
81: return @_[1];
82: } else {
83: if ( $external::target eq "web") {
84: #$SCRIPT_RESULT.=@_[0];
85: return @_[0];
86: } else {
87: #$SCRIPT_RESULT.=@_[2];
88: return @_[2];
89: }
90: }
91: }
92:
93: sub problem {
94: $SCRIPT_RESULT.='1';
95: return '';
96: }
97:
1.1 harris41 98: sub hinton {
99: return 0;
100: }
101:
102: sub random {
103: my ($start,$end,$step)=@_;
1.3 albertel 104: if ( ! $RANDOMINIT ) { srand($external::randomseed); $RANDOMINIT=1; }
1.1 harris41 105: my $num=1+int(($end-$start)/$step);
106: my $result=$start + int(rand() * $num)*$step;
107: return $result;
108: }
109:
110: sub tan { sin($_[0]) / cos($_[0]) }
111: sub acos { atan2(sqrt(1 - $_[0] * $_[0]), $_[0] ); }
112: sub asin { atan2($_[0], sqrt(1- $_[0] * $_[0]) ); }
113:
114: sub html {
1.4 albertel 115: if ( $external::target eq "web" ) {
116: #$SCRIPT_RESULT.=@_[0];
117: return @_[0];
1.1 harris41 118: }
119: }
120:
121:
122: sub pow {return $_[0] ** $_[1]; }
123: sub ceil {return (($_[0]-int($_[0]))== 0.0) ? $_[0] : (int($_[0])+ 1); }
124: sub floor {return int($_[0]); }
125:
1.2 albertel 126: sub format {
127: my ($value,$fmt)=@_;
128: $SCRIPT_RESULT.=sprintf('%.'.$fmt,$value);
1.10 ! albertel 129: return $SCRIPT_RESULT;
1.2 albertel 130: }
1.5 albertel 131:
132: sub map {
133: my $num = $#_/2;
134: my $i;
1.6 albertel 135: my @used;
136: my @permutation;
137: for ($i=0; $i < $num;) {
138: $rand = &random(1,$num,1);
139: if ( $used[$rand] == '0' ) {
140: $i++;
141: $used[$rand]='1';
142: $permutation[$i]=$rand;
143: }
144: }
1.5 albertel 145: for ( $i=1 ; $i<$num+1 ; $i++ ) {
1.6 albertel 146: ${$_[$permutation[$i]]}=$_[$i+$num]
1.5 albertel 147: }
148: }
149:
150: sub choose {
151: my $num = $_[0];
152: return $_[$num];
153: }
1.6 albertel 154: #$external::randomseed=time;
1.5 albertel 155: #$a=2;
156: #$b=2;
1.6 albertel 157: #$c=2;
158: #&map(1,\$a,\$b,\$c,3,4,5);
1.5 albertel 159: #print $a."\n".$b."\n";
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>