[system] / trunk / webwork / system / courseScripts / PGgraders.pl Repository:
ViewVC logotype

Annotation of /trunk/webwork/system/courseScripts/PGgraders.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 146 - (view) (download) (as text)

1 : sh002i 146
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 :    
158 :     # return 1 so that this file can be included with require
159 :     1

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9