Skip to content

Commit 81dc61b

Browse files
committed
Make the problem graders also save the sub_status when needed.
Basically, anytime that reduced scoring is not enabled or if it is but it is before the reduced scoring period, then the sub_status needs to also be set to the same thing as the status. Otherwise the "unreduced" score will not be computed correctly. So the problem graders now take this into account. This fixes issue #2873.
1 parent 2bd468a commit 81dc61b

File tree

8 files changed

+43
-14
lines changed

8 files changed

+43
-14
lines changed

htdocs/js/ProblemGrader/singleproblemgrader.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
version_id: saveData.versionId,
126126
problem_id: saveData.problemId,
127127
status: parseInt(scoreInput.value) / 100,
128+
...(saveData.saveSubStatus === '1' ? { sub_status: parseInt(scoreInput.value) / 100 } : {}),
128129
mark_graded: true
129130
}),
130131
signal: controller.signal

lib/WeBWorK/ContentGenerator/Instructor/ProblemGrader.pm

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use HTML::Entities;
1313
use WeBWorK::Utils::JITAR qw(jitar_id_to_seq);
1414
use WeBWorK::Utils::Rendering qw(renderPG);
1515
use WeBWorK::Utils::Sets qw(get_test_problem_position format_set_name_display);
16+
use WeBWorK::Utils::DateTime qw(before);
1617

1718
async sub initialize ($c) {
1819
my $authz = $c->authz;
@@ -96,6 +97,17 @@ async sub initialize ($c) {
9697
if ($c->param('assignGrades')) {
9798
$c->addgoodmessage($c->maketext('Grades have been saved for all current users.'));
9899

100+
# Get all of the merged user sets for this set. These are needed to determine if the problem sub_status also
101+
# needs to be set. The sub_status must be set if reduced scoring is not enabled for the course or set or if it
102+
# is before the reduced scoring date.
103+
my %mergedSets;
104+
if ($c->stash->{set}->assignment_type =~ /gateway/) {
105+
$mergedSets{ $_->user_id }{ $_->version_id } = $_
106+
for $db->getMergedSetVersionsWhere({ set_id => { like => "$setID,v\%" } });
107+
} else {
108+
%mergedSets = map { $_->user_id => { 0 => $_ } } $db->getMergedSetsWhere({ set_id => $setID });
109+
}
110+
99111
for my $user (@{ $c->stash->{users} }) {
100112
my $userID = $user->user_id;
101113
for (@{ $user->{data} }) {
@@ -115,9 +127,16 @@ async sub initialize ($c) {
115127
$_->{problem}{flags} =~ s/:needs_grading$//;
116128
if ($c->param("$userID.$versionID.mark_correct")) {
117129
$_->{problem}->status(1);
130+
$_->{problem}->sub_status(1);
118131
} elsif (defined $c->param("$userID.$versionID.score")) {
119132
my $newscore = $c->param("$userID.$versionID.score") / 100;
120-
if ($newscore != $_->{problem}->status) { $_->{problem}->status($newscore); }
133+
if ($newscore != $_->{problem}->status) {
134+
$_->{problem}->status($newscore);
135+
$_->{problem}->sub_status($newscore)
136+
if !$ce->{pg}{ansEvalDefaults}{enableReducedScoring}
137+
|| !$mergedSets{$userID}{$versionID}->enable_reduced_scoring
138+
|| before($mergedSets{$userID}{$versionID}->reduced_scoring_date);
139+
}
121140
}
122141

123142
if ($versionID) { $db->putProblemVersion($_->{problem}); }

lib/WeBWorK/ContentGenerator/Problem.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,7 @@ sub output_message ($c) {
11341134
# Output the problem grader if the user has permissions to grade problems
11351135
sub output_grader ($c) {
11361136
if ($c->{will}{showProblemGrader}) {
1137-
return WeBWorK::HTML::SingleProblemGrader->new($c, $c->{pg}, $c->{problem})->insertGrader;
1137+
return WeBWorK::HTML::SingleProblemGrader->new($c, $c->{pg}, $c->{problem}, $c->{set})->insertGrader;
11381138
}
11391139

11401140
return '';

lib/WeBWorK/HTML/SingleProblemGrader.pm

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ as a student.
1111

1212
use WeBWorK::Localize;
1313
use WeBWorK::Utils 'wwRound';
14+
use WeBWorK::Utils::DateTime qw(before);
1415

15-
sub new ($class, $c, $pg, $userProblem) {
16+
sub new ($class, $c, $pg, $userProblem, $mergedSet) {
1617
$class = ref($class) || $class;
1718

1819
my $db = $c->db;
@@ -43,7 +44,12 @@ sub new ($class, $c, $pg, $userProblem) {
4344
recorded_score => $recordedScore,
4445
past_answer_id => $userPastAnswerID // 0,
4546
comment_string => $comment,
46-
c => $c
47+
c => $c,
48+
# The grader needs to also save the sub_status if reduced scoring is not enabled,
49+
# or if it is but it is before the reduced scoring date.
50+
save_sub_status => !$c->ce->{pg}{ansEvalDefaults}{enableReducedScoring}
51+
|| !$mergedSet->enable_reduced_scoring
52+
|| before($mergedSet->reduced_scoring_date)
4753
};
4854
bless $self, $class;
4955

lib/WebworkWebservice.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ sub command_permission {
248248

249249
# WebworkWebservice::ProblemActions
250250
getUserProblem => 'access_instructor_tools',
251-
# Note: The modify_student_data permission is checked in the following three methods and only the status and
252-
# comment_string can actually be modified by users with the problem_grader permission only.
251+
# Note: The modify_student_data permission is checked in the following three methods and only the status,
252+
# sub_status, and comment_string can actually be modified by users with the problem_grader permission only.
253253
putUserProblem => 'problem_grader',
254254
putProblemVersion => 'problem_grader',
255255
putPastAnswer => 'problem_grader',

lib/WebworkWebservice/ProblemActions.pm

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,17 @@ sub putUserProblem {
3838
'source_file', 'value', 'max_attempts', 'showMeAnother',
3939
'showMeAnotherCount', 'prPeriod', 'prCount', 'problem_seed',
4040
'attempted', 'last_answer', 'num_correct', 'num_incorrect',
41-
'att_to_open_children', 'counts_parent_grade', 'sub_status', 'flags'
41+
'att_to_open_children', 'counts_parent_grade', 'flags'
4242
)
4343
{
4444
$userProblem->{$_} = $params->{$_} if defined $params->{$_};
4545
}
4646
}
4747

48-
# The status is the only thing that users with the problem_grader permission can change.
48+
# The status and sub_status are the only things that users with the problem_grader permission can change.
4949
# This method cannot be called without the problem_grader permission.
50-
$userProblem->{status} = $params->{status} if defined $params->{status};
50+
$userProblem->{status} = $params->{status} if defined $params->{status};
51+
$userProblem->{sub_status} = $params->{sub_status} if defined $params->{sub_status};
5152

5253
# Remove the needs_grading flag if the mark_graded parameter is set.
5354
$userProblem->{flags} =~ s/:needs_grading$// if $params->{mark_graded};
@@ -77,16 +78,17 @@ sub putProblemVersion {
7778
'source_file', 'value', 'max_attempts', 'showMeAnother',
7879
'showMeAnotherCount', 'prPeriod', 'prCount', 'problem_seed',
7980
'attempted', 'last_answer', 'num_correct', 'num_incorrect',
80-
'att_to_open_children', 'counts_parent_grade', 'sub_status', 'flags'
81+
'att_to_open_children', 'counts_parent_grade', 'flags'
8182
)
8283
{
8384
$problemVersion->{$_} = $params->{$_} if defined($params->{$_});
8485
}
8586
}
8687

87-
# The status is the only thing that users with the problem_grader permission can change.
88+
# The status and sub_status are the only things that users with the problem_grader permission can change.
8889
# This method cannot be called without the problem_grader permission.
89-
$problemVersion->{status} = $params->{status} if defined $params->{status};
90+
$problemVersion->{status} = $params->{status} if defined $params->{status};
91+
$problemVersion->{sub_status} = $params->{sub_status} if defined $params->{sub_status};
9092

9193
# Remove the needs_grading flag if the mark_graded parameter is set.
9294
$problemVersion->{flags} =~ s/:needs_grading$// if $params->{mark_graded};

templates/ContentGenerator/GatewayQuiz.html.ep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@
643643
%
644644
% # Initialize the problem graders for the problem.
645645
% if ($c->{will}{showProblemGrader} && !$pg->{flags}{error_flag}) {
646-
<%= WeBWorK::HTML::SingleProblemGrader->new($c, $pg, $problems->[ $probOrder->[$i] ])
646+
<%= WeBWorK::HTML::SingleProblemGrader->new($c, $pg, $problems->[ $probOrder->[$i] ], $c->{set})
647647
->insertGrader =%>
648648
% }
649649
</div>

templates/HTML/SingleProblemGrader/grader.html.ep

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@
271271
data-set-id="<%= $grader->{set_id} %>"
272272
data-version-id="<%= $grader->{version_id} %>"
273273
data-problem-id="<%= $grader->{problem_id} %>"
274-
data-past-answer-id="<%= $grader->{past_answer_id} %>">
274+
data-past-answer-id="<%= $grader->{past_answer_id} %>"
275+
data-save-sub-status="<%= $grader->{save_sub_status} %>">
275276
<%= maketext('Save') =%>
276277
</button>
277278
</div>

0 commit comments

Comments
 (0)