Skip to content

Commit ca3032b

Browse files
committed
reflect moderated grading status in assignment needs grading count
test plan: * enable moderated grading on a course assignment * make some student submissions * the "X needs grading" count on the course and user home dashboard sidebars should reflect the provisional grading status i.e. it should decrement for a grader when they've made a provisional mark or when other users have made marks and no more are needed closes #CNVS-23232 Change-Id: Iec5ecea8598a1f6e4e53b518f0fdae9273a6a4ee Reviewed-on: https://gerrit.instructure.com/63442 Reviewed-by: Jeremy Stanley <jeremy@instructure.com> Tested-by: Jenkins QA-Review: Jahnavi Yetukuri <jyetukuri@instructure.com> Product-Review: James Williams <jamesw@instructure.com>
1 parent 71a6441 commit ca3032b

3 files changed

Lines changed: 87 additions & 6 deletions

File tree

app/models/assignments/needs_grading_count_query.rb

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,50 @@ def count
4141
assignment.shard.activate do
4242
# the needs_grading_count trigger should change assignment.updated_at, invalidating the cache
4343
Rails.cache.fetch(['assignment_user_grading_count', assignment, user].cache_key) do
44-
case visibility_level
45-
when :full, :limited
46-
da_enabled? ? manual_count : assignment.needs_grading_count
47-
when :sections
48-
section_filtered_submissions.count(:id, distinct: true)
44+
if assignment.moderated_grading? && !assignment.grades_published?
45+
needs_moderated_grading_count
4946
else
50-
0
47+
case visibility_level
48+
when :full, :limited
49+
da_enabled? ? manual_count : assignment.needs_grading_count
50+
when :sections
51+
section_filtered_submissions.count(:id, distinct: true)
52+
else
53+
0
54+
end
5155
end
5256
end
5357
end
5458
end
5559

60+
def needs_moderated_grading_count
61+
level = visibility_level
62+
return 0 unless [:full, :limited, :sections].include?(level)
63+
64+
# ignore submissions this user has graded
65+
graded_sub_ids = assignment.submissions.joins(:provisional_grades).
66+
where("moderated_grading_provisional_grades.final = ?", false).
67+
where("moderated_grading_provisional_grades.scorer_id = ?", user.id).pluck(:id)
68+
69+
moderation_set_student_ids = assignment.moderated_grading_selections.pluck(:student_id)
70+
71+
# ignore submissions that are fully graded
72+
pg_scope = assignment.submissions.joins(:provisional_grades).
73+
where("moderated_grading_provisional_grades.final = ?", false).group("submissions.id", "submissions.user_id")
74+
pg_scope = pg_scope.where("submissions.id NOT IN (?)", graded_sub_ids) if graded_sub_ids.any?
75+
pg_scope.count.each do |key, count|
76+
sub_id, user_id = key
77+
graded_sub_ids << sub_id if count >= (moderation_set_student_ids.include?(user_id) ? 2 : 1)
78+
end
79+
80+
scope = (level == :sections) ? section_filtered_submissions : all_submissions
81+
if graded_sub_ids.any?
82+
scope.where("submissions.id NOT IN (?)", graded_sub_ids).count(:id, distinct: true)
83+
else
84+
scope.count(:id, distinct: true)
85+
end
86+
end
87+
5688
def count_by_section
5789
assignment.shard.activate do
5890
Rails.cache.fetch(['assignment_user_grading_count_by_section', assignment, user].cache_key) do

app/models/moderated_grading/provisional_grade.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@ class ModeratedGrading::ProvisionalGrade < ActiveRecord::Base
1515
validates :scorer, presence: true
1616
validates :submission, presence: true
1717

18+
after_create :touch_graders # to update grading counts
19+
1820
scope :scored_by, ->(scorer) { where(scorer_id: scorer) }
1921
scope :final, -> { where(:final => true)}
2022
scope :not_final, -> { where(:final => false)}
2123

24+
def touch_graders
25+
submission.touch_graders
26+
end
27+
2228
def valid?(*)
2329
infer_grade
2430
set_graded_at if @force_save || grade_changed? || score_changed?

spec/models/assignments/needs_grading_count_query_spec.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,49 @@ module Assignments
109109
expect(count[:needs_grading_count]).to eql(1)
110110
end
111111
end
112+
113+
context "moderated grading count" do
114+
before do
115+
@assignment = @course.assignments.create(:title => "some assignment",
116+
:submission_types => ['online_text_entry'], :moderated_grading => true)
117+
@students = []
118+
3.times do
119+
student = student_in_course(:course => @course, :active_all => true).user
120+
@assignment.submit_homework(student, :submission_type => "online_text_entry", :body => "o hai")
121+
@students << student
122+
end
123+
124+
@ta1 = ta_in_course(:course => course, :active_all => true).user
125+
@ta2 = ta_in_course(:course => course, :active_all => true).user
126+
end
127+
128+
it "should only include students with no marks when unmoderated" do
129+
querier = NeedsGradingCountQuery.new(@assignment, @teacher)
130+
expect(querier.count).to eq 3
131+
132+
@students[0].submissions.first.find_or_create_provisional_grade!(scorer: @teacher)
133+
expect(querier.count).to eq 2
134+
135+
@students[1].submissions.first.find_or_create_provisional_grade!(scorer: @ta1)
136+
expect(querier.count).to eq 1
137+
end
138+
139+
it "should only include students without two marks when moderated" do
140+
@students.each{|s| @assignment.moderated_grading_selections.create!(:student => s)}
141+
142+
querier = NeedsGradingCountQuery.new(@assignment, @teacher)
143+
expect(querier.count).to eq 3
144+
145+
@students[0].submissions.first.find_or_create_provisional_grade!(scorer: @teacher)
146+
expect(querier.count).to eq 2 # should not show because @teacher graded it
147+
148+
@students[1].submissions.first.find_or_create_provisional_grade!(scorer: @ta1)
149+
expect(querier.count).to eq 2 # should still count because it needs another mark
150+
151+
@students[1].submissions.first.find_or_create_provisional_grade!(scorer: @ta2)
152+
expect(querier.count).to eq 1 # should not count because it has two marks now
153+
end
154+
end
112155
end
113156
end
114157
end

0 commit comments

Comments
 (0)