fix grade calculator with postgres 12

Switching to postgres 12 exposed some float addition that was resulting
in long precision. It looks like 9.5 was hiding that helpfully, but the
behavior isn't guaranteed and somewhere from 9.5 to 12 had changes in
that regard.

fixes EVAL-1104
flag=none

Test Plan
- Have postgres12.
- Have 2 assignments worth 1000 points each.
- Give a grade of 142.7 and a grade of 99.6.
- Verify in a console that there isn't floating point weirdness for the
user's scores.

Change-Id: Ic2c85a12909a3c99d7a58351ca9b4f0df4ff656e
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/245252
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Keith Garner <kgarner@instructure.com>
Reviewed-by: Syed Hussain <shussain@instructure.com>
Reviewed-by: Kai Bjorkman <kbjorkman@instructure.com>
QA-Review: Kai Bjorkman <kbjorkman@instructure.com>
Product-Review: Syed Hussain <shussain@instructure.com>
This commit is contained in:
Gary Mei 2020-08-17 10:53:20 -05:00
parent 9a27545ffe
commit a97aeb35ea
2 changed files with 2 additions and 20 deletions

View File

@ -817,8 +817,8 @@ class GradeCalculator
kept = drop_assignments(group_submissions, group.rules_hash)
dropped_submissions = (group_submissions - kept).map { |s| s[:submission]&.id }.compact
score, possible = kept.reduce([0, 0]) { |(s_sum,p_sum),s|
[s_sum + s[:score], p_sum + s[:total]]
score, possible = kept.reduce([0.0, 0.0]) { |(s_sum,p_sum),s|
[s_sum.to_d + s[:score].to_d, p_sum.to_d + s[:total].to_d]
}
{

View File

@ -1120,8 +1120,6 @@ describe GradeCalculator do
end
it 'unposted current assignment group points are updated' do
skip 'EVAL-1104 (08/13/2020)'
# 99.6 + 142.7 + 95.0 + 131.4
expect(assignment_group_scores.map(&:unposted_current_points)).to eq([242.30, 226.40])
end
@ -1132,8 +1130,6 @@ describe GradeCalculator do
end
it 'unposted final assignment group points are updated' do
skip 'EVAL-1104 (08/13/2020)'
# 99.6 + 142.7 + 95.0 + 131.4
expect(assignment_group_scores.map(&:unposted_final_points)).to eq([242.30, 226.40])
end
@ -1165,27 +1161,21 @@ describe GradeCalculator do
end
it 'unposted current assignment group scores are updated' do
skip 'EVAL-1104 (08/13/2020)'
# [142.7 / 150, 131.4 / 150]
expect(assignment_group_scores.map(&:unposted_current_score)).to eq([80.77, 75.47])
end
it 'unposted current assignment group points are updated' do
skip 'EVAL-1104 (08/13/2020)'
# 99.6 + 142.7 + 95.0 + 131.4
expect(assignment_group_scores.map(&:unposted_current_points)).to eq([242.30, 226.40])
end
it 'unposted final assignment group scores are updated' do
skip 'EVAL-1104 (08/13/2020)'
# (99.6 + 142.7 + 95.0 + 131.4) / 600
expect(assignment_group_scores.map(&:unposted_final_score)).to eq([80.77, 75.47])
end
it 'unposted final assignment group points are updated' do
skip 'EVAL-1104 (08/13/2020)'
# 99.6 + 142.7 + 95.0 + 131.4
expect(assignment_group_scores.map(&:unposted_final_points)).to eq([242.30, 226.40])
end
@ -1605,8 +1595,6 @@ describe GradeCalculator do
end
it 'unposted current assignment group points are updated' do
skip 'EVAL-1104 (08/13/2020)'
# 99.6 + 142.7 + 95.0 + 131.4
expect(assignment_group_scores.map(&:unposted_current_points)).to eq([242.30, 226.40])
end
@ -1617,8 +1605,6 @@ describe GradeCalculator do
end
it 'unposted final assignment group points are updated' do
skip 'EVAL-1104 (08/13/2020)'
# 99.6 + 142.7 + 95.0 + 131.4
expect(assignment_group_scores.map(&:unposted_final_points)).to eq([242.30, 226.40])
end
@ -1655,8 +1641,6 @@ describe GradeCalculator do
end
it 'unposted current assignment group points are updated' do
skip 'EVAL-1104 (08/13/2020)'
# 99.6 + 142.7 + 95.0 + 131.4
expect(assignment_group_scores.map(&:unposted_current_points)).to eq([242.30, 226.40])
end
@ -1667,8 +1651,6 @@ describe GradeCalculator do
end
it 'unposted final assignment group points are updated' do
skip 'EVAL-1104 (08/13/2020)'
# 99.6 + 142.7 + 95.0 + 131.4
expect(assignment_group_scores.map(&:unposted_final_points)).to eq([242.30, 226.40])
end