Skip to content

Commit 60fd03d

Browse files
committed
fix: increase grades rounding precision
Enabling the rounding in openedx#16837 has been causing noticeable (up to 1 percentage point) differences between non-rounded subsection grades and a total grade for a course. This increases the grade precision to reduce the negative implications of double rounding. (cherry picked from commit 84d2ad9)
1 parent 446a483 commit 60fd03d

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

Diff for: lms/djangoapps/grades/rest_api/v1/tests/test_views.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def setUpClass(cls):
302302
+ [
303303
{
304304
'category': 'Homework',
305-
'detail': 'Homework Average = 0%',
305+
'detail': 'Homework Average = 0.00%',
306306
'label': 'HW Avg', 'percent': 0.0,
307307
'prominent': True
308308
}
@@ -332,21 +332,21 @@ def setUpClass(cls):
332332
},
333333
{
334334
'category': 'Lab',
335-
'detail': 'Lab Average = 0%',
335+
'detail': 'Lab Average = 0.00%',
336336
'label': 'Lab Avg',
337337
'percent': 0.0,
338338
'prominent': True
339339
},
340340
{
341341
'category': 'Midterm Exam',
342-
'detail': 'Midterm Exam = 0%',
342+
'detail': 'Midterm Exam = 0.00%',
343343
'label': 'Midterm',
344344
'percent': 0.0,
345345
'prominent': True
346346
},
347347
{
348348
'category': 'Final Exam',
349-
'detail': 'Final Exam = 0%',
349+
'detail': 'Final Exam = 0.00%',
350350
'label': 'Final',
351351
'percent': 0.0,
352352
'prominent': True

Diff for: lms/djangoapps/grades/scores.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ def compute_percent(earned, possible):
162162
Returns the percentage of the given earned and possible values.
163163
"""
164164
if possible > 0:
165-
# Rounds to two decimal places.
166-
return around(earned / possible, decimals=2)
165+
# Rounds to four decimal places.
166+
return around(earned / possible, decimals=4)
167167
else:
168168
return 0.0
169169

Diff for: lms/djangoapps/grades/tests/test_course_grade_factory.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -185,26 +185,26 @@ def test_course_grade_summary(self):
185185
'section_breakdown': [
186186
{
187187
'category': 'Homework',
188-
'detail': 'Homework 1 - Test Sequential X with an & Ampersand - 50% (1/2)',
188+
'detail': 'Homework 1 - Test Sequential X with an & Ampersand - 50.00% (1/2)',
189189
'label': 'HW 01',
190190
'percent': 0.5
191191
},
192192
{
193193
'category': 'Homework',
194-
'detail': 'Homework 2 - Test Sequential A - 0% (0/1)',
194+
'detail': 'Homework 2 - Test Sequential A - 0.00% (0/1)',
195195
'label': 'HW 02',
196196
'percent': 0.0
197197
},
198198
{
199199
'category': 'Homework',
200-
'detail': 'Homework Average = 25%',
200+
'detail': 'Homework Average = 25.00%',
201201
'label': 'HW Avg',
202202
'percent': 0.25,
203203
'prominent': True
204204
},
205205
{
206206
'category': 'NoCredit',
207-
'detail': 'NoCredit Average = 0%',
207+
'detail': 'NoCredit Average = 0.00%',
208208
'label': 'NC Avg',
209209
'percent': 0,
210210
'prominent': True

Diff for: lms/djangoapps/grades/tests/test_subsection_grade.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@ddt
1515
class SubsectionGradeTest(GradeTestBase): # lint-amnesty, pylint: disable=missing-class-docstring
1616

17-
@data((50, 100, .50), (59.49, 100, .59), (59.51, 100, .60), (59.50, 100, .60), (60.5, 100, .60))
17+
@data((50, 100, .5), (.5949, 100, .0059), (.5951, 100, .006), (.595, 100, .0059), (.605, 100, .006))
1818
@unpack
1919
def test_create_and_read(self, mock_earned, mock_possible, expected_result):
2020
with mock_get_score(mock_earned, mock_possible):

Diff for: xmodule/graders.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ def grade(self, grade_sheet, generate_random_scores=False):
387387
section_name = scores[i].display_name
388388

389389
percentage = scores[i].percent_graded
390-
summary_format = "{section_type} {index} - {name} - {percent:.0%} ({earned:.3n}/{possible:.3n})"
390+
summary_format = "{section_type} {index} - {name} - {percent:.2%} ({earned:.3n}/{possible:.3n})"
391391
summary = summary_format.format(
392392
index=i + self.starting_index,
393393
section_type=self.section_type,
@@ -421,7 +421,7 @@ def grade(self, grade_sheet, generate_random_scores=False):
421421
if len(breakdown) == 1:
422422
# if there is only one entry in a section, suppress the existing individual entry and the average,
423423
# and just display a single entry for the section.
424-
total_detail = "{section_type} = {percent:.0%}".format(
424+
total_detail = "{section_type} = {percent:.2%}".format(
425425
percent=total_percent,
426426
section_type=self.section_type,
427427
)
@@ -430,7 +430,7 @@ def grade(self, grade_sheet, generate_random_scores=False):
430430
'detail': total_detail, 'category': self.category, 'prominent': True}, ]
431431
else:
432432
# Translators: "Homework Average = 0%"
433-
total_detail = _("{section_type} Average = {percent:.0%}").format(
433+
total_detail = _("{section_type} Average = {percent:.2%}").format(
434434
percent=total_percent,
435435
section_type=self.section_type
436436
)

0 commit comments

Comments
 (0)