[system] / trunk / pg / macros / PGanswermacros.pl Repository:
ViewVC logotype

Diff of /trunk/pg/macros/PGanswermacros.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1249 Revision 1250
112BEGIN { 112BEGIN {
113 be_strict(); # an alias for use strict. This means that all global variable must contain main:: as a prefix. 113 be_strict(); # an alias for use strict. This means that all global variable must contain main:: as a prefix.
114} 114}
115 115
116 116
117my ($BR , # convenient localizations. 117my ($BR , # convenient localizations.
118 $PAR , 118 $PAR ,
119 $numRelPercentTolDefault , 119 $numRelPercentTolDefault ,
120 $numZeroLevelDefault , 120 $numZeroLevelDefault ,
121 $numZeroLevelTolDefault , 121 $numZeroLevelTolDefault ,
122 $numAbsTolDefault , 122 $numAbsTolDefault ,
123 $numFormatDefault , 123 $numFormatDefault ,
124 $functRelPercentTolDefault , 124 $functRelPercentTolDefault ,
125 $functZeroLevelDefault , 125 $functZeroLevelDefault ,
126 $functZeroLevelTolDefault , 126 $functZeroLevelTolDefault ,
127 $functAbsTolDefault , 127 $functAbsTolDefault ,
128 $functNumOfPoints , 128 $functNumOfPoints ,
129 $functVarDefault , 129 $functVarDefault ,
130 $functLLimitDefault , 130 $functLLimitDefault ,
131 $functULimitDefault , 131 $functULimitDefault ,
132 $functMaxConstantOfIntegration , 132 $functMaxConstantOfIntegration ,
133 $CA 133 $CA ,
134 $rh_envir ,
134); 135);
135 136
136 137
137 138
138 139
139sub _PGanswermacros_init { 140sub _PGanswermacros_init {
140 141
141 $BR = $main::BR; # convenient localizations. 142 $BR = main::PG_restricted_eval(q!$main::BR!);
142 $PAR = $main::PAR; 143 $PAR = main::PG_restricted_eval(q!$main::PAR!);
143 144
144 # import defaults 145 # import defaults
145 # these are now imported from the %envir variable 146 # these are now imported from the %envir variable
146 $numRelPercentTolDefault = $main::numRelPercentTolDefault; 147 $numRelPercentTolDefault = main::PG_restricted_eval(q!$main::numRelPercentTolDefault!);
147 $numZeroLevelDefault = $main::numZeroLevelDefault; 148 $numZeroLevelDefault = main::PG_restricted_eval(q!$main::numZeroLevelDefault!);
148 $numZeroLevelTolDefault = $main::numZeroLevelTolDefault; 149 $numZeroLevelTolDefault = main::PG_restricted_eval(q!$main::numZeroLevelTolDefault!);
149 $numAbsTolDefault = $main::numAbsTolDefault; 150 $numAbsTolDefault = main::PG_restricted_eval(q!$main::numAbsTolDefault!);
150 $numFormatDefault = $main::numFormatDefault; 151 $numFormatDefault = main::PG_restricted_eval(q!$main::numFormatDefault!);
151 $functRelPercentTolDefault = $main::functRelPercentTolDefault; 152 $functRelPercentTolDefault = main::PG_restricted_eval(q!$main::functRelPercentTolDefault!);
152 $functZeroLevelDefault = $main::functZeroLevelDefault; 153 $functZeroLevelDefault = main::PG_restricted_eval(q!$main::functZeroLevelDefault!);
153 $functZeroLevelTolDefault = $main::functZeroLevelTolDefault; 154 $functZeroLevelTolDefault = main::PG_restricted_eval(q!$main::functZeroLevelTolDefault!);
154 $functAbsTolDefault = $main::functAbsTolDefault; 155 $functAbsTolDefault = main::PG_restricted_eval(q!$main::functAbsTolDefault!);
155 $functNumOfPoints = $main::functNumOfPoints; 156 $functNumOfPoints = main::PG_restricted_eval(q!$main::functNumOfPoints!);
156 $functVarDefault = $main::functVarDefault; 157 $functVarDefault = main::PG_restricted_eval(q!$main::functVarDefault!);
157 $functLLimitDefault = $main::functLLimitDefault; 158 $functLLimitDefault = main::PG_restricted_eval(q!$main::functLLimitDefault!);
158 $functULimitDefault = $main::functULimitDefault; 159 $functULimitDefault = main::PG_restricted_eval(q!$main::functULimitDefault!);
159 $functMaxConstantOfIntegration = $main::functMaxConstantOfIntegration; 160 $functMaxConstantOfIntegration = main::PG_restricted_eval(q!$main::functMaxConstantOfIntegration!);
160 161 $rh_envir = main::PG_restricted_eval(q!\%main::envir!);
161
162
163} 162}
164 163
165########################################################################## 164##########################################################################
166########################################################################## 165##########################################################################
167## Number answer evaluators 166## Number answer evaluators
581=cut 580=cut
582 581
583sub std_num_cmp { # compare numbers allowing use of elementary functions 582sub std_num_cmp { # compare numbers allowing use of elementary functions
584 my ( $correctAnswer, $relPercentTol, $format, $zeroLevel, $zeroLevelTol ) = @_; 583 my ( $correctAnswer, $relPercentTol, $format, $zeroLevel, $zeroLevelTol ) = @_;
585 584
586 my %options = ( 'relTol' => $relPercentTol, 585 my %options = ( 'relTol' => $relPercentTol,
587 'format' => $format, 586 'format' => $format,
588 'zeroLevel' => $zeroLevel, 587 'zeroLevel' => $zeroLevel,
589 'zeroLevelTol' => $zeroLevelTol 588 'zeroLevelTol' => $zeroLevelTol
590 ); 589 );
591 590
592 set_default_options( \%options, 591 set_default_options( \%options,
593 'tolType' => 'relative', 592 'tolType' => 'relative',
594 'tolerance' => $numRelPercentTolDefault, 593 'tolerance' => $numRelPercentTolDefault,
595 'mode' => 'std', 594 'mode' => 'std',
596 'format' => $numFormatDefault, 595 'format' => $numFormatDefault,
597 'relTol' => $numRelPercentTolDefault, 596 'relTol' => $numRelPercentTolDefault,
598 'zeroLevel' => $numZeroLevelDefault, 597 'zeroLevel' => $numZeroLevelDefault,
599 'zeroLevelTol' => $numZeroLevelTolDefault, 598 'zeroLevelTol' => $numZeroLevelTolDefault,
600 'debug' => 0, 599 'debug' => 0,
601 ); 600 );
602 601
603 num_cmp([$correctAnswer], %options); 602 num_cmp([$correctAnswer], %options);
604} 603}
605 604
1013 foreach my $key (@keys) { 1012 foreach my $key (@keys) {
1014 warn "$key must be defined in options when calling NUM_CMP" unless defined ($num_params{$key}); 1013 warn "$key must be defined in options when calling NUM_CMP" unless defined ($num_params{$key});
1015 } 1014 }
1016 1015
1017 my $correctAnswer = $num_params{'correctAnswer'}; 1016 my $correctAnswer = $num_params{'correctAnswer'};
1018 my $format = $num_params{'format'}; 1017 my $format = $num_params{'format'};
1019 my $mode = $num_params{'mode'}; 1018 my $mode = $num_params{'mode'};
1020 1019
1021 if( $num_params{tolType} eq 'relative' ) { 1020 if( $num_params{tolType} eq 'relative' ) {
1022 $num_params{'tolerance'} = .01*$num_params{'tolerance'}; 1021 $num_params{'tolerance'} = .01*$num_params{'tolerance'};
1023 } 1022 }
1024 1023
1497 my %options = @_; 1496 my %options = @_;
1498 set_default_options( \%options, 1497 set_default_options( \%options,
1499 'vars' => [qw( x y )], 1498 'vars' => [qw( x y )],
1500 'params' => [], 1499 'params' => [],
1501 'limits' => [ [0,1], [0,1]], 1500 'limits' => [ [0,1], [0,1]],
1502 'reltol' => $main::functRelPercentTolDefault, 1501 'reltol' => $functRelPercentTolDefault,
1503 'numPoints' => $main::functNumOfPoints, 1502 'numPoints' => $functNumOfPoints,
1504 'zeroLevel' => $main::functZeroLevelDefault, 1503 'zeroLevel' => $functZeroLevelDefault,
1505 'zeroLevelTol' => $main::functZeroLevelTolDefault, 1504 'zeroLevelTol' => $functZeroLevelTolDefault,
1506 'debug' => 0, 1505 'debug' => 0,
1507 ); 1506 );
1508 1507
1509 my $var_ref = $options{'vars'}; 1508 my $var_ref = $options{'vars'};
1510 my $ra_params = $options{ 'params'}; 1509 my $ra_params = $options{ 'params'};
2468 my $ans_eval = sub { 2467 my $ans_eval = sub {
2469 2468
2470 # then mail out all of the answers, including this last one. 2469 # then mail out all of the answers, including this last one.
2471 2470
2472 send_mail_to( $user_address, 2471 send_mail_to( $user_address,
2473 'subject' => "$main::courseName WeBWorK questionnaire", 2472 'subject' => "$main::courseName WeBWorK questionnaire",
2474 'body' => $QUESTIONNAIRE_ANSWERS, 2473 'body' => $QUESTIONNAIRE_ANSWERS,
2475 'ALLOW_MAIL_TO' => $envir{ALLOW_MAIL_TO} 2474 'ALLOW_MAIL_TO' => $rh_envir->{ALLOW_MAIL_TO}
2476 ); 2475 );
2477 2476
2478 my $ans_hash = new AnswerHash( 'score' => 1, 2477 my $ans_hash = new AnswerHash( 'score' => 1,
2479 'correct_ans' => '', 2478 'correct_ans' => '',
2480 'student_ans' => 'Answer recorded', 2479 'student_ans' => 'Answer recorded',
2524 $subject = "$main::courseName WeBWorK questionnaire" unless defined $subject; 2523 $subject = "$main::courseName WeBWorK questionnaire" unless defined $subject;
2525 2524
2526 send_mail_to($user_address, 2525 send_mail_to($user_address,
2527 'subject' => $subject, 2526 'subject' => $subject,
2528 'body' => $QUESTIONNAIRE_ANSWERS, 2527 'body' => $QUESTIONNAIRE_ANSWERS,
2529 'ALLOW_MAIL_TO' => $envir{ALLOW_MAIL_TO} 2528 'ALLOW_MAIL_TO' => $rh_envir->{ALLOW_MAIL_TO}
2530 ); 2529 );
2531} 2530}
2532 2531
2533########################################################################## 2532##########################################################################
2534########################################################################## 2533##########################################################################
2923 2922
2924 if (defined($PG_eval_errors) and $PG_eval_errors =~/\S/ ) { 2923 if (defined($PG_eval_errors) and $PG_eval_errors =~/\S/ ) {
2925 $PG_eval_errors = clean_up_error_msg($PG_eval_errors); 2924 $PG_eval_errors = clean_up_error_msg($PG_eval_errors);
2926 2925
2927 my $PGanswerMessage = "There was an error in converting the expression 2926 my $PGanswerMessage = "There was an error in converting the expression
2928 $main::BR $originalEqn $main::BR into a function. 2927 $BR $originalEqn $BR into a function.
2929 $main::BR $PG_eval_errors."; 2928 $BR $PG_eval_errors.";
2930 $rh_ans->{rf_student_ans} = $function_sub; 2929 $rh_ans->{rf_student_ans} = $function_sub;
2931 $rh_ans->{ans_message} = $PGanswerMessage; 2930 $rh_ans->{ans_message} = $PGanswerMessage;
2932 $rh_ans->{error_message} = $PGanswerMessage; 2931 $rh_ans->{error_message} = $PGanswerMessage;
2933 $rh_ans->{error_flag} = 1; 2932 $rh_ans->{error_flag} = 1;
2934 # we couldn't compile the equation, we'll return an error message. 2933 # we couldn't compile the equation, we'll return an error message.

Legend:
Removed from v.1249  
changed lines
  Added in v.1250

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9