fix: increase grades rounding precision
Enabling the rounding in #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.
This commit is contained in:
committed by
Piotr Surowiec
parent
649bd42f9c
commit
84d2ad9515
@@ -302,7 +302,7 @@ class SectionGradesBreakdownTest(GradeViewTestMixin, APITestCase):
|
||||
+ [
|
||||
{
|
||||
'category': 'Homework',
|
||||
'detail': 'Homework Average = 0%',
|
||||
'detail': 'Homework Average = 0.00%',
|
||||
'label': 'HW Avg', 'percent': 0.0,
|
||||
'prominent': True
|
||||
}
|
||||
@@ -332,21 +332,21 @@ class SectionGradesBreakdownTest(GradeViewTestMixin, APITestCase):
|
||||
},
|
||||
{
|
||||
'category': 'Lab',
|
||||
'detail': 'Lab Average = 0%',
|
||||
'detail': 'Lab Average = 0.00%',
|
||||
'label': 'Lab Avg',
|
||||
'percent': 0.0,
|
||||
'prominent': True
|
||||
},
|
||||
{
|
||||
'category': 'Midterm Exam',
|
||||
'detail': 'Midterm Exam = 0%',
|
||||
'detail': 'Midterm Exam = 0.00%',
|
||||
'label': 'Midterm',
|
||||
'percent': 0.0,
|
||||
'prominent': True
|
||||
},
|
||||
{
|
||||
'category': 'Final Exam',
|
||||
'detail': 'Final Exam = 0%',
|
||||
'detail': 'Final Exam = 0.00%',
|
||||
'label': 'Final',
|
||||
'percent': 0.0,
|
||||
'prominent': True
|
||||
|
||||
@@ -162,8 +162,8 @@ def compute_percent(earned, possible):
|
||||
Returns the percentage of the given earned and possible values.
|
||||
"""
|
||||
if possible > 0:
|
||||
# Rounds to two decimal places.
|
||||
return around(earned / possible, decimals=2)
|
||||
# Rounds to four decimal places.
|
||||
return around(earned / possible, decimals=4)
|
||||
else:
|
||||
return 0.0
|
||||
|
||||
|
||||
@@ -185,26 +185,26 @@ class TestCourseGradeFactory(GradeTestBase):
|
||||
'section_breakdown': [
|
||||
{
|
||||
'category': 'Homework',
|
||||
'detail': 'Homework 1 - Test Sequential X with an & Ampersand - 50% (1/2)',
|
||||
'detail': 'Homework 1 - Test Sequential X with an & Ampersand - 50.00% (1/2)',
|
||||
'label': 'HW 01',
|
||||
'percent': 0.5
|
||||
},
|
||||
{
|
||||
'category': 'Homework',
|
||||
'detail': 'Homework 2 - Test Sequential A - 0% (0/1)',
|
||||
'detail': 'Homework 2 - Test Sequential A - 0.00% (0/1)',
|
||||
'label': 'HW 02',
|
||||
'percent': 0.0
|
||||
},
|
||||
{
|
||||
'category': 'Homework',
|
||||
'detail': 'Homework Average = 25%',
|
||||
'detail': 'Homework Average = 25.00%',
|
||||
'label': 'HW Avg',
|
||||
'percent': 0.25,
|
||||
'prominent': True
|
||||
},
|
||||
{
|
||||
'category': 'NoCredit',
|
||||
'detail': 'NoCredit Average = 0%',
|
||||
'detail': 'NoCredit Average = 0.00%',
|
||||
'label': 'NC Avg',
|
||||
'percent': 0,
|
||||
'prominent': True
|
||||
|
||||
@@ -14,7 +14,7 @@ from .utils import mock_get_score
|
||||
@ddt
|
||||
class SubsectionGradeTest(GradeTestBase): # lint-amnesty, pylint: disable=missing-class-docstring
|
||||
|
||||
@data((50, 100, .50), (59.49, 100, .59), (59.51, 100, .60), (59.50, 100, .60), (60.5, 100, .60))
|
||||
@data((50, 100, .5), (.5949, 100, .0059), (.5951, 100, .006), (.595, 100, .0059), (.605, 100, .006))
|
||||
@unpack
|
||||
def test_create_and_read(self, mock_earned, mock_possible, expected_result):
|
||||
with mock_get_score(mock_earned, mock_possible):
|
||||
|
||||
@@ -387,7 +387,7 @@ class AssignmentFormatGrader(CourseGrader):
|
||||
section_name = scores[i].display_name
|
||||
|
||||
percentage = scores[i].percent_graded
|
||||
summary_format = "{section_type} {index} - {name} - {percent:.0%} ({earned:.3n}/{possible:.3n})"
|
||||
summary_format = "{section_type} {index} - {name} - {percent:.2%} ({earned:.3n}/{possible:.3n})"
|
||||
summary = summary_format.format(
|
||||
index=i + self.starting_index,
|
||||
section_type=self.section_type,
|
||||
@@ -421,7 +421,7 @@ class AssignmentFormatGrader(CourseGrader):
|
||||
if len(breakdown) == 1:
|
||||
# if there is only one entry in a section, suppress the existing individual entry and the average,
|
||||
# and just display a single entry for the section.
|
||||
total_detail = "{section_type} = {percent:.0%}".format(
|
||||
total_detail = "{section_type} = {percent:.2%}".format(
|
||||
percent=total_percent,
|
||||
section_type=self.section_type,
|
||||
)
|
||||
@@ -430,7 +430,7 @@ class AssignmentFormatGrader(CourseGrader):
|
||||
'detail': total_detail, 'category': self.category, 'prominent': True}, ]
|
||||
else:
|
||||
# Translators: "Homework Average = 0%"
|
||||
total_detail = _("{section_type} Average = {percent:.0%}").format(
|
||||
total_detail = _("{section_type} Average = {percent:.2%}").format(
|
||||
percent=total_percent,
|
||||
section_type=self.section_type
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user