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