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

View of /trunk/pg/macros/PGgraders.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4997 - (download) (as text) (annotate)
Mon Jun 11 18:16:40 2007 UTC (12 years, 8 months ago) by gage
File size: 10848 byte(s)
Fixing docementation so that it can be read from the web.

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9