…  
…  
151  (\%problem_result, \%problem_state); 
151  (\%problem_result, \%problem_state); 
152  
152  
153  
153  
154  } 
154  } 
155  
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 24 parts right, 40% 


179  # credit for getting 56 parts right, 60% credit for getting 79 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  } 
156  
281  
157  
282  
158  # return 1 so that this file can be included with require 
283  # return 1 so that this file can be included with require 
159  1 
284  1 