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

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

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

Revision 1064 Revision 1080
1#!/usr/bin/perl 1
2 2
3# Answer evaluator which always marks things correct 3# Answer evaluator which always marks things correct
4sub auto_right { 4sub auto_right {
5 my $ae = std_str_cmp(""); 5 my $ae = std_str_cmp("");
6 6
7 my $ans_eval = sub { 7 my $ans_eval = sub {
8 my $tried = shift; 8 my $tried = shift;
9 my $ans_hash = &$ae($tried); 9 my $ans_hash = &$ae($tried);
10 $ans_hash->{score} = 1; 10 $ans_hash->{score} = 1;
11 return $ans_hash; 11 return $ans_hash;
15 15
16# Evaluate in tth mode 16# Evaluate in tth mode
17 17
18sub tthev { 18sub tthev {
19 my $cmt = shift; 19 my $cmt = shift;
20 20
21 $mdm = $main::displayMode; 21 $mdm = $main::displayMode;
22 $main::displayMode = 'HTML_tth'; 22 $main::displayMode = 'HTML_tth';
23 $cmt = EV3($cmt); 23 $cmt = EV3($cmt);
24 $cmt =~ s/\\par/<P>/g; 24 $cmt =~ s/\\par/<P>/g;
25 $cmt =~ s/\\noindent//g; 25 $cmt =~ s/\\noindent//g;
112 if ($process_ans_hash) { 112 if ($process_ans_hash) {
113 $rh_ans = $num; 113 $rh_ans = $num;
114 $num = $rh_ans->{original_student_ans}; 114 $num = $rh_ans->{original_student_ans};
115 } 115 }
116 my $is_ok = 0; 116 my $is_ok = 0;
117 117
118 return $is_ok unless defined($num); 118 return $is_ok unless defined($num);
119 119
120 if (($yesno and ($num =~ /$str/)) or (!($yesno) and !($num=~ /$str/))) { 120 if (($yesno and ($num =~ /$str/)) or (!($yesno) and !($num=~ /$str/))) {
121 $is_ok = 1; 121 $is_ok = 1;
122 } 122 }
123 123
124 if ($process_ans_hash) { 124 if ($process_ans_hash) {
125 if ($is_ok == 1 ) { 125 if ($is_ok == 1 ) {
126 $rh_ans->{original_student_ans}=$num; 126 $rh_ans->{original_student_ans}=$num;
127 return $rh_ans; 127 return $rh_ans;
128 } else { 128 } else {
134 } else { 134 } else {
135 $rh_ans->throw_error('NUMBER', ""); 135 $rh_ans->throw_error('NUMBER', "");
136 } 136 }
137 return $rh_ans; 137 return $rh_ans;
138 } 138 }
139 139
140 } else { 140 } else {
141 return $is_ok; 141 return $is_ok;
142 } 142 }
143 }; 143 };
144 return $newfilt; 144 return $newfilt;
147sub raw_student_answer_filter { 147sub raw_student_answer_filter {
148 my ($rh_ans) = shift; 148 my ($rh_ans) = shift;
149# warn "answer was ".$rh_ans->{student_ans}; 149# warn "answer was ".$rh_ans->{student_ans};
150 $rh_ans->{student_ans} = $rh_ans->{original_student_ans} 150 $rh_ans->{student_ans} = $rh_ans->{original_student_ans}
151 unless ($rh_ans->{student_ans} =~ /[a-zA-Z]/); 151 unless ($rh_ans->{student_ans} =~ /[a-zA-Z]/);
152# warn "2nd time ... answer was ".$rh_ans->{student_ans}; 152# warn "2nd time ... answer was ".$rh_ans->{student_ans};
153 153
154 return $rh_ans; 154 return $rh_ans;
155} 155}
156 156
157sub no_decimal_list { 157sub no_decimal_list {
158 my ($ans) = shift; 158 my ($ans) = shift;
231} 231}
232 232
233# Wrapper for an answer evaluator which can also supply comments 233# Wrapper for an answer evaluator which can also supply comments
234sub with_comments { 234sub with_comments {
235 my ($old_evaluator, $cmt) = @_; 235 my ($old_evaluator, $cmt) = @_;
236 236
237# $mdm = $main::displayMode; 237# $mdm = $main::displayMode;
238# $main::displayMode = 'HTML_tth'; 238# $main::displayMode = 'HTML_tth';
239# $cmt = EV2($cmt); 239# $cmt = EV2($cmt);
240# $main::displayMode =$mdm; 240# $main::displayMode =$mdm;
241 241
242 my $ans_evaluator = sub { 242 my $ans_evaluator = sub {
243 my $tried = shift; 243 my $tried = shift;
244 my $ans_hash; 244 my $ans_hash;
245 245
246 if ( ref($old_evaluator) eq 'AnswerEvaluator' ) { # new style 246 if ( ref($old_evaluator) eq 'AnswerEvaluator' ) { # new style
248 } elsif (ref($old_evaluator) eq 'CODE' ) { #old style 248 } elsif (ref($old_evaluator) eq 'CODE' ) { #old style
249 $ans_hash = &$old_evaluator($tried); 249 $ans_hash = &$old_evaluator($tried);
250 } else { 250 } else {
251 warn "There is a problem using the answer evaluator"; 251 warn "There is a problem using the answer evaluator";
252 } 252 }
253 253
254 if($ans_hash->{score}>0) { 254 if($ans_hash->{score}>0) {
255 $ans_hash -> setKeys( 'ans_message' => $cmt); 255 $ans_hash -> setKeys( 'ans_message' => $cmt);
256 } 256 }
257 return $ans_hash; 257 return $ans_hash;
258 }; 258 };
265# it applies evaluators from the list until it hits one with positive credit, 265# it applies evaluators from the list until it hits one with positive credit,
266# weights it by the partial credit factor, and throws in its comment 266# weights it by the partial credit factor, and throws in its comment
267 267
268sub pc_evaluator { 268sub pc_evaluator {
269 my ($evaluator_list) = @_; 269 my ($evaluator_list) = @_;
270 270
271 my $ans_evaluator = sub { 271 my $ans_evaluator = sub {
272 my $tried = shift; 272 my $tried = shift;
273 my $ans_hash; 273 my $ans_hash;
274 for($j=0;$j<scalar(@{$evaluator_list}); $j++) { 274 for($j=0;$j<scalar(@{$evaluator_list}); $j++) {
275 my $old_evaluator = $evaluator_list->[$j][0]; 275 my $old_evaluator = $evaluator_list->[$j][0];
281 } elsif (ref($old_evaluator) eq 'CODE' ) { #old style 281 } elsif (ref($old_evaluator) eq 'CODE' ) { #old style
282 $ans_hash = &$old_evaluator($tried); 282 $ans_hash = &$old_evaluator($tried);
283 } else { 283 } else {
284 warn "There is a problem using the answer evaluator"; 284 warn "There is a problem using the answer evaluator";
285 } 285 }
286 286
287 if($ans_hash->{score}>0) { 287 if($ans_hash->{score}>0) {
288 $ans_hash -> setKeys( 'ans_message' => $cmt); 288 $ans_hash -> setKeys( 'ans_message' => $cmt);
289 $ans_hash->{score} *= $weight; 289 $ans_hash->{score} *= $weight;
290 return $ans_hash; 290 return $ans_hash;
291 }; 291 };
292 }; 292 };
293 return $ans_hash; 293 return $ans_hash;
294 }; 294 };
295 295
296 $ans_evaluator; 296 $ans_evaluator;
297} 297}
298 298
299sub nicestring { 299sub nicestring {
300 my($thingy) = shift; 300 my($thingy) = shift;
377 $out .= "\n\\begin{rawhtml} <TABLE BORDER=0>\n\\end{rawhtml}"; 377 $out .= "\n\\begin{rawhtml} <TABLE BORDER=0>\n\\end{rawhtml}";
378 } 378 }
379 elsif ($displayMode eq 'HTML' || $displayMode eq 'HTML_tth' || $displayMode eq 'HTML_dpng') { 379 elsif ($displayMode eq 'HTML' || $displayMode eq 'HTML_tth' || $displayMode eq 'HTML_dpng') {
380 $out .= "<TABLE BORDER=0>\n" 380 $out .= "<TABLE BORDER=0>\n"
381 } 381 }
382 else { 382 else {
383 $out = "Error: beginmatrix: Unknown displayMode: $displayMode.\n"; 383 $out = "Error: beginmatrix: Unknown displayMode: $displayMode.\n";
384 } 384 }
385 $out; 385 $out;
386} 386}
387 387
403# $main::imagesURL."/left$numrows.png\" >"; 403# $main::imagesURL."/left$numrows.png\" >";
404# return $out; 404# return $out;
405 $out .= '\(\left.\begin{array}{c}'; 405 $out .= '\(\left.\begin{array}{c}';
406 for($j=0;$j<$numrows;$j++) { $out .= ' \\\\'; } 406 for($j=0;$j<$numrows;$j++) { $out .= ' \\\\'; }
407 $out .= '\end{array}\right(\)'; 407 $out .= '\end{array}\right(\)';
408 408
409 if($displayMode eq 'Latex2HTML') { $out .= '\begin{rawhtml}'; } 409 if($displayMode eq 'Latex2HTML') { $out .= '\begin{rawhtml}'; }
410 $out .= "<td><table border=0 cellspacing=5>\n"; 410 $out .= "<td><table border=0 cellspacing=5>\n";
411 if($displayMode eq 'Latex2HTML') { $out .= '\end{rawhtml}'; } 411 if($displayMode eq 'Latex2HTML') { $out .= '\end{rawhtml}'; }
412 return $out; 412 return $out;
413 } 413 }
422 422
423sub matright { 423sub matright {
424 my $numrows = shift; 424 my $numrows = shift;
425 my $out=''; 425 my $out='';
426 my $j; 426 my $j;
427 427
428 if ($displayMode eq 'TeX') { 428 if ($displayMode eq 'TeX') {
429 return ""; 429 return "";
430 } 430 }
431 431
432 if(($displayMode eq 'HTML_dpng') || ($displayMode eq 'Latex2HTML')) { 432 if(($displayMode eq 'HTML_dpng') || ($displayMode eq 'Latex2HTML')) {
433 if($displayMode eq 'Latex2HTML') { $out .= '\begin{rawhtml}'; } 433 if($displayMode eq 'Latex2HTML') { $out .= '\begin{rawhtml}'; }
434 $out .= "</table><td nowrap=\"nowrap\" align=\"right\">"; 434 $out .= "</table><td nowrap=\"nowrap\" align=\"right\">";
435 if($displayMode eq 'Latex2HTML') { $out .= '\end{rawhtml}'; } 435 if($displayMode eq 'Latex2HTML') { $out .= '\end{rawhtml}'; }
436 436
437# $out .= "<img alt=\"(\" src = \"". 437# $out .= "<img alt=\"(\" src = \"".
438# "/webwork_system_html/images"."/right$numrows.png\" >"; 438# "/webwork_system_html/images"."/right$numrows.png\" >";
439 $out .= '\(\left)\begin{array}{c}'; 439 $out .= '\(\left)\begin{array}{c}';
440 for($j=0;$j<$numrows;$j++) { $out .= ' \\\\'; } 440 for($j=0;$j<$numrows;$j++) { $out .= ' \\\\'; }
441 $out .= '\end{array}\right.\)'; 441 $out .= '\end{array}\right.\)';

Legend:
Removed from v.1064  
changed lines
  Added in v.1080

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9