handle submissions with no score correctly in grade calc

An assignment can have a submission but no score, if that
happened the calculator dropped those submissions for
the final_grade instead of using a score of 0

closes #4491

Change-Id: Ic49816c887aec001ecdd9d99412dc588e2c891e6
Reviewed-on: https://gerrit.instructure.com/3552
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Brian Whitmer <brian@instructure.com>
This commit is contained in:
Bracken Mosbacker 2011-05-09 11:32:57 -06:00
parent 6b278bd203
commit af08b162c3
2 changed files with 41 additions and 2 deletions

View File

@ -87,9 +87,13 @@ class GradeCalculator
end
# Sort the submissions that have a grade by score (to easily drop lowest/highest grades)
sorted_assignment_submissions = assignment_submissions.select { |hash| hash[:submission] && hash[:submission].score }
if ignore_ungraded
sorted_assignment_submissions = assignment_submissions.select { |hash| hash[:submission] && hash[:submission].score }
else
sorted_assignment_submissions = assignment_submissions.select { |hash| hash[:submission] }
end
sorted_assignment_submissions = sorted_assignment_submissions.sort_by do |hash|
val = ((hash[:submission].score / hash[:assignment].points_possible) rescue 999999)
val = (((hash[:submission].score || 0)/ hash[:assignment].points_possible) rescue 999999)
val.to_f.finite? ? val : 999999
end

View File

@ -197,6 +197,41 @@ describe GradeCalculator do
@user.enrollments.first.computed_final_score.should eql(90.0)
end
it "should properly handle submissions with no score" do
course_with_student
@group = @course.assignment_groups.create!(:name => "group2", :group_weight => 50)
@assignment_1 = @group.assignments.build(:title => "some assignments", :points_possible => 10)
@assignment_1.context = @course
@assignment_1.save!
@assignment_2 = @group.assignments.build(:title => "some assignments", :points_possible => 4)
@assignment_2.context = @course
@assignment_2.save!
@group2 = @course.assignment_groups.create!(:name => "assignments", :group_weight => 40)
@assignment2_1 = @group2.assignments.build(:title => "some assignments", :points_possible => 40)
@assignment2_1.context = @course
@assignment2_1.save!
@assignment_1.grade_student(@user, :grade => nil)
@assignment_2.grade_student(@user, :grade => "1")
@assignment2_1.grade_student(@user, :grade => "40")
@course.group_weighting_scheme = "percent"
@course.save!
@user.reload
@user.enrollments.first.computed_current_score.should eql(52.5)
@user.enrollments.first.computed_final_score.should eql(43.6)
@course.group_weighting_scheme = nil
@course.save!
@user.reload
@user.enrollments.first.computed_current_score.should eql(93.2)
@user.enrollments.first.computed_final_score.should eql(75.9)
end
end
end