File:
[LON-CAPA] /
loncom /
homework /
default_homework.lcpm
Revision
1.64:
download - view:
text,
annotated -
select for diffs
Tue Jun 24 20:41:56 2003 UTC (21 years, 1 month ago) by
albertel
Branches:
MAIN
CVS tags:
version_1_0_3,
version_1_0_2,
version_1_0_1,
version_1_0_0,
version_0_99_5,
version_0_99_4,
version_0_99_3,
HEAD
= BUG#1849, answers that are in arrays didn't work, now pass the answer in through a varglob into the safe space, and then through a parameter to the capa_check_answer function
1: # The LearningOnline Network with CAPA
2: # used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run()
3: #
4: # $Id: default_homework.lcpm,v 1.64 2003/06/24 20:41:56 albertel Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: # Guy Albertelli
30: #
31: # 05/25/2001 H. K. Ng
32: # 05/31/2001 H. K. Ng
33: # 12/21/2001 Matthew
34: #
35: #init some globals
36: $hidden::RANDOMINIT=0;
37: $pi=atan2(1,1)*4;
38: $rad2deg=180.0/$pi;
39: $deg2rad=$pi/180.0;
40: $"=' ';
41:
42: sub caparesponse_check {
43: #not properly used yet: calc
44: #not to be used: $ans_fmt
45: my ($type,$tol,$sig,$ans_fmt,$unit,$calc,$samples) =
46: eval $_[2].
47: ';return ($type,$tol,$sig,$ans_fmt,$unit,$calc,$samples);';
48:
49: my $tol_type=''; # gets it's value from whether tol has a % or not done
50: my $sig_lbound=''; #done
51: my $sig_ubound=''; #done
52: my ($answer,$response,$expr)=@_;
53:
54:
55: #type's definitons come from capaParser.h
56: my $message='';
57: #remove leading and trailing whitespace
58: if ($response=~ /^\s|\s$/) {
59: $response=~ s:^\s+|\s+$::g;
60: $message .="Removed ws now :$response:\n";
61: } else {
62: $message .="no ws in :$response:\n";
63: }
64:
65: if (length($response) > 500) { return "TOO_LONG: Answer too long"; }
66:
67: if ($type eq '' ) {
68: $message .= "Didn't find a type :$type:$expr: defaulting\n";
69: if ( $answer eq ($answer *1.0)) { $type = 2;
70: } else { $type = 3; }
71: } else {
72: if ($type eq 'cs') { $type = 4;
73: } elsif ($type eq 'ci') { $type = 3;
74: } elsif ($type eq 'mc') { $type = 5;
75: } elsif ($type eq 'fml') { $type = 8;
76: } elsif ($type eq 'subj') { $type = 7;
77: } elsif ($type eq 'float') { $type = 2;
78: } elsif ($type eq 'int') { $type = 1;
79: } else { return "ERROR: Unknown type of answer: $type" }
80: }
81:
82: my $points;
83: my $id_list;
84: #formula type setup the sample points
85: if ($type eq '8') {
86: ($id_list,$points)=split(/@/,$samples);
87: $message.="Found :$id_list:$points: points in $samples\n";
88: }
89: if ($tol eq '') {
90: $tol=0.0;
91: $tol_type=1; #TOL_ABSOLUTE
92: } else {
93: if ($tol =~ /%$/) {
94: chop $tol;
95: $tol_type=2; #TOL_PERCENTAGE
96: } else {
97: $tol_type=1; #TOL_ABSOLUTE
98: }
99: }
100:
101: if ($sig eq '') {
102: $sig_lbound = 0; #SIG_LB_DEFAULT
103: $sig_ubound =15; #SIG_UB_DEFAULT
104: } else {
105: ($sig_lbound,$sig_ubound) = split /,/,$sig;
106: if (!defined($sig_lbound)) {
107: $sig_lbound = 0; #SIG_LB_DEFAULT
108: $sig_ubound =15; #SIG_UB_DEFAULT
109: }
110: if (!defined($sig_ubound)) { $sig_ubound=$sig_lbound; }
111: }
112: my $result = &caparesponse_capa_check_answer($response,$answer,$type,
113: $tol_type,$tol,
114: $sig_lbound,$sig_ubound,
115: $ans_fmt,$unit,$calc,$id_list,
116: $points,$external::randomseed);
117:
118: if ($result == '1') { $result='EXACT_ANS'; }
119: elsif ($result == '2') { $result='APPROX_ANS'; }
120: elsif ($result == '3') { $result='SIG_FAIL'; }
121: elsif ($result == '4') { $result='UNIT_FAIL'; }
122: elsif ($result == '5') { $result='NO_UNIT'; }
123: elsif ($result == '6') { $result='UNIT_OK'; }
124: elsif ($result == '7') { $result='INCORRECT'; }
125: elsif ($result == '8') { $result='UNIT_NOTNEEDED'; }
126: elsif ($result == '9') { $result='ANS_CNT_NOT_MATCH'; }
127: elsif ($result =='10') { $result='SUB_RECORDED'; }
128: elsif ($result =='11') { $result='BAD_FORMULA'; }
129: elsif ($result =='12') { $result='WANTED_NUMERIC'; }
130: else {$result = "ERROR: Unknown Result:$result:$@:";}
131:
132: return "$result:\nError $error:\nAnswer $answer:\nResponse $response:\n type-$type|$tol|$tol_type|$sig:$sig_lbound:$sig_ubound|$unit|\n$message$expr";
133: }
134:
135: sub get_array_args {
136: my ($expr,$arg)=@_;
137: # do these first, because who knows what varname the instructor might have used
138: # but it probably isn't $CAPARESPONSE_CHECK_LIST_answer
139: my $CAPARESPONSE_CHECK_LIST_answer = eval $expr.';return $'.$arg; #' stupid emacs
140: my $GET_ARRAY_ARGS_result="expr is $expr\narg is $arg\nfirst answer guess is $CAPARESPONSE_CHECK_LIST_answer\n";
141: my @GET_ARRAY_ARGS_list;
142: if ($CAPARESPONSE_CHECK_LIST_answer =~ /^\s*[\$\@]/) {
143: (@GET_ARRAY_ARGS_list) = eval $CAPARESPONSE_CHECK_LIST_answer;
144: }
145: $GET_ARRAY_ARGS_result.="error:$@:\n";
146: # if the eval fails just use what is in the answer exactly
147: if (!(@GET_ARRAY_ARGS_list) || !defined($GET_ARRAY_ARGS_list[0])) {
148: $GET_ARRAY_ARGS_result.="list zero is undefined\n";
149: $GET_ARRAY_ARGS_list[0]=$CAPARESPONSE_CHECK_LIST_answer;
150: }
151: return $GET_ARRAY_ARGS_result,@GET_ARRAY_ARGS_list;
152: }
153:
154: sub caparesponse_check_list {
155: my ($response,$expr)=@_;
156: # $expr =~ s/\\/\\\\/g;
157: # $expr =~ s/\'/\\\'/g;
158: # my ($result,@list) = &get_array_args($expr,'answer');
159: # $expr =~ s/\\\'/\'/g;
160: # $expr =~ s/\\\\/\\/g;
161: my ($result,@list);
162: @list=@CAPARESPONSE_CHECK_LIST_answer;
163: my $aresult='';
164: my $current_answer;
165: my $answers=join(':',@list);
166: $result.="Got response :$answers:\n";
167: my @responselist;
168: my $type =eval $expr.';return $type;';
169: if ($type ne '' && $#list > 0) {
170: (@responselist)=split /,/,$response;
171: } else {
172: (@responselist)=($response);
173: }
174: my $unit='';
175: $result.="Initial final response :$responselist['-1']:\n";
176: if ($type eq '' || $type eq 'float') {
177: #for numerical problems split off the unit
178: if ( $responselist['-1']=~ /(.*[^\s])\s+([^\s]+)/ ) {
179: $responselist['-1']=$1;
180: $unit=$2;
181: }
182: }
183: $result.="Final final response :$responselist['-1']:\n";
184: $result.=":$#list: answers\n";
185: $unit=~s/\s//;
186: my $i=0;
187: my $awards='';
188: for ($i=0; $i<@list;$i++) {
189: $result.="trying answer :$list[$i]:\n";
190: my $thisanswer=$list[$i];
191: # $thisanswer=~ s/\\/\\\\/g;
192: # $thisanswer =~ s/\'/\\\'/g;
193: $result.="trying answer :$thisanswer:\n";
194: if ($unit eq '') {
195: $aresult=&caparesponse_check($thisanswer,$responselist[$i],
196: $expr);
197: } else {
198: $aresult=&caparesponse_check($thisanswer,$responselist[$i]." $unit",
199: $expr);
200: }
201: my ($temp)=split /:/, $aresult;
202: $awards.="$temp,";
203: $result.=$aresult;
204: }
205: chop $awards;
206: return "$awards:\n$result";
207: }
208:
209: sub tex {
210: if ( $external::target eq "tex" ) {
211: return $_[0];
212: } else {
213: return $_[1];
214: }
215: }
216:
217: sub var_in_tex {
218: if ( $external::target eq "tex" ) {
219: return $_[0];
220: } else {
221: return "";
222: }
223: }
224:
225: sub web {
226: if ( $external::target eq "tex" ) {
227: return $_[1];
228: } else {
229: if ( $external::target eq "web" || $external::target eq "answer") {
230: return $_[2];
231: } else {
232: return $_[0];
233: }
234: }
235: }
236:
237: sub html {
238: if ( $external::target eq "web" ) {
239: return shift;
240: }
241: }
242:
243: sub hinton {
244: return 0;
245: }
246:
247: sub random {
248: my ($start,$end,$step)=@_;
249: if ( ! $hidden::RANDOMINIT ) {
250: if ($external::randomseed == 0) { $external::randomseed=1; }
251: if ($external::randomseed =~/,/) {
252: my ($num1,$num2)=split(/,/,$seed);
253: &random_set_seed(abs($num1),abs($num2));
254: } else {
255: &random_set_seed(1,int(abs($external::randomseed)));
256: }
257: &math_random_uniform();
258: $hidden::RANDOMINIT=1;
259: }
260: if (!defined($step)) { $step=1; }
261: my $num=1+int(($end-$start)/$step);
262: my $result=$start + int(&math_random_uniform() * $num)*$step;
263: return $result;
264: }
265:
266: sub random_normal {
267: my ($item_cnt,$seed,$av,$std_dev) = @_;
268: my @oldseed=&random_get_seed();
269: my @retArray;
270: &random_set_seed_from_phrase($seed);
271: @retArray=&math_random_normal($item_cnt,$av,$std_dev);
272: &random_set_seed(@oldseed);
273: return @retArray;
274: }
275:
276: sub random_beta {
277: my ($item_cnt,$seed,$aa,$bb) = @_;
278: my @oldseed=&random_get_seed();
279: my @retArray;
280: &random_set_seed_from_phrase($seed);
281: @retArray=&math_random_beta($item_cnt,$aa,$bb);
282: &random_set_seed(@oldseed);
283: return @retArray;
284: }
285:
286: sub random_gamma {
287: my ($item_cnt,$seed,$a,$r) = @_;
288: my @oldseed=&random_get_seed();
289: my @retArray;
290: &random_set_seed_from_phrase($seed);
291: @retArray=&math_random_gamma($item_cnt,$a,$r);
292: &random_set_seed(@oldseed);
293: return @retArray;
294: }
295:
296: sub random_exponential {
297: my ($item_cnt,$seed,$av) = @_;
298: my @oldseed=&random_get_seed();
299: my @retArray;
300: &random_set_seed_from_phrase($seed);
301: @retArray=&math_random_exponential($item_cnt,$av);
302: &random_set_seed(@oldseed);
303: return @retArray;
304: }
305:
306: sub random_poisson {
307: my ($item_cnt,$seed,$mu) = @_;
308: my @oldseed=&random_get_seed();
309: my @retArray;
310: &random_set_seed_from_phrase($seed);
311: @retArray=&math_random_poisson($item_cnt,$mu);
312: &random_set_seed(@oldseed);
313: return @retArray;
314: }
315:
316: sub random_chi {
317: my ($item_cnt,$seed,$df) = @_;
318: my @oldseed=&random_get_seed();
319: my @retArray;
320: &random_set_seed_from_phrase($seed);
321: @retArray=&math_random_chi_square($item_cnt,$df);
322: &random_set_seed(@oldseed);
323: return @retArray;
324: }
325:
326: sub random_noncentral_chi {
327: my ($item_cnt,$seed,$df,$nonc) = @_;
328: my @oldseed=&random_get_seed();
329: my @retArray;
330: &random_set_seed_from_phrase($seed);
331: @retArray=&math_random_noncentral_chi_square($item_cnt,$df,$nonc);
332: &random_set_seed(@oldseed);
333: return @retArray;
334: }
335:
336: sub random_f {
337: my ($item_cnt,$seed,$dfn,$dfd) = @_;
338: my @oldseed=&random_get_seed();
339: my @retArray;
340: &random_set_seed_from_phrase($seed);
341: @retArray=&math_random_f($item_cnt,$dfn,$dfd);
342: &random_set_seed(@oldseed);
343: return @retArray;
344: }
345:
346: sub random_noncentral_f {
347: my ($item_cnt,$seed,$dfn,$dfd,$nonc) = @_;
348: my @oldseed=&random_get_seed();
349: my @retArray;
350: &random_set_seed_from_phrase($seed);
351: @retArray=&math_random_noncentral_f($item_cnt,$dfn,$dfd,$nonc);
352: &random_set_seed(@oldseed);
353: return @retArray;
354: }
355:
356: sub random_multivariate_normal {
357: my ($item_cnt,$seed,$mean,$covar) = @_;
358: my @oldseed=&random_get_seed();
359: &random_set_seed_from_phrase($seed);
360: @retArray=&math_random_multivariate_normal($item_cnt,@$mean,@$covar);
361: &random_set_seed(@oldseed);
362: return @retArray;
363: }
364:
365: sub random_multinomial {
366: my ($item_cnt,$seed,@p) = @_;
367: my @oldseed=&random_get_seed();
368: my @retArray;
369: &random_set_seed_from_phrase($seed);
370: @retArray=&math_random_multinomial($item_cnt,@p);
371: &random_set_seed(@oldseed);
372: return @retArray;
373: }
374:
375: sub random_permutation {
376: my ($seed,@inArray) = @_;
377: my @oldseed=&random_get_seed();
378: my @retArray;
379: &random_set_seed_from_phrase($seed);
380: @retArray=&math_random_permutation(@inArray);
381: &random_set_seed(@oldseed);
382: return @retArray;
383: }
384:
385: sub random_uniform {
386: my ($item_cnt,$seed,$low,$high) = @_;
387: my @oldseed=&random_get_seed();
388: my @retArray;
389: &random_set_seed_from_phrase($seed);
390: @retArray=&math_random_uniform($item_cnt,$low,$high);
391: &random_set_seed(@oldseed);
392: return @retArray;
393: }
394:
395: sub random_uniform_integer {
396: my ($item_cnt,$seed,$low,$high) = @_;
397: my @oldseed=&random_get_seed();
398: my @retArray;
399: &random_set_seed_from_phrase($seed);
400: @retArray=&math_random_uniform_integer($item_cnt,$low,$high);
401: &random_set_seed(@oldseed);
402: return @retArray;
403: }
404:
405: sub random_binomial {
406: my ($item_cnt,$seed,$nt,$p) = @_;
407: my @oldseed=&random_get_seed();
408: my @retArray;
409: &random_set_seed_from_phrase($seed);
410: @retArray=&math_random_binomial($item_cnt,$nt,$p);
411: &random_set_seed(@oldseed);
412: return @retArray;
413: }
414:
415: sub random_negative_binomial {
416: my ($item_cnt,$seed,$ne,$p) = @_;
417: my @oldseed=&random_get_seed();
418: my @retArray;
419: &random_set_seed_from_phrase($seed);
420: @retArray=&math_random_negative_binomial($item_cnt,$ne,$p);
421: &random_set_seed(@oldseed);
422: return @retArray;
423: }
424:
425: sub abs { abs(shift) }
426: sub sin { sin(shift) }
427: sub cos { cos(shift) }
428: sub exp { exp(shift) }
429: sub int { int(shift) }
430: sub log { log(shift) }
431: sub atan2 { atan2($_[0],$_[1]) }
432: sub sqrt { sqrt(shift) }
433:
434: sub tan { CORE::sin($_[0]) / CORE::cos($_[0]) }
435: #sub atan { atan2($_[0], 1); }
436: #sub acos { atan2(sqrt(1 - $_[0] * $_[0]), $_[0] ); }
437: #sub asin { atan2($_[0], sqrt(1- $_[0] * $_[0]) ); }
438:
439: sub log10 { CORE::log($_[0])/CORE::log(10); }
440:
441: sub factorial {
442: my $input = CORE::int(shift);
443: return "Error - unable to take factorial of an negative number ($input)" if $input < 0;
444: return "Error - factorial result is greater than system limit ($input)" if $input > 170;
445: return 1 if $input == 0;
446: my $result = 1;
447: for (my $i=2; $i<=$input; $i++) { $result *= $i }
448: return $result;
449: }
450:
451: sub sgn {
452: return -1 if $_[0] < 0;
453: return 0 if $_[0] == 0;
454: return 1 if $_[0] > 0;
455: }
456:
457: sub min {
458: my @sorted = sort { $a <=> $b || $a cmp $b } @_;
459: return shift @sorted;
460: }
461:
462: sub max {
463: my @sorted = sort { $a <=> $b || $a cmp $b } @_;
464: return pop @sorted;
465: }
466:
467: sub roundto {
468: my ($input,$n) = @_;
469: return sprintf('%.'.$n.'f',$input);
470: }
471:
472: sub to_string {
473: my ($input,$n) = @_;
474: return sprintf($input) if $n eq "";
475: $n = '.'.$n if $n !~ /^\./;
476: return sprintf('%'.$n,$input) if $n ne "";
477: }
478:
479: sub sub_string {
480: my ($str,$start,$len) = @_;
481: return substr($str,$start-1,$len);
482: }
483:
484: sub pow {return $_[0] ** $_[1]; }
485: sub ceil {return (($_[0]-CORE::int($_[0]))== 0.0) ? $_[0] : (($_[0] > 0) ? (CORE::int($_[0])+ 1) : CORE::int($_[0])); }
486: sub floor {return (($_[0]-CORE::int($_[0]))== 0.0) ? $_[0] : (($_[0] > 0) ? CORE::int($_[0]) : (CORE::int($_[0])-1)); }
487: #sub floor {return int($_[0]); }
488:
489: sub format {
490: my ($value,$fmt)=@_;
491: my $dollarmode;
492: if ($fmt =~ /^\$(.*)/) { $fmt=$1; $dollarmode=1; }
493: my $result=sprintf('%.'.$fmt,$value);
494: $result=~s/(E[+-]*)0/$1/;
495: if ($dollarmode) {$result=&dollarmode($result);}
496: return $result;
497: }
498:
499: sub prettyprint {
500: my ($value,$fmt)=@_;
501: my $result;
502: my $dollarmode;
503: if ($fmt =~ /^\$(.*)/) { $fmt=$1; $dollarmode=1; }
504: if ($fmt) { $value=sprintf('%.'.$fmt,$value); }
505: if ($value =~ /([0-9\.\-\+]+)E([0-9\-\+]+)/ ) {
506: my $frac=$1;
507: if ($dollarmode) { $frac=&dollarformat($frac); }
508: my $exponent=$2;
509: $exponent=~s/^\+0*//;
510: $exponent=~s/^-0*/-/;
511: if ($exponent) {
512: if ($external::target eq 'web') {
513: $result=$frac.'×10<sup>'.$exponent.'</sup>';
514: } elsif ($external::target eq 'tex') {
515: $result='\ensuremath{'.$frac.'\times 10^{'.$exponent.'}}';
516: } else {
517: $result=$value;
518: }
519: } else {
520: $result=$frac;
521: }
522: } else {
523: $result=$value;
524: if ($dollarmode) { $result=&dollarformat($result); }
525: }
526: return $result;
527: }
528:
529: sub dollarformat {
530: my ($number) = @_;
531: if ($number =~ /\./) {
532: while ($number =~ /([^\.,]+)([^\.,][^\.,][^\.,])([,0-9]*\.[0-9]*$)/) {
533: $number = $1.','.$2.$3;
534: }
535: } else {
536: while ($number =~ /([^,]+)([^,][^,][^,])([,0-9]*)$/) {
537: $number = $1.','.$2.$3;
538: }
539: }
540: if ($external::target eq 'tex') {
541: $number='\$'.$number; #' stupid emacs
542: } else {
543: $number='$'.$number; #' stupid emacs
544: }
545: return $number;
546: }
547:
548: sub map {
549: my ($phrase,$dest,$source)=@_;
550: my @oldseed=&random_get_seed();
551: my @seed = &random_seed_from_phrase($phrase);
552: &random_set_seed(@seed);
553: my $destct = scalar(@$dest);
554: if (!$source) {
555: my @output;
556: my @idx = &math_random_permuted_index($destct);
557: my $ctr = 0;
558: while ($ctr < $destct) {
559: $output[$ctr] = $$dest[$idx[$ctr]];
560: $ctr++;
561: }
562: &random_set_seed(@oldseed);
563: return @output;
564: } else {
565: my $num = scalar(@$source);
566: my @idx = &math_random_permuted_index($num);
567: my $ctr = 0;
568: my $tot = $num;
569: $tot = $destct if $destct < $num;
570: if (ref($$dest[0])) {
571: while ($ctr < $tot) {
572: ${$$dest[$ctr]} = $$source[$idx[$ctr]];
573: $ctr++;
574: }
575: } else {
576: while ($ctr < $tot) {
577: $$dest[$ctr] = $$source[$idx[$ctr]];
578: $ctr++;
579: }
580: }
581: }
582: &random_set_seed(@oldseed);
583: return '';
584: }
585:
586: sub rmap {
587: my ($phrase,$dest,$source)=@_;
588: my @oldseed=&random_get_seed();
589: my @seed = &random_seed_from_phrase($phrase);
590: &random_set_seed(@seed);
591: my $destct = scalar(@$dest);
592: if (!$source) {
593: my @idx = &math_random_permuted_index($destct);
594: my $ctr = 0;
595: my @r_idx;
596: while ($ctr < $destct) {
597: $r_idx[$idx[$ctr]] = $ctr;
598: $ctr++;
599: }
600: my @output;
601: $ctr = 0;
602: while ($ctr < $destct) {
603: $output[$ctr] = $$dest[$r_idx[$ctr]];
604: $ctr++;
605: }
606: &random_set_seed(@oldseed);
607: return @output;
608: } else {
609: my $num = scalar(@$source);
610: my @idx = &math_random_permuted_index($num);
611: my $ctr = 0;
612: my $tot = $num;
613: $tot = $destct if $destct < $num;
614: my @r_idx;
615: while ($ctr < $tot) {
616: $r_idx[$idx[$ctr]] = $ctr;
617: $ctr++;
618: }
619: $ctr = 0;
620: if (ref($$dest[0])) {
621: while ($ctr < $tot) {
622: ${$$dest[$ctr]} = $$source[$r_idx[$ctr]];
623: $ctr++;
624: }
625: } else {
626: while ($ctr < $tot) {
627: $$dest[$ctr] = $$source[$r_idx[$ctr]];
628: $ctr++;
629: }
630: }
631: }
632: &random_set_seed(@oldseed);
633: return '';
634: }
635:
636: sub capa_id { return }
637:
638: sub problem { return }
639:
640: sub name{
641: my $fullname = &EXT('environment.lastname').', '.&EXT('environment.firstname').' '.&EXT('environment.middlename');
642: $fullname = "" if $fullname eq ", ";
643: $fullname =~ s/\%2d/-/g;
644: return $fullname;
645: }
646:
647: sub student_number {
648: my $id = &EXT('environment.id');
649: $id = '' if $id eq "";
650: return $id;
651: }
652:
653: sub class {
654: my $course = &EXT('course.description');
655: $course = '' if $course eq "";
656: return $course;
657: }
658:
659: sub sec {
660: my $sec = &EXT('request.course.sec');
661: $sec = '' if $sec eq "";
662: return $sec;
663: }
664:
665: sub open_date {
666: my @dc = split(/\s+/,localtime(&EXT('resource.0.opendate')));
667: return '' if ($dc[0] eq "Wed" and $dc[2] == 31 and $dc[4] == 1969);
668: my @hm = split(/:/,$dc[3]);
669: my $ampm = " am";
670: if ($hm[0] > 12) {
671: $hm[0]-=12;
672: $ampm = " pm";
673: }
674: return $dc[0].', '.$dc[1].' '.$dc[2].', '.$dc[4].' at '.$hm[0].':'.$hm[1].$ampm;
675: }
676:
677: sub due_date {
678: my @dc = split(/\s+/,localtime(&EXT('resource.0.duedate')));
679: return '' if ($dc[0] eq "Wed" and $dc[2] == 31 and $dc[4] == 1969);
680: my @hm = split(/:/,$dc[3]);
681: my $ampm = " am";
682: if ($hm[0] > 12) {
683: $hm[0]-=12;
684: $ampm = " pm";
685: }
686: return $dc[0].', '.$dc[1].' '.$dc[2].', '.$dc[4].' at '.$hm[0].':'.$hm[1].$ampm;
687: # return $dc[0].', '.$dc[1].' '.$dc[2].', '.$dc[4].' at '.$dc[3];
688: }
689:
690: sub answer_date {
691: my @dc = split(/\s+/,localtime(&EXT('resource.0.answerdate')));
692: return '' if ($dc[0] eq "Wed" and $dc[2] == 31 and $dc[4] == 1969);
693: my @hm = split(/:/,$dc[3]);
694: my $ampm = " am";
695: if ($hm[0] > 12) {
696: $hm[0]-=12;
697: $ampm = " pm";
698: }
699: return $dc[0].', '.$dc[1].' '.$dc[2].', '.$dc[4].' at '.$hm[0].':'.$hm[1].$ampm;
700: # return $dc[0].', '.$dc[1].' '.$dc[2].', '.$dc[4].' at '.$dc[3];
701: }
702:
703: sub array_moments {
704: my @input=@_;
705: my (@output,$N);
706: $N=scalar (@input);
707: $output[0]=$N;
708: if ($N <= 1) {
709: $output[1]=$input[0];
710: $output[1]="Input array not defined" if ($N == 0);
711: $output[2]="variance undefined for N<=1";
712: $output[3]="skewness undefined for N<=1";
713: $output[4]="kurtosis undefined for N<=1";
714: return @output;
715: }
716: my $sum=0;
717: foreach my $line (@input) {
718: $sum+=$line;
719: }
720: $output[1] = $sum/$N;
721: my ($x,$sdev,$var,$skew,$kurt) = 0;
722: foreach my $line (@input) {
723: $x=$line-$output[1];
724: $var+=$x**2;
725: $skew+=$x**3;
726: $kurt+=$x**4;
727: }
728: $output[2]=$var/($N-1);
729: $sdev=CORE::sqrt($output[2]);
730: if ($sdev == 0) {
731: $output[3]="inf-variance=0";
732: $output[4]="inf-variance=0";
733: return @output;
734: }
735: $output[3]=$skew/($sdev**3*$N);
736: $output[4]=$kurt/($sdev**4*$N)-3;
737: return @output;
738: }
739:
740: sub choose {
741: my $num = $_[0];
742: return $_[$num];
743: }
744:
745: # expiremental idea
746: sub proper_path {
747: my ($path)=@_;
748: if ( $external::target eq "tex" ) {
749: return '/home/httpd/html'.$path;
750: } else {
751: return $path;
752: }
753: }
754:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>