Parent Directory
|
Revision Log
moved PG modules and macro files from webwork-modperl to pg -sam
1 2 3 sub full_partial_grader { 4 # Get the standard inputs to a grader: 5 my $rh_evaluated_answers = shift; 6 my $rh_orig_problem_state = shift; 7 my %original_problem_state = %$rh_orig_problem_state; 8 my %form_options = @_; 9 # The hash $rh_evaluated_answers typically contains: 10 # 'AnSwEr1' => 34, 'AnSwEr2'=> 'Mozart', etc. 11 12 13 # Evaluate these inputs using the "average problem grader" 14 my ($rh_problem_result, $rh_problem_state) = 15 &avg_problem_grader($rh_evaluated_answers,$rh_orig_problem_state,%form_options); 16 17 18 19 20 # #If the final answer is correct, then the problem is given full credit 21 # # and a message is generated to that effect. 22 23 24 my $count = keys %{$rh_evaluated_answers}; 25 my $last_label = 'AnSwEr'.$count; 26 27 28 if (defined($rh_evaluated_answers->{$last_label}) and ${ $rh_evaluated_answers->{$last_label} }{score} == 1) { 29 $rh_problem_result->{score} = 1; 30 ${ $rh_evaluated_answers->{$last_label} }{ans_message} = 31 'You get full credit for this problem because this answer is correct.'; 32 33 34 $rh_problem_state->{recorded_score} = $rh_problem_result->{score} if 35 $rh_problem_result->{score} > $rh_problem_state->{recorded_score}; 36 } 37 38 39 # change the problem message 40 $rh_problem_result->{msg} = 'You can earn full credit by answering just the last part.' if $count > 1; 41 $rh_problem_result->{type} = 'full_partial_grader'; # change grader type 42 43 44 # return the correct data 45 if ($rh_problem_result->{score} == 1) { 46 $rh_problem_state->{num_of_correct_ans} = $original_problem_state{num_of_correct_ans} + 1; 47 $rh_problem_state->{num_of_incorrect_ans} = $original_problem_state{num_of_incorrect_ans}; 48 } 49 else { 50 $rh_problem_state->{num_of_correct_ans} = $original_problem_state{num_of_correct_ans}; 51 $rh_problem_state->{num_of_incorrect_ans} = $original_problem_state{num_of_incorrect_ans}+1; 52 } 53 54 55 56 # Return the results of grading the problem. 57 ($rh_problem_result, $rh_problem_state); 58 } 59 60 61 ################################################################ 62 # We need a special problem grader on this problem, since we 63 # want the student to get full credit for all five answers correct, 64 # 60% credit for four correct, and 0% for three or fewer correct. 65 # To change this scheme, look through the following mess of code 66 # for the place where the variable $numright appears, and change 67 # that part. 68 # Also change the long line beginning "msg ==>", to show what will 69 # appear on the screen for the student. 70 # 71 # To look at the problem itself, look for the boxed comment below 72 # announcing the problem itself. 73 ################################################################ 74 75 76 sub custom_problem_grader_0_60_100 { 77 my $rh_evaluated_answers = shift; 78 my $rh_problem_state = shift; 79 my %form_options = @_; 80 my %evaluated_answers = %{$rh_evaluated_answers}; 81 # The hash $rh_evaluated_answers typically contains: 82 # 'answer1' => 34, 'answer2'=> 'Mozart', etc. 83 84 # By default the old problem state is simply passed back out again. 85 my %problem_state = %$rh_problem_state; 86 87 88 # %form_options might include 89 # The user login name 90 # The permission level of the user 91 # The studentLogin name for this psvn. 92 # Whether the form is asking for a refresh or 93 # is submitting a new answer. 94 95 # initial setup of the answer 96 my $total=0; 97 my %problem_result = ( score => 0, 98 errors => '', 99 type => 'custom_problem_grader', 100 msg => 'To get full credit, all answers must be correct. Having 101 all but one correct is worth 60%. Two or more incorrect answers gives a score 102 of 0%.', 103 ); 104 105 106 # Return unless answers have been submitted 107 unless ($form_options{answers_submitted} == 1) { 108 109 # Since this code is in a .pg file we must use double tildes 110 # instead of Perl's backslash on the next line. 111 return(\%problem_result,\%problem_state); 112 } 113 # Answers have been submitted -- process them. 114 115 ######################################################## 116 # Here's where we compute the score. The variable # 117 # $numright is the number of correct answers. # 118 ######################################################## 119 120 121 my $numright=0; 122 123 124 $numright += ($evaluated_answers{'AnSwEr1'}->{score}); 125 $numright += ($evaluated_answers{'AnSwEr2'}->{score}); 126 $numright += ($evaluated_answers{'AnSwEr3'}->{score}); 127 $numright += ($evaluated_answers{'AnSwEr4'}->{score}); 128 $numright += ($evaluated_answers{'AnSwEr5'}->{score}); 129 130 131 if ($numright == 5) { 132 $total = 1; 133 } elsif ($numright == 4) { 134 $total = 0.6; 135 } else { 136 $total = 0; 137 } 138 139 140 $problem_result{score} = $total; 141 # increase recorded score if the current score is greater. 142 $problem_state{recorded_score} = $problem_result{score} if $problem_result{score} > $problem_state{recorded_score}; 143 144 145 146 $problem_state{num_of_correct_ans}++ if $total == 1; 147 $problem_state{num_of_incorrect_ans}++ if $total < 1 ; 148 149 # Since this code is in a .pg file we must use double tildes 150 # instead of Perl's backslash on the next line. 151 (\%problem_result, \%problem_state); 152 153 154 } 155 156 ################################################################ 157 # This problem grader was contributed by Prof. Zig Fiedorowicz, 158 # Dept. of Mathematics, Ohio State University on 8/25/01. 159 # As written, the problem grader should be put in a separate macro file. 160 # If actually inserted into a problem, you need to replace a couple 161 # of backslashes by double tildes. 162 163 # This is a generalization of the previous custom grader. 164 # This grader expects two array references to be passed to it, eg. 165 # $ENV['grader_numright'] = [2,5,7,10]; 166 # $ENV['grader_scores'] = [0.1,0.4,0.6,1] 167 # Both arrays should be of the same length, and in strictly 168 # increasing order. The first array is an array of possible 169 # raw scores, the number of parts of the problem the student might 170 # get right. The second array is the corresponding array of scores 171 # the student would be credited with for getting that many parts 172 # right. The scores should be real numbers between 0 and 1. 173 # The last element of the 'grader_scores' array should be 1 (perfect 174 # score). The corresponding last element of 'grader_numright' would 175 # be the total number of parts of the problem the student would have 176 # to get right for a perfect score. Normally this would be the total 177 # number of parts to the problem. In the example shown above, the 178 # student would get 10% credit for getting 2-4 parts right, 40% 179 # credit for getting 5-6 parts right, 60% credit for getting 7-9 parts 180 # right, and 100% credit for getting 10 (or more) parts right. 181 # A message to be displayed to the student about the grading policy 182 # for the problems should be passed via 183 # $ENV{'grader_message'} = "The grading policy for this problem is..."; 184 # or something similar. 185 ################################################################ 186 187 188 sub custom_problem_grader_fluid { 189 my $rh_evaluated_answers = shift; 190 my $rh_problem_state = shift; 191 my %form_options = @_; 192 my %evaluated_answers = %{$rh_evaluated_answers}; 193 # The hash $rh_evaluated_answers typically contains: 194 # 'answer1' => 34, 'answer2'=> 'Mozart', etc. 195 196 # By default the old problem state is simply passed back out again. 197 my %problem_state = %$rh_problem_state; 198 199 200 # %form_options might include 201 # The user login name 202 # The permission level of the user 203 # The studentLogin name for this psvn. 204 # Whether the form is asking for a refresh or 205 # is submitting a new answer. 206 207 # initial setup of the answer 208 my $total=0; 209 my %problem_result = ( score => 0, 210 errors => '', 211 type => 'custom_problem_grader', 212 msg => $ENV{'grader_message'} 213 ); 214 215 216 # Return unless answers have been submitted 217 unless ($form_options{answers_submitted} == 1) { 218 219 # Since this code is in a .pg file we must use double tildes 220 # instead of Perl's backslash on the next line. 221 return(\%problem_result,\%problem_state); 222 } 223 # Answers have been submitted -- process them. 224 225 ######################################################## 226 # Here's where we compute the score. The variable # 227 # $numright is the number of correct answers. # 228 ######################################################## 229 230 231 my $numright=0; 232 my $i; 233 my $ans_ref; 234 my @grader_numright = @{$ENV{'grader_numright'}}; 235 my @grader_scores = @{$ENV{'grader_scores'}}; 236 237 238 if ($#grader_numright != $#grader_scores) { 239 WARN("Scoring guidelines inconsistent: unequal arrays!"); 240 } 241 for ($i=0;$i<$#grader_numright;$i++) { 242 if($grader_numright[$i]>=$grader_numright[$i+1]) { 243 WARN("Scoring guidelines inconsistent: raw scores not increasing!"); 244 } 245 if($grader_scores[$i]>=$grader_scores[$i+1]) { 246 WARN("Scoring guidelines inconsistent: scores not increasing!"); 247 } 248 } 249 if ($grader_scores[$#grader_scores] != 1) { 250 WARN("Scoring guidelines inconsistent: best score < 1"); 251 } 252 $i = 1; 253 while (defined($ans_ref = $evaluated_answers{'AnSwEr'."$i"})) { 254 $numright += $ans_ref->{score}; 255 $i++; 256 } 257 258 for($i=0;$i<=$#grader_numright;$i++) { 259 if ($numright>=$grader_numright[$i]) { 260 $total = $grader_scores[$i]; 261 } 262 } 263 264 265 266 $problem_result{score} = $total; 267 # increase recorded score if the current score is greater. 268 $problem_state{recorded_score} = $problem_result{score} if $problem_result{score} > $problem_state{recorded_score}; 269 270 271 272 $problem_state{num_of_correct_ans}++ if $total == 1; 273 $problem_state{num_of_incorrect_ans}++ if $total < 1 ; 274 275 # Since this code is in a .pg file we must use double tildes 276 # instead of Perl's backslash on the next line. 277 (\%problem_result, \%problem_state); 278 279 280 } 281 282 283 # return 1 so that this file can be included with require 284 1
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |