Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions cms/djangoapps/contentstore/api/views/course_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import statistics
import time

import numpy as np
from edxval.api import get_course_videos_qset
from openedx_authz.authz import COURSES_VIEW_COURSE
from rest_framework.generics import GenericAPIView
Expand Down Expand Up @@ -276,8 +275,10 @@ def _stats_dict(self, data): # pylint: disable=missing-function-docstring
return dict(
min=min(data),
max=max(data),
mean=np.around(np.mean(data)),
median=np.around(np.median(data)),
# round() rounds half to even, as np.around() did. float()
# keeps the serialized values the same as before (2.0, not 2).
mean=float(round(statistics.fmean(data))),
median=float(round(statistics.median(data))),
# On a tie, report the smallest of the most common values.
mode=min(statistics.multimode(data)),
)
8 changes: 5 additions & 3 deletions lms/djangoapps/grades/scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from logging import getLogger

from numpy import around
from xblock.core import XBlock

from openedx.core.lib.cache_utils import process_cached
Expand Down Expand Up @@ -151,8 +150,11 @@ def compute_percent(earned, possible):
Returns the percentage of the given earned and possible values.
"""
if possible > 0:
# Rounds to four decimal places.
return around(earned / possible, decimals=4)
# Rounds half to even, to four decimal places. This is deliberately not
# round(x, 4): scaling, rounding to an integer, and scaling back is how
# numpy.around() works, and it produces slightly different results from
# round(x, 4) for some values. Changing it could shift persisted grades.
return round(earned / possible * 10000) / 10000
else:
return 0.0

Expand Down
Loading