diff --git a/cms/djangoapps/contentstore/api/views/course_quality.py b/cms/djangoapps/contentstore/api/views/course_quality.py index 99c7a65ac45e..b843f81bc9d1 100644 --- a/cms/djangoapps/contentstore/api/views/course_quality.py +++ b/cms/djangoapps/contentstore/api/views/course_quality.py @@ -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 @@ -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)), ) diff --git a/lms/djangoapps/grades/scores.py b/lms/djangoapps/grades/scores.py index 82e255c8d935..c0c966ac7da9 100644 --- a/lms/djangoapps/grades/scores.py +++ b/lms/djangoapps/grades/scores.py @@ -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 @@ -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