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

View of /branches/gage_dev/pg/macros/PGgraders.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6433 - (download) (as text) (annotate)
Thu Sep 16 03:36:41 2010 UTC (2 years, 8 months ago) by gage
File size: 12429 byte(s)
make changes to PGgraphmacros.pl and PGalias.pm to protect periods, commas and at 
signs when creating links to pictures

add Arnie's changes to PGgraders.pl in trunk to gage_dev



    1 
    2 =head1 PGgraders.pl DESCRIPTION
    3 
    4 Grader Plug-ins
    5 
    6 =cut
    7 
    8 =head3 full_partial_grader
    9 
   10 =pod
   11 
   12  ###########################################################
   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 
   18 =cut
   19 
   20 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 =head3 custom_problem_grader_0_60_100(@rh_evaluated_answers,$rh_problem_state,%form_options)
   71 
   72 =pod
   73 
   74  ################################################################
   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 
   90 =cut
   91 
   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{'AnSwEr0001'}->{score});
  141     $numright += ($evaluated_answers{'AnSwEr0002'}->{score});
  142     $numright += ($evaluated_answers{'AnSwEr0003'}->{score});
  143     $numright += ($evaluated_answers{'AnSwEr0004'}->{score});
  144     $numright += ($evaluated_answers{'AnSwEr0005'}->{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 =head3 NOTE:
  173 
  174 =pod
  175 
  176  ################################################################
  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 
  208 =cut
  209 
  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   # Answers have been submitted -- process them.
  281   foreach my $ans_name (keys %evaluated_answers) {
  282       $numright += $evaluated_answers{$ans_name}->{score};
  283     }
  284 
  285 
  286     for($i=0;$i<=$#grader_numright;$i++) {
  287       if ($numright>=$grader_numright[$i]) {
  288          $total = $grader_scores[$i];
  289       }
  290     }
  291 
  292     $problem_state{num_of_correct_ans}++ if $total == 1;
  293     $problem_state{num_of_incorrect_ans}++ if $total < 1 ;
  294 
  295     $problem_result{score} = $total;
  296 
  297 # Determine if we are in the reduced scoring period and if the reduced scoring period is enabled and act accordingly
  298 #warn("enable_reduced_scoring is $enable_reduced_scoring");
  299 #warn("dueDate is $dueDate");
  300 
  301   my $reducedScoringPeriodSec = $reducedScoringPeriod*60;   # $reducedScoringPeriod is in minutes
  302   if (!$enable_reduced_scoring or time() < ($dueDate - $reducedScoringPeriodSec)) { # the reduced scoring period is disabled or it is before the reduced scoring period
  303     # increase recorded score if the current score is greater.
  304     $problem_state{recorded_score} = $problem_result{score} if $problem_result{score} > $problem_state{recorded_score};
  305     # the sub_recored_score holds the recored_score before entering the reduced scoring period
  306     $problem_state{sub_recorded_score} = $problem_state{recorded_score};
  307   }
  308 elsif (time() < $dueDate) { # we are in the reduced scoring period.
  309     # student gets credit for all work done before the reduced scoring period plus a portion of work done during period
  310     my $newScore = 0;
  311     $newScore =   $problem_state{sub_recorded_score} + $reducedScoringValue*($problem_result{score} - $problem_state{sub_recorded_score})  if ($problem_result{score} > $problem_state{sub_recorded_score});
  312     $problem_state{recorded_score} = $newScore if $newScore > $problem_state{recorded_score};
  313     my $reducedScoringPerCent = int(100*$reducedScoringValue+.5);
  314     $problem_result{msg} = $problem_result{msg}."<br />You are in the Reduced Credit Period: All additional work done counts $reducedScoringPerCent\% of the original.";
  315   }
  316 
  317     (\%problem_result, \%problem_state);
  318 }
  319 
  320 
  321 # return 1 so that this file can be included with require
  322 1

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9